Generating a time interval in assembly
Paul M
Posts: 95
I have an assembly loop which runs at about 50us per loop. I want to also run a chunk of code every second or so.
The following code snippet sort of works except of course when the value of cnt+_Gate results in an overflow. Using signed maths makes things worse. I suppose I could test for the overflow, set a flag, and then do some tests before comparing cnt_ with cnt......
Or is there a simpler solution?
The following code snippet sort of works except of course when the value of cnt+_Gate results in an overflow. Using signed maths makes things worse. I suppose I could test for the overflow, set a flag, and then do some tests before comparing cnt_ with cnt......
Or is there a simpler solution?
DAT mov cnt_, cnt 'setup time interval add cnt_, _Gate '_Gate is initialised elsewhere ' "the value of _Gate">>"time to execute entire loop" loop 'do stuff every time round the loop 'check if interval has elapsed mov temp, cnt cmp temp, cnt_ wc 'C flag set if cnt_ > temp if_c jmp #over 'interval has not elapsed 'do other stuff approximately every _Gate ticks ' ' mov cnt_ , cnt add cnt_ , _Gate 'set up next interval over 'do yet more stuff ' ' ' jmp #loop
Comments
Note that the comparison looks "backward" -- this is required because phsb cannot be used in the destination field of cmp.
Of course, when signal is detected (a DMX byte has been rx'd), the timer is reset by clearing phsb.
@JonnyMac Just out of interest, how do you do what I was trying to do using signed maths - I just couldn't get it to work properly whatever combination of ADD, ADDS, CMP, CMPS etc. that I used?