petrim
Newbie level 1
Hello,
I need advice from anybody who has experiences with PIC24F microcontrollers and used EEPROM memory and High/Low Voltage Detector (HLVD).
When low voltage is detected by HLVD the interrupt is generated and handler stores single word value to EEPROM.
But one of a few experiments, happens that writing into EEPROM is erroneous. The value read from EEPROM after reboot is malformed.
On-board power supply has sufficient capacity to keeps voltage for MCU for approximately 10ms then drops under operating minimum 1.8V.
It happens only in combination with HLVD, which confirm experiments with read and write operations by buttons, which were successful.
Thank you for any advice.
Martin Petřík
There is example of my code:
I need advice from anybody who has experiences with PIC24F microcontrollers and used EEPROM memory and High/Low Voltage Detector (HLVD).
When low voltage is detected by HLVD the interrupt is generated and handler stores single word value to EEPROM.
But one of a few experiments, happens that writing into EEPROM is erroneous. The value read from EEPROM after reboot is malformed.
On-board power supply has sufficient capacity to keeps voltage for MCU for approximately 10ms then drops under operating minimum 1.8V.
It happens only in combination with HLVD, which confirm experiments with read and write operations by buttons, which were successful.
Thank you for any advice.
Martin Petřík
There is example of my code:
Code:
// Save value to eeprom
unsigned int addr = 0;
unsigned int test_data = 0xAAAA;
void _ISR _HLVDInterrupt(void)
{
unsigned int offset;
// Clear interrupt flag
IFS4bits.HLVDIF = FALSE;
// Set up NVMCON to write one word of data EEPROM
NVMCON = 0x4004;
// Set up a pointer to the EEPROM location to be written
TBLPAG = 0x7f;
offset = 0xfe00 | ((addr & 0x7f) << 1);
// Write Data Value To Holding Latch
__builtin_tblwtl(offset, test_data);
// Disable Interrupts For 5 Instructions
asm volatile ("disi #5");
// Issue Unlock Sequence & Start Write Cycle
__builtin_write_NVM();
// Wait until write operation is done
while (NVMCONbits.WR == 1);
}