I'm looking at the help files for PWM using the CCP module.
It is a bit confusing as to which of two methods to use and I am unsure whether DUTY is a percent or from 0 to 255.
Do I define frequency and duty cycle using
HPWM, channel,freq,duty (where duty runs from 0 to 255)
Then can I use PWMon and PWMoff to toggle?
or do I use
#define PWM_freq
#define PWM_duty (as a percent)
the second method does not seem to offer a channel selection
Last edit: David Stephenson 2015-08-07
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Yes. That is the correct method. I am not sure what level of accurancy you need but on my scope here with 16MHz internal oscillator .... if you really needed 200 khz I needed to use HPWM 1,205,128 gives 50% duty cycle. HPWM 1,200,128 gave 191khz and 53% duty cycle.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm looking at the help files for PWM using the CCP module.
It is a bit confusing as to which of two methods to use and I am unsure whether DUTY is a percent or from 0 to 255.
Do I define frequency and duty cycle using
HPWM, channel,freq,duty (where duty runs from 0 to 255)
Then can I use PWMon and PWMoff to toggle?
or do I use
the second method does not seem to offer a channel selection
Last edit: David Stephenson 2015-08-07
I think I've got this sorted now. I used HPWM 1,200,128
to get a 50% duty cycle on channel 1 at 200 kHz.
Then PWMoff to stop.
Yes. That is the correct method. I am not sure what level of accurancy you need but on my scope here with 16MHz internal oscillator .... if you really needed 200 khz I needed to use HPWM 1,205,128 gives 50% duty cycle. HPWM 1,200,128 gave 191khz and 53% duty cycle.
And.... you could use the following to give you 199.5khz at 50%
define PWM_freq 205
define PWM_duty 50
PWMOn