View previous topic :: View next topic |
Author |
Message |
Yasin
Joined: 08 Jul 2009 Posts: 3
|
Half bridge PWM [solved] |
Posted: Fri Oct 26, 2012 11:23 pm |
|
|
Dears,
Kindly help in generating a half bridge PWM in CCS C Complier v4.084 for PIC16F690 for using in a buck converter. I have used the following code it is not working.
Code: |
#include "C:\Program Files\PICC\Devices\16F690.h"
#DEVICE ADC=10,*=16
#fuses INTRC_IO,NOWDT,NOPROTECT,NOBROWNOUT,PUT,FCMEN,NOCPD,NOIESO
#use delay(clock=8000000)
#define BUCK_CTRL_PWM PIN_C5 //PWM Pins SPV & MCA charge pins as PWM and other two as GPIO
#define BUCK_FB_PWM PIN_C4
#define AUX_SUP_PWM PIN_C3
#define PWM_A_Channel 1 //Buck control PWM1 // for disable and enable program
#define PWM_B_Channel 2 //Buck control PWM2
#define PWM_C_Channel 3 //Auxillary power supply PWM
#define PWM_AB_Channels 4
#define PWM_All_Channels 5 //Disable all
void Init_controller(void)
{
setup_oscillator(OSC_8MHZ);
set_tris_a(0xdf); //Configure PORTA
set_tris_b(0x7f); //Configure PORTB
set_tris_c(0xc7); //Configure PORTC
Disable_pwms(PWM_All_Channels);
Init_pwm();
}
void Init_timer1(void)
{
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
enable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL);
}
void Init_pwm(void)
{
setup_timer_2(T2_DIV_BY_1,200,1); //TIMER2 PRESCALER=16; Built in function
setup_ccp1(CCP_PWM, CCP_PWM_HALF_BRIDGE | CCP_PWM_H_H );
set_deadband(10);
set_pwm1_duty(0);
Disable_pwms(PWM_All_Channels);
}
void set_deadband(int deadband)
{
#byte PWM1CON = 0x9B
if(deadband > 127)
deadband == 127;
PWM1CON = deadband;
}
void Disable_pwms(unsigned char j)
{
channel = j;
switch(channel)
{
case 1: input(BUCK_CTRL_PWM);
break;
case 2: input(BUCK_FB_PWM);
break;
case 3: input(AUX_SUP_PWM);
break;
case 4: input(BUCK_CTRL_PWM);
input(BUCK_FB_PWM);
break;
case 5: input(BUCK_CTRL_PWM);
input(BUCK_FB_PWM);
input(AUX_SUP_PWM);
break;
default: break;
}
}
void Enable_pwms(unsigned char j)
{
channel = j;
switch(channel)
{
case 1: output_low(BUCK_CTRL_PWM);
break;
case 2: output_low(BUCK_FB_PWM);
break;
case 3: output_low(AUX_SUP_PWM);
break;
case 4: output_low(BUCK_CTRL_PWM);
output_low(BUCK_FB_PWM);
break;
case 5: output_low(BUCK_CTRL_PWM);
output_low(BUCK_FB_PWM);
output_low(AUX_SUP_PWM);
break;
default: break;
}
}
void main()
{
Init_controller();
while(!OSC_STATE_STABLE)
{ }
Enable_pwms(PWM_AB_Channels);
while(1)
{
setup_ccp1(CCP_PWM, CCP_PWM_HALF_BRIDGE | CCP_PWM_H_H );
set_deadband(10);
set_pwm1_duty(50);
}
}
|
Pls help to find my error or pls provide a half bridge pwm working code.
It is very urgent. |
|
![](templates/subSilver/images/spacer.gif) |
Yasin
Joined: 08 Jul 2009 Posts: 3
|
HB PWM working but dead time not working |
Posted: Sat Oct 27, 2012 12:24 am |
|
|
the pwm is now working ok. when I change
Code: |
setup_ccp1(CCP_PWM, CCP_PWM_HALF_BRIDGE | CCP_PWM_H_L);
|
to
Code: |
setup_ccp1(CCP_PWM_HALF_BRIDGE | CCP_PWM_H_H);
|
the half bridge pwm is working.
But still the dead time is not working.
Pls help for dead time generation in PIC16F690. |
|
![](templates/subSilver/images/spacer.gif) |
Yasin
Joined: 08 Jul 2009 Posts: 3
|
|
![](templates/subSilver/images/spacer.gif) |
magnoedu
Joined: 29 May 2009 Posts: 11
|
y trying the same project |
Posted: Tue Jul 28, 2015 9:09 pm |
|
|
I am trying the same project, but this code don't compile, he is make lot of errors with define.
Anyone help me. |
|
![](templates/subSilver/images/spacer.gif) |
dyeatman
Joined: 06 Sep 2003 Posts: 1924 Location: Norman, OK
|
|
Posted: Wed Jul 29, 2015 5:25 am |
|
|
You are correct. The code he posted will not compile/work for many
reasons. What they are actually using is definitely not this code as written..
The link he references may help _________________ Google and Forum Search are some of your best tools!!!! |
|
![](templates/subSilver/images/spacer.gif) |
|