Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Thread

Sleep ATMega16

Sleep ATMega16

2009-04-29 by Gmail

I am working on on a system to record temperature on a flash memory at a  programmed rate.
As there is nothing to be done between samples (1 Sec- 15 Mins) and it is battery powered I want it to sleep between samples.

I am using Mega 16, A/D MCP3550 on Spi, running on 3.6864 Mhz Crystal.

The first step I did was to read from A/d and send it by uart to check readings, it was ok.

When I started to introduce sleep, I got zeros received by uart! even the number of bytes sent.
So I conclude that the problem is when waking after the sleep, is there any thing that I missed or settings to be done so that I get it work as I want it?

Code Bellow.

Thanks,
Moataz Hussein

;/////////////////
; Timer2 overflow
;/////////////////

Timer2_Ovf:

 clr temp  ; Disable sleep
 out mcucr,temp

 dec temp1  ; Loops counter
 brne hh

 ldi temp1, 225  ; Reset Counter value to 225 when done

hh:
 ldi Temp,LOW(Sec1) ; After interupt completed go back to Sec1
 push Temp
 ldi Temp,HIGH(Sec1)
 push Temp
 reti

;/////////////////
; Main
;/////////////////

Main_sample:

 rcall sample   ; Read from A/d And send by UART

 sei
 ldi temp, 0b01000000
 out timsk, temp

 Ldi Temp, 0b00000100 ; Prescaller 64
 out tccr2, temp
 ldi temp1, 225  ; No of loops to get 1 Sec



TMRLOOP:

 ldi temp,0b01010000 ; Enable sleep, mode
; out mcucr,temp
 sleep 
 Rjmp TMRloop

Sec1:
 Ldi temp, 225
 cpse temp, temp1
 rjmp tmrloop
 
 Rjmp Main_sample

[Non-text portions of this message have been removed]

Re: [AVR-Chat] Sleep ATMega16

2009-04-29 by Jim Hatley

Probably need to enable internal pullup on receive pin or put on an external pullup to be sure receive pin is kept high.

Jim
Show quoted textHide quoted text
  ----- Original Message ----- 
  From: Gmail 
  To: AVR-Chat@yahoogroups.com 
  Sent: Wednesday, April 29, 2009 9:23 AM
  Subject: [AVR-Chat] Sleep ATMega16





  I am working on on a system to record temperature on a flash memory at a programmed rate.
  As there is nothing to be done between samples (1 Sec- 15 Mins) and it is battery powered I want it to sleep between samples.

  I am using Mega 16, A/D MCP3550 on Spi, running on 3.6864 Mhz Crystal.

  The first step I did was to read from A/d and send it by uart to check readings, it was ok.

  When I started to introduce sleep, I got zeros received by uart! even the number of bytes sent.
  So I conclude that the problem is when waking after the sleep, is there any thing that I missed or settings to be done so that I get it work as I want it?

  Code Bellow.

  Thanks,
  Moataz Hussein

  ;/////////////////
  ; Timer2 overflow
  ;/////////////////

  Timer2_Ovf:

  clr temp ; Disable sleep
  out mcucr,temp

  dec temp1 ; Loops counter
  brne hh

  ldi temp1, 225 ; Reset Counter value to 225 when done

  hh:
  ldi Temp,LOW(Sec1) ; After interupt completed go back to Sec1
  push Temp
  ldi Temp,HIGH(Sec1)
  push Temp
  reti

  ;/////////////////
  ; Main
  ;/////////////////

  Main_sample:

  rcall sample ; Read from A/d And send by UART

  sei
  ldi temp, 0b01000000
  out timsk, temp

  Ldi Temp, 0b00000100 ; Prescaller 64
  out tccr2, temp
  ldi temp1, 225 ; No of loops to get 1 Sec

  TMRLOOP:

  ldi temp,0b01010000 ; Enable sleep, mode
  ; out mcucr,temp
  sleep 
  Rjmp TMRloop

  Sec1:
  Ldi temp, 225
  cpse temp, temp1
  rjmp tmrloop

  Rjmp Main_sample

  [Non-text portions of this message have been removed]



  

