Hello everyone, I have a bit of headache trying to figure out the best approach for an issue I recently encountered. Turn out I even have hard time to explain, better place a few forewords.
I'm building an antenna rotator, grade precision with feeback of actual aiming. The construction obviously have cables coming down, thus I cannot rotate indefinitely. Say, I can rotate one full turn, and overlap 90° after each turn, to allow some more freedom.
Plan is to keep track of the 'overlapping' status and write to EEPROM, so that if power goes down, this crucial information can retrieved and the 'do no go any further, please come back' command to be issued.
Now, I successfully have all this data, write to registry, direction of rotation etc etc.
Problem: Have a data stream coming in from magnetometer. This is not steady value by any means, and even though range from -say- +-1degree which is perfectly fine for my application, during the transition between the 'zero' point it returns an abundance of positive and negative values, forcing the program to rewrite EEPROM, at each passage, a dozen times. That's no good.
I have 'current position', 'heading position', 'turning direction', but I can't make up my mind the best way to approach this issue and mark the transit only one time each direction. Also consider, for safety assurance, the 'write on EEPROM' must to done precisely at the time the rotator transit over the 'zero', not at the end of operation, just in case power goes down in the process.
Perhaps I'm lost in a mental loop, but please press the break button and show me the way out
Thanks to everyone for any hint.