8. Shaft bi-direction counting

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:

techElder

Well-known member
Single track Grey code encoder patent

What you need is called a 'quadrature encoder' and gives you forward and reverse direction indication with the count.

ADDITIONAL CONTENT: Single track Grey code encoder patent

I got interested and read further on quadrature encoders. This patent has an interesting forward (introduction) by the inventor. I know that this would have solved a problem that I had in my past, but that was before it was 'invented'.

The source of the attachment is here: Single track Grey code encoder in Footnote #21.

CREATED NEW THREAD: After rereading the OP, joliebrise wasn't interested in quadrature encoders, so I started a new thread on the subject here.
 

Attachments

Last edited:

fernando_g

Senior Member
Jolie;
first of all, congratulations on your woodworking skills...I wish I had half your skill.
"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." I've not studied your routine in detail, but that is the way I would do it.

One thing I would also do, is to put a backup limit-switch in case the software resets and attempts to pull the winch further than its mechanical travel would allow.
This is not as farfetched as it seems. Imagine you have the winch active and the variable is at the middle of its count, and suddenly a voltage glitch resets the Picaxe. The Picaxe will then reload your variable at 0 and will reach the end of travel before it reaches the end of count.

In this case, the solution posted by whiteknuckles would solve this issue. Even if power fails, the potentiometer's position remains in place.
 

joliebrise

New Member
Thanks for your replys.

The multi turn pot would be a fail safe solution but it would add 40mm to the overall length which is not acceptable. Also it adds a significant cost at £8.

My original designs had micro switches to limit sheet travel but this made the winch 50% bigger and invovled 4 gears, large cam, two micro switches and copious wiring + 10A speed controller costing £30+

I discounted Encodes as sensening the shaft direction can easily be done by taking a signal from the Picaxe motor controller which is under construction.

Using a Picaxe reduces cost and considerable size. It has many uses for model boat builders.

Has anybody got experience in modifying my code.

Tony
 

WHITEKNUCKLES

New Member
Your schematic shows the Slot on pin 4 and your Motor on pin3 which appears to be reversed in your program.

If you include the following then in the simulator your code appears to work forwards and backwards.

Dave

symbol MOTOR = pin3
symbol SLOT = pin4

And

countingback:
low 1
 
Last edited:
Top