Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Atmega32 Timer0

Status
Not open for further replies.

Haricharan

New Member
Friends, I am looking for some help in timer0 application. I am using timer0 In CTC mode ie clear timer on compare match. I ILoaded decimal 50 in register OCR0 register And started timer0. As you are aware When a match occurs between TNCT0 and OCR0, a flag OCF0 is set in TIFR register. How to read this bit is my question. The Instruction SBIS TiFR,1 is out of range. I am not enabling any hardware interrupts. I wanted to proceed further by reading the bit OCFO in TIRF register. Kindly advice. Thanks in advance
Best regards
Hari charan
 
Ahhh, didn't realize there were different instructions for registers and I/O.

Mike.
 
Mike sir,
The instruction SBIS TIFR,1 Can be used only on registers having 00 to 31 address TIFR address Is 38. The assembler In Atmel studio 7 Flags it and says out of range. In fact it does not work on registers having addresses more than 31. Friends kindly advise. Thanks in advance
Regards
BJ Haricharan
 
dear friends
I have some problem with Atmega32 Timer0 application. I just wanted the timer0 to give a interrupt when a compare match occurs (CTC) mode. given below is the listing. i am using a Atmel studio 7 simulator. Everything works fine while simulating, but when match occurs between TCNT0 and OCR0, the flag OCF0 is also set in TIFR register bit 1, , and TCNT0 rolls back to 00 and starts again. but the program doesn't go to its vector address $0014. I have enabled SEI as well as CTC interrupt. ?. Kindly help thanks in advance
regards
BJ Hari charan


; soap.asm
; Author : BJ Hari; 5147d = 141Bh
;
;INCLUDE "M32DEF.INC"

.ORG $000

JMP START
.ORG $0002
;JMP SER_INTER

.ORG $0014
JMP MATCH

.ORG $75
START:
LDI R16,HIGH(RAMEND)
OUT SPH,R16
LDI R16,LOW(RAMEND)
OUT SPL,R16
;********Serial port intializasion***********
LDI R16,(1<<RXEN)|(1<<TXEN)
OUT UCSRB,R16
LDI R16,(1<<UCSZ1)|(1<<UCSZ0)|(1<<URSEL)
OUT UCSRC,R16
LDI R16,39
OUT UBRRL,R16
LDI R16,$00
OUT UBRRH,R16
;***not used***interrupt intialisation**********
;SBI DDRC,3 ;
;SBI PORTD,2 ; pull up resistor
;LDI R20,(1<<INT0)
;OUT GICR,R20
;SEI
;WAIT:
;RJMP WAIT
;********************************************
;**Trigger Ultrasonic***PORT A AS OUTPUT INTIALISATION*****

SBI DDRA,3 ; OUT PUT
SBI DDRA,4
SBI PORTA,3;LED PULSE
CALL DELAY
CALL DELAY
CALL DELAY
CBI PORTA,3;LED PULSE OFF
SBI PORTA,4

MINI_DLAY:
LDI R17,70
NOP
COUNT:
DEC R17
BRNE COUNT
NOP
CBI PORTA,4

;********Timer0 intialisation****+ Start******
LDI R16,(1<<OCIE0) ; COMPARE MATCH INTERUPT ENABLE FOR TIMER0
OUT TIMSK,R16
SEI

LDI R20,00
OUT TCNT0,R20 ;
LDI R20,$0C ; FOR MATCHING
OUT OCR0,R20
LDI R20,$09; B; 0B00100011; CTC mode; CLOCK DIV BY 64
OUT TCCR0,R20; start timer0

FIND:
RJMP FIND

;**Hex to BCD*********DIV 1000*********03ff**
LDI R23,$03
LDI R22,$db
LDI R21,$03 ;small r23 r22 03FF
LDI R20,$0E8 ;r21 r20 03E8= 1000
REPEAT1:
STS TEMPH,R23
STS TEMPL,R22
SUB R22,R20 ; remainder R23,R22
SBC R23,R21 ;
BRCC next1 ; branch on no carry
RJMP next2
next1:
INC R18
STS digit3,R18
RJMP REPEAT1
next2:
;*******Div by 100********
LDS R23,TEMPH ;get old R23,R22
LDS R22,TEMPL
LDI R21,$00 ;
LDI R20,$64 ;100
Repeat2:
STS TEMPH,R23
STS TEMPL,R22
SUB R22,R20
SBC R23,R21
BRCC next3
RJMP next4
next3: INC R18
STS digit2,R18
RJMP Repeat2
next4:
;***********Div by 10 *****
LDI R18,0
LDS R23,TEMPH ; get old values
LDS R22,TEMPL
LDI R21,0
LDI R20,10
Repeat3:
STS TEMPH,R23
STS TEMPL,R22
SUB R22,R20
SBC R23,R21 ;div by 10
BRCC next5
LDS R23,TEMPH
LDS R22,TEMPL
STS digit0,R22; REMINDER
Hang:
RJMP Hang
next5:
INC R18
STS digit1,R18
RJMP Repeat3

CHECK: ;WAIT FOR TIMER0 MATCH
RJMP CHECK; STOP Here after Compare match interrup

;**************************************************
SER_INTER:
;************************************************
LDI R16,$FF
OUT DDRB,R16 ;Port B output
LDI R22,$00
OUT PORTB,R22

LDI R22,$FF
OUT PORTB,R22; toggle led
CALL DELAY
CALL DELAY
CALL DELAY
LDI R22,$00
OUT PORTB,R22;off

LDI ZH,HIGH(EXTRACT<<1)
LDI ZL,LOW(EXTRACT<<1)
AGAIN1:
LPM R20,Z
TST R20

BREQ OVER
CALL TRANSMT
INC ZL
RJMP AGAIN1
OVER:
RETI
;*******************
NOP
;*******************
TRANSMT:
SBIS UCSRA,UDRE
RJMP TRANSMT
OUT UDR,R20
CALL DELAY
RET
;********************
DELAY:
LDI R23,200
AGAIN:
LDI R24,255
HERE:
NOP
NOP
NOP
DEC R24
BRNE HERE
DEC R23
BRNE AGAIN
RET
;********************
.ORG $200
EXTRACT:

.DB $1F,$11," BJ HARICHARAN",$00

MATCH:
LDI R18,8
OUT TCCR0,R18 ; STOP TIMER0
RETI

 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top