Simple count program wanted please.

The bear

Senior Member
Hello Everyone,

My project, is to motorise a garden awning, using a 12 volt car wiper motor.
I have a program, that uses two limit switches.
My friend JPB33 suggested using a counter instead, to simplify the wiring,
it made sense to me.
However, I'm stuck. I 've searched the forums but cannot find anything that works for me.
I would like to be able to count the revolutions of the motor shaft, e.g. say 50 then stop the
motor, awning now fully open. Likewise to close it. I have some sensors.
http://www.vishay.com/docs/83760/tcrt5000.pdf

Program attached. ( Note to Tex, I have used symbols, just hope they are meaningful).
Code:
	;Awning Project 3 (Limit Switches) 21.05.15 65 Bytes
	
	#picaxe 14m2
	#No_data
	
	let dirsC = %000110
	let dirsB = %0111001
	
	symbol paus = 1000 ;mS
	symbol open_switch = pinC.3	;OPEN
	symbol close_switch = pinC.0	;CLOSEsymbol motor_on_open = C.1 
	symbol motor_close = C.2 
	symbol motor_open = C.1
	symbol limit_switch1 = pinB.1 ;Open
	symbol limit_switch2 = pinB.2 ;Close
	low C.1:low C.2
	
main: 
	pause paus
	if open_switch = 1 then		;OPEN switch
	gosub open_awning
	endif
	if close_switch = 1 then	;CLOSE switch
	gosub  close_awning
	endif
	goto main
	
close_awning:
	pause paus 
	high motor_close		;To transistor & relay 2 (Clockwise)
Do until limit_switch2 = 1 ; pinB.2 = 1
loop
	low motor_close		;To transistor & relay 2  (Clockwise)
	pause paus
return

open_awning:
	pause paus 
	high motor_open		;To transistor & relay 1 (Anticlockwise)
Do until limit_switch1 = 1 ;pinB.1 = 1    
loop
	low motor_open	;To transistor & relay 1 (Anticlockwise) 
	pause paus
return
 

The bear

Senior Member
Hi Everyone,
Update/correction: What I failed to mention, was that I would like to replace the two limit switches with a counter or with whatever would do the job.
Any help appreciated.

Regards, Bear..
 

techElder

Well-known member
:D :D :D Made my day! Program is very easy to read!

First, you need some sort of limit switch in case your count routine goes bonkers. Like a garage door has a pressure sensitive reversing cycle if someone gets under the door.

Look on the forum for "grey code" counters and "quadrature" counters.

Quadrature counters allow you to count both up cycle and down cycle.
 

The bear

Senior Member
@ Tex,
Thanks for the praise, and the pointer to quadrature encoders, very helpful.
I've modded the program to suit the application.
Should be attached.

We could do with some global warming, it's 10°/50°F, windy, raining and cold with it.
Regards, Bear.
.
Code:
		;Quad counter
;Here's some pseudo code to get you started: From forum
	#picaxe 08m2
	#No_data
	let dirsC = %0000111
	let b1 = 0
 
 do

			
 do
 loop until pinC.3 = 0
 do
 loop until pinC.3 = 1	;Wait for rising edge of pulse
	high c.2		;motor on
	inc b1	 	;Increment pulse counter
 	if b1 = 10 then	;pulse_count to be adjusted.
	low c.2:stop	;motor off
	endif
 	pause 2000
loop
 

geoff07

Senior Member
Counters will work up to a point, but differing tension on the fabric will mean that the end points wander and the motor may over tighten when closing or not open fully unless you have some kind of limit detection to recalibrate each time it operates. One at the almost-closed position should do it, so not too complicated.

To add to the complexity, however, my awnings use accelerometers to detect high winds, and close them automatically when they are at risk. They are little battery units attached to the outer end rail that send a radio signal to the controller. Without this feature mine would have been destroyed at least once.
 

eggdweather

Senior Member
We have an electric awning and it has limit switches and I would not want to take them off and use them as a fall-back for when things go wrong. The opening an closing on ours is set by two potentiometers and clearly adjust the timing of the motor runs either in or out. It has a full-out position and three intermediate positions, all determined by a timed motor run, you may wish to try emulating that as it would be quite easy. From closed to opened takes about 15-secs on ours, so quite easy to implement a realy providing power for about that time...
 
Top