' Demo PWM motor demo- PICAXE-08 May 2003 SiChip Ver 1.0 11th Mar.03 ' Best assembled & tested with solderless "PICNIK" box as detailed SiChip Feb.03 ' Refer http://picaxe.orcon.net.nz for background info & potential of PICAXE-08 ! ' Extra parts=DSE P-8980 "Solar Motor", 4.7k resistor, NPN BC547 transistor ' General Si diode & 100-220nF polyester cap (both to stop motor hash & "back emf") ' Dummy cell for 4.5V use. Optional counter =cheap calculator(!) +LDR & heatshrink ' New commands here = symbol ' Ref.PICAXE prog.editor .pdf help files,& BASIC Stamp 1 manuals etc for insights ' via Stan. SWAN ( MU@W, New Zealand ) => s.t.swan@massey.ac.nz <= '--------------------------------------------------------------------------------- ' Byte variables b0= slowing down, b1 = speeding up, b2= slow spin demo '--------------------------------------------------------------------------------- ' Lines beginning ' are program documentation & could be ignored if need be. ' Program available for web download => http://picaxe.orcon.net.nz/motorpwm.bas '--------------------------------------------------------------------------------- symbol slowdown = b0 'redefine variables b0 , b1, b2 symbol speedup = b1 ' using PICAXE "symbol" command symbol slowspin = b2 ' to make easier recall/understanding kickstart: ' brief routine to overcome initial motor friction pwm 2,255,8 ' 8 industrial strength pwm cycles to pin 2 wait 2 ' short wait before main routine begins pwmspin: ' main pwm demo routine pulsout 4,3000 ' pulse LED pin 4 for 3mSec to indicate start for speedup = 70 to 255 step 1 ' values < 70 found unable to easily spin motor pwm 2,speedup,4 ' 4 cycles at pin 2 of increasing pwm duty next speedup ' continue to full speed ( 255 = 100%) for slowdown = 255 to 70 step -1 ' slow motor down at same rate pwm 2,slowdown,4 ' 4 cycles at pin 2 of decreasing pwm duty next slowdown ' continue until at slowest reliable speed for slowspin= 1 to 80 ' longer slow speed spin demo- repeat 80 times pwm 2,70,10 ' 10 cycles 70/255 % of 5V at pin 2 next slowspin ' continue loop goto pwmspin ' repeat entire motor spin demo routine