Author Topic: I'm having trouble with my crystal timer interrupts  (Read 3554 times)

0 Members and 1 Guest are viewing this topic.

Offline Hot_Dog

  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3006
  • Rating: +445/-10
    • View Profile
I'm having trouble with my crystal timer interrupts
« on: August 16, 2011, 01:10:38 am »
Here's my problem: In my program, the calculator seems to be relying on the hardware timers.  I don't think that the crystal timer is generating interrupts.

I know that I'm doing something wrong, but I don't know what it is.  Below is the following code: My interrupt routine, and the code that initalizes the first crystal timer to generate interrupts.  Please don't comment on how my code could be optimized, because that's something I plan to work on once I get this thing working

Code: [Select]

TurnOnInterrupts:

ld a, $80
out ($10), a

ld a, 3 ;3 resets the timer each time.
ld hl, plotsscreen
ld de, 11 ;Add to hl each time
ld b, 64
ld c, $11
ex af, af'
exx

ld c, $10
ld a, $20
ld (copycolumn), a
_
in f, (c)
jp m, -_
out ($10), a

ld a, $80
out ($30), a

ld a, 3
out ($31), a
im 2
ei
ld a, 100
out ($32), a

             ret


Interrupt Routine:


exx ;4
ex af, af' ;4
out ($31), a ;11
dec c ;4
_
in f, (c)
jp m, -_

inc c
outi




add hl, de ;11
exx ;4
jr z, _ ;7
ex af, af'
;ei
ret ;10
_


;Here, go to the next row of the screen

exx

push af
ld a, (copycolumn)
inc a
ld (copycolumn), a

cp $2c

;If $2C, turn off interrupts and timers

jr z, EndCopy


dec h
dec h
dec h
inc hl

_
dec c
in f, (c)
jp m, -_

out ($10), a
inc c
ld b, 64
exx


ld a, $80
out ($30), a

ld a, 3
out ($31), a

;ld a, 80
;out ($32), a
pop af

ex af, af'
;exx
;ei
ret


EndCopy:

exx
xor a
out ($30), a
out ($31), a
di
pop af
ex af, af'
ret









Offline thepenguin77

  • z80 Assembly Master
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1594
  • Rating: +823/-5
  • The game in my avatar is bit.ly/p0zPWu
    • View Profile
Re: I'm having trouble with my crystal timer interrupts
« Reply #1 on: August 16, 2011, 01:22:21 am »
Well, I think I see two problems, one is probably pretty serious though.

1. You need that EI in your interrupt routine, interrupts start with interrupts disabled so that your calculator doesn't endlessly interrupt and stack overflow.

2. This one you're not going to like, but it's a fact of life. The interrupt routine takes 19 t-states to complete. So take your current interrupt t-states and add 19 to them. This would imply that the next interrupt will be firing before the current one finishes, so while that won't stop the interrupts from working, it just means that it will instantly reloop without executing regular instructions.


The way you set up the crystal timers looks good though, I'd just put that EI after the OUT to ($32).

Edit:
   Also, once the interrupt occurs, I don't think you can throw it away. This means when you go to the next row, things might get a little ugly since you have the interrupt waiting to occur at the next EI.

Edit2:
   Well, it kind of works. You don't need to output to ($30) again. And while I believe you did it for the wrong reason, that second output to ($31) is actually necessary. This is because if you let the crystal timer expire twice, your interrupts die, which means yours will die if you don't intervene within 200 t-states. So the second OUT ($31), A renews this timer for you. Just remember that your EI \ RET is going to instantly go back to your interrupt routine though.
« Last Edit: August 16, 2011, 01:32:33 am by thepenguin77 »
zStart v1.3.013 9-20-2013 
All of my utilities
TI-Connect Help
You can build a statue out of either 1'x1' blocks or 12'x12' blocks. The 1'x1' blocks will take a lot longer, but the final product is worth it.
       -Runer112

Offline Hot_Dog

  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3006
  • Rating: +445/-10
    • View Profile
Re: I'm having trouble with my crystal timer interrupts
« Reply #2 on: August 16, 2011, 10:25:28 am »
Hmmm...I think I get it.  I'll try it out when I have the chance.  I am left with 2 questions though:

