Hi,
The program itself is fine at the 12 to 0 changeover, but with a DEADBAND, it complicates things.
Ioannis suggested Modulus also using a 24Hr clock.
After trying to get to know Modulus, for a while, I can only guess, that it won't correct my problem. The problem is a DEADBAND, so 'say' 3 with a DEADBAND of 1 would be 2 to 4. At o it will be -1 to 1. I don't get the impression that Modulus works with minus numbers.
I experimented with the 24 hour clock, and as the clock goes round and round, eventually it will be 24 then 0 again, so a similar problem. I finally only use 24Hr for a small section around 12 or 0. then revert back to 12 hour, this works fine.
Thanks for all suggestions, C.
Normally you won't count to 24 but up to 23:59. But I have missed the point of -/+1 here.
Ioannis
Hi I,
My actual system uses 0 to 3581 steps, but that's complicating thingsThis is why I used the clock analogy. And yes, it is 0 to 23:59, but again this is complicating things, as there are 60 minutes/hour. So I'll use 0 to 11.
The mechanics of my system: A motor moves the pointer to the incoming data, so if it is pointing to 3 and data says 4 then it moves cwise till it matches. The motor moves quickly, so as it comes towards 4 it needs to switch off the motor, before it matches, so I added a deadband, which gives data -1 and +1, where no power to the motor within this band. Now say the pointer is at 3 and data says 5 the pointer is moves cwise and switches the power off at 4. In this example, this looks coarse, but in reality, it is much finer.
I hope this clarifies things.
C.
Hi,
Try this:/Henrik.Code:Position VAR WORD Target VAR WORD Distance VAR WORD Position = 1234 Main: HSEROUT[13, "You're at position: ", DEC Position, 13] HSEROUT["Enter new target: ",13] HSERIN[DEC Target] ' Actual calculation starts here. ' When done the variable Distance contains the ' number of "ticks" to target in two's complement format. Distance = Target - Position IF Distance.15 = 0 THEN ' Distance is positive If Distance > 1790 THEN Distance = Distance - 3580 Endif ENDIF IF Distance.15 = 1 THEN ' Distance is negative IF ABS Distance > 1790 THEN Distance = Distance + 3580 ENDIF ENDIF ' End of calculation, result now in Distance. Done: IF Distance.15 = 1 THEN ' Distance is negative HSEROUT["CCW "] ELSE HSEROUT["CW "] ENDIF HSEROUT[DEC ABS Distance, " ticks.", 13] Position = Target Goto Main
Hi H,
Thank you, I will try it and let you know what happens. I'm a bit slow understanding code though
Will you annotate where the DEADBAND is in your code please?
C.
There's no deadband but it's easy enough to add that after the actual calculation, before you decide to move or not/Henrik.Code:IF ABS Distance > Deadband THEN ' Make the move ELSE ' Sit tight ENDIF
Bookmarks