Author Options:

Turn dial to generate pulses Answered

Here is my proposal.

I'm building a pan/tilt unit. I plan to have a 200 step motor attached to a 20:1 worm gear, (the latter is needed so it will 'lock' in place, and not be solely reliant on the motor's holding torque.. So in order for the output shaft to turn 180 degrees needs the worm gear to turn 10 times. In turn the motor must do 10 revs, which would need 2000 pulse steps.

It's the pulse generation that's proving difficult. Whilst a 555 timer could generate pulses, I want it to be 'mechanical' For example, if I turn the knob 90 degrees, I want to create 1000 pulses, (45 degrees creates 500 pulses) and so on, so the knob matches the physical position of the camera. If I turn the knob 180 degrees in 1 second ... the motor will turn 180 degrees in 1 sec. If I turn the knob slowly, pulses will be generated slowly, and the camera/motor will turn slowly.

My idea at present is some sort of optical encoder ... but that would need 4000 divisions on the wheel!! Or - a 1024ppr wheel with a 1:4 step up gearing ... but such encoders are several hunderd Pounds!! And I would need two of them!!

I have software that will allow me to print an encoder wheel, but resolution will have to be 'course' since it will use an LED / transistor, so I suspect around 64 divs.

I purchased a RC servo, wondering if I could remove the motor, and turn the output shaft by hand. Couldn't be done.

I've also considered 'planatary gears' in reverse to 'step up' the revs ... but I cannot locate any 'hobbyist' versions other than the Tamayia type.

Also briefly looked at RC servos, but having done the maths, it would be impractical to get the output to move (say) 0.1 degrees as the motor would only move about 1/4 of a rev and have no torque!! (One option may be to make it continuos rev, and place a feedback pot externally.but again, moving 0.1 degree around a pot would create minimal feedback) Incidentally, 0.1 degrees is the stepper resolution 180 degrees / 2000 steps

Anyone any ideas? Bearing in mind that the speed of the pulse train is dependant on how fast the control (pot) is turned, and also matches physical camera position. Encoders are preferred option as it's then possible to electronically guage which way the motor is turning.

If electronic, here is (sort of) what the circuit would need to compute. (Sample and hold?) Moved from 0 to 45 degrees in one second. That degree of movement needs 500 pulses, thus need to generate a pulse width to get 500 pulses in 1 second timescale. ** This is just to give an example. The actual sampling rate would be much faster. If it was a 'slow' 1/10th second, in the above example it would check every 4.5 degrees, and generate 50 pulses in that time scale.


Your best bet is a microprocessor that will measure the angle of you control (via a POT) and then generate the required number of step pulses - the programming would be fairly basic.

Whilst I can program in HTML, PERL and CSS, learning Arduino code - and the DA interface to connect the pot to the processor - is a totally new ball game. Maybe the question might be better suited to an arduino forum.


Progrqmmed in Basic - even I can do it.

Will take a look at that. Just spent 2hrs looking at Arduino, and the motor shield. That could work, and cost around £34 here in UK. I like the Uno as that has built in A-D converter which will switch the analogue voltage to 1024 steps.

My coding - in my head - would be something along the lines of: Read input line into variable NEW. Pop result of array[0] and load into variable OLD. Compare OLD to NEW. If more, set forward flag and generate a pulse, and store NEW in array[0]. If less, set reverse flag, generate pulse, generate a second pulse and store NEW in array[0]. If same, do nothing. (An if, elseif, else block). Loop

Why generate the second pulse? A-D creates 1024 'steps' and I need 20(48) to drive steppers

My THEORY is that since the processor will be generating control pulses FASTER than I could physically turn knob, the code will spend most of its time in the "do nothing" block, and may occasionally generate a single pulse. For example, if knob turns in 0.5 sec, each pulse would be generated in 0.00025sec. In that time, the processor could have (theoretically) generated 10's or even 100's of pulses.

Anyway, let's take a look at picaxe

Ah your in the Uk


You only need 2 analogue inputs to read the value of a 10K pot

and 2 outputs to send the servo signal to the RC servos.

A picaxe 08M will do that

Personally I would buy a project board to make connecting easier around £1.99, You will need a download cable - USB to Serial £9.99 but you only ever buy it once all the rest is free.

Programming is easy If you have issues with it either ask here or they have a really good help forum that solves most problems.

The 14M gives you more inputs/outputs for only a few pence more.

Thanks for previous offer to code chip, but I think I'll experiment, then if it goes wrong, I can debug. I've looked at manuals1 and 3, (2 too long at this stage), and getting the idea. I'm not sure at present what pic to use. With bipolar stepper, I'll need four output stages per motor, and since I have two motors (pan and tilt) that is 8 output stages. Then there is the smaller servo that keeps the camera stage at 90 degrees to ground even when craneing up and down, so that's another output. So the 14M might be better along with Darlington driver chip. (I've also got to watch which have 8 bit DAC, and which have 10 bit)

