View previous topic :: View next topic |
Author |
Message |
sentinel
Joined: 02 Feb 2009 Posts: 141 Location: Tasmania
|
Posted: Fri Oct 01, 2021 3:53 am Post subject: Not exiting Powersave reliably |
|
|
When I run this (stripped-down) code, the firmware often does not exit Powersave regardless of the state of the power supply.
Pin C.5 (alias Power_on) is high when the circuit is powered and triggers entry into Powersave mode when the power drops out.
The problem is that it sometimes sticks in the power down state, and of course, the watchdog is never triggered.
Grateful for any suggestions
Code: |
$regfile = "m168def.dat"
'Oscillator Is 8 Mhz not divided By 8 Internally.
$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 Bit
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
Power_on Alias Pinc.5
Const On = 1
Const Off = 0
Portc.0 = 1
Portb.3 = 1
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 Nosave
Enable Wdt
Start Watchdog
Enable Interrupts
'===========================================================================
'Main program
'===========================================================================
Do
If Power_on = 1 Then
If Uart = Off Then
Ucsr0b.txen0 = 1
Ucsr0b.rxen0 = 1
Uart = On
Start Adc
Start Watchdog
End If
'Main loop tasks here
Else
If Uart = On Then
Ucsr0b.txen0 = 0 'Disable USART0 transmit
Ucsr0b.rxen0 = 0 'Disable USART0 receive
Uart = Off
Stop Adc
Stop Watchdog
End If
Powersave
End If
Reset Watchdog
Loop
'===========================================================================
'Timer interrupt subroutine
'===========================================================================
Sectic:
Timerflag = 1
OCR2B = 0 'Wait for the write cycle of Timer2.
Do
Loop Until ASSR.OCR2BUB = 0
Return
Wdt_isr:
Date_saved = Date$ : Time_saved = Time$
!jmp $0000
Return
'=========================================
' Serial input interrupt routine
' ========================================
Serial0charmatch:
Incr Messageflag
Return
End
|
(BASCOM-AVR version : 2.0.8.2 , Latest : 2.0.8.4 )
Last edited by sentinel on Sat Oct 02, 2021 2:04 am; edited 1 time in total |
|
Back to top |
|
|
EDC
Joined: 26 Mar 2014 Posts: 971
|
Posted: Fri Oct 01, 2021 7:42 pm Post subject: |
|
|
Do you understand what Nosave argument means?
Or in another way - how you think it work? |
|
Back to top |
|
|
EDC
Joined: 26 Mar 2014 Posts: 971
|
Posted: Fri Oct 01, 2021 7:51 pm Post subject: |
|
|
Nosave argument means that you know what registers will be used and they should be saved on the stack and after your operation is done they should be restored by your code. When you use Nosave argument you should save and restore registers that was handy during ISR yourself because you tell to the Bascom - I care of them myself.
So.. |
|
Back to top |
|
|
i.dobson
Joined: 05 Jan 2006 Posts: 1570 Location: Basel, Switzerland
|
Posted: Fri Oct 01, 2021 8:23 pm Post subject: |
|
|
Hi,
I can't see where your actually enabling interrupts with "Enable Interrupts"
Regards
Ian Dobson _________________ Walking on water and writing software to specification is easy if they're frozen. |
|
Back to top |
|
|
sentinel
Joined: 02 Feb 2009 Posts: 141 Location: Tasmania
|
Posted: Sat Oct 02, 2021 12:16 am Post subject: |
|
|
EDC wrote: | Do you understand what Nosave argument means?
Or in another way - how you think it work? |
As you suspect, not well enough to be able to justify why I included it in my code. It was lifted wholesale from someone else's example.
I'll get rid of the Nosave and try again.
Thanks for the input. |
|
Back to top |
|
|
sentinel
Joined: 02 Feb 2009 Posts: 141 Location: Tasmania
|
Posted: Sat Oct 02, 2021 12:19 am Post subject: |
|
|
i.dobson wrote: | Hi,
I can't see where your actually enabling interrupts with "Enable Interrupts"
Regards
Ian Dobson |
Hi Ian, yes, you're right, I "stripped down" the code too much and deleted it from the original code in error.
"Enable Interrupts" is in the original problematic code.
I've added it to the sample code above. |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Sat Oct 02, 2021 8:54 am Post subject: |
|
|
EDC wrote: | When you use Nosave argument you should save and restore registers that was handy during ISR yourself because you tell to the Bascom - I care of them myself.
So.. |
So what?
You was drifting off target and discussing non-issues, which you could have avoided if you had checked what the NOSAVE-ISR actually does: Calls EEPROM-functions and then restarts.
What registers you want toi save for a restart? |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Sat Oct 02, 2021 10:26 am Post subject: Re: Not exiting Powersave reliably |
|
|
sentinel wrote: | The problem is that it sometimes sticks in the power down state, and of course, the watchdog is never triggered. |
If UART is on and power is off this sequence executes:
Code: | Stop Adc
Stop Watchdog
Powersave |
After in your code, only async timer2 can pull the controller from sleep by executing timer2 ISR, which again calls the SECTIC stub.
In this matter I wonder about the purpose of this code construct, as more as the comment does not match exactly what it does.
Code: | Sectic:
Timerflag = 1
OCR2B = 0 'Wait for the write cycle of Timer2.
Do
Loop Until ASSR.OCR2BUB = 0
Return |
It does not exactly wait till a write cycle is enabled, in contrary it shoots first and asks later.
Also I wonder about the (non-)sense of triggering a wait for write enable, as more OCR2B seems not be used elsewhere.
Would you explain? |
|
Back to top |
|
|
sentinel
Joined: 02 Feb 2009 Posts: 141 Location: Tasmania
|
Posted: Mon Oct 04, 2021 12:35 am Post subject: |
|
|
I would explain, except I can't.
This is fossil code from another project that I left in through laziness. As you say, there is no apparent need for it in this application, so out it goes. Rigorous testing will ensue.
Thank you for casting your critical eye over this effort. |
|
Back to top |
|
|
|