| Author |
Message |
sturgessb
Joined: 25 Apr 2008
Location: Norwich, UK
|
|
Posted: 26 September 2009, 22:50 PM Post subject: Timer1 CompA ISR |
|
|
Hi all
Im trying to get a an ISR to fire every time Timer1 Reaches a certain value.
I have the following code but its just freezing up the zx (128ne)
| Code: |
Register.TCCR1A = bx0000_0000
Register.TXXR1B = bx0000_0011
Register.TIMSK = bx0001_0000
Register.OCR1AL = 0
Register.OCR1AH = 0
|
and this is the ISR
| Code: |
ISR TIMER1_COMPA()
debug.print "compare match"
END ISR
|
What am i doing wrong?
Cheers
ben |
|
| Back to top |
|
 |
sturgessb
Joined: 25 Apr 2008
Location: Norwich, UK
|
|
Posted: 27 September 2009, 11:11 AM Post subject: |
|
|
I have also tried it on the zx24n with the following code....
| Code: |
Sub InitTimer()
Register.TCCR1B = bx0000_0100
Register.TIMSK1 = bx0000_0010
Register.OCR1AL = 0
Register.OCR1AH = 0
Register.TCNT1L = 0
Register.TCNT1H = 0
End Sub
ISR Timer1_CompA()
debug.print "MATCH"
END ISR
|
And still nothing.........?
Ben |
|
| Back to top |
|
 |
pjc30943
Joined: 02 Dec 2005
|
|
Posted: 27 September 2009, 23:05 PM Post subject: |
|
|
[Unhelpful comment deleted in light of Mike's reply...]
Last edited by pjc30943 on 28 September 2009, 21:15 PM; edited 1 time in total |
|
| Back to top |
|
 |
mikep
Joined: 24 Sep 2005
Location: Austin, TX
|
|
Posted: 28 September 2009, 5:38 AM Post subject: |
|
|
I wouldn't use debug.print for production code but it is ok to get something going. I'm away from my office at present so I don't have a device to test with. I compared your registers to the datasheet. There are two things missing:
1. You need to use CTC mode which WGM12 (bit 4) in TCCR1B.
2. You need to use a non-zero value in OCR1. For the prescaler you have chosen of 64, I would suggest a hex value of 1C2 to get 512 interrupts per second. The math is 14745600/(512*64) = 450 = 0x1C2.
Similarly for the mega644p in the ZX-24n. |
|
| Back to top |
|
 |
dkinzer Site Admin
Joined: 03 Sep 2005
Location: Portland, OR
|
|
Posted: 29 September 2009, 3:28 AM Post subject: |
|
|
| mikep wrote: | | I wouldn't use debug.print for production code but it is ok to get something going. | I would vociferously recommend against using Debug.Print in an ISR under any conditions. The problem is that in an ISR interrupts are disabled. If the Com1 output queue is full, Debug.Print will wait for space to become available but, since interrupts are disabled, space will never become available.
A better strategy is to turn on an LED, or just toggle an I/O line and monitor it with a logic probe, logic analyzer, oscilloscope, etc. Any other indicator that you can think of that doesn't require interrupts to be serviced will also work. |
|
| Back to top |
|
 |
mikep
Joined: 24 Sep 2005
Location: Austin, TX
|
|
Posted: 29 September 2009, 5:50 AM Post subject: |
|
|
| dkinzer wrote: | | The problem is that in an ISR interrupts are disabled. If the Com1 output queue is full, Debug.Print will wait for space to become available but, since interrupts are disabled, space will never become available. | Good point.
I never usually have to debug my ISRs in any case as they work first time because they are so short  |
|
| Back to top |
|
 |
sturgessb
Joined: 25 Apr 2008
Location: Norwich, UK
|
|
Posted: 29 September 2009, 13:48 PM Post subject: |
|
|
Ok ill change it to an LED flash.
and add the missing Bit.
Thanks |
|
| Back to top |
|
 |
|