View previous topic :: View next topic |
Author |
Message |
dmccric
Joined: 07 Dec 2009 Posts: 7 Location: Bradford, West Yorkshire
|
PIC18F4431 & Power PWM |
Posted: Wed Apr 28, 2010 10:13 am |
|
|
I am trying to get PWM3 (RB3 on PWM Generator #1) working on the Power PWM Module for the PIC18F4431 (QFN) but for some reason it gives me an 'Invalid PWM Combination' error.
My code is:
Code: |
setup_power_pwm_pins( PWM_OFF, PWM_ODD_ON, PWM_OFF, PWM_OFF );
setup_power_pwm( PWM_CLOCK_DIV_4 | PWM_FREE_RUN, 2, 0, 999, 0, 0, 32 ); |
I have set PWM channel 1 to 'PWM_ODD_ON' and disabled the rest.
I want a frequency of 1KHz with an 8MHz Internal RC Oscillator. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Apr 28, 2010 1:07 pm |
|
|
What's your compiler version ?
In vs. 4.107, CCS has commented out the PWM_OFF option, in 184431.h:
Code: |
// Constants used for SETUP_POWER_PWM_PINS() are:
//#define PWM_OFF 0
#define PWM_ODD_ON 1
#define PWM_BOTH_ON 2
#define PWM_COMPLEMENTARY 3 |
|
|
![](templates/subSilver/images/spacer.gif) |
dmccric
Joined: 07 Dec 2009 Posts: 7 Location: Bradford, West Yorkshire
|
|
Posted: Thu Apr 29, 2010 2:14 am |
|
|
I am on version 4.101 and I have noticed that define is uncommented but it is still in the file but further at the top.
I was wondering that I might have a compiler issue. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19360
|
|
Posted: Thu Apr 29, 2010 2:28 am |
|
|
The reason for the compiler 'moan' though, is that the chip doesn't support the combination you are trying for....
Look at register 17-3 in the data sheet. Do you see any combination here that gives PWM on PWM3 alone?.
Depending on what else you want to do, you may be able to get this 'functionally', by selecting the option that gives PWM1, _and_ PWM3 as outputs, and using the output override ability on PWM1 to give logic outputs when needed.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
dmccric
Joined: 07 Dec 2009 Posts: 7 Location: Bradford, West Yorkshire
|
|
Posted: Fri Apr 30, 2010 3:02 am |
|
|
for some reason someone has designed the hardware for this and add overkill. I am using the HIP4081 Full bridge fet driver which drives 4 fets.
So i only need 3 pins to drive the motor:
RB3/PWM3 -> PWM_EN
RB1/PWM1 -> PWM_FWD
RB4/PWM5 -> PWM_RVS
For Forward and Reverse I simply complement RB1 & RB4 and then PWM RB3, this could have been done by using the simpler CCP PWM but I did not design the hardware.
I am using the simulator to see my PWM signals but I only want RB3 to PWM and keep getting 'Invalid PWM Combination'. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19360
|
|
Posted: Fri Apr 30, 2010 5:56 am |
|
|
As I have said, the hardware won't do this.
What you need to do, is set PWM_ODD_ON, for both the first two combinations, and then use the output override ability to trun RB1 on/off, rather than output_high, or low. This overrides the PWM 'stream' on this pin, leaving RB3 as the only one outputting a PWM.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
|