View previous topic :: View next topic |
Author |
Message |
sentinel
Joined: 02 Feb 2009 Posts: 141 Location: Tasmania
|
Posted: Wed Jan 19, 2022 6:03 am Post subject: Chip hanging in Powersave(?) even with watchdog |
|
|
I have been having instances of the (cut down for clarity) code below hanging when coming out of Powersave after a power cut.
It was only happening on perhaps one in ten boards, but since the micro-controller was backed up by a supercap, there was no way to manually reset the inaccessible PCB.
I later added the watchdog option to try to cure the fault, but it doesn't seem to have improved matters much. The occassional board will still freeze with no signs of life until I manually reset the chip.
Code: | $regfile = "m168def.dat"
$crystal = 8000000
Baud = 9600
$baud = 9600
$hwstack = 60
$swstack = 60
$framesize = 60
Dim Date_saved as Eram string * 8
Dim Time_saved as Eram string * 8
Dim Timerflag As Byte
Dim Uart As Bit
Dim Messageflag As Byte
Config Serialin = Buffered , Size = 40 , Bytematch = 10
Config Serialout = Buffered , Size = 120
Config Clock = Soft , Gosub = Sectic
Config Date = Dmy , Separator = /
Ddrb = &B110111 'Configure inputs and outputs
Ddrc = &B0011110 'Configure inputs and outputs
Ddrd = &B11111100 'Configure inputs and outputs
Const On = 1
Const Off = 0
Solenoid Alias PortB.2
Blue_led Alias Portc.3
Power_on Alias Pinc.5
Config Adc = Single , Prescaler = Auto , Reference = INTERNAL_1.1
Config Watchdog = 8192 'Set the watchdog to time out at 8 seconds
On Wdt Wdt_isr
Enable Wdt
Start Watchdog
Enable Interrupts
Date$ = Date_saved 'Recover the saved date & time
Time$ = Time_saved
'===========================================================================
'Main program
'===========================================================================
Do
If Power_on = 1 Then 'Is mains power on?
If Uart = Off Then
Ucsr0b.txen0 = 1
Ucsr0b.rxen0 = 1
Uart = On 'Set flag indicating startup of these functions when power is restored after power cut
Start Adc
Start Watchdog
End If
'=========================================
' Main code
' ========================================
If Timerflag = 1 Then 'Executed once per second
Timerflag = 0
Blue_led = On 'Flash heartbeat briefly once per second
Waitus 250
Blue_led = Off
Print "Tick" 'Monitor via UART
End if
'=========================================
' End of main code
' ========================================
Else 'If power has gone off, then Powersave
If Uart = On Then
Solenoid = Off
Blue_led = Off
Ucsr0b.txen0 = 0 'Disable USART0 transmit
Ucsr0b.rxen0 = 0 'Disable USART0 receive
Uart = Off 'Reset flag indicating shutdown of these functions when power is cut
Stop Adc
Stop Watchdog
End If
Powersave
End If
Reset Watchdog 'Watchdog is reset every loop
Loop
'===========================================================================
'Timer interrupt subroutine
'===========================================================================
Sectic:
Timerflag = 1
Return
'=========================================
' Serial input interrupt routine
' ========================================
Serial0charmatch:
Incr Messageflag
Return
'=========================================
' Watchdog interrupt routine
' ========================================
Wdt_isr: 'This is executed if the main loop has been stopped for more than 8 seconds
Date_saved = Date$ : Time_saved = Time$
!jmp $0000
Return
End |
I was considering leaving out the "If Uart = Off Then" condition, thus carrying out the shutdown and startup commands at every loop, but this seems messy and might add to the current consumption during Powersave.
Can anyone see where the freezing problem might lie?
(BASCOM-AVR version : 2.0.8.2 , Latest : 2.0.8.5 ) |
|
Back to top |
|
|
Paulvk
Joined: 28 Jul 2006 Posts: 1257 Location: SYDNEY
|
Posted: Wed Jan 19, 2022 10:13 am Post subject: Reset option |
|
|
Not a code solution but a cmos 555 timer could be used as a hard reset watch dog
just like the internal watch dog if its not reset it would hard reset the cpu
Just an idea
Regards Paul |
|
Back to top |
|
|
SZTRAD
Joined: 30 Dec 2019 Posts: 165
|
Posted: Wed Jan 19, 2022 10:33 am Post subject: |
|
|
Hi
if you don't have one, try activating the BOD. You can get the voltage to a level where the 168 won't run anymore.
At a minimum I would activate it after coming out of sleep mode.
Page 41 datasheet
RS |
|
Back to top |
|
|
sentinel
Joined: 02 Feb 2009 Posts: 141 Location: Tasmania
|
Posted: Wed Jan 19, 2022 11:44 am Post subject: |
|
|
Paul, yes, a 555 would reset the micro-controller while it was in Powersave mode unless it was reset each second when the micro momentarily woke up, but I have to work with the hardware I have.
SZTRAD, the BOD is already set at 1.8V, but should not normally get activated for several hours as the supercap slowly discharges from 3.3V
Something else is hanging the micro and preventing the watchdog from doing its job.
Edit: To clarify, the BOD was not programmed while this behaviour was evident, but when it was later programmed as a test, the chip would reset every time the power was cycled, as if the supercap backup wasn't there.
Last edited by sentinel on Thu Jan 20, 2022 5:55 am; edited 1 time in total |
|
Back to top |
|
|
SZTRAD
Joined: 30 Dec 2019 Posts: 165
|
Posted: Wed Jan 19, 2022 12:02 pm Post subject: |
|
|
Hi
that's a power threshold of 168.
What letter is 168 in the name? Is it P or PB or PV? It doesn't matter.
RS |
|
Back to top |
|
|
sentinel
Joined: 02 Feb 2009 Posts: 141 Location: Tasmania
|
Posted: Wed Jan 19, 2022 12:44 pm Post subject: |
|
|
ATmega168A |
|
Back to top |
|
|
SZTRAD
Joined: 30 Dec 2019 Posts: 165
|
Posted: Wed Jan 19, 2022 5:26 pm Post subject: |
|
|
Hi
Page 387 datasheet
Figure 33-1
RS |
|
Back to top |
|
|
sentinel
Joined: 02 Feb 2009 Posts: 141 Location: Tasmania
|
|
Back to top |
|
|
Paulvk
Joined: 28 Jul 2006 Posts: 1257 Location: SYDNEY
|
Posted: Thu Jan 20, 2022 9:19 am Post subject: |
|
|
sentinel wrote: | Paul, yes, a 555 would reset the micro-controller while it was in Powersave mode unless it was reset each second when the micro momentarily woke up, but I have to work with the hardware I have.
|
I only suggested it as the 555 could be run only when full power available so if the cpu did not wake up from power fail
it would reset it and it only needs a output from the cpu to reset but is small enough to put together as a separate thing
only draws draws 1 milliwatt and works at 1.5 volts
just a thought if all else fails and something for me to keep in mind for creating a hard reset with remote rs232 software update.
Regards Paul |
|
Back to top |
|
|
sentinel
Joined: 02 Feb 2009 Posts: 141 Location: Tasmania
|
Posted: Thu Jan 20, 2022 11:01 am Post subject: |
|
|
Yes Paul, it's definitely an option for the future.
If I recall correctly, the 7555 is the CMOS version which draws very little current.
Another possibility would be to use the connection status pin of the Bluetooth module which toggles at 1Hz when disconnected and is high when connected. Yet another possibly would be to be able to pulse a pin of the BT module to reset the micro.
But these band-aid solutions are not as good as having the watchdog operate reliably at all times. I just need to figure out where my code is going wrong.
(Can a micro-controller freeze while in Powersave mode?) |
|
Back to top |
|
|
SZTRAD
Joined: 30 Dec 2019 Posts: 165
|
Posted: Thu Jan 20, 2022 1:58 pm Post subject: |
|
|
Hi
page 312 figure 29-1
RS |
|
Back to top |
|
|
sentinel
Joined: 02 Feb 2009 Posts: 141 Location: Tasmania
|
|
Back to top |
|
|
SZTRAD
Joined: 30 Dec 2019 Posts: 165
|
Posted: Thu Jan 20, 2022 2:37 pm Post subject: |
|
|
Hi
That's strange.
I downloaded the datasheet from the link you sent before and I have it there.
It is about the relationship between frequency and voltage. |
|
Back to top |
|
|
sentinel
Joined: 02 Feb 2009 Posts: 141 Location: Tasmania
|
Posted: Thu Jan 20, 2022 3:25 pm Post subject: |
|
|
My apologies, I was looking at the paragraph numbering instead of the figure number.
8MHz at 3.3V when power is on is fine then. And if Vcc ever drops below 1.8V during the "battery" backup phase, the chip will reset when power returns. |
|
Back to top |
|
|
SZTRAD
Joined: 30 Dec 2019 Posts: 165
|
Posted: Thu Jan 20, 2022 3:46 pm Post subject: |
|
|
Hi
But for you it stops working as you wrote when operating from backup power. Are you sure you won't get voltage below 2.3V even when starting the device? Isn't there already a defined start-up and frequency stability of 8MHz. Try lowering the frequency to 4MHz to see if that does it too.
RS |
|
Back to top |
|
|
|