Calculation of the binding energy in negative ions of calcium and barium