View previous topic :: View next topic |
Author |
Message |
SeeCwriter
Joined: 18 Nov 2013 Posts: 160
|
Halfbridge PWM |
Posted: Mon Mar 02, 2015 12:12 pm |
|
|
Using a 18F8722, v5.042 PCWHD. I configured CCP1 for PWM mode and half-bridge operation using output pins A & B. I get the correct output on pin A, but nothing on pin B.
Code: |
setup_timer_2(T2_DIV_BY_1,99,1); // Used by CCP1 for PWM mode.
// Setup PWM module for half-bridge mode, 50% duty-cycle, at 100kHz.
// Set Dead-band delay: 2-cycles (~200ns). See pg 202 of datasheet.
setup_ccp1(CCP_PWM | CCP_PWM_HALF_BRIDGE | CCP_SHUTDOWN_AC_L | CCP_SHUTDOWN_BD_L, 2);
set_pwm1_duty((int16)198); // 50% duty cycle.
|
What am I missing? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19510
|
|
Posted: Mon Mar 02, 2015 12:34 pm |
|
|
First, are you sure you are checking the right pin?. This is controlled by the ECCPH ECCPL fuse selection.
Second on pins that are relocatable, the compiler often won't set the TRIS. So with the pin you want selected in the fuses, add 'output_drive(pin_name)' for the pin the signal should be on. This turns the output on. |
|
|
SeeCwriter
Joined: 18 Nov 2013 Posts: 160
|
|
Posted: Mon Mar 02, 2015 12:58 pm |
|
|
Setting PIN-E6 to an output fixed it. What do the two fuses you mentioned do? They are listed in the header file, and they aren't in the 18F8722 datasheet or the CCS manual. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19510
|
|
Posted: Mon Mar 02, 2015 2:43 pm |
|
|
They are not two fuses, just one.
ECCPH sets the ECCPMX fuse high.
ECCPL sets ECCPMX low.
Determines where the ECCP pins actually 'go'.
Because the compiler does not know which set of pins you are sending the ECCP 'to', it doesn't set the TRIS. I'd explicitly set the selection, since assuming the default will stay the same, is always dangerous. |
|
|
SeeCwriter
Joined: 18 Nov 2013 Posts: 160
|
|
Posted: Wed Mar 04, 2015 12:32 pm |
|
|
Setting PIN E6 to an output fixed the problem as I said before. But since you also said to add one of the fuses ECCPH or ECCPL, I did. Adding ECCPH causes the phase B of the PWM to stop. and Adding ECCPL generates a compiler error about an Unknown Keyword in #FUSES.
The only way to get both phases of the half-bridge PWM to work is to not use either fuse and set the phase B output pin to an output.
I'm using V5.042 of the IDE, on a 18F8722. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Mar 04, 2015 12:58 pm |
|
|
The allowable fuses are listed at the top of the 18F8722.h file:
Quote: |
//////// Fuses: CCP2C1,ECCPH,ECCPE,NOLPT1OSC,LPT1OSC,NOMCLR,MCLR,NOSTVREN |
|
|
|
SeeCwriter
Joined: 18 Nov 2013 Posts: 160
|
|
Posted: Wed Mar 04, 2015 2:26 pm |
|
|
Well that's embarrassing. I guess I assumed if the first fuse was ECCPH, the opposite fuse would be ECCPL.
Thanks. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19510
|
|
Posted: Thu Mar 05, 2015 1:53 am |
|
|
Apologies. I was thinking set the bit high/low, which is how it is displayed in my programmer, but CCS use the name of the port the bits are routed too, so ECCPE sends the bits to port E, and ECCPH sends then to port H.
Didn't bother to check the names that CCS use for the bit.... |
|
|
|