Let's Make Robots!

Yet another PWM Picaxe question

I am programming my Mr Basic with Mr Basic moron driver. I use a Picaxe 28x1. It is a very basic setup indeed, with a small servo carrying a sharp IR distance sensor.

After reading many pages of manuals and LMR and example code of other victims, I ran into a wall. It's the dreaded "PWM and servopos don't mix" wall on picaxes.

I understand from all the frustrated posts on LMR that the valid workaround would be to not mix pwm and servo commands. Use one after the other, but never simultaneously. That's were I fail. How do I switch off a servo signal or pwm signal?

My current code makes a PWM signal and the servo responds to it. The electrical signal is not to blame. Noisy as it might be. When I delete the servo commands from my code, but leave everything plugged in (servo, sharp, driver), the servo stops jittering.

I tried to bring the servopin low, to bring the pwm pin low, but neither is stopping the timer issue. Should I force the timer to OFF in between commands? Should my uC take a very short "nap"? Is there an official answer here at all?

Comment viewing options

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

Hi Rik,

Quote: How do I switch off a pwm signal?

Picaxe manual 2, page 140:

"This command is different to most other BASIC commands in that the pwmout
runs continuously (in the background) until another pwmout command is sent."

"To stop pwmout on a pin it is necessary to isssue a ‘pwmout pin, off’ command."

Thanks Markus. Could I have missed that because I was (at the time) reading an old version of the manual? I will investigate. I'd love to blame someone else. ;-)

If I could do the same to a servo(pos) command, I'd be 100% helped.

You don't need to switch off a servo(pos) command. Any other timer command like pause should stop the servo(pos) command. Just add a line with pause 500 for instance. If you still have problems, please post the part of your code, which makes trouble :)



Is that true for any timer-related command? Because my servo keeps jittering as soon as my pwm kicks in.

I'll try to replicate the effect with as little code as possible. This may take a week or more. Madrid is gonna distract me from robots, I guess ;-)

Hi Rik,

You mean, the servo begin to jitter as soon as you start any pmw command even there is no temporary servo command? Then electrical noise could be a possibility, but you had already put this out of the question.



I ruled out noise, I think, by plugging the servo to the board, NOT issueing any servo commands => still jitter.

Removing PWM from code clears this up. This places the blame with PWM, I think.

But I still need to isolate this when my head is fresh again. Or sun burned. Whatever.

Is the PWM pin connected to anything? If so; the noise may be some sort of signal spillover outside the 28X1. you might try running the code with PWM but without connecting anything to the PWM pin(s)

Anyway. All the timer related stuff in the picaxe kept giving me unexpected behavior, when combined with other timer related functions. So I swore to only use dedicated PicAxes for PWM and dedicated Picaxes to control servos.

I am starting to understand how people would give up and just throw an extra 08M at the problem. This has been frustrating as hell so far. I am kennelijk a newbie at this picaxe timer stuff. So I started out fresh.

It would be so nice to be able to say "I recommend an extra IC for PWM because the valid workaround is such a hack". But without a proper valid workaround, all I can say now is: "Just give up before you get frustrated, like I did.".

And Mintelt.

And Oddbot.

And MarkusB.

And Fritsl.

And Chris the Carpenter.

And ...

Don't be frustrated, that's part of electronics :)

Let's start to determinate, if electrical noise is the problem. If not, then we try to work on the program. Keep a second chip as last solution ;-)

Hi Rik,

But do you drive any motors during PWM and plugged in servo? I ask to terminate if not the motors cause some electrical noise during PWM.