Back to Home Page
I am no longer using Microprocessor control for the motor timing, but now using a direct drive system using OpAmps.
Machine Construction Home Page
Back To Electronic Drive Home Page
          Using the Picaxe 18M2  can give a range from off to full on.
main:
symbol peri     = b2      
symbol dutyc   = b3
let peri = 63            
readadc B.4, dutyc         
pwmout B.3,peri,dutyc     'period of 63 gives Freq 15700 and 255 dcyc @ 100%, 0 @ 0%
pause  200
goto main
The PWM, once set, runs in the background until power off or until turned off or altered.
The Period (peri) is set at 63, which gives a frequency of 15,700 switchings per second.
The Duty Cycle (dutyc) is adjustable via a 5000ohm variable resistor (pot), and controls the motor voltage, therefore the motor speed. The micro loops back every 200 milli secs to read the input at B.4, and store the value in variable dutyc.
The readadc command has a range of 0 to 255. This works perfectly for a full range of duty cycle at 15,700Hz. Motor theory recommends a frequency of 20,000 to avoid audible switching.

The lowest practical frequency for 0% to 100% PWM for the Picaxe 18M2 is 245Hz

pwmout pwmdiv64, B.3, 254, 1020 =  245Hz @ 100%
pwmout pwmdiv64, B.3, 254, 0  =  245Hz @  0%

Using the readadc10 command gives adjustment to 1024 which is slightly too much.

main:
symbol peri     = b2     
symbol dutyc   = w3
let peri = 254           
readadc10  B.4, dutyc
if dutyc > 1020 then
dutyc = 1020   
endif  
pwmout pwmdiv64,  B.3,peri,dutyc     'peri of 254 gives Freq 245Hz and 'dutyc of 1020 = 100%, 0 = 0%
pause  200
goto main
The Picaxe Programming Editor is completely free for private use. It checks your program for errors, and has a simulator to show program operation. Also a Wizard to set the PWM for you.