I am having difficulty with Codevision AVR in storing a value to EEPROM by using an Analog Comparator 0 interrupt-service routine.
The comparator interrupt-service routine is triggered when the power to the board is shut off and the voltage to the comparator (-) input falls through the value of the on-board band-gap reference (about 1.1V).
A voltage divider feeding the analog comparator (-) input is arranged to make that happen before the AVR supply voltage drops below 5.0V. So, the AVR is still able to "hear" the comparator when it toggles and store a value to EEPROM.
I have attached a simple program (EEPROM Dilemma) to illustrate my problem.
Either line 49 or line 172 provides the call to the function "location_mode ( )", where a value is assigned to a variable 'dim_cmd'.
If line 49 is active (and 172 is commented out), location_mode ( ) is called only ONCE, from main ( ). I have verified that the correct value of 127 is stored in EEPROM when I shut the power off and Analog Comparator 0 does its job.
If line 172 is active (and line 49 is commented out), then location_mode ( ) is called REPETITIVELY from inside the TIMER0 interrupt service routine, repeatedly assigning the value 127 to dim_cmd. However, when the power is removed and the analog comparator trips, the default value of 255 is stored in EEPROM, not the value (127) which had been repeatedly assigned to dim_cmd inside "location_mode ( )".
In my real program, I am assigning a value to dim_cmd from within "location_mode ( )", and -- as in the case where line 172 is active in the sample program-- it does not work.
Why is this so?