1. The first interrupt occurs from hardware timers as opposed to crystal timers.  I assume that it's normal and that there's nothing I can do about it?
2. The 84+ uses two of the three timers.  Which of the three is free to use?

Offline thepenguin77

  • z80 Assembly Master
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1594
  • Rating: +823/-5
  • The game in my avatar is bit.ly/p0zPWu
    • View Profile
Re: I'm having trouble with my crystal timer interrupts
« Reply #3 on: August 16, 2011, 11:31:08 am »
1. The first interrupt occurs from hardware timers as opposed to crystal timers.  I assume that it's normal and that there's nothing I can do about it?

You could turn the regular interrupts off. "XOR A \ OUT (03), A". After the out, you won't have another normal interrupt until you restart port 3.

Quote
2. The 84+ uses two of the three timers.  Which of the three is free to use?

All three are always free to use. The OS does use two timers, but that is only during USB stuff. I'm not really sure how the rumor got started that you can only use one of them, because you can use all three at any time. I guess the only time you couldn't is if you are in a hook, but you shouldn't use them in a hook anyways.
zStart v1.3.013 9-20-2013 
All of my utilities
TI-Connect Help
You can build a statue out of either 1'x1' blocks or 12'x12' blocks. The 1'x1' blocks will take a lot longer, but the final product is worth it.
       -Runer112

Offline Hot_Dog

  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3006
  • Rating: +445/-10
    • View Profile
Re: I'm having trouble with my crystal timer interrupts
« Reply #4 on: August 17, 2011, 10:58:17 am »
The interrupts/timers are working perfectly now, but apparently something else is wrong.  On Wabbitemu the interrupt routine successfully copies all of plotsscreen, but on actual hardware only the first 2 1/2 columns are copied.  Here's my modified interrupt routine.  Again, please leave out comments of optimization.

Code: [Select]
Interrupt Routine:


exx
ex af, af'  
out ($31), a
dec c
_
in f, (c)
jp m, -_

inc c
outi




add hl, de
exx
jr z, _
ex af, af'
ei
ret
_


;Here, go to the next row of the screen

exx

push af
ld a, (copycolumn)
inc a
ld (copycolumn), a

cp $2c

;If $2C, turn off interrupts and timers

jr z, EndCopy


dec h
dec h
dec h
inc hl
             dec c
_

in f, (c)
jp m, -_

out ($10), a
inc c
ld b, 64
exx


ld a, $80
out ($30), a

ld a, 3
out ($31), a

ld a, 155
out ($32), a
pop af

ex af, af'
exx
ei
ret


EndCopy:

exx
xor a
out ($30), a
out ($31), a
di
pop af
ex af, af'
ret
« Last Edit: August 17, 2011, 11:27:43 am by Hot_Dog »

Offline thepenguin77

  • z80 Assembly Master
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1594
  • Rating: +823/-5
  • The game in my avatar is bit.ly/p0zPWu
    • View Profile
Re: I'm having trouble with my crystal timer interrupts
« Reply #5 on: August 18, 2011, 11:14:12 am »
Well, I see one of two things happening:
1. Your interrupt routine is relapsing in on itself. I don't think this is the problem, as it would probably cause a crash, but we can't rule it out.
2. You are restarting this whole sequence before it finishes. This would make sense as it is cleanly drawing stuff and just stopping.

The reason for this is because your calculator is not as good hardware wise as wabbitemu. I don't think wabbitemu emulates the 19 t-state delay I talked about and wabbitemu's screen only requires 60 t-states of delay after a write, (and I'm not positive, but I think this is regardless of speed), so what that means is that your program is finishing much quicker on wabbitemu and therefore has time to finish updating the screen.

Or I could be completely wrong. ;D
zStart v1.3.013 9-20-2013 
All of my utilities
TI-Connect Help
You can build a statue out of either 1'x1' blocks or 12'x12' blocks. The 1'x1' blocks will take a lot longer, but the final product is worth it.
       -Runer112

Offline Hot_Dog

  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3006
  • Rating: +445/-10
    • View Profile
Re: I'm having trouble with my crystal timer interrupts
« Reply #6 on: August 18, 2011, 11:24:43 am »
No, I think you're right :)   The sequence was restarted before it finished.