View previous topic :: View next topic |
Author |
Message |
Evert :-)
Joined: 18 Feb 2005 Posts: 2156
|
Posted: Thu Aug 02, 2012 9:07 pm Post subject: BOD under software control |
|
|
In the pico mega's (i'm using 328P) , it's possible to disable the BOD in software.
It's also possible to disable the BOD just before going in POWERSAVE mode, BOD will be automatic enabled when leaving powersave mode. This to reduce power consumption during powersave.
Did some one has made this already ?
Ps Need it for my battery powered watch _________________ www.evertdekker.com Bascom code vault |
|
Back to top |
|
|
kimmi
Joined: 24 Feb 2006 Posts: 1922 Location: Denmark
|
Posted: Thu Aug 02, 2012 11:40 pm Post subject: |
|
|
Hi Evert,
Do you mean like this ?
'turn bod off atmega328P ONLY P model
'set both bit6 & bit5
MCUCR.6 = 1 ' BODS
MCUCR.5 = 1 ' BODSE
'set bit6 & reset bit5
MCUCR.6 = 1
MCUCR.5 = 0
POWERSAVE
Timed Sequence to disable BOD:
1. Set BODS and BODSE to "1"
2. Within four clock cycles, BODS must be set to "1" and BODSE to "0"
3. While BODS bit is active for three clock cycles, execute sleep instruction
4. BODS is then automatically cleared after three clock cycles
=> BOD is now deactivated in sleep mode
See more :
Datasheet atmega328 PAGE 46
MCUCR – MCU Control Register _________________ / Kim |
|
Back to top |
|
|
Evert :-)
Joined: 18 Feb 2005 Posts: 2156
|
Posted: Fri Aug 03, 2012 8:07 am Post subject: |
|
|
Hi Kimmi,
I have tried that, sorry i didn't mentioned it.
The problem is in (I think) 3. While BODS bit is active for three clock cycles, execute sleep instruction
It take's Bascom 5 clockcycles to execute the Powersave statement end therefore execute the sleep instruction, and that's to long. _________________ www.evertdekker.com Bascom code vault |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Fri Aug 03, 2012 8:55 am Post subject: |
|
|
instead of powersave which must set some registers, you need to use !sleep instruction _________________ Mark |
|
Back to top |
|
|
Evert :-)
Joined: 18 Feb 2005 Posts: 2156
|
Posted: Fri Aug 03, 2012 10:23 am Post subject: |
|
|
This takes also to long 6 cycles, only 4 cycles allowed.
Code: |
'set bit6 & reset bit5
MCUCR.6 = 1
MCUCR.5 = 0
|
This is working, but i'm not sure if i mes up the IVSEL IVCE and PUD bit in the MCUCR register by setting them all to zero??
Code: |
Smcr = &B00000111 'Setting up the sleep mode control register
Mcucr.6 = 1 ' BODS
Mcucr.5 = 1 ' BODSE
Mcucr = &B01000000 <- ????
!Sleep
|
_________________ www.evertdekker.com Bascom code vault |
|
Back to top |
|
|
laborratte
Joined: 27 Jul 2005 Posts: 299 Location: Berlin
|
Posted: Fri Aug 03, 2012 10:54 am Post subject: |
|
|
IMHO you have to do it in assembler:
Code: |
$asm
lds r25,MCUSR 'get current MCUSR
sbr r25,&B01100000 'Set bit 5 & 6 (BODSE & BODS) (1 Clks)
sts MCUSR,r25 'save to MCUSR (2 Clks)
cbr r25,&B00100000 'Clear bit 5 (BODSE) (1 Clks)
sts MCUSR,r25 'save to MCUSR (2 Clks)
sleep 'good night (1 Clks)
$asm
|
|
|
Back to top |
|
|
Evert :-)
Joined: 18 Feb 2005 Posts: 2156
|
Posted: Fri Aug 03, 2012 11:48 am Post subject: |
|
|
Hi laborratte,
Almost, it's MCUCR instead of MCUSR.
This works fine for me;
Code: |
$asm
lds r25,MCUCR 'get current MCUcR
sbr r25,&B01100000 'Set bit 5 & 6 (BODSE & BODS) (1 Clks)
sts MCUcR,r25 'save to MCUcR (2 Clks)
sbr r25,&B01000000 'Set bit 6 (BODS) (1 Clks)
cbr r25,&B00100000 'Clear bit 5 (BODSE) (1 Clks)
sts MCUCR,r25 'save to MCUcR (2 Clks)
Sleep 'good night (1 Clks)
$end Asm
|
No need to PUSH/POP R25? _________________ www.evertdekker.com Bascom code vault |
|
Back to top |
|
|
laborratte
Joined: 27 Jul 2005 Posts: 299 Location: Berlin
|
Posted: Fri Aug 03, 2012 12:00 pm Post subject: |
|
|
oops, dirty glasses...
In normal program flow there is no need to push/pop registers. Normal BASCOM statements don't do that either.
Of course, don't use the BASCOM specific registers r4,r5,r6,r8,r9 and Y (r28,r29)... |
|
Back to top |
|
|
enniom
Joined: 20 Oct 2009 Posts: 537
|
Posted: Sat Aug 04, 2012 4:13 am Post subject: |
|
|
This might be an interesting function to have built into BASCOM. We can call it BOD_Evert().
Ennio |
|
Back to top |
|
|
TSEYFARTH
Joined: 01 Jul 2006 Posts: 1054
|
Posted: Fri Apr 24, 2015 6:44 am Post subject: |
|
|
Hello all,
In Everts Asm code, is "sleep" the same as MCS BASCOM "Powerdown"?
If not, can anyone tell me how to modify Everts asm code to emulate the Powerdown command of MCS BASCOM?
Thank you,
Tim |
|
Back to top |
|
|
|