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 support@ccsinfo.com

saving data and shutdown when INT_LOWVOLT

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



Joined: 30 Jul 2007
Posts: 112
Location: Moscow, Russia

View user's profile Send private message

saving data and shutdown when INT_LOWVOLT
PostPosted: Fri Feb 05, 2016 1:29 am     Reply with quote

Is this correct way to immediately save data and end all job when power down. Schematic powered from 12V by 7805.

Code:

#INT_LOWVOLT
void  LOWVOLT_isr(void)
{ disable_interrupts(global);
   write_int32_eeprom(T_adr,T);
   write_int32_eeprom(sec_adr,sec);
   
   sleep();
}

Ttelmah



Joined: 11 Mar 2010
Posts: 19360

View user's profile Send private message

PostPosted: Fri Feb 05, 2016 2:05 am     Reply with quote

Generally, 'possibly'....

Why are you disabling interrupts(GLOBAL) in the ISR?. The hardware does this. If you have interrupt priorities in use, then the lowvolt should be a high priority ISR, and if so it cannot be interrupted.

Then the key first thing is the design of your PSU, needs to be such that it will ensure the supply voltage remains above the minimum needed for eeprom writes, for long enough to write 8 bytes, after the point where lowvolt triggers. This, even with the smallest capacitor value that the tolerances allow (remember nominal values for things like electrolytic capacitors have huge margins. A '100uF' capacitor may well in some cases only be 75uF.....).

Then the code after writing, should monitor the lowvolt signal, and if it goes high, and stays high, exit the interrupt. Alternatively, use the watchdog, reset this, and if it triggers, perform a restart. There needs to be some mechanism by which the code will recover, if the lowvolt triggers, but then the supply recovers....
40inD



Joined: 30 Jul 2007
Posts: 112
Location: Moscow, Russia

View user's profile Send private message

PostPosted: Fri Feb 05, 2016 2:29 am     Reply with quote

In my case, when power supply goes down it will not recover by itself. So i need just save data until next boot.

Do You know how the 7805 regulator behaves when the voltage drops below the minimum needed for regulation? I can't find datasheet whith Vin/Vout Chart
temtronic



Joined: 01 Jul 2010
Posts: 9170
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Feb 05, 2016 2:39 am     Reply with quote

7805 needs about 2.5-3 volt differential, so about 8 volts on the Vin. Be sure to add a 1N4001,cath to Vin, anode to Vout for protection. Typically you need 1000 mfd per amp on the input and 500mfd should be fine on the output.
The 'trick' is the output cap has to have enough energy(electrons) to allow the PIC to write to the EEPROM. You need to read the datasheet and see how long the writing will take. DOUBLE that time to be the MINIMUM needed for the cap to supply power.

Jay
40inD



Joined: 30 Jul 2007
Posts: 112
Location: Moscow, Russia

View user's profile Send private message

PostPosted: Fri Feb 05, 2016 2:49 am     Reply with quote

Temtronic, i mean, what happens on the output of 7805 when input voltage drops below 7 volt to 0? Output drops immediately to 0 or drops gradually, propotionally?
Ttelmah



Joined: 11 Mar 2010
Posts: 19360

View user's profile Send private message

PostPosted: Fri Feb 05, 2016 2:59 am     Reply with quote

Slowly.

However a big 'beware' here.

If you have a reasonable amount of capacitance on the output of the 7805, so that the supply will be maintained for the EEPROM write when the input drops, then the 7805, will become reverse biased, if the input goes down below this. This can destroy the 7805. Texas specifically show a diode added across the 7805 to stop this destroying the IC. Problem then is that if there is something else trying to draw power on the input (12v) side, the capacitors on the output side will have to also power them....
40inD



Joined: 30 Jul 2007
Posts: 112
Location: Moscow, Russia

View user's profile Send private message

PostPosted: Fri Feb 05, 2016 3:02 am     Reply with quote

i have found this chart:
http://xreferat.com/image/38/1305959650_23.png
So, i need a diode and input capacitor bigger than output capacitor, yes?
temtronic



Joined: 01 Jul 2010
Posts: 9170
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Feb 05, 2016 7:19 am     Reply with quote

yes..
input cap = 1000mfd
output cap = 500 mfd
1N4001, cath to Vin, anode to vout

should be a good starting point

once you have PIC circuit 'up and running,if you have a scope watch Vout ( +5 volts) and see how long +5 takes to drop. If it's too fast, increase input cap, say to 5000 mfd.

My typical +5 supplies have input cap of 10,000 Mfd .

Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19360

View user's profile Send private message

PostPosted: Fri Feb 05, 2016 10:22 am     Reply with quote

As one other comment, consider the alternative of not using the low volt interrupt, but instead using the input voltage to the regulator, fed via a divider, into a comparator, and using this to trigger the save. So (for instance) have the supply falling below perhaps 10v, triggering the save.
Big advantage, a lot more time available to do the save, with smaller capacitors necessary. May mean a few extra saves, if this does give saves when the power does not actually go off, but you are then always writing with 5v available, and don't have to hurry quite so much.
I have quite a few systems using an external power monitor chip that interrupts to save when the incoming supply droops, rather than the 5v. On these the chip also generates a reset, and will automatically recover if it does not actually go off.These have always been very reliable indeed.
temtronic



Joined: 01 Jul 2010
Posts: 9170
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Feb 05, 2016 12:16 pm     Reply with quote

Another alternative is to monitor the low voltage AC before the full wave bridge-filter capacitor-regulator. A simple diode and 2 resistors is all that's needed for the signal to be fed into an interrupt pin. It will trigger at line frequency( typically 50 or 60 Hz). Depending on your application this this may work and should give a 'flag' faster than the other 'low voltage' detection methods. If you have a MAX232 chip for RS232 serial, an unused portion can become a great 'signal conditioning' section. Even a 78L05 can do the job !!

Jay
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