Next two stages of research; does the picaxe send 0.1 - 0.2ms pulses to server directly, or is it coded. And will the three inputs multi-task thro' one chip. (I think I read there was a limitation to parallel processing if using clock increase / PWM ??)

That flow charting editor is a nice approach. Will save time coding. (With PERL for websites, I write it all in EditPadPro, then test it on a Windows / Apache offline server!!!)

The Picaxe has firmware to deal with RC servos but for a stepper you will need to drive the outputs direct from the chip - As you say via a L293D a stepper driver.

There is sample code in manual 3 the interface manual.

Although there are about 40 commands available you only really need a small number to do 90% of what you need.

High and low turn outputs on and off

Readadc reads the voltage on the ADC pin i.e. your pot.

the usual If, then, elseif make decisions.

With gosub you will quickly recognise the command structure.

There is a simulator in the free to download programme editor so you don't even have to commit to the hardware until you are pretty certain your programme works.

from manual 3

"This sample procedure makes the motor spin 100 steps to the left and then 100 steps

to the right by using two sub-procedures. lstep causes the motor to move one step to

the left, rstep causes the motor to move one step to the right. Variable b1 is used to

store the step position and so should not be used elsewhere in the program.


for b3 = 0 to 99 ‘

start a for...next loop

gosub lstep ‘

call left step sub-procedure

next b3 ‘

next loop

for b3 = 0 to 99 ‘

start a for...next loop

gosub rstep ‘

call left step sub-procedure

next b3 ‘

next loop


let b1 = b1 + 1 ‘

add 1 to variable b1

goto step2 ‘ goto the lookup table


let b1 = b1 - 1 ‘

subtract 1 from variable b1


let b1 = b1 & %00000011 ‘ mask lower two bits of b1

lookup b1,(%1010,%1001,%0101,%0110),b2 ‘

lookup code into b2

let pins = b2 ‘

output b2 onto control lines


Most of the code seems familiar to other programs. The lookup is a new one. It appears to be an array of 4 binary values, and the value chosen is dependant on b1 which is then output to b2 pins. As you say, the editor has a simulator, so will try that this savvy / tomorrow.

