Variable PWM?

MikeGyver

Senior Member
I searched the forum but couldn't seem to find much on this.

Using a picaxe, I'd like to control a DC motor's speed variably with a pot. No discreet 'steps', completely variable from 0 to 100% (ideally) Is this even possible?
 

premelec

Senior Member
You can take the pot from V+ to V- and put the wiper on an ADC input then READADC and use that value to vary PWM or PWMOUT [for continuous background]... check the manual #2 for these commands. Ultimately it's probably more complicated than you hope but that's how we learn to do stuff :) [don't forget to isolate the PICAXE from the noisy motor power supply spikes... capacitors or separate supplies etc.] have fun...
 

BeanieBots

Moderator
If you don't want ANY steps, then you'll have to go analogue and forget all about micro-processors. However, at some point the number of steps and the noise level of ANY electronic component start to blurr together.

So, what step size would be acceptable?
The PICAXE has the ability to read a POT to 10-bit accuracy. That's about 0.1%. The PWMout function has the same resolution which I defy you to detect over and above the mechanical noise in any brushed DC motor.

To control PWM from a POT to 10-bit accuracy is literally as easy as this.
(from 0% to 100% in 0.1% steps)

main:
readadc10 pin,var
pwmout pin,255,var
goto main

There's actually quite a lot about controlling motors with PWM on this forum.
 
Last edited:

212

Senior Member
main:
readadc10 pin,var
pwmout pin,255,var
goto main

I can read and read the manual 100 times and never "Get it" I just don't know the meaning of half...no 3/4 of what is in there. Someone have mercy on me and write this code where it will work with an 08M. I want to substitute a LDR for the pot, and an LED array for the motor, but I think I can do that part myself. I just need a working example to learn from...
 

BCJKiwi

Senior Member
For the 08M;

READADC10
Manual2 page 128:- readadc10 channel,wordvariable (refers to channel here - usually pin)
Manual2 page 126 tells you which pins can be used - 1,2 or 4 for the 08M
readadc10 1,var
var is variable - in this case a word variable. Lets use w1 for no particular reason (except w0 has some additional featues so lets keep that in reserve).
so this line becomes;
readadc10 1,w1

pwmout
Again pwm only works on certain pins
Manual2 page 123 tells you that for the 08M only pin2 is supported.
pwmout pin,period,duty cycles
Until you have an understanding of how this works, it's best to use the nifty pwm calculator kindly supplied by Rev-Ed right there in the programmer!
Picaxe / wizards / pwmout - make sure the right chip is slected (if not go to View Options and click on 08M) and the right clock speed (4Mhz unless you've set it to something else).
In the wizard, click calculate, copy, yes, close

you will now have;
pwmout 2 , 99, 200
in your program!

The last number (200) is the duty and can be substituted by a variable - w1
pwmout 2, 99, w1
that's it.

Now, the value read into w1 by readadc10, will be the value used to set the duty in pwmout.
 

212

Senior Member
Thank you very much! I must have a different version of the manuals, because the pages do not seem to be the same, but you have explained it where it makes since to me now. On behalf of the people that have only begun Picaxe-ing...again...thank you :)
 
Top