pwm questions
Moderator: Benj
-
- Posts: 438
- Joined: Mon Aug 29, 2011 12:26 am
- Location: arizona
- Has thanked: 175 times
- Been thanked: 173 times
pwm questions
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
- Attachments
-
- 1938 pwm ccp5.fcf
- (31.93 KiB) Downloaded 243 times
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: pwm questions
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
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
Martin
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: pwm questions
I have modified Flowchart for you to have a look at.
Martin
Martin
- Attachments
-
- 1938 pwm ccp5 Modified.fcf
- (36.09 KiB) Downloaded 266 times
Martin
-
- Posts: 438
- Joined: Mon Aug 29, 2011 12:26 am
- Location: arizona
- Has thanked: 175 times
- Been thanked: 173 times
Re: pwm questions
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

-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: pwm questions
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
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
Martin
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: pwm questions
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
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
Martin