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 support@ccsinfo.com

PWM half Bridge Problem

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



Joined: 05 Oct 2011
Posts: 11
Location: South Africa

View user's profile Send private message Yahoo Messenger

PWM half Bridge Problem
PostPosted: Wed Oct 05, 2011 3:43 am     Reply with quote

Hi All,

I have a problem making the half bridge PWM work on 18F4550.

Code:

#include<18f4550.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)

void main()
{
unsigned int pwm1;

pwm1=0;
setup_ccp1(CCP_PWM_HALF_BRIDGE | CCP_PWM_H_H);
setup_timer_2(T2_DIV_BY_16, 249, 1);
pwm1=120; //duty cycle
set_pwm1_duty(pwm1);
while(TRUE)
{
}   
}

When i simulate on Proteus, P1A has an output and P1B is 0.

Any ideas?

Compiler Version is 4.093
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Wed Oct 05, 2011 7:34 am     Reply with quote

You need to set the TRIS.
The compiler unfortunately gets confused by using the standard PWM commands, and doesn't realise that TRIS D5, needs to be set to zero for P1B to output.
Code:

#include<18f4550.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
 
void main(void) {
   unsigned int pwm1;
   pwm1=0;
   setup_ccp1(CCP_PWM_HALF_BRIDGE | CCP_PWM_H_H);
   setup_timer_2(T2_DIV_BY_16, 249, 1);
   pwm1=120; //duty cycle
   output_drive(PIN_D5);
   set_pwm1_duty(pwm1);
   do {
   } while(TRUE); //This avoids the compiler error message 
}


Best Wiishes
azykazy



Joined: 05 Oct 2011
Posts: 11
Location: South Africa

View user's profile Send private message Yahoo Messenger

PostPosted: Wed Oct 05, 2011 7:41 am     Reply with quote

Thanks Very Happy

I have tried it and it works!

Much appreciated!
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