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.

writing data into internal EEPROM in pic16f1789 when sudden powerfailure

Status
Not open for further replies.

narasimha.gandham

Newbie level 1
Joined
Nov 18, 2015
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
7
can any one explain how to write data into EEPROM in pic16f1789 when the sudden power failure.in my project im using the one counter for warranty.if some cases power failure occurs then the counter value is write into EEPROM in pic16f1789.
 
Last edited by a moderator:

In that case you need to find out after power failure how much time your cpu can work.
EEPROM writing process is little slow i am considering you r using internal eeprom. Im not used that cpu so not aware of its peripherals.
I did it same in pic18f87k22, in that project i have enough time to write important data to eeprom (or else use can extend time using capacitors).
You need to detect power failure first in my case im using HLVD interrupt base, you can configure the voltage level to detect power failure.

This project is long time ago so configuration not sure u need to see datasheet of 87k22 or u r cpu if support HLVD(search for high low voltage detect)


Code:
// INTERRUPT VECTORS.
#pragma interrupt chk_isr         // used for high priority interrupt only.

void chk_isr(void)
{
     if(PIR2bits.HLVDIF==1)
     {
	     PIR2bits.HLVDIF=0;
	     power_down();
	     PIR2bits.HLVDIF=0;
	 } 
     
}

void power_down(void)
{
   if(power_on==1)
  {
  //turn off all the outputs
  //turn off power consuming peripherals
  //write to eeprom
  while(1);
   }
//till power is completely off do nothing.
}


void main(void)
{

	HLVDCON=0x3A;
	PIE2=0x04;

}
also when power on u get interrupt of HLVD so you need to ignore it
i used one flag if this flag is zero dont enter to power_down routine or u will stuck in routine at power on


Code:
unsigned char power_on=0;

void main(void)
{
....
....
.....

....
//all u r config
just before while loop
power_on=1;
    while(1)
   {

    }
}
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top