CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Backup data using INT_HLVD

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
vtrx



Joined: 11 Oct 2017
Posts: 142

View user's profile Send private message

Backup data using INT_HLVD
PostPosted: Tue Aug 02, 2022 9:04 am     Reply with quote

I'm experimenting with a backup system to write a value to the PIC's internal Eeprom to be able to use it when powering on the system.
Initially it is working fine, but there are some details that need to be clarified.
I use the PIC 18F45K50.
The Hardware uses a 330ยต x 10v capacitor connected to the + and -, this value is sufficient according to the tests done using an external 5v power supply or USB PC power.


Code:
#include <18F45K50.h>

#FUSES PLLEN,NOXINST,INTRC_IO,NOFCMEN,NOIESO //1#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES PUT,NOBROWNOUT,NOWDT //2
#FUSES NOMCLR,NOLVP  //3
#FUSES NOSTVREN,NODEBUG //4
#FUSES PROTECT,CPB,CPD,NOPBADEN//5
#FUSES NOWRT,NOWRTC,NOWRTB,NOWRTD, 
#FUSES NOEBTR,NOEBTRB
...
#use delay(int, clock=48MHz, USB_FULL, act=USB)
#bit LVDIF_BIT = getenv("SFR:PIR2").2
#bit IRVST_BIT = getenv("SFR:HLVDCON").5 
...
#INT_HLVD
void lvd_isr(void)
  {
   disable_interrupts(INT_HLVD);
   write_eeprom(110,Creditos);
  }
...
void main(void)
 {
...
   setup_low_volt_detect(LVD_47 | LVD_TRIGGER_BELOW);
   while(IRVST_BIT==0);
   LVDIF_BIT = 0;
...
   usb_init();
   
   enable_interrupts(INT_HLVD); 
   enable_interrupts(GLOBAL);
...

 }


I need to know about some details:

1-#bit LVDIF_BIT = getenv("SFR:PIR2").2
#bit IRVST_BIT = getenv("SFR:HLVDCON").5 , are they correct?

2-"while(IRVST_BIT==0);", is this part waiting for the voltage to stabilize? Is it correct?

A problem that occurs here is that the circuit is only started on windows (USB) if the capacitor is fully discharged, otherwise windows does not recognize the circuit, I have to discharge the capcitor.
If I don't use the capacitor, the backup writes a random number, usually 255, but Windows instantly recognizes the circuit.
Can this be improved?
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Tue Aug 02, 2022 10:34 am     Reply with quote

I solved a similar issue in a project a long time ago, based in this great and self explanatory example posted
by PCM Programmer as starting point.

https://www.ccsinfo.com/forum/viewtopic.php?p=51682
_________________
Humber
Ttelmah



Joined: 11 Mar 2010
Posts: 19529

View user's profile Send private message

PostPosted: Tue Aug 02, 2022 10:54 am     Reply with quote

Also as a comment, 330uF sound much too large. You only need to ensure
that the supply is above the EEPROM minimum write voltage for long
enough to write the single byte you show. With 4.7v trigger, this is
VddMIN on this chip 2.7v at 48MHz), so assuming 20mA (the chip draws
9,5mAQ, and the data sheet does not show how much current the EEPROM
draws, but the program memory draws 10mA for a write), so:

t=(c * [v0-V1])/I

= (330uF * [4.7-2.7])/0.02

gives 33mSec. You only need 4mSec. So perhaps 50uF with a 25% margin.
Now being this large means that the supply is unlikely to fall low enough
to trigger the reset inside the PIC for an absolute age.

On the bits, access these by name. Far less likely to be wrong. So:

Code:

#bit LVDIF_BIT = getenv("BIT:HLVDIF")
#bit IRVST_BIT = getenv("BIT:IRVST")


Look at having a proper reset circuit on the MCLR pin. Much more likely
to give reliable reset operation.

Also turn on brownout reset. Set this to reset at perhaps 2.5v.

Problem is that when the chip drops below about 1.5v, everything stops.
Almost no power drawn. Now the reset circuit does not work till the supply
drops to 0.7v. So you need to either be using the brownout reset, or
some other way to make the chip reset, or it may not correctly reset if
the power comes back on and has not dropped right down....
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group