[Non-text portions of this message have been removed]

Re: [AVR-Chat] Sleep ATMega16

2009-04-29 by wagnerj@proaxis.com

Be aware that the processor takes time to wake up. Also, be careful NOT to
sleep until all of the bytes have been sent. This means staying awake
until the very last stop bit has left the UART. In other words, you cannot
just put a byte into the UDR, then sleep. You need to wait until the byte
is actually finished.

Jim Wagner
Oregon Research Electronics
Show quoted textHide quoted text
> I am working on on a system to record temperature on a flash memory at a
> programmed rate.
> As there is nothing to be done between samples (1 Sec- 15 Mins) and it is
> battery powered I want it to sleep between samples.
>
> I am using Mega 16, A/D MCP3550 on Spi, running on 3.6864 Mhz Crystal.
>
> The first step I did was to read from A/d and send it by uart to check
> readings, it was ok.
>
> When I started to introduce sleep, I got zeros received by uart! even the
> number of bytes sent.
> So I conclude that the problem is when waking after the sleep, is there
> any thing that I missed or settings to be done so that I get it work as I
> want it?
>
> Code Bellow.
>
> Thanks,
> Moataz Hussein
>
> ;/////////////////
> ; Timer2 overflow
> ;/////////////////
>
> Timer2_Ovf:
>
>  clr temp  ; Disable sleep
>  out mcucr,temp
>
>  dec temp1  ; Loops counter
>  brne hh
>
>  ldi temp1, 225  ; Reset Counter value to 225 when done
>
> hh:
>  ldi Temp,LOW(Sec1) ; After interupt completed go back to Sec1
>  push Temp
>  ldi Temp,HIGH(Sec1)
>  push Temp
>  reti
>
> ;/////////////////
> ; Main
> ;/////////////////
>
> Main_sample:
>
>  rcall sample   ; Read from A/d And send by UART
>
>  sei
>  ldi temp, 0b01000000
>  out timsk, temp
>
>  Ldi Temp, 0b00000100 ; Prescaller 64
>  out tccr2, temp
>  ldi temp1, 225  ; No of loops to get 1 Sec
>
>
>
> TMRLOOP:
>
>  ldi temp,0b01010000 ; Enable sleep, mode
> ; out mcucr,temp
>  sleep
>  Rjmp TMRloop
>
> Sec1:
>  Ldi temp, 225
>  cpse temp, temp1
>  rjmp tmrloop
>
>  Rjmp Main_sample
>
> [Non-text portions of this message have been removed]
>
>

Re: [AVR-Chat] Sleep ATMega16

2009-04-29 by Philippe Habib

I don't know what the case is with your part, but some parts have a  
sleep mode that lets the ADC run and the int can trigger an ADC read  
to happen.

I'd read up on the various sleep mode and see if one is a good fit for  
what you're trying to do.
Show quoted textHide quoted text
On Apr 29, 2009, at 11:53 AM, wagnerj@proaxis.com wrote:

