Pwm and clock speed

retepsnikrep

Senior Member
Just a quicky.

I want to program an 08M to provide a 2khz 25% duty pwm signal from the pwm pin.

Using the wizard I found 2khz was too low, but I could acheive 4khz with 4mhz clock, so I am using the 4khz setting but then underclocking the pic to 2mhz.

Will this acheive what I require?

It looks reasonable on the scope, frequency appears OK, but I was a bit worried about the duty, is the duty number a counter/timer?

So If for instance duty is 100 (example number) but underclocked to 2mhz it actually takes twice as long to count the duty period?

So should I have changed duty to 50 (halved it) as well as underclocking chip to maintain the duty interval with correct frequency?
 

BeanieBots

Moderator
No, the duty will remain at whatever you set it to.
Changing the clock to half will halve the PWM frequency but the duty will remain the same.
 

eclectic

Moderator
Peter.
Another idea, keeping your Picaxe at “normal” speed.

Based on Dippy's posting here:
http://www.picaxeforum.co.uk/showthread.php?t=5872&highlight=jeremy+pwm

Try the following two programs,
and view the results on your 'scope

Code:
#picaxe 08m

looper:
pwmout 2,124,125 ; 8kHz from Wizard
peek $12,b1
sertxd ("Normal: ",#b1,13,10)
pause 4000
b1 = b1 + 1			' add 1 (bin 1)
poke $12, b1
peek $12,b1			' peek to confirm
sertxd ("Prescale / 4: b1= ",#b1,13,10)

pause 4000
goto looper

Which can then be shortened to:

Code:
#picaxe 08m

pwmout 2,124,125
poke $12,5

do
; the rest of your program here
loop
e
 
Top