lord loh.
Member
I am trying to simulate the 16bit timer on Atmega8535. I have enabled the global interrupt enable and also the Interrupt on Timer1 overflow. My interrupts are also working fine but the TOV1 flag is never set. I put the break points at the right places to see the flag conditions on AVR Studio. If I manually set the flag, the interrupt occurs. But undernatural free running simulation, the OCF1A (Compare Register A match) flag is set. However the OCF1B is never set. I do not understand the reason for this behaviour.
Please help.
The code
main.asm
macros.inc
Please help.
The code
main.asm
Code:
.EQU Xtal=8
.NOLIST
#include<m8535def.inc>
.include"macros.inc"
.LIST
.CSEG
;Interrupt Vector Table
.ORG 0x000
rjmp main ;Reset Vector
.ORG 0x008
rjmp timer1_ovf ;Timer1 Overflow
.ORG 0x00E
rjmp adccomplete ;ADC conversion Complete.
;Main Subroutine
.ORG 0x015
main:
ldi r16,HIGH(ramend) ;Init. Stack pointer
out sph,r16
ldi r16,LOW(ramend)
out spl,r16
bset SREG_I ;Enable Global Interrupt
rcall loadtimer
ldi r16,$04 ;Enable Timer1 Overflow Interrupt.
out timsk,r16
ldi r16,$00
out tccr1a,r16
ldi r16,tccr1b_value ;Start Timer1
out tccr1b,r16
terminate: rjmp terminate ;END Programme here.
;Timer1 Overflow Interrupt service routine
timer1_ovf:
nop
nop
reti
;ADC Conversion Complete service routine
adccomplete:
reti
;Other Subroutines
loadtimer:
;F424 counts @8MHz and prescale 64 accounts for 0.5s
;0DBD to FFFF accounts for F424
ldi r16,$0D
out tcnt1h,r16
ldi r16,$BD
out tcnt1l,r16
ret
macros.inc
Code:
//Half Second count Values @ some prescaler settings
.IF (xtal==8)
.EQU COUNT=0x0DBD
.EQU PRESCALE=0x03 ;prescale 64
.ELIF (xtal==1)
.EQU COUNT=0x0DBD
.EQU PRESCALE=0x02 ;prescale 2
.ENDIF
.SET tccr1b_value=PRESCALE