Normally you won't count to 24 but up to 23:59. But I have missed the point of -/+1 here.
Ioannis
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
Have you tried it?
Using your numbers with 3580 ticks around the circle:
If you're moving from 0 to 11 distance is +11.
If you're moving from 11 to 0 distance is -11.
In both cases the ABSolute value of distance is 11. If you have deadband set to 1 then you'll move because distance is larger than deadband.
If you're moving from 11 to 12 distance is +1.
If you're moving from 12 to 11 distance is -1.
In both cases the ABSolute value of distance is 1. If you have deadband set to 1 then you won't move because distance is not larger than deadband.
/Henrik.
Bookmarks