Sicknote
Newbie level 1
Hi,
As part of a uni project I need to program a pic to vary the PWM period and duty cycle in conjunction with 2 potentiometers.
I have set up both ADC channels and have checked they're both functioning properly.
The PWM is set up and running.
One of the pots works fine with the ADC to provide a new value for CCPR1L and thus change the duty cycle however I am not sure how to program it to change the period, once the PWM is running.
Once the result of the 2nd ADC has been saved in a register, can this then be moved, at any point, in to the PR2 register (for PWM period) or are there certain conditions that must be set before PR2 can be given a new value?
Also, how do I get the mark:space ratio to remain unchanged so that the 'ON' time increases proportionally with the Period time and maintaining the current duty cycle?
Any help would be greatly appreciated.
Thanks
As part of a uni project I need to program a pic to vary the PWM period and duty cycle in conjunction with 2 potentiometers.
I have set up both ADC channels and have checked they're both functioning properly.
The PWM is set up and running.
One of the pots works fine with the ADC to provide a new value for CCPR1L and thus change the duty cycle however I am not sure how to program it to change the period, once the PWM is running.
Once the result of the 2nd ADC has been saved in a register, can this then be moved, at any point, in to the PR2 register (for PWM period) or are there certain conditions that must be set before PR2 can be given a new value?
Also, how do I get the mark:space ratio to remain unchanged so that the 'ON' time increases proportionally with the Period time and maintaining the current duty cycle?
Any help would be greatly appreciated.
Thanks