joliebrise
New Member
Module 8 is part of the control system for my servoless self tailing winch. It counts the number of rotations of the shaft to let the sail sheet out (forwards) and pull it in (reverse). Total sheet travel is seven turns = 7 x 12 slots on the disc = 84 pulses.
To set the counter to zero, the sail sheet is left fully in when turning the power off. The counter is set to zero when the power is turned back on. b1 = 0 (reset facilities may be required).
The position of the Joystick controlling the separate Speed Controller module 12 can be used to set the direction of shaft rotation. Above 1.5ms = forwards and below = reverse. This avoids to complication of having multiple sensors, see Quadrature Encoders in previous module.
The direction can be sent to the counting module as a High = forwards or low = reverse on pin4. A switch can be used to simulate this input to test its validity.
The output pins 1 and 2 signals are sent back to the speed controller to stop the motor and to restrict the motor to turn only in certain directions.
Results
When the shaft turns forwards 84 slots, it turns the output pin1 on sending a High (green led) to the speed controller turning off the motor and restricting any forwards motion. However, when the shaft is reversed, the forwards output signal (green led) is not turned low so the motor cannot rotate forwards when needed.
Question
I tried putting “if counter > 80 then low 1” in “countingback” to put the output low when counter was less than 80 but the whole code stopped working.
I am wondering if there should be only one count routine with only the inc/dec line change dependant on pin4 being high INC or low DEC. Any suggestions?
Code:
symbol MOTOR = pin4
symbol SLOT = pin3
symbol counter = b1
counter = 0
main:
if MOTOR = 1 then forinput ; high input from speed controller motor forwards
if MOTOR = 0 then backinput ; low input from speed controller motor reverse
forinput:
if SLOT = 1 then countingfor
if SLOT = 0 then forinput ; waits for input high
countingfor:
do
loop while SLOT = 1 ; Sit here while pin3 is high
inc counter ; increment by +1
if counter>84 then high 1 ; check for condition b1 higher than 84 then green
endif
goto main ; loop back waiting for the next high/low
backinput:
if SLOT = 1 then countingback
if SLOT = 0 then backinput ; waits for input high
countingback:
do
loop while SLOT = 1 ; Sit here while pin3 is high
dec counter ; increment by -1
if counter<6 then high 2 ; check for condition b1 less than 6 then red
endif
goto main ; loop back waiting for the next high/low
Last edited: