View previous topic :: View next topic |
Author |
Message |
enniom
Joined: 20 Oct 2009 Posts: 537
|
Posted: Sat Sep 20, 2014 7:05 pm Post subject: RTC Running During PowerSave on XMEGA |
|
|
Hello Forum,
The code below does keep proper clock time during power reduction periods and I see power consumption going from about 19 mA to about 50 uA on my setup (which is OK but would prefer a little less).
However, the code seems not very smart. The micro is woken up every second by the RTC Interrupt, increments the time variable and goes back to PowerSave mode. This continues until the user pushes a button on PORTE.5.
Is there a better way to do this? Possibly reduce power consumption a little more?
Code: | $regfile = "xm128a3def.dat"
$hwstack = 1200
$swstack = 1200
$framesize = 1200
$crystal = 32000000
Config Osc = Enabled , 32mhzosc = Enabled 'internal 2 MHz and 32 MHz enabled
Config Sysclock = 32mhz , Prescalea = 1 , Prescalebc = 1_1 'use 32 MHz
Stop Watchdog
Config Power_reduction = Dummy , Aes = Off , Dma = Off , Ebi = Off , Evsys = Off , _
Daca = Off , Dacb = Off , Adcb = Off , Aca = Off , Acb = Off , Rtc = On , _
Twic = Off , Twid = Off , Twie = Off , _
Usartc0 = Off , Usartc1 = Off , Usartd0 = Off , _
Usartd1 = Off , Usarte0 = On , Usarte1 = Off , Usartf0 = Off , _
Tcc0 = Off , Tcc1 = Off , _
Tcd0 = Off , Tcd1 = Off , _
Tce0 = Off , Tce1 = Off , _
Tcf0 = Off
Config Submode = New
'============================================
'Config SOFT Clock
'============================================
Config Clock = Soft , Rtc = 1khz_int32khz_ulp , Gosub = Sectic 'select internal 1 KHz clock from the 32KHz internal oscillator
Dim Calc_ave As Byte , Long_time As Long , No_power As Byte
Date$ = "09/20/14" : Time$ = "09:58:01" 'Hard time dummy date
Long_time = Syssec()
Config Priority = Static , Vector = Application , Lo = Enabled , Med = Enabled
'====================================================
'Wake Up
'====================================================
' 7654_3210
Const Port_conf = &B0010_0000 'Define Pins on PORT
Wake_pin Alias Pine
Config Wake_pin.5 = Input
Config Xpin = Porte.5 , Outpull = Pullup , Sense = Low_level 'enable Pull up
Porte_int0mask = Port_conf 'include PINs in INT0 Mask for Port
Porte_intctrl = &B0000_00_01
' ^ 'Low Level INT0 Interrupt for Port
On Porte_int0 Wake_detect_isr 'ISR
Enable Porte_int0 , Lo
Enable Interrupts
Wakeup_start:
Config Com5 = 57600 , Mode = Asynchroneous , Parity = None , Stopbits = 1 , Databits = 8
Open "COM5:" For Binary As #1
' ===== M A I N =====
Do
If Calc_ave <> _sec Then
Calc_ave = _sec
Print #1 , Time(long_time)
End If
If _sec = 0 Then 'time to shutdown
Config Power_reduction = Dummy , Usarte0 = Off
Usarte0_ctrlb.6 = 0 : Usarte0_ctrlb.4 = 0 : Usarte0_ctrlb.3 = 0
Porta = 0 : Portb = 0 : Portc = 0 : Portd = 0 : Porte = 0 : Portf = 0 : Portr = 0
No_power = 1
Waitms 100
Enable Porte_int0 , Lo 'make sure can wake up
Do
Config Powermode = Powersave
Loop Until No_power = 0
Exit Do
End If
Loop
Goto Wakeup_start
End 'end program
Close #1
Wake_detect_isr:
No_power = 0
Return
Sectic:
Incr Long_time
Return
|
(BASCOM-AVR version : 2.0.7.7 ) |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Sat Sep 20, 2014 10:37 pm Post subject: |
|
|
Some suggestions:
a) An outer Do/loop instead of the Goto would look nicer.
b) In Powersave mode, clock to peripherals is already stopped, so Config Power_reduction won't achieve anything in Powersave mode.
In active mode it may help a bit, but I think there you revert the effect, as you issue a second Config Power_reduction command, which according to the help, does not work selectively, instead absolutely.
Means you re-enable everything, which you did previously disable.
c) I'd disable Porte_int0 within the int0-ISR, to avoid continuous interrupts, if the user keeps the button pressed.
d) According the data sheet the XM128 should use at ambient temperature a bit around 0.5ľA, which means 50ľA is way too much.
Either your measuring instrument gives you wrong values, or you have something on your PCB that draws this current.
I'd write some simple code, which sends the controller to Powersave, nothing else. Then disconnect everything and measure the current. |
|
Back to top |
|
|
enniom
Joined: 20 Oct 2009 Posts: 537
|
Posted: Sat Sep 20, 2014 11:35 pm Post subject: |
|
|
Quote: | b) In Powersave mode, clock to peripherals is already stopped, so Config Power_reduction won't achieve anything in Powersave mode. |
I did not know this. Will change it accordingly.
Quote: | In active mode it may help a bit, but I think there you revert the effect, as you issue a second Config Power_reduction command, which according to the help, does not work selectively, instead absolutely. Means you re-enable everything, which you did previously disable. |
This is interesting. I will remove the statement.
Quote: | c) I'd disable Porte_int0 within the int0-ISR, to avoid continuous interrupts, if the user keeps the button pressed. |
You're right MWS. This was a snippet and the full code does handle it as you suggested.
Quote: | d) According the data sheet the XM128 should use at ambient temperature a bit around 0.5ľA, which means 50ľA is way too much.
Either your measuring instrument gives you wrong values, or you have something on your PCB that draws this current.
I'd write some simple code, which sends the controller to Powersave, nothing else. Then disconnect everything and measure the current. |
Yes, I know I have poor instruments to measure current, and, the 50 uA was measured on a board with some other circuits - including resistor dividers to ground for ADC.
So overall, the "ugly" part of the code that includes waking up the micro every second to increment the time variable, is the only way to do this.
Thanks for your help. |
|
Back to top |
|
|
enniom
Joined: 20 Oct 2009 Posts: 537
|
Posted: Mon Oct 19, 2015 2:39 pm Post subject: |
|
|
Hello,
After reading the manual in more detail, I found that the 32.768kHz RTC clock for XMEGAs does have a Prescaler that can be set to the desired value. The "Sectic" Interrupt will then be changed to that corresponding value.
For example:
Code: | Config Clock = Soft , Rtc = 1khz_int32khz_ulp , Gosub = Sectic 'select internal 1 KHz clock from the 32KHz internal oscillator
RTC_CTRL = 3 '1=clock interrupt/second - OR 2=2, 3=8, 4=16, 5=64, 6=256, 7=1024 seconds
|
This will trigger the Sectic Interrupt every 8 seconds. Available options are 1, 2, 8, 16, 64, 256 and 1024 seconds. This feature is extremely useful where the uC has to wake up periodically to perform defined checks.
It might be interesting to change the CONFIG Clock statement to include the PRESCALER = xx option.
Edit:
HOWEVER, it seems that the uC is still woken up from Powerdown/Powersave every second - but the Sectic ISR is only executed every Nth time as defined by RTC_CTRL. This is very strange!!!!
Edit2:
The above seems to be true for the XMEGA192A3U.
The RTC_CTRL register does not seem to have any effect on the 16/32E5s. This chip wakes up via the Sectic Interrupt and executes the ISR every second - regardless of the settings.
E |
|
Back to top |
|
|
enniom
Joined: 20 Oct 2009 Posts: 537
|
Posted: Tue Oct 20, 2015 12:40 pm Post subject: |
|
|
Solution:
It seems as if the Clock Configuration has to execute at least once prior to changing RTC_CTRL.
For example:
Code: |
Config Clock = Soft , Rtc = 1khz_int32khz_ulp , Gosub = Sectic 'select internal 1 KHz clock from the 32KHz internal oscillator
RTC_CTRL = 3 '1=clock interrupt/second - OR 2=2, 3=8, 4=16, 5=64, 6=256, 7=1024 seconds
| This will not set the clock interrupt properly to once every 8 seconds.
But this will:
Code: |
Config Clock = Soft , Rtc = 1khz_int32khz_ulp , Gosub = Sectic 'select internal 1 KHz clock from the 32KHz internal oscillator
Wait 2 'This allows the ISR to execute at least once, then the clock Sectic period can be set properly.
RTC_CTRL = 3 '1=clock interrupt/second - OR 2=2, 3=8, 4=16, 5=64, 6=256, 7=1024 seconds
|
I hope this helps those looking for longer PowerSave periods... but still have accurate clock/time.
E |
|
Back to top |
|
|
|
|
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 You cannot attach files in this forum You cannot download files in this forum
|
|