Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

why the Sleep does not?

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
abracadabra

Bascom Member



Joined: 27 Dec 2012
Posts: 24
Location: Paris

france.gif
PostPosted: Sun Jan 25, 2015 3:09 pm    Post subject: why the Sleep does not? Reply with quote

HI!...

all in the question ...
Code:
'        CONFIGURATION PLATINE Tiny2313
$regfile = "ATtiny2313.dat"
$crystal = 8000000
$hwstack = 16                           ' default use 32 for the hardware stack
$swstack = 10                           ' default use 10 for the SW stack
$framesize = 8                          ' default use 40 for the frame space
'____________________ Configuration  LCD
R_s Alias Portd.0
E_e Alias Portd.1
D_b4 Alias Portd.3
D_b5 Alias Portd.4
D_b6 Alias Portd.5
D_b7 Alias Portd.6
Config Lcdpin = Pin , Rs = R_s , E = E_e , Db4 = D_b4 , Db5 = D_b5 , Db6 = D_b6 , Db7 = D_b7
Config Lcd = 16 * 2
Cursor Off : Cls
'========================= VARIABLES ======================================
Dim A As Byte
'========================= INITIALISATIONS ================================
Config Timer1 = Counter , Prescale = 1024
On Ovf1 Ovf_int
Enable Timer1
Enable Ovf1
Enable Interrupts
   cbr R16 , Sm0+sm1                    'IDLE mode
   !out mcucr,r16
   sbr R16 , Se                         'SLEEP authorization
   !out mcucr,r16
'========================= MAIN ===========================================
Do
      Incr A
      Locate 1 , 1
      Lcd A ; "  "
      sleep
Loop
End
'========================= INTERRUPTS ======================================
Ovf_int:
'        PUSH      R24                                       'Push register on stack                                  
   Counter1 = 0                                  
'        POP       R24                                       'Pop register from stack
Return
 


Why never 'SLEEP'?
Thank you.

(BASCOM-AVR version : 2.0.7.5 , Latest : 2.0.7.8 )
Back to top
View user's profile
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 673

poland.gif
PostPosted: Sun Jan 25, 2015 4:32 pm    Post subject: Reply with quote

Tinny Sleep and this You can see in symulator but..on 31 site of datasheet for ATtiny2313 You can read that in Idle mode even I/o change on ports wake up micro. Laughing So if Timer is a counter then on every impuls Sleep mode is Off and On again.
Yu can easy watch this in simulator

Have a nice day
Back to top
View user's profile Visit poster's website
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 1801

blank.gif
PostPosted: Sun Jan 25, 2015 6:06 pm    Post subject: Reply with quote

EDC wrote:
You can read that in Idle mode even I/o change on ports wake up micro.

As this statement is wrong, you should reference, where you got that from.
Back to top
View user's profile
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 673

poland.gif
PostPosted: Sun Jan 25, 2015 6:25 pm    Post subject: Reply with quote

Quote:
on 31 site of datasheet for ATtiny2313 You can read that in Idle mode even I/o change on ports wake up micro


If You you quote me, please do not PULL words out of context as .. Thank You. maybe it`s my bad english. Better if I used "page" but it`s too late Laughing

Here is a picture fron datasheet


I also test this with simulator and watch R16 with a small trick.
Code:
'        CONFIGURATION PLATINE Tiny2313
$sim
$regfile = "ATtiny2313.dat"
$crystal = 8000000
$hwstack = 16                                               ' default use 32 for the hardware stack
$swstack = 10                                               ' default use 10 for the SW stack
$framesize = 8                                              ' default use 40 for the frame space
'____________________ Configuration  LCD
R_s Alias Portd.0
E_e Alias Portd.1
D_b4 Alias Portd.3
D_b5 Alias Portd.4
D_b6 Alias Portd.5
D_b7 Alias Portd.6
Config Lcdpin = Pin , Rs = R_s , E = E_e , Db4 = D_b4 , Db5 = D_b5 , Db6 = D_b6 , Db7 = D_b7
Config Lcd = 16 * 2
Cursor Off : Cls
'========================= VARIABLES ======================================
Dim A As Byte ,
Dim B As Iram Byte At 16
Dim C As Byte
'========================= INITIALISATIONS ================================
Config Timer1 = Counter , Prescale = 1024
On Ovf1 Ovf_int
Enable Timer1
Enable Ovf1
Enable Interrupts
   cbr R16 , Sm0+sm1                                        'IDLE mode
   !out mcucr,r16
   sbr R16 , Se                                             'SLEEP authorization
   !out mcucr,r16
'========================= MAIN ===========================================
Do
      Incr A
      Locate 1 , 1
      Lcd A ; "  "
      Lowerline
      C = B
      Lcd C ; "  "


       'config powermode = idle
      sleep
Loop
End
'========================= INTERRUPTS ======================================
Ovf_int:
'        PUSH      R24                                       'Push register on stack
   Counter1 = 0
'        POP       R24                                       'Pop register from stack
Return


But I don`t want to prove what im trying to say..
Back to top
View user's profile Visit poster's website
abracadabra

Bascom Member



Joined: 27 Dec 2012
Posts: 24
Location: Paris

france.gif
PostPosted: Sun Jan 25, 2015 7:36 pm    Post subject: Reply with quote

I changed my main routine:
Code:
Do
      Incr A
      Locate 1 , 1
      Lcd A ; "  "
      sbr R16 , Se                      'SLEEP authorization
      !out mcucr,r16
      nop
      sleep
      cbr R16 , Se                      'SLEEP unauthorization
      !out mcucr,r16
Loop

but the Sleep still does not work....

@EDC: I tried your program: it does not work
Back to top
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 1801

blank.gif
PostPosted: Sun Jan 25, 2015 7:37 pm    Post subject: Reply with quote

EDC wrote:
If You you quote me, please do not PULL words out of context as .. Thank You. maybe it`s my bad english. Better if I used "page" but it`s too late

It's not bad English, it's not out of context, it's simply wrong.
Your lack of understanding was made obvious by this sentence:
Quote:
So if Timer is a counter then on every impuls Sleep mode is Off and On again.

You tell pretty clear, that toggling the counter input pin would wake up the uC from idle.
And that's why I've asked for a reference.

This:
Quote:
Here is a picture fron datasheet

does not confirm your statement.
This table shows which clock domains are active for the different modes, and further which interfaces may wake up the uC. Pronouncation is on "may", for example: a signal on INT0 doesn't wake up anything, as long the INT0-interrupt isn't enabled. But to make the INT0 possible at all, the IO periphery must be active in the corresponding power mode.

Quote:
I also test this with simulator and watch R16 with a small trick.

AFAIK the simulator's capabilities go not as far, as simulating sleep behaviour.
Back to top
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 1801

blank.gif
PostPosted: Sun Jan 25, 2015 8:01 pm    Post subject: Reply with quote

abracadabra wrote:
Code:
Do
      Incr A
      Locate 1 , 1
      Lcd A ; "  "
      sbr R16 , Se                      'SLEEP authorization
      !out mcucr,r16
      nop
      sleep
      cbr R16 , Se                      'SLEEP unauthorization
      !out mcucr,r16
Loop

Why you mess around with this crappy code, instead of using Power Idle?
Where do the constants Se, Sm0, Sm1 come from?

Do you even know, what the opcode SBR actually does?
I give you a hint: It's an OR between the register's content and the constant following SBR.

Means, you take register R16, with unknown content from previous operations, OR it with constants you don't know, and write this mess into MCUCR.
And you wonder at all, why it doesn't work...
Back to top
View user's profile
Visovian

Bascom Member



Joined: 31 Oct 2007
Posts: 584
Location: Czech

czechrepublic.gif
PostPosted: Mon Jan 26, 2015 7:21 am    Post subject: Reply with quote

Code:
cbr R16 , Sm0+sm1
!out mcucr,r16                                        'IDLE mode

This will not clear bits SM0, SM1.
You need
Code:
cbr r16, 2^SM0 + 2^SM1
!out mcucr,r16
Back to top
View user's profile
abracadabra

Bascom Member



Joined: 27 Dec 2012
Posts: 24
Location: Paris

france.gif
PostPosted: Mon Jan 26, 2015 9:43 am    Post subject: Reply with quote

MWS I understand that you never do forget (Maybe?). No need to insult me to tell me that it lacks a reading MCUCR.
Learn to read the datasheet 'Register summary' (page 214) and you will understand this code (in the example ATMEL documentation).
Needless to troll.

visiovian: thank you; but, a 'XOR' reverse the bits. It does not put them to 0. (This statement is not necessary here: init program starts all MCUCR register is $00, so SM1 = SM0 = 0)
Back to top
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 1801

blank.gif
PostPosted: Mon Jan 26, 2015 10:50 am    Post subject: Reply with quote

abracadabra wrote:
No need to insult me to tell me that it lacks a reading MCUCR.

That was no insult, rather a conclusion.
Quote:
Learn to read the datasheet 'Register summary' (page 214) and you will understand this code.
Needless to troll.

It's really funny, you tell me, who's second name is ASM, I'm trolling because I tell you how to do things in ASM?

For your better understanding, and that's also what Visovian told you:

Constants like SE, SM0 and SM1 are bit names of MCUCR, and reflect the bit position from 0 to 7 within the register.
This way it's in Bascom, the same as it is in other languages, like in C or ASM, where you may have found an example for.

In ATiny2313 SE is on bit position 5, SM0 on position 4, SM1 on position 6, the corresponding values are 32, 16 and 64.
This said, your code is completely senseless, you can't add SM0 + SM1, as this gives 4 + 6 = 10, while the actual required value is 16 + 64 = 80.

Moreover you don't only assign the wrong value to the register R16, you even OR/AND it, as that's what SBR/CBR does.
Additionally you don't clear R16, so the register may contain a random value from previous use, which is written into MCUCR over the other bits, with more interesting and unwanted side-effects.

Correct use would be either to first read MCUCR into R16, then do a CBR/SBR.
Or, if the content of the other bits is known, simply assign the value via LDI.

Hopefully now you understand how far off from target you really are. Very Happy

And btw., still I do not understand, why you don't use the recommended Power Idle, as this does exactly, what you try to achieve with your code-mess.


Last edited by MWS on Mon Jan 26, 2015 7:43 pm; edited 2 times in total
Back to top
View user's profile
Evert :-)

Bascom Expert



Joined: 18 Feb 2005
Posts: 2107

netherlands.gif
PostPosted: Mon Jan 26, 2015 8:30 pm    Post subject: Reply with quote

Hi,
No fight please, there's enough sh*t in the world.

Why not the easy approach?
Code:

 
$regfile = "ATtiny2313.dat"
$crystal = 1200000                                         '1.2MHz   (9.6MHz/DIV8 = 1.2MHz)
$hwstack = 30
$swstack = 30
$framesize = 24
 
 
On Int0 Int0_isr                                           'INT0 will be the wake-up source for Idle Mode
Config Int0 = Low Level
Enable Int0
 
 
'###############################################################################
Do
  Wait 3                                                   ' now we have 3 second to measure the Supply Current in Active Mode
 
  Enable Interrupts
 
  ' Now call Idle function
  Config Powermode = Idle
 
  'Here you have time to measure Idle current consumption until a Low Level on Portb.1 which is the Idle wake-up
Loop
'###############################################################################
End
 
 
Int0_isr:
' wake_up
Return
 


Or if you want to control the register's yourself
Code:

reset mcucr.sm0
reset mcucr.sm1

'or

mcucr.sm0=0
mcucr.sm1=0
 


Have fun,
Evert

_________________
www.evertdekker.com Bascom code vault
Back to top
View user's profile Visit poster's website
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 1801

blank.gif
PostPosted: Mon Jan 26, 2015 9:07 pm    Post subject: Reply with quote

Evert Smile wrote:
No fight please, there's enough sh*t in the world.

I wrote:
Quote:
... instead of using Power Idle?

And I wrote also:
Quote:
...why you don't use the recommended Power Idle

The only fight needed is the one against the TO's ignorance, who is equally responsive like a brick wall.
Back to top
View user's profile
abracadabra

Bascom Member



Joined: 27 Dec 2012
Posts: 24
Location: Paris

france.gif
PostPosted: Tue Jan 27, 2015 12:35 pm    Post subject: Reply with quote

Evert thank you: your clear and simple explanations, they, have fought against my ignorance.
I will say nothing of others, whom I thank however.
my problem is solved.
Back to top
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 1801

blank.gif
PostPosted: Tue Jan 27, 2015 8:36 pm    Post subject: Reply with quote

abracadabra wrote:
I will say nothing of others, whom I thank however.

To avoid any further discomfort for you, I've put you on my list of people, whom I won't answer again.
It's the best for all, and for sure the forum will answer any of your highly sophisticated questions. Very Happy
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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