CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Halfbridge PWM

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
SeeCwriter



Joined: 18 Nov 2013
Posts: 160

View user's profile Send private message

Halfbridge PWM
PostPosted: Mon Mar 02, 2015 12:12 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Mar 02, 2015 12:34 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Mar 02, 2015 12:58 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Mar 02, 2015 2:43 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Mar 04, 2015 12:32 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Mar 04, 2015 12:58 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Mar 04, 2015 2:26 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Mar 05, 2015 1:53 am     Reply with quote

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....
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group