View previous topic :: View next topic |
Author |
Message |
azykazy
Joined: 05 Oct 2011 Posts: 11 Location: South Africa
|
PWM half Bridge Problem |
Posted: Wed Oct 05, 2011 3:43 am |
|
|
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: 19504
|
|
Posted: Wed Oct 05, 2011 7:34 am |
|
|
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
|
|
Posted: Wed Oct 05, 2011 7:41 am |
|
|
Thanks
I have tried it and it works!
Much appreciated! |
|
|
|