View previous topic :: View next topic |
Author |
Message |
TSEYFARTH
Joined: 01 Jul 2006 Posts: 1054
|
Posted: Fri Apr 24, 2015 8:58 pm Post subject: Is the Assembler 'sleep' command the same as BASCOM Powerdo |
|
|
Hello all,
Can anyone tell me if the Asm code, "sleep" is 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?
Code: |
' Powerdown
'The asm code below by Evert Dekker disables the Brownout Detect, And puts the device to sleep.
$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
|
Thank you,
Tim
(BASCOM-AVR version : 2.0.7.8 ) |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5921 Location: Holland
|
Posted: Fri Apr 24, 2015 9:08 pm Post subject: |
|
|
sleep is an assembler mnemonic.
powerdown uses sleep too. All sleep modes require to set some bits in a register in a special sequence and end with the sleep instruction.
it differs from chip to chip. _________________ Mark |
|
Back to top |
|
|
TSEYFARTH
Joined: 01 Jul 2006 Posts: 1054
|
Posted: Fri Apr 24, 2015 9:28 pm Post subject: |
|
|
Hi Mark,
I am using an Atmega 168PA. I was using the BASCOM command "powerdown". But I wanted to also turn off the BOD. I found a thread wherein Evert wrote the asm code I included in the original post. I wanted to be sure that the effect of using the assembler mnemonic command 'sleep' was the same as the powerdown command built into BASCOM.
Tim |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5921 Location: Holland
|
Posted: Fri Apr 24, 2015 9:43 pm Post subject: |
|
|
please stick to bascoms config power= . it is really the best for you to do.
or take time to read the data sheet. the MCUCR register in the mentioned chip is totally different. as far as i can see the bod can only be turned off by the fuse bits in the m168.
Table 10-1 in the pdf lists the various power modes. _________________ Mark |
|
Back to top |
|
|
laborratte
Joined: 27 Jul 2005 Posts: 299 Location: Berlin
|
Posted: Mon Apr 27, 2015 2:59 pm Post subject: |
|
|
Hi.
The M168PA is a picoPower device and supports BOD software disable. The mechanism for enabling is identical to the chip Evert was using.
The sleep mode which is executed by the sleep instruction depends on SMCR (sleep mode control register). See datasheet chapter 10 for details.
For your specific mode and chip the assemble instructions could be as follow:
Code: |
'Power down on M168PA with BOD disable
$asm
ldi r25,&B00000101 'set sleep mode to power down (SM2:0 = 010) and enable sleep (SE = 1)
sts SMCR,r25 'save to SMCR
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) (this line is redundant and don't need to execute)
cbr r25,&B00100000 'Clear bit 5 (BODSE) (1 Clks)
sts MCUCR,r25 'save to MCUCR (2 Clks)
Sleep 'good night (1 Clks)
clr r25 'it is recommend to disable sleep after wake up (see datasheet)
sts SMCR,r25 'save to SMCR
$end Asm
|
Keep in mind that this sequence is chip specific and may not work on other chips. That is why Mark recommend to use config power...
Edit: if you are using interrupts you should encapsulate this seqence in a disable interrupts - enable interrupts instruction pair. |
|
Back to top |
|
|
TSEYFARTH
Joined: 01 Jul 2006 Posts: 1054
|
Posted: Mon Apr 27, 2015 4:37 pm Post subject: |
|
|
Hi laboratte,
Yes, I know it was the same family and supports this feature. I just wanted to be sure that the sleep command is the same as the BASCOM sleep. Previously, I was using only the built in commands. I started looking into turning off BOD as saw the thread on the forum - discussing the timing issues and the necessity to use asm - which I have not a clue about coding.
I see the differences you made and thank you. I had not tested either yet but plan to today.
One thing, can you tell me what r25 means?
Thank you again,
Tim |
|
Back to top |
|
|
laborratte
Joined: 27 Jul 2005 Posts: 299 Location: Berlin
|
Posted: Mon Apr 27, 2015 4:47 pm Post subject: |
|
|
r25 is one of 32 general purpose registers of the CPU. Nearly every data transfer and caluculation has to be done with these registers. For details see Chapter 7 of 168PA's datasheet. |
|
Back to top |
|
|
TSEYFARTH
Joined: 01 Jul 2006 Posts: 1054
|
Posted: Mon Apr 27, 2015 5:20 pm Post subject: |
|
|
Thanks will do!
Tim |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5921 Location: Holland
|
Posted: Mon Apr 27, 2015 10:02 pm Post subject: |
|
|
Sorry, i had the wrong PDF open. Laboratte is right. The P(A) indeed supports this for some of the sleep modes. it is probably a good idea to add this option. _________________ Mark |
|
Back to top |
|
|
TSEYFARTH
Joined: 01 Jul 2006 Posts: 1054
|
Posted: Mon Apr 27, 2015 10:09 pm Post subject: |
|
|
Thanks for the confirmation Mark.
Have a wonderful evening!
Tim |
|
Back to top |
|
|
|