Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] PIC24F: Write to EEPROM from HLVD interrupt routine

Status
Not open for further replies.

petrim

Newbie level 1
Joined
Nov 22, 2016
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
12
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:
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);
}
 

Which EEPROM type? I think, it's a bad idea to start EEPROM writing when LVD interrupt is triggered. The best solution would be to monitor the voltage regulator input voltage, if your design doesn't allow this, use a VDD voltage monitor with threshold at e.g. 3V.
 

You don't say which PIC24F device you are using so what follows is generic and based on the FRM section #36 'High Level Integration with Programmable High/Low-Voltage Detection (HLVD)' (https://ww1.microchip.com/downloads/en/DeviceDoc/39725a.pdf). I've also randomly selected the PIC24F08KL401 device as one that has an EEPROM and the HLVD.
As FvM has said, writing to the internal EEPROM (or FLASH) memory (your use of the table write builtin macros shows that is what you are doing) is certainly not recommended with a low Vdd. (Also watch out for limitations on the number of erase/write cycles the FLASH can take - if you try to do this frequently, you can easily cause the cell to become unreliable, all other things being equal.)
Section 36.4.3.6 does make the suggestion that this peripheral can be used for a 'low battery voltage' detector but this still assumes that you have seconds or even minutes before the supply falls below the minimum operating voltage.
If you are trying to detect a loss of Vdd, then this can occur in milliseconds and the 'self timed write cycle time' ('Tiwd', Table 26-13 of the data sheet of my selected MCU) is typically 4mSec at Vdd of 3.3V - it will probably take longer with a lower Vdd and the additional current (Iddpd, same table) of 7mA while writing will hasten any voltage drop from a failing PSU.
Susan
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top