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

Half bridge PWM [solved]

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



Joined: 08 Jul 2009
Posts: 3

View user's profile Send private message Yahoo Messenger

Half bridge PWM [solved]
PostPosted: Fri Oct 26, 2012 11:23 pm     Reply with quote

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.
Yasin



Joined: 08 Jul 2009
Posts: 3

View user's profile Send private message Yahoo Messenger

HB PWM working but dead time not working
PostPosted: Sat Oct 27, 2012 12:24 am     Reply with quote

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.
Yasin



Joined: 08 Jul 2009
Posts: 3

View user's profile Send private message Yahoo Messenger

HB PWM working but dead time not working
PostPosted: Sat Oct 27, 2012 12:38 am     Reply with quote

Thanks to the following post both half bridge and dead time is working fine.
http://www.ccsinfo.com/forum/viewtopic.php?p=156440
Thanks every body.
magnoedu



Joined: 29 May 2009
Posts: 11

View user's profile Send private message MSN Messenger

y trying the same project
PostPosted: Tue Jul 28, 2015 9:09 pm     Reply with quote

I am trying the same project, but this code don't compile, he is make lot of errors with define.
Anyone help me.
dyeatman



Joined: 06 Sep 2003
Posts: 1933
Location: Norman, OK

View user's profile Send private message

PostPosted: Wed Jul 29, 2015 5:25 am     Reply with quote

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