Posted by Jerry Eckert.
Engineer from Looking for a team in Raleigh, NC sponsored by .
Posted on 1/24/2000 12:11 AM MST
In Reply to: Re: Programing help… posted by Nate Smith on 1/23/2000 11:49 AM MST:
First, I second the previous comment that using a software timing loop to control the motor operation is not a wise thing to do. It is not a very precise control mechanism - you will be much better off using some type of mechanical limit switch or sensor such as a reed switch or the optical sensor (if they are included in the kit this year).
There are two errors in the example program:
(1) The initialization code is run each time through the loop while the trigger is depressed. This causes the motor to start running when the trigger is depressed, but the timer doesn’t start until the switch is released.
(2) The termination test will not work properly if packet_num is .leq. 15 when the timer starts (i.e., end_packet does not wrap).
Also, you can save some bytes and cycles by inverting the sense of the tests. For example, instead of.
IF a = 1 THEN L1
GOTO L2
L1:
foo
L2:
bar
Use the following:
IF a = 0 THEN L2
foo
L2:
bar
Here’s a rewritten version of the example program.
IF motor_running = 1 THEN check_time
IF trigger = 0 THEN skip_check ’ nothing to do
’
’ Initialize the timer
’
motor_running = 1 ’ turn motor on
start_packet = packet_num
end_packet = packet_num + (run_time * 40)
test_wrapped = 0 ’ assume end_packet didn’t wrap
IF end_packet .gt. start_packet THEN skip_check ’ don’t need to check time because we just turned on
test_wrapped = 1 ’ bad assumption
GOTO skip_check ’ don’t neet to check time this time through
CHECK_TIME:
BRANCH test_wrapped, [L1, L2]
L1: ’ test_wrapped = 0
IF packet_num .geq. start_packet AND packet_num .lt. end_packet THEN skip_check ’ not time yet
GOTO motor_off
L2:
IF packet_num .geq. start_packet OR packet_num .lt. end_packet THEN skip_check ’ not time yet
MOTOR_OFF:
motor_running = 0
SKIP_CHECK:
*** NOTES ***
(1) In the above ‘.geq.’ is greater/equal, .lt. is less than. Three quarters of this posting was eaten when I used the symbols, presumably because the ^&$^ applicating tried to parse them as HTML tags.
(2) START_PACKET and END_PACKET are declared as bytes; MOTOR_RUNNING and TEST_WRAPPED are bit variables.
(3) RUN_TIME can be either a constant or variable containing the time delay in seconds. The maximum value is limited by the delay between consecutive executions of the code loop. The code provided assumes that if the motor is running and not being turned off, that the next loop will execute before PACKET_NUM wraps past START_PACKET.
(4) The constant 40 used in computing END_PACKET is based a statement made in a previous reply that PACKET_NUM is incremented approximately 40 times/second. Your mileage may vary.
Jerry
(Sorry for not including the note I am replying to, but it was mangled by the HTML parser…)