If Thens getting stuck behind waitcnts
mattbutsko
Posts: 8
So I'm still working on that clock, and it's really coming along, but I've got a slight problem. I enabled two buttons that change the hours and minutes. Problem is, in order to make the time change slow enough, I have to add to waitcnt commands inside the buttons' IFs. This causes the limiter if blocks to get stalled, which allows 13 to be seen briefly before changing to 1. (the limiter checks to see if the clock is displaying 13:00 and changes it to display 1:00 instead.) Since it get's stuck behind the "waitcnt(clkfreq/3 + cnt)", you still see 13:00 for a third of a second before it changes over to 1:00.
Is there any way I can run the checkers without them getting delayed? Preferably without launching a new cog altogether? Thanks for looking.
Is there any way I can run the checkers without them getting delayed? Preferably without launching a new cog altogether? Thanks for looking.
PUB changetime dira[24..25] := %00 repeat if ina[25] == 1 hours01 +=1 waitcnt(clkfreq/3 + cnt) if ina[24] == 1 minutes01 +=1 waitcnt(clkfreq/5 + cnt) if minutes01 == 10 minutes10+=1 minutes01 := 0 if minutes10 == 6 minutes10 := 0 if hours01 == 10 hours01 := 0 hours10+=1 if hours10 == 1 ' Keeps the time from going past 12 o'clock if hours01 == 3 hours10 := 0 hours01 := 1
Comments
Note: I assume that you've got some other cog that's continually updating the display from the hours10, hours01, etc. variables. There's still a very short window between the changes to each of the two digits where the display cog may briefly flash the wrong digit combination sometimes. This is where the semaphores (lockXXX statements) are intended to be used. Another option is to store all the 4 digits in one long and update it all at once. That way the display cog will only see correct digit combinations since the whole long is updated in a single operation.
Just thoughts,
Frank
In addition, if you use a single minute value and hour value, you could do your increments like this:
That way you only have to handle a single roll-over. The modulo operation (which I *think* is //) returns the remainder of a division. So, 62 modulo 60 is 2, 14 modulo 10 is 4, and so on. By keeping the "hour" value from 0 to 11 you can use the modulo operation to handle wrapping it around instead of using an if statement.