Pause using 1/2 as duration mystery
T Chap
Posts: 4,223
I was looking for ways to get a shorter Pause than 1ms, which I have been told is the shortest duration available for pause times. I just tried using a variable for Pause duration called PauseTime. The resuslts are strange in that using the code below, the time it takes to run the loop is as follows:
(Measure starting at count 1 on release of reset on demo board)
PauseTime = 0 5 seconds approx
PauseTime = 1 5 seconds
PauseTime = 1/2 close to 3 seconds
PauseTIme = 1/3 or smaller 3 seconds
I guess it really is dividing the pause time in half, although there is some slight variance with my counting(without a stopwatch). What is going on here?
COUNTER VAR WORD
PauseTime VAR BYTE
PulseCount = 0 'Zero out PulseCount
'PauseTime = 0
PauseTime = 1/2
'PauseTime = 1
MAIN:
FOR counter = 1 TO 1000
Mstep = 1
PAUSE pausetime
DEBUG "*"
Mstep = 0
PAUSE pausetime
DEBUG "-"
NEXT
DEBUG ? counter
END
(Measure starting at count 1 on release of reset on demo board)
PauseTime = 0 5 seconds approx
PauseTime = 1 5 seconds
PauseTime = 1/2 close to 3 seconds
PauseTIme = 1/3 or smaller 3 seconds
I guess it really is dividing the pause time in half, although there is some slight variance with my counting(without a stopwatch). What is going on here?
COUNTER VAR WORD
PauseTime VAR BYTE
PulseCount = 0 'Zero out PulseCount
'PauseTime = 0
PauseTime = 1/2
'PauseTime = 1
MAIN:
FOR counter = 1 TO 1000
Mstep = 1
PAUSE pausetime
DEBUG "*"
Mstep = 0
PAUSE pausetime
DEBUG "-"
NEXT
DEBUG ? counter
END
Comments
If you want better control over your pauses, you can send the PULSOUT command to an unused I/O pin. For example, PULSOUT 1, 0, results in about a 210 us delay. Since PULSOUT command's Duration argument specifies the number of 2 us increments the pulse should last on the BASIC Stamp 2, you can use the fact that the PULSOUT command itself takes 210 us to create delays with a finer resolution than the PAUSE command's 1 ms Duration time increments.
For example, let's say your application needs a 1.5 ms (1500 us) pause. For a 1.5 ms pulse, you would use PULSOUT 1, 750 because 750 x 2 us = 1500 us = 1.5 ms. Since the BASIC Stamp 2 execution time for a PULSOUT command is about 210 us, subtract 105 (2 us per PULSOUT Duration unit) from 750. The result (PULSOUT 1, 645) should give you a delay that's very close to 1.5 ms.
Lee Harker
Using Pause it is simple, just use:
STEP VAR Out1
PauseTime VAR BYTE
Counter VAR Word
PauseTime = 255
RampUp:
For counter = 1 to 255
PauseTime = PauseTime -1
STEP = 1
PAUSE PauseTime
STEP = 0
PAUSE PauseTime
Next
GOTO Speed1Dir1
Speed1Dir1:
PauseTime = 1
For counter = 1 to 40000
STEP = 1
PAUSE PauseTime
STEP = 0
PAUSE PauseTime
Next
GOTO RampDown
etc etc
This makes the pauses very slow at dirst on rampup, then after every pulse the pause is reduced, so that after 255 pulses, pausetime is at 1, wqhich is full spped on the stepper.
Can something similar be written using PULSEOUT using a variable for duration?
I don't really know of a way to get that kind of timing without that kind of tinkering. The SX·and Propeller microcontrollers both have features that will give you much more control over your stepper motor timing.
COUNTER VAR WORD
PauseTime VAR WORD
OUT0 = 0
main:
counter = 0
pausetime = 10000
FOR counter = 1 TO 1000
PAUSEtime = PAUSEtime -10
PULSOUT 0, PAUSEtime
DEBUG "-"
NEXT
DEBUG "done"
END