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

How to generate Half-bridge PWM on PIC18F4580 ECCP

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







How to generate Half-bridge PWM on PIC18F4580 ECCP
PostPosted: Mon Jun 16, 2008 9:58 am     Reply with quote

I would like to generate two pwm output for Half bridge PWM on PIC18F4580. But I try much times that also fail to output. My program as below. Anybody can help me to revise it . Thanks a lot.

setup_ccp1(CCP_PWM_HALF_BRIDGE|CCP_PWM_H_H);
setup_timer_2(T2_DIV_BY_1,pwm_rate,1);
set_pwm1_duty(duty);
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jun 18, 2008 1:01 pm     Reply with quote

I don't have a 18F4580, but I do have an 18F458. It's a similar chip
with respect to the ECCP module. The following code demonstrates
how to do a simple setup of the eccp module. I don't think CCS
properly supports this mode with their functions, so I created two new
functions to support it. I tested the following code with vs. 4.074 and
it works OK.
Code:

#include <18F458.h>
#fuses HS,NOWDT,BROWNOUT,PUT,NOLVP
#use delay (clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

#define P1A  PIN_D4
#define P1B  PIN_D5
#define P1C  PIN_D6
#define P1D  PIN_D7

#byte ECCP1CON = 0xFBA

void setup_eccp1(int8 value) 
{
ECCP1CON = value;

switch(value & 0xC0)
  {
   case CCP_PWM_FULL_BRIDGE:
   case CCP_PWM_FULL_BRIDGE_REV:
     output_low(P1A);
     output_low(P1B);
     output_low(P1C);
     output_low(P1D);
     break;

   case CCP_PWM_HALF_BRIDGE:
     output_low(P1A);
     output_low(P1B);
     break;

   default:
     output_low(P1A);
  }

}

//---------------------
#byte ECCPR1L = 0xFBB

void set_eccp1_duty(int8 value)
{
ECCPR1L = value;

}

//=================================
void main()
{

setup_eccp1(CCP_PWM_HALF_BRIDGE | CCP_PWM_H_H);
setup_timer_2(T2_DIV_BY_1, 255, 1);
set_eccp1_duty(64);   // 25% duty cycle

while(1);
}
eiby



Joined: 07 Oct 2008
Posts: 3

View user's profile Send private message

eccp problem 18f458
PostPosted: Thu Oct 23, 2008 6:14 pm     Reply with quote

Hi, I try this code except the serial comm part but I'm getting no answer from the pic. I'm simulating and doing the implementation but none are working.
Is it problem of my compiler vs 4.065 ?
_________________
Best regards,,

Abraham Guerrero
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Oct 23, 2008 6:26 pm     Reply with quote

I compiled that code with PCH vs. 4.065 and vs. 4.074. I compared
the .LST files with ExamDiff. The only difference is the first line, which
contains the version of the compiler.

Therefore, your simulator is not configured correctly or it's not working.
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