View previous topic :: View next topic |
Author |
Message |
mpo
Joined: 18 Dec 2009 Posts: 39
|
|
Back to top |
|
|
Arera
Joined: 23 Sep 2007 Posts: 386 Location: Wuppertal, Germany
|
Posted: Mon Nov 04, 2013 2:10 pm Post subject: |
|
|
To tell weather your problem is HW or SW, I would change R23 from 0R to 1K. Then pull down the regarding input, while power is still up and stable.
If the code works fine, you need more capacitiy on your backup-C!
Marc |
|
Back to top |
|
|
mpo
Joined: 18 Dec 2009 Posts: 39
|
Posted: Mon Nov 04, 2013 9:15 pm Post subject: |
|
|
I tried this.
When INT1 is just pulled via resistor and I ground it manually, interrupt occurs and eeprom is written.
But I see no reason why backup capacitor is not enough. I tried to add 1000uF more and still nothing. According to datasheet, required current in active state is about 50% less than in atmega8.
Weird... |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Mon Nov 04, 2013 9:35 pm Post subject: |
|
|
mpo wrote: | According to datasheet, required current in active state is about 50% less than in atmega8. |
If current is drawn from an active pin, the current for the cpu is negligible.
Quote: | I tried to add 1000uF more and still nothing. |
I'd try an 1k parallel to C2 to have a sharp drop in input voltage. |
|
Back to top |
|
|
Evert :-)
Joined: 18 Feb 2005 Posts: 2156
|
|
Back to top |
|
|
mpo
Joined: 18 Dec 2009 Posts: 39
|
Posted: Mon Nov 04, 2013 10:22 pm Post subject: |
|
|
MWS wrote: |
I'd try an 1k parallel to C2 to have a sharp drop in input voltage. |
Good idea - I'll try this tomorrow.
I have lot of power consumers connected before schottky diode, so drop should be immediate. But 1k will not harm.
Evert,
I did not measured power consumption. I believe in datasheets
There is enough energy in 220uF cap to write at least eight bytes to eeprom on interrupt (using atmega8 without any power saving methods). Maybe I can write much more - never tried.
So I assume it should be sufficient also in case of atmega168. But maybe something is differently designed inside chip.
Work in progress... |
|
Back to top |
|
|
Neill
Joined: 08 Dec 2008 Posts: 50
|
Posted: Tue Nov 05, 2013 10:11 am Post subject: |
|
|
Is it too late to make some changes in hardware? I would use a comparator to generate the interrupt signal, with a crude reference like a Zener on one pin and a Voltage divider from Vcc on the other.
I think some AVRs even have an analogue comparator built in, perhaps it can generate an interrupt, something to look into? |
|
Back to top |
|
|
Arera
Joined: 23 Sep 2007 Posts: 386 Location: Wuppertal, Germany
|
Posted: Tue Nov 05, 2013 12:00 pm Post subject: |
|
|
Signal forming is a good point, but I think doing that on the SW side using any kind of debounce should do.
What I woory about is the potential on the input.
If Vcc drops, there is no more Vcc. But does that mean there is a proper GND?
A 1k from Vcc to GND could help, but not for signal forming but to get a proper potential at the input. |
|
Back to top |
|
|
six1
Joined: 27 Feb 2009 Posts: 553
|
Posted: Tue Nov 05, 2013 12:04 pm Post subject: |
|
|
the +5V line is connected to other parts, so there might be a big capacitance inside which holds the 5V up!
Take another Diode to INT Input with little C and 10K R for defined drop down! _________________ For technical reasons, the signature is on the back of this message. |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Tue Nov 05, 2013 12:55 pm Post subject: |
|
|
six1 wrote: | Take another Diode to INT Input with little C and 10K R for defined drop down! |
Won't make any difference.
Quote: | the +5V line is connected to other parts, so there might be a big capacitance inside which holds the 5V up! |
If the capacitance can hold up the 5V line, it will do the same via diode, cap and resistor, minus the voltage drop of the diode.
A simple bleeding resistor as suggested will solve that. |
|
Back to top |
|
|
laborratte
Joined: 27 Jul 2005 Posts: 299 Location: Berlin
|
Posted: Tue Nov 05, 2013 1:53 pm Post subject: |
|
|
I agree to Neill. Monitoring a power line is a task for analog circuts.
If the falling time in power line is too slow (i.e. a big cap in power supply) the avr power behind the diode will also be fallen when the int occur. INT as digital input has a LOW voltage of about 0,2 to 0,3 Vcc, so it is depended on your voltage behind the diode. In worst case there will be not enough voltage for writing EEPROM when the interrupt occurs. AVRs are very sensitve on voltage for EEPROM write access, that is the reason why it is recommend to use BOD when working with EEPROM.
It seems that the mega8 could handle the EEPROM write with the cap's energy but the mega168 (PA?) fails because of slightly different electrical characterisics on LOW voltage and needed voltage for EEPROM write.
If you can change your circut use the analog comparator of the AVR. You can make a voltage divider in your power line (i.e: 3:1) which gives you a nominal 1,25V. Feed this in negative input of analog comparator and put the positive to the internal bandgap reference (1,1V). The comparator then can fire an interrupt when the voltage drops below 1,1V, which equals a 4,4V on power line. This gives you enough headroom for writing the EEPROM. Or choose a voltage divider which fits your needs, but make shure that you have at least 2,4V for 5ms after interrupt occurs. This is in fact an BOD which points to an isr rather than a reset.
BTW your isr should also handle the case where main power returns before the AVR stops working, i.e. a short power drop. Could also be done with watchdog... |
|
Back to top |
|
|
mpo
Joined: 18 Dec 2009 Posts: 39
|
Posted: Tue Nov 05, 2013 3:18 pm Post subject: |
|
|
Well, the PCB is fixed, so there is no room for additional comparator.
On the output of 7805 I have only one 100nF cap. Total current is about 100-200mA, so voltage should drop immediately.
Some progress...
I tried 1k resistor in parallel to C2 - no changes.
I removed ceramic C2 - no changes
I replaced ceramic C2 with tantalum cap 1uF - random trash in eeprom
I added again 1k to 1uF - much better, but sometimes random eeprom address is written with random value
Unfortunatelly I have no possibility to check how fast voltage drops before diode and how long it's high enough on backup capacitor.
laboratte,
As I wrote, I don't have big cap on power supply line.
This used to be worked with smaller chip and I'm very surprised with this situation.
According to datasheet mega168 (not the picopower version in my case) works properly from 1,8V so it should be even more time before energy from cap will exhaust.
What do you mean by "fails because of slightly different electrical characterisics on LOW voltage and needed voltage for EEPROM write."?
Regarding 'power return situation' - I have watchdog running. When avr stop after eeprom write, it will be restarted after timeout.
I wonder if it will make difference if I disable pullup on D3 (INT1) pin? |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Tue Nov 05, 2013 4:50 pm Post subject: |
|
|
You can try (if your circuit allows for it) to disable the output pins in the voltage-low ISR, maybe one of the pins sucks out the µC's power, so disabling them can buy you some time. The same, disabling the pullups can help therefore.
As you run in a stop-loop you could also use NOSAVE, which spares a few cycles. However, shouldn't make a difference, compared to the cycles used up by eeprom-erase/write.
But try it out...
Code: | On Int1 Power_fail NOSAVE
...
Power_fail:
DDRD = 0
SFIOR.PUD = 1
E_pulses_current = Pulses_current
Stop
Return |
Are you aware, as power down may interrupt in-midst of writing Pulses_current, that the value therein may be invalid?
Btw., I see in your circuit the cap for the µC's VCC/GND is 10n, that's too less. Should be 100n ceramic for sourcing the current peaks while writing the eeprom. |
|
Back to top |
|
|
mpo
Joined: 18 Dec 2009 Posts: 39
|
|
Back to top |
|
|
Arera
Joined: 23 Sep 2007 Posts: 386 Location: Wuppertal, Germany
|
Posted: Wed Nov 06, 2013 11:18 am Post subject: |
|
|
Here we go again:
DON'T WASTE TIME IN ISR!
just set flag (bit) in the ISR.
Check for that flag in the main routine and do your stuff if it's set. Don't forget to reset the flag after your are done with the things to do aftre that int occured.
Marc |
|
Back to top |
|
|
|