> Be aware that the processor takes time to wake up. Also, be careful  
> NOT to
> sleep until all of the bytes have been sent. This means staying awake
> until the very last stop bit has left the UART. In other words, you  
> cannot
> just put a byte into the UDR, then sleep. You need to wait until the  
> byte
> is actually finished.
>
> Jim Wagner
> Oregon Research Electronics
>
>> I am working on on a system to record temperature on a flash memory  
>> at a
>> programmed rate.
>> As there is nothing to be done between samples (1 Sec- 15 Mins) and  
>> it is
>> battery powered I want it to sleep between samples.
>>
>> I am using Mega 16, A/D MCP3550 on Spi, running on 3.6864 Mhz  
>> Crystal.
>>
>> The first step I did was to read from A/d and send it by uart to  
>> check
>> readings, it was ok.
>>
>> When I started to introduce sleep, I got zeros received by uart!  
>> even the
>> number of bytes sent.
>> So I conclude that the problem is when waking after the sleep, is  
>> there
>> any thing that I missed or settings to be done so that I get it  
>> work as I
>> want it?
>>
>> Code Bellow.
>>
>> Thanks,
>> Moataz Hussein
>>
>> ;/////////////////
>> ; Timer2 overflow
>> ;/////////////////
>>
>> Timer2_Ovf:
>>
>> clr temp  ; Disable sleep
>> out mcucr,temp
>>
>> dec temp1  ; Loops counter
>> brne hh
>>
>> ldi temp1, 225  ; Reset Counter value to 225 when done
>>
>> hh:
>> ldi Temp,LOW(Sec1) ; After interupt completed go back to Sec1
>> push Temp
>> ldi Temp,HIGH(Sec1)
>> push Temp
>> reti
>>
>> ;/////////////////
>> ; Main
>> ;/////////////////
>>
>> Main_sample:
>>
>> rcall sample   ; Read from A/d And send by UART
>>
>> sei
>> ldi temp, 0b01000000
>> out timsk, temp
>>
>> Ldi Temp, 0b00000100 ; Prescaller 64
>> out tccr2, temp
>> ldi temp1, 225  ; No of loops to get 1 Sec
>>
>>
>>
>> TMRLOOP:
>>
>> ldi temp,0b01010000 ; Enable sleep, mode
>> ; out mcucr,temp
>> sleep
>> Rjmp TMRloop
>>
>> Sec1:
>> Ldi temp, 225
>> cpse temp, temp1
>> rjmp tmrloop
>>
>> Rjmp Main_sample
>>
>> [Non-text portions of this message have been removed]
>>
>>
>
>
>
>
> ------------------------------------
>
> Yahoo! Groups Links
>
>
>

Re: [AVR-Chat] Sleep ATMega16

2009-04-29 by Gmail

What i did is that when it wakes, i inserted a delay of 200 ms then started to get data from AD (SPI) and send it (UART), nothing happened; same results.

 Moataz Hussein
Show quoted textHide quoted text
  ----- Original Message ----- 
  From: wagnerj@proaxis.com 
  To: AVR-Chat@yahoogroups.com 
  Sent: Wednesday, April 29, 2009 9:53 PM
  Subject: Re: [AVR-Chat] Sleep ATMega16





  Be aware that the processor takes time to wake up. Also, be careful NOT to
  sleep until all of the bytes have been sent. This means staying awake
  until the very last stop bit has left the UART. In other words, you cannot
  just put a byte into the UDR, then sleep. You need to wait until the byte
  is actually finished.

  Jim Wagner
  Oregon Research Electronics

  > I am working on on a system to record temperature on a flash memory at a
  > programmed rate.
  > As there is nothing to be done between samples (1 Sec- 15 Mins) and it is
  > battery powered I want it to sleep between samples.
  >
  > I am using Mega 16, A/D MCP3550 on Spi, running on 3.6864 Mhz Crystal.
  >
  > The first step I did was to read from A/d and send it by uart to check
  > readings, it was ok.
  >
  > When I started to introduce sleep, I got zeros received by uart! even the
  > number of bytes sent.
  > So I conclude that the problem is when waking after the sleep, is there
  > any thing that I missed or settings to be done so that I get it work as I
  > want it?
  >
  > Code Bellow.
  >
  > Thanks,
  > Moataz Hussein
  >
  > ;/////////////////
  > ; Timer2 overflow
  > ;/////////////////
  >
  > Timer2_Ovf:
  >
  > clr temp ; Disable sleep
  > out mcucr,temp
  >
  > dec temp1 ; Loops counter
  > brne hh
  >
  > ldi temp1, 225 ; Reset Counter value to 225 when done
  >
  > hh:
  > ldi Temp,LOW(Sec1) ; After interupt completed go back to Sec1
  > push Temp
  > ldi Temp,HIGH(Sec1)
  > push Temp
  > reti
  >
  > ;/////////////////
  > ; Main
  > ;/////////////////
  >
  > Main_sample:
  >
  > rcall sample ; Read from A/d And send by UART
  >
  > sei
  > ldi temp, 0b01000000
  > out timsk, temp
  >
  > Ldi Temp, 0b00000100 ; Prescaller 64
  > out tccr2, temp
  > ldi temp1, 225 ; No of loops to get 1 Sec
  >
  >
  >
  > TMRLOOP:
  >
  > ldi temp,0b01010000 ; Enable sleep, mode
  > ; out mcucr,temp
  > sleep
  > Rjmp TMRloop
  >
  > Sec1:
  > Ldi temp, 225
  > cpse temp, temp1
  > rjmp tmrloop
  >
  > Rjmp Main_sample
  >
  > [Non-text portions of this message have been removed]
  >
  >



  

