View previous topic :: View next topic |
Author |
Message |
Johnson Guest
|
How to generate Half-bridge PWM on PIC18F4580 ECCP |
Posted: Mon Jun 16, 2008 9:58 am |
|
|
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
|
|
Posted: Wed Jun 18, 2008 1:01 pm |
|
|
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
|
eccp problem 18f458 |
Posted: Thu Oct 23, 2008 6:14 pm |
|
|
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
|
|
Posted: Thu Oct 23, 2008 6:26 pm |
|
|
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. |
|
|
|