Page 1 of 1
pwm questions
Posted: Sun Apr 22, 2012 9:42 pm
by brandonb
im using the pwm ccp5 on a 16f1938 and was wondering if i can change the osccon settings from menu? dont see how i could set the flowcode speed though?.... also wondering if i can change the prescaler rate with c code blocks, if so what code would i use to change the pwm prescaler? would be nice to have a couple different frequencies while using the accuracy of this module
Re: pwm questions
Posted: Sun Apr 22, 2012 10:45 pm
by medelec35
Hi Brandon.
Did you know you change the frequency of PWM by selecting ChangPeriod part of PWM component.
There you should be able to change both Period and Prescaler.
So no need to change osccon.
Even if you could change osccon, then you would also have to change the Clock speed of the target device as well, otherwise all delays will be out.
Does not sound that practical to me, but I could be wrong.
Martin
Re: pwm questions
Posted: Sun Apr 22, 2012 11:19 pm
by medelec35
I have modified Flowchart for you to have a look at.
Martin
Re: pwm questions
Posted: Sun Apr 22, 2012 11:35 pm
by brandonb
martin, i like it

!!!!...i played with that sometime ago but the way i did it the periods were not equel, whats the magic way of calculating the numbers for what the period is gonna be and still have 0-100% duty with count #s 0-100.....i didnt think the way i asked at first would have worked either because there were too many obtacles
Re: pwm questions
Posted: Sun Apr 22, 2012 11:51 pm
by medelec35
Not sure if this will help:
http://eng-serve.com/pic/pic_pwm.html
as I have not got enough time tonight to find what your after.
It will show the max value required to produce a duty of 100% (which is not exactly what you require)
So that value could be a 16bit int.
I will see if I can find out more tomorrow or event create something on excel that will give different frequencies for 0 to 100 = duty of 0 to 100.
Martin
Re: pwm questions
Posted: Mon Apr 23, 2012 9:15 pm
by medelec35
Hi Brandon,
I have been doing some number crunching and trust me, I'm not that good at it!
My conclusions is to use 0 to 100 to get a duty of 0 to 100.
You leave the period register set to 99
Then for different frequencies change prescaler.
If it was me, I would work out exactly what frequency I require. Then I would still use a variable of 0 to 100, but I would then use a formula to change to give the corresponding PWM duty of 0 to 100%
Martin