compass tilt compensation issues

Hey everyone,
I ve got a hmc5883L magnetometer with a mmA73X1 accelerometer and im trying to make a tilt compensated compass. For some reason though, Im not able to correctly implement the tilt compensation formula on the data I am getting from the two sensors. Attached is an excel file with readings from the magnetomer and accelerometer [ pitch, roll,yaw compensated, yaw uncompensated, mag x, magy, and magz ] I think the readings are right, because they look pretty reasonable in the graph.Somethings wrong though, cos yaw uncompensated is more accurate than yaw compensated! can someone just see if they can help me out here with some insight? (some sign problem, some conceptual issue?)Also attached the arduino codeā€¦

thanks
Harsha

tilt1.ino (6.91 KB)

file for forum.ods (42.7 KB)

cos yaw uncompensated is more accurate than yaw compensated

What about sin yaw uncompensated?

man, I meant "because yaw uncompensated is more accurate than yaw compensated " :slight_smile:

Thanks for the reply though