Let's Make Robots!

Picaxe :- Pwm motor controlling and servo scanning

I wish to connect 1 or more servos to a picaxe 28x1 .......with 2 motors controlled by pwm

So Far :-

I have managed to get two motors working with pwm control . (jumps on table in amazement - its my first picaxe enterprise)

I have used pins 12(pwm 1) and 13(pwm 2) for the motor control (with output 7,6,5,4 for direction ie via an Ld293 chip)

using  pwmout ....... pwmduty commands - works well.........

My pressing Question :-  How on earth do i connect a Servo ? ------ it beats me.........

when i issue servo commands - the servo is "silence" ...... not even a "dickie-bird", if i remove my pwm motor code - the servo works

2nd Question :- The hpwm command has 4 outputs - can you issue different pwm signals to each (the book says it not possibe as there is only 1 pwm out controlling the 4 hpwm outputs).....is this correct ?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

I am currently programming my mini servo controller. It is based on a 08M. With the version I have now you can set servo positions by sending a serial command to pin3. I am working on speed control, but its hard to fit it in only 256bytes of program memory and 14 bytes of variables.

For (software) PWM I use a separate 08M. Also driven with serial commands to pin3. Program can be found here. I also made a board for this setup.

 

I can understand why you are using multiple picaxes now, i have also started in the same direction.

ie. have one big picaxe to do serial and computation - storage ..... and mini picaxes for driving your motors/servos and stuff.

With each mini-picaxe you gain a "timer" and thats exactly what we want.

This is why I like 08m procs  :) they allow for that little extra bit of processing. Though I guess you could do the same with a multicore like the prop or even the xmos chips(xn-1 and higher).

You are exactly right, voodoo but you could be easier than that. You get a command via serial in, you send out the servo command. I can't think of a situation where you would need to send commands faster than the servo could actually move. By the time you would want to reposition the servo, you have already looped back to the serin command. I can't see why you couldn't simply let the 08m "camp" on the serin command. --You get another pin outta the deal.

main:

serin pin,qualifier,b1,b2

servo b1,b2

goto main

--or-- I use this on Walter's head...

main:

serin pin,qualifter,b7,b8,b9,b10

servocalc:
for b11= 1 to 255 step 1
if b7>b4 then let b4=b4+b10 max b7 'b4 is where you are, b7 is where you are going, b10 is how fast
endif
if b4>b7 then let b4=b4-b10 min b7 'b4 is where you are, b7 is where you are going, b10 is how fast
endif
endif
if b8>b5 then let b5=b5+b10 max b8 'same here
endif
if b5>b8 then let b5=b5-b10 min b8 'same here
endif
if b9>b6 then let b6=b6+b10 max b9 'same here
endif
if b6>b9 then let b6=b6-b10 min b9 'same here
endif
if b4=b7 and b5=b8 and b6=b9 then 'if where you are = where you wanted to go then return
return
endif
gosub servomove
next b11
return

servomove:
servo 1,(b4)
servo 2,(b5)
servo 3,(b6)
pause b18 'increase this if you want to slow things down
return

So this is a basic system that I use a lot with walters head. The head consists of one rotate servo and 2 tilt servos. I needed a way for all of these to smoothly transistion from move to move. It is a simple system of the posistion of where the servos are now and where you want it to stop. I hope the code above is understandable.

Your code for walters head may be just the thing to make it all fit in an 08M. At least it waits for the move to finish before the serin command.

I see you dont use SERVOPOS but only the SERVO command. Do you have any problems with jitter?? The manual says: initialize with servo and then use servopos.

main:

serin pin,qualifier,b1,b2

servo b1,b2

goto main 

This code will not work. The serin command stops the servos while it is waiting for the serial data. So if you set a new position, the servos will only move a tiny bit until the next command is received.

It needs an interrupt. Something like:

 

main:

setint 0,%00001000 'interrupt on pin3 when low

CODE TO PROCESS NEW COMMANDS / POSITIONS

do

pause 5

loop while new_cmd = 0

goto main

interrupt:

serin RECEIVE COMMANDS ETC.

return

Everyone has had to find out they have this problem... I got so sick of it, I just went ahead and used a dedicated servo controller. They are cheap and easy to use. If you are wanting to go this route, just ask and I will find some good links for you.

Servo controller :- would it not be possible to make a servo controller out of a 08M and send out from the 28x1 a serial servo command (ie to the 08M).....Hmmmm ....er  this should be possible ..... hmmmm²

I wish to stay as native "picaxe" as i can just to check out its capabilities....

Yes, it would be possible to do this. 2 pins, serial input and an interupt pin to know when to receive the data as with the 08m when you do serin it doesn't allow for a timeout if no data is recieved.

Super, i thought i was going around the bend  - thanks mintvelt.

That is not such a bad thing  (re:- turning off pwm and then using servo) at least i now know there is one solution, as i can get away with a general forward detect - then stop - and scan (provided it looks far enough ahead ...... it could add extra charater)........

I have been also reading and re-reading the docs re:- hpwm (it is so close to being a "brill" system)........

...... but then i could also slip in an 08M for the scanning part....hmmmm