CpuSleep

Started by anakatalan September 26, 2006
Hello, I'm a new user of Bx24 and I have ploblems with the instruction
CpuSleep. In my program I am using com1, and com3, and 2 pins are ADC. I
would like to call CpuSleep after a time without any change.

I have seen an example (Low_power_App_Note_Bx24), but when I use it in
my program, it is became hung up.

Please, I need help. [(:|]

thanks
> ... CpuSleep...

If you want to sleep the processor to save power, you must:

- disable all I/O devices
- float all processor pins
- prepare the wakeup mechanism (a jiggle switch, in my case)
- wait until output queues are empty or EEPROM write done
- set processor sleep mode
- wait for wakeup stimulus
- reinitialize all hardware states
- reenter main loop

The following code is extracted from one of my projects; it is not
complete but should serve as a guide. Sub Power_PowerDownMode is called
when a motion timeout occurs (i.e. the device has become static).

sub Power_PowerDownMode()
call Display_SetControlRegisters(0, 0) 'sleep display
call Power_PeripheralPower(bxOutputLow) 'sensors off
call Power_FloatPins 'minimum current
call Power_InitJiggleSwitch 'set wakeup interrupt
call sleep(0.1) 'output queue quiet, EEPROM write done
call Power_SleepAndWakeup 'snooze
call Power_InitPins 'pins out of float
call Power_InitPWMT1 'restart display PWM, dimmed
call Power_PeripheralPower(bxOutputHigh) 'sensors, display on
call Inclinometer_PutByte_3(&h01) 'interrogate sensor
call Display_Clear 'reinit display
end sub

sub Power_SleepAndWakeup()
register.DDRD = register.DDRD and bx1111_1011 'pullup Int0
register.PortD = register.PortD or bx0000_0100
tfInterruptIsPending = True
tfWakeUpTaskIsActive = False
CallTask "Power_WakeUpTask", WakeUpTaskStack
do until (tfWakeUpTaskIsActive)
call sleep(0)
loop
register.MCUCR = register.MCUCR and bx1110_1111 'clear SM0
register.MCUCR = register.MCUCR or bx0110_0000 'set SE
if (tfInterruptIsPending) then
call CPUSleep 'sleep until interrupt
end if
register.MCUCR = register.MCUCR and bx1001_1111 'clear SE, SM
end sub

sub Power_WakeupTask()
tfWakeUpTaskIsActive = True
call WaitForInterrupt(bxPinLow) 'sleep
tfInterruptIsPending = False
end sub

sub Power_FloatPins()
dim bX as byte
for bX = 5 to 20
call PutPin(bx, bxInputTriState)
next
for bX = 25 to 27
call PutPin(bx, bxInputTriState)
next
end sub

sub Power_InitPins()
call PutPin(Pin_Display_DataOut, bxOutputLow)
call PutPin(Pin_Display_RegisterSelect, bxOutputLow)
... etc
call PutPin(Pin_GreenLED, bxInputPullup)
Call PutPin(Pin_Display_BrightnessPWMNot, bxOutputHigh)
end sub
Tom
Tom,

What are the power requirments in sleep mode. Mine pulls ~20ma when
running w/o any pins high.

--- In b..., Tom Becker wrote:
>
> > ... CpuSleep...
>
> If you want to sleep the processor to save power, you must:
>
> - disable all I/O devices
> - float all processor pins
> - prepare the wakeup mechanism (a jiggle switch, in my case)
> - wait until output queues are empty or EEPROM write done
> - set processor sleep mode
> - wait for wakeup stimulus
> - reinitialize all hardware states
> - reenter main loop
>
> The following code is extracted from one of my projects; it is not
> complete but should serve as a guide. Sub Power_PowerDownMode is
called
> when a motion timeout occurs (i.e. the device has become static).
>
> sub Power_PowerDownMode()
> call Display_SetControlRegisters(0, 0) 'sleep display
> call Power_PeripheralPower(bxOutputLow) 'sensors off
> call Power_FloatPins 'minimum current
> call Power_InitJiggleSwitch 'set wakeup interrupt
> call sleep(0.1) 'output queue quiet, EEPROM write done
> call Power_SleepAndWakeup 'snooze
> call Power_InitPins 'pins out of float
> call Power_InitPWMT1 'restart display PWM, dimmed
> call Power_PeripheralPower(bxOutputHigh) 'sensors, display on
> call Inclinometer_PutByte_3(&h01) 'interrogate sensor
> call Display_Clear 'reinit display
> end sub
>
> sub Power_SleepAndWakeup()
> register.DDRD = register.DDRD and bx1111_1011 'pullup Int0
> register.PortD = register.PortD or bx0000_0100
> tfInterruptIsPending = True
> tfWakeUpTaskIsActive = False
> CallTask "Power_WakeUpTask", WakeUpTaskStack
> do until (tfWakeUpTaskIsActive)
> call sleep(0)
> loop
> register.MCUCR = register.MCUCR and bx1110_1111 'clear SM0
> register.MCUCR = register.MCUCR or bx0110_0000 'set SE
> if (tfInterruptIsPending) then
> call CPUSleep 'sleep until interrupt
> end if
> register.MCUCR = register.MCUCR and bx1001_1111 'clear SE, SM
> end sub
>
> sub Power_WakeupTask()
> tfWakeUpTaskIsActive = True
> call WaitForInterrupt(bxPinLow) 'sleep
> tfInterruptIsPending = False
> end sub
>
> sub Power_FloatPins()
> dim bX as byte
> for bX = 5 to 20
> call PutPin(bx, bxInputTriState)
> next
> for bX = 25 to 27
> call PutPin(bx, bxInputTriState)
> next
> end sub
>
> sub Power_InitPins()
> call PutPin(Pin_Display_DataOut, bxOutputLow)
> call PutPin(Pin_Display_RegisterSelect, bxOutputLow)
> ... etc
> call PutPin(Pin_GreenLED, bxInputPullup)
> Call PutPin(Pin_Display_BrightnessPWMNot, bxOutputHigh)
> end sub
> Tom
>
Tom,

Nevermind, I just read the AppNote. Sorry

Jim
--- In b..., Tom Becker wrote:
>
> > ... CpuSleep...
>
> If you want to sleep the processor to save power, you must:
>
> - disable all I/O devices
> - float all processor pins
> - prepare the wakeup mechanism (a jiggle switch, in my case)
> - wait until output queues are empty or EEPROM write done
> - set processor sleep mode
> - wait for wakeup stimulus
> - reinitialize all hardware states
> - reenter main loop
>
> The following code is extracted from one of my projects; it is not
> complete but should serve as a guide. Sub Power_PowerDownMode is
called
> when a motion timeout occurs (i.e. the device has become static).
>
> sub Power_PowerDownMode()
> call Display_SetControlRegisters(0, 0) 'sleep display
> call Power_PeripheralPower(bxOutputLow) 'sensors off
> call Power_FloatPins 'minimum current
> call Power_InitJiggleSwitch 'set wakeup interrupt
> call sleep(0.1) 'output queue quiet, EEPROM write done
> call Power_SleepAndWakeup 'snooze
> call Power_InitPins 'pins out of float
> call Power_InitPWMT1 'restart display PWM, dimmed
> call Power_PeripheralPower(bxOutputHigh) 'sensors, display on
> call Inclinometer_PutByte_3(&h01) 'interrogate sensor
> call Display_Clear 'reinit display
> end sub
>
> sub Power_SleepAndWakeup()
> register.DDRD = register.DDRD and bx1111_1011 'pullup Int0
> register.PortD = register.PortD or bx0000_0100
> tfInterruptIsPending = True
> tfWakeUpTaskIsActive = False
> CallTask "Power_WakeUpTask", WakeUpTaskStack
> do until (tfWakeUpTaskIsActive)
> call sleep(0)
> loop
> register.MCUCR = register.MCUCR and bx1110_1111 'clear SM0
> register.MCUCR = register.MCUCR or bx0110_0000 'set SE
> if (tfInterruptIsPending) then
> call CPUSleep 'sleep until interrupt
> end if
> register.MCUCR = register.MCUCR and bx1001_1111 'clear SE, SM
> end sub
>
> sub Power_WakeupTask()
> tfWakeUpTaskIsActive = True
> call WaitForInterrupt(bxPinLow) 'sleep
> tfInterruptIsPending = False
> end sub
>
> sub Power_FloatPins()
> dim bX as byte
> for bX = 5 to 20
> call PutPin(bx, bxInputTriState)
> next
> for bX = 25 to 27
> call PutPin(bx, bxInputTriState)
> next
> end sub
>
> sub Power_InitPins()
> call PutPin(Pin_Display_DataOut, bxOutputLow)
> call PutPin(Pin_Display_RegisterSelect, bxOutputLow)
> ... etc
> call PutPin(Pin_GreenLED, bxInputPullup)
> Call PutPin(Pin_Display_BrightnessPWMNot, bxOutputHigh)
> end sub
> Tom
>
> What are the power requirements in sleep mode.

The application note says 1.5mA for the BX-24 module alone, but my
overall project draws 4.3mA when sleeping.
Tom