View previous topic :: View next topic |
Author |
Message |
jaikumar
Joined: 15 Dec 2006 Posts: 109
|
Re: Power failure detection problem. |
Posted: Sat Aug 10, 2013 6:20 am |
|
|
Hi All,
controller: PIC16F887
compiler ver: 4.140.
I am trying to save variables when power fails.
I am feeding the 12V supply reduced with 5V Zener and fed to PIN A0 (pin 2) of comparator.
I am using comparator in Interrupt mode. The problem is that it works most of the time when i turn on and off the power supply, but some times it just misses and does not even get interrupted(it does not even go in to the interrupt routine). What can cause this.
Also i do read CMCON everytime at the beginning of program start to end mismatch.
Any help would be great.
Thanks and regards,
Jai. |
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Sat Aug 10, 2013 8:03 am |
|
|
I hope you are current limiting your zener with an appropriate resistor.
i would actually just use a high R voltage divider to get 4.5V and a 5.1 Zener as a fall back.
OR
Use and Opto Isolator on the raw voltage input... Better.
Either way you could also use the Interrupt on change of Port B... and not have to mess with the comparator voltage settings...
another thing is that the incoming voltage has to drop faster than the voltage after the regulator... so if you have alot of capacitance before the regulator (at 12V) and little capacitance after the regulator (5V) your power failure will not be detected..
but you also have to be careful not to reverse bias your regulator.. (im assuming 7805)...
hardware is very important for power failure detection.
G. _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
jaikumar
Joined: 15 Dec 2006 Posts: 109
|
|
Posted: Sat Aug 10, 2013 10:01 am |
|
|
thanks for your reply.
Yes i have current limited.
I have tried various combinations. I did try with int RB0 same thing happens. Doesn't always get interrupted. I also connected the zener output using lm339 and lm339 comparator output
to RB0. Still had missing interrupt. I have seen with the scope i get about 200msec diff between power off indication and 5v reaching 4.50 volt controller reset.
It gets interrupted, but sometimes it simply misses.
Regards,
Jai |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19549
|
|
Posted: Sat Aug 10, 2013 11:25 am |
|
|
Your design doesn't sound very hopeful...
You need to start by knowing more about your '12v supply'. Is this regulated, or just a smoothed rail from a rectifier?.
What capacitance has it got attached?.
What is the load current?.
How is the rail converted to 5v?.
Now, lets give some 'examples' from an imaginary starting point.
12v, regulated.
470uF capacitance.
7805LDO regulator. (6.5vmin)
42mA load + 5mA used by the regulator.
Now, to actually 'work' with this, you want a voltage divider to bring the measured voltage under 5v. So, say 10KR to ground. Then lets assume we want to switch when the '12v', goes under 10.5v, and perhaps use 2v as the switch point, so current through the 10K = 0.2mA. So the upper resistor on the divider would then need to be:
(10.5-2)/0.2E-3 = 42500R.
Add a zener across the 10KR, as 'safety protection'.
Then program your comparator for 2v.
With the example current (47mA), the 470uF will discharge 100v/second (10mSec/volt) (remember 1v/A/Farad ). The example has 1/20th amp, and 1/2000th Farad. So it'll take 10.5-6.5*10mSec to discharge from the 'switch' point, to the 'supply starts to fail' point. 40mSec. If this is long enough (remember you need to allow for things like capacitors having very large errors in their sizes - typically 50%....), then the other thing you need to add is 'recovery'. After saving everything, wait for a time, and then re-test the input, and if it has gone back to 'good', then resume normal operation. If it is not long enough, then the capacitance on the incoming rail needs to rise, or you need to work out ways of reducing the current drawn.
It sounds at present, as if you are testing much too 'late' in the supply dropping.
Best Wishes |
|
|
jaikumar
Joined: 15 Dec 2006 Posts: 109
|
|
Posted: Sat Aug 10, 2013 12:17 pm |
|
|
Thanks Ttelmah,
I need to know if I am on a timer interrupt and the ext int or comparator int happens when I am inside timer1 int, will i miss the ext int / comp int?
Regards,
Jai. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19549
|
|
Posted: Sat Aug 10, 2013 12:22 pm |
|
|
This is down to the calculation of 'time needed'.
The old rule applies - keep normal handlers short.
Now writing to the EEPROM takes an age (typically a couple of mSec/byte). If you need to write 8 bytes, the time needed to get out of another interrupt handler should be tiny (few uSec).
If (for instance), your total time in the timer handler is 10uSec, it makes no significant difference to the total time the rail needs to be maintained.
Best Wishes |
|
|
jaikumar
Joined: 15 Dec 2006 Posts: 109
|
|
Posted: Sat Aug 10, 2013 12:32 pm |
|
|
My question is i also have timer1 int and while in that interrupt will the global interrupt be disabled, will i miss other interrupts?
Thanks,
Jai. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19549
|
|
Posted: Sat Aug 10, 2013 2:32 pm |
|
|
Global interrupts will be disabled, but this doesn't mean other interrupts will be missed. They will be handled as soon as you exit the first interrupt. Hence the 'time'. Being in another interrupt will just delay handling for however long the handler takes. This is always the case.
Best Wishes |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9245 Location: Greensville,Ontario
|
|
Posted: Sat Aug 10, 2013 5:28 pm |
|
|
Another way to detect 'power loss' is to monitor the AC before the main filter cap. Just add a 1N4007 and a small cap,resistor and zener.In effect a small '5 volt power supply'.In can be faster to see the AC fail than the DC after the filter cap,thus giving you more time to save data..
hth
jay |
|
|
jaikumar
Joined: 15 Dec 2006 Posts: 109
|
|
Posted: Sat Aug 10, 2013 7:58 pm |
|
|
My design is exactly like temtronic. I will follow some advice here and try again.
The only thing that works is polling. my code does not have any blocking code.
So i see with the scope that in the while loop i get to the polling code every 800usec.
I get about 100 to 200 msec after power detection. So it always works.
Thanks all for your input.
Regards,
Jai. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19549
|
|
Posted: Sun Aug 11, 2013 12:45 am |
|
|
OK. Monitoring before the bridge is 'good', but you then need something to decide the difference between the zero's at every mains half cycle, and power loss. Ideally something like a re-triggerable monostable multivibrator with it's output interval at 11mSec. Trigger this from the signal from the bridge. Normally it'll remain permanently triggered since there is a half cycle ever 100th or 120th second (50/60Hz).
It involves less circuitry to monitor the DC rail coming of of the rectifier, since then the supply capacitance integrates the incoming signal.
Temtronic is using a small capacitor to give this filtering, but the problem here is that you need to ensure this rail will fall faster than the main supply rail. If the loads are constant, this is relatively easy to do, but if the supply loads can vary there can be problems....
In either case, there are dozens of little supply monitor IC's from people like Linear, and Texas, that provide hysteresis, and the required delays.
Best Wishes |
|
|
jaikumar
Joined: 15 Dec 2006 Posts: 109
|
|
Posted: Mon Aug 12, 2013 5:49 am |
|
|
Hi,
I have just posted the power failure detector circuit here, it does not get the comparator interrupt firing sometimes.
Is this Ok. or how can i make it better.
Regards,
Jai.
[/img] |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9245 Location: Greensville,Ontario
|
|
Posted: Mon Aug 12, 2013 5:59 am |
|
|
my hrdware comments...
1) put the 2200mfd cap on the input of the 7805
2) put the 470mfd cap on the output of the 7805
3) add a 1N4007 acorr the output to input pins of the 7805
cathode on the input. protect the regultor.
4) r1( 10K) might be too high, though a 'scope should tell.see what the response is to power on,off,on,off....to see how clean and duration of signal.
hth
jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19549
|
|
Posted: Mon Aug 12, 2013 7:51 am |
|
|
Think about the time constant....
What is discharging the 10uF?. 11.5KR at a nominal 12vish. So approx 1mA. It'll take 0.1mSec to discharge a volt. By the time the comparator triggers, the main supply may well already be below the point that matters....
Your detector circuit _must_ discharge significantly faster than the supply.
_Small_ capacitor (the 0.1uF is enough).
Then second the comment about the capacitors on the regulator. But go even further. I'd put the 10uF paralleled with a 0.1uF on the output of the 7805. Large capacitors on the output side can blow the regulator (not normally below 7v, but with the sheer size of capacitor involved here it will be getting close - you can add a reverse biased diode across the regulator to prevent this). Big capacitors on the secondary of the regulator, can encourage slow responses. Also they don't block HF.
The voltage the regulator actually 'receives' will be 0.6v(ish) below the voltage you are trying to detect, because of the drop in the 4007.
Best Wishes |
|
|
jaikumar
Joined: 15 Dec 2006 Posts: 109
|
|
Posted: Mon Aug 12, 2013 8:57 am |
|
|
Hi,
Altering circuit according to temtronic, i was able to get better delay.
Now the 10k ohms and 1.5k, the 2v that i get has some ripple i have to figure out
Correct values to get a clean 2V.
I tried to make 10k ohms to 4.7k and the waveform did not get too much better.
Next i will try to make the changes as Ttelmah advised.
Also i would like to know if comparator senses voltage or edge, i want to know how fast or slow the level has to fall from 5V to 0V for the comparator input to recogonize.
Thanks and regards,
Jai. |
|
|
|