We consider orthoferrite and orthochromite perovskites with the formula RMO3, where R is a lanthanide and M is Fe or Cr. We identify an atomistic interaction that couples the magnetic moments of the R and M cations with the oxygen octahedral rotations characterizing these crystals. We show that this interaction results in an effective magnetic field acting on the R atoms, which in turn explains several intriguing features of these compounds, such as the existence (or absence) of a net magnetization associated to the R sublattice, its crystallographic direction, etc. Further, considered together with the couplings described by Bellaiche et al. [J. Phys.: Condens. Matt. 24, 312201 (2012)], this interaction explains why some RMO3 compounds display a compensation temperature at which the magnetization cancels and changes sign, while others do not.