Timer Counter 3 Interrupt

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Pepsi helped me get my code to compile. Now I don't seem to get my interrupt interrupting. I'm trying to get an interrupt every so often. In previous programs I've used timer 1 for this, but now I want to use the output capture dealy on timer 1 for something else. If I move the junk code from the interrupt routine to the Reloop, it runs.

Let's see the salient code. Perhaps I'll figure it out while making the post.
Ok, here's the whole program :roll:

.include "m162def.inc"

.def scratch =r16
.def CurrentSpeed = r17
.def DesiredSpeed = r18
.def CurrentDirection = r19
.def DesiredDirection = r20

.cseg ;CODE Segment
.org 0
rjmp reset ;Reset vector

.org TIMER3OVFaddr ; Timer 1 overflow vector
rjmp timer3interrupt

reset: ; Here on reset
ldi r16,high(RAMEND) ;Intialize stackpointer
out SPH,r16
ldi r16,low(RAMEND)
out SPL,r16
ldi scratch, 0
out MCUCR,scratch ; Disable Sleep
out DDRA,scratch ; Set all port A pins to input
ldi scratch,4 ; Port B just the cap control pin is output.
OUT DDRB,scratch
LDI scratch,255 ; Port D is output
OUT DDRD,scratch
CALL InitTimers
SEI ; Enable Interrupts
ReLoop:
RJMP Reloop

InitTimers:
; Timer 3 is timebase for opperations

ldi scratch,0b00000000 ; Timer 3 for accelleration
STS TCCR3A,scratch
ldi scratch,0b00000101 ; TCCR21B Clock / 1024
STS TCCR3B,scratch
CALL SetTimer3
ldi scratch,0b00000100 ; Enable overflow interrupt on Timer 3
STS TIMSK,scratch
RET

SetTimer3:
ldi scratch,255 ; -55 counts from overflow
STS TCNT3H,scratch
ldi scratch,200
STS TCNT3L,scratch
RET

Timer3Interrupt:

PUSH scratch

INC DesiredSpeed ; Just to see if something's happening
OUT PORTD,DesiredSpeed

;Toggle the capacitor bit
BST CurrentSpeed,2
BRTC NotSet
LDI CurrentSpeed,0
OUT PORTB,CurrentSpeed
RJMP DoneCBit
NotSet:
LDI CurrentSpeed,4
OUT PORTB,CurrentSpeed
DoneCBit:
CALL SetTimer3
POP scratch
SEI
RETI

The largest known prime number: 282589933-1

It's easy to stop breaking the 10th commandment! Break the 8th instead. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Timer counter 3 interrupt masks are in the "Extended Timer/Counter Interrupt Mask Register – ETIMSK".

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks.

I'm not at all fluent in AVRish yet :oops:

The largest known prime number: 282589933-1

It's easy to stop breaking the 10th commandment! Break the 8th instead.