System Clock issue... I think
CannibalRobotics
Posts: 535
Hi all,
I am using this loop to hold for a precision pulse delay. It works great for awhile then the loop just·hangs for several minutes then starts back up again working beautifully. It runs for a while then hangs again consistantly repeating this process. I'm·pretty sure·that I'm hitting the zero cross-over on the system clock (cnt) and it's not a·hang but a very long delay increment has been inserted into t2. The t2 counts run·between 72_000 to 152_000. Since the loop does not depend on anything else and the other two calls are rock solid I'm thinking this is the solution.
Any clever ways to avoid this or should I just increment a register based counter that always starts at 0?
Thanks
Jim-
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Signature space for rent!
Send $1 to CannibalRobotics.com.
I am using this loop to hold for a precision pulse delay. It works great for awhile then the loop just·hangs for several minutes then starts back up again working beautifully. It runs for a while then hangs again consistantly repeating this process. I'm·pretty sure·that I'm hitting the zero cross-over on the system clock (cnt) and it's not a·hang but a very long delay increment has been inserted into t2. The t2 counts run·between 72_000 to 152_000. Since the loop does not depend on anything else and the other two calls are rock solid I'm thinking this is the solution.
Any clever ways to avoid this or should I just increment a register based counter that always starts at 0?
Thanks
Jim-
MOV Chan,#0 ' Set Chan to #0 ' End of Loop setup MainLoop MOV t1,buff ' Put Incomming data buffer address on t1 ADD t1,Chan ' Offset buffer Address by channel rdlong t2,t1 ' Read value in address t1 into register t2 ADD t2,CNT ' Add system count to t2 CALL #SetBit ' Turn the pulse on at Chan (16 clock cycles) Call #SendData ' Put it out on the latch (4.7uSec) :MainLoopDelay CMP t2,cnt wc ' compare t2 to system clock set carry if t2 < CNT if_nc jmp #:MainLoopDelay ' if c is not set, have not counted high enough, go round again
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Signature space for rent!
Send $1 to CannibalRobotics.com.
Comments
This is the code used in the serial port for bit timing. The sub and cmp doesn't handle the wrap.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Signature space for rent!
Send $1 to CannibalRobotics.com.
Here's one implementation. "minDelay" has to be the maximum number of system clock cycles needed for everything from the "add t2,cnt" to the "waitcnt" plus a little extra. It provides a "floor" for the time delay. You could leave out the "min t2,#minDelay" if you're certain that the incoming data will never have a delay shorter than the minimum allowed.
What I'm hearing is that if I set #mindelay to a number just greater than the total cycle time of #SetBit and #SendData this should work without the wrapping issue?
Jim-
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Signature space for rent!
Send $1 to CannibalRobotics.com.
Rather than pre-stuff the buffer I decided the safety margin of 'min' was nice. Just in case some other routine jammed a zero in at some inoppertune moment.
Thanks Mike!
Jim-
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Signature space for rent!
Send $1 to CannibalRobotics.com.
I've mentioned before that weird problems with code are often due to problems with initial conditions or assumptions that you've made that that are false. It's a learnable skill to be able to back off and look at your own code as if you were someone else new coming to look at it. It's very useful.