I will probably do is as a loop to check the ADC value, and then gosub if value changes. Thanks for details re servo software. Got to do a bit more manual reading. (I know it's in man3 - just got to let it sink into my brainbox!)

The component stores I use offer the 18M2 for £2:24 - £3:34, and a PCB to fit - together with 2003 Darlington / IC sockets - for £3:33 (All plus VAT) No doubt I could draw up the PCB ... but it's then got to be exposed / etched / drilled, so the ready made version is probably best.

The lead seems a bit pricey at £10, (wonder if it has any circuitry in USB / 3.5mm jack. If a straight USB-->3.5mm, surely an old USB lead could be hacked ... if they gave you the USB pinout and not just 3.5mm jack!! )

Just googled the lead, and it does contain circuitry in USB. I suppose that justifies the price.

NB: I don't like this messageboard: Just found you cannot edit posts, and every time I hit "Make Comment", it either does nothing ... or then posts it three times!!

Yes the lead is "intelligent" I actually use an older serial 9 pin tD connector to stereo 3 pin plug - works as well the cct is in the manuals but a lot of laptops no longer have the Serial D type connector.

The look up table give you the output patterns for driving the coils of a bipolar stepper motor. It writes direct to the output register. It just compacts and speeds up the code a little You could just a easy use High and low but it would be a little slower in operation.

Just tried the Picaxe editor, and initially it was definately a case of WTF!! It's slowly starting to make sense now.

Am I right in saying the flowchart is only a GUIDE that you can simulate workflow, and then you have to write the BASIC code yourself? I can't see any button that converts flowchart to BASIC, or BASIC to flowchart.

Am I also correct in thinking the pictures that show the dice simulation etc are only available for the samples, ie no way to set up your own pushbuttons / LED's etc

The old flow chart system has been replaced by Logicator. There is a link to download it. You can do a conversion from flow charting to Loadable basic.

The whole system was / is aimed at the educational market. the flow charting was included for those students - or even staff - who didn't want to tackle programming. Personally I find it harder than writing the programme using the basic commands. As I said you only need a few.

Readadc - reads the analogue input

High - sets an output on

Low - sets an output off

If then else etc. reads the state of inputs

You can attach LEDs directly to the outputs (see relevant diagram in manual for right pins) You should use a current limiting resistor, say 330 ohms but most LEDs will work direct from the output (experience)

You can connect switches to any input pin and Vcc . Usually you pull the input down to ground with a 10K resistor. This gives positive switching action between zero and + volts.


Will double check, but I think "Logicator" is now incorporated into the editor, and there is no need for the separate link. But still not located the flwchart to basic conversion

Just googled the lead, and it does contain circuitry in USB. I suppose that justifies the price.

NB: I don't like this messageboard: Just found you cannot edit posts, and every time I hit "Make Comment", it either does nothing ... or then posts it three times!!

The secret to the multi post is to use chrome, or to clock post slowly, stop when the post appears. - You can of course delete the extra posts.

If you don't really want to spend on the cable I can programme the chip and send it to you in the post.

I have seen several Pan and tilt projects here using simple RC servos. Much easier to handle via a microprocessor like the Picaxe or Arduino.


In actual fact for £ 2 or £3 you can buy a RC servo tester that will control the servo without any other work on your part. - turn the knob and the servo moves through it's full 270 Deg range. I have one on the desk in front of me now.

I did consider servos to do the main pan / tilt, but I reasoned the definition of the servo pot would be a very fine if only moving a small amount (say a few microvolts between start and end point), and it could lead the motor to jiggle as it hunts for the exact position of feedback. Plus, I did some calcs and worked out if I was to move something like 5 degrees, the motor would only make about 5 revs and wouldn't create a lot of torque. (The camera itself if 500g - or about 750g with motors on pan head. When the camera is tllted forward of pivot point, there is quite a lot of 'force' on the pivot / gear point since there is no counterbalance, so needs a fairly robust motor) Again, OK if you want to simply move camera from one point to another ... but not for an infinate degree of control


3 years ago

What would be wrong with a basic rotary encoder? You could use a set of gears or a belt to get the pulses/turn you need based on the resolution of the encoder. Or use a pot connected to a microprocessor, if you choose to go with arduino, there should already be libraries for driving stepper motors, and that would make the programming very easy I would imagine.

Well, let's keep it simple, and say the encoder is 64 sectors. To generate the required 2048 pulses, it would have to rotate 32 times. Yet the knob would go through half a turn. That would give a gear UP of sixty-four times. (I've found plenty of gear DOWN, but gear UP is very difficult. And before you say it, it's not simply a case of turning the output shaft to turn the input shaft as there are torque/forces at play.)

A microprocessor may be the solution, but that's a whole new genre. It's got to read the value the pot starts at, the value it is now - which require analogue to digital interface - over what time frame to work out how many pulses to generate, and repeat the process around 10 - 20 times a second. Would need a good programmer and electronics person to devise that.

I'm building a pan and tilt as well...

Perhaps a joystick would work? Easier than building a rotary encoder, but you still can probably set it up so you get some sort of "feedback" from it. Doing it without a microcontroller will be hard though.

"A microprocessor may be the solution, but that's a whole new genre. It's got to read the value the pot starts at, the value it is now - which require analogue to digital interface - over what time frame to work out how many pulses to generate, and repeat the process around 10 - 20 times a second."

That's actually a set of circumstances that a microcontroller would be fairly ideal! Many micros have ADCs onboard and can measure time pretty well.

Hi Astroboy. (Sorry for late response. Only just seen your comment 'tagged' onto bottom of page)

A joystick may be an option - although it's not as 'visual' as the method I'm proposing. It would be OK for an analogy of (say) "Move joystick left to pan left, move right to pan right" etc (As they with most CCTV surveilance units) But what I want to do is use the knob, and visualise it as if looking down on camera. So if the knob is pointing to 9 o'clock position, the camera points to far left. If I move the knob about 45 degrees, the camera will point forward 45 degrees. When I move knob to 12 o' clock, the camera will point directly forward. (Sorry if I'm labouring the point, but I'm trying to create a picture in your Mind's Eye ... 'cos although I can visualise it, it may be tricky for another person to see) It's 'academic' at present until the 'guts'/ microprocessor has been developed.

For example, this arrangement will allow the camera to 'track' a moving object. Suppose you wish to follow a car along the road, and pan with it as it passes the camera. As it approches the viewpoint, the pan will be slow. It will then become a whip pan as car passes, and then a slow pan again as it receeds into the distance. With practice, it COULD be done by adjusting the =speed= of the pan, (slow/fast/slow), but if the speed is slightly wrong, it will overshoot / undershoot where you want the camera to be, (watch any CCTV controller when trying to position the camera on a subject. They will go too far one way, have to back up etc) Much easier if the knob emulates the pan head itself.

With my pot design, they could even be incorporated into a tripod head itself. Put a monitor on the head, and it will be as if viewing through the camera. Pan the head, and the camera will move in unison! (But hey, that's a future project!!)

Another slight drawback of the joystick is that it only moves around the mid 1/3rd of the potentiometer track. It would be very tricky to get the 0 to 5v range the processor will need to see in this exact area of the pot. It would be fine for a 555 timer delivering pulses as the further the joystick is moved, the faster the pulses, but I think it might be difficult to 'fine tune' an exact speed.