[Non-text portions of this message have been removed]

Re: Branchging intsruction-- BRMI

2009-05-21 by Don Kinzer

--- In AVR-Chat@yahoogroups.com, "Gmail" <moatazhussein@...> wrote:
> I want to branch at a certain part of the program when a
> register (Temp) value is greater than or equal to $FA.
I doubt that BRMI is the instruction you should be using.  It would more commonly be used when the operands are signed values.  Instead, look at BRSH (branch if same or higher).  It works just as well following a subtract instruction as it does following a compare instructions.  After all, a compare is just a subtract that doesn't save the result.

Note, particularly, that BRSH is used for unsigned values while BRGE is used for signed values.
 
> It is not working as understood, i see other flags are
> also affected. there is something that i do not see!!
You need to consult the "AVR Instruction Set" document available from the Atmel site.  For SUBI, it indicates that all status flags except I and T may be modified.

Here is a link to the instruction set document:
http://www.atmel.com/dyn/resources/prod_documents/doc0856.pdf

Don Kinzer
ZBasic Microcontrollers
http://www.zbasic.net

Branchging intsruction-- BRMI

2009-05-21 by Gmail

Hi,

I want to branch at a certain part of the program when a register (Temp) value is greater than or equal to $FA.
Temp has different values as in not just incrementing.

I did as follow

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Subi Temp, $FA

Brmi Inc_Start    ; Go to Inc start if temp passed the limit 250 ($FA)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:

It is not working as understood, i see other flags are also affected. there is something that i do not see!!

Is this correct or there is other way to do it.

Thanks 

Moataz Hussein

[Non-text portions of this message have been removed]

Re: [AVR-Chat] Re: Branchging intsruction-- BRMI

2009-05-21 by Gmail

Thanks for your help, tested and is working now..


Moataz Hussein
Show quoted textHide quoted text
  ----- Original Message ----- 
  From: Don Kinzer 
  To: AVR-Chat@yahoogroups.com 
  Sent: Thursday, May 21, 2009 5:40 PM
  Subject: [AVR-Chat] Re: Branchging intsruction-- BRMI





  --- In AVR-Chat@yahoogroups.com, "Gmail" <moatazhussein@...> wrote:
  > I want to branch at a certain part of the program when a
  > register (Temp) value is greater than or equal to $FA.
  I doubt that BRMI is the instruction you should be using. It would more commonly be used when the operands are signed values. Instead, look at BRSH (branch if same or higher). It works just as well following a subtract instruction as it does following a compare instructions. After all, a compare is just a subtract that doesn't save the result.

  Note, particularly, that BRSH is used for unsigned values while BRGE is used for signed values.

  > It is not working as understood, i see other flags are
  > also affected. there is something that i do not see!!
  You need to consult the "AVR Instruction Set" document available from the Atmel site. For SUBI, it indicates that all status flags except I and T may be modified.

  Here is a link to the instruction set document:
  http://www.atmel.com/dyn/resources/prod_documents/doc0856.pdf

  Don Kinzer
  ZBasic Microcontrollers
  http://www.zbasic.net



  

[Non-text portions of this message have been removed]

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.