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

pic16F887 Half Bridge problem
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
aliaj00



Joined: 11 May 2011
Posts: 24

View user's profile Send private message

pic16F887 Half Bridge problem
PostPosted: Wed May 11, 2011 1:42 pm     Reply with quote

Hi all i am trying to get the pic16F887 to generate half bridge PWM at 1 Khz. i am able to generate variable pwm at 1khz with setup default and DC but in the setup there for half bridge i didn't found a place for the dead time delay.

can someone point me in the right direction.

thanks to all,

BR's,

Aliaj00
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed May 11, 2011 2:06 pm     Reply with quote

This post has a routine to set the dead-band for the 16F887:
http://www.ccsinfo.com/forum/viewtopic.php?t=42456&start=15

Put that routine above main(), then call it in your program with
the desired dead-band parameter.
aliaj00



Joined: 11 May 2011
Posts: 24

View user's profile Send private message

PostPosted: Wed May 11, 2011 2:53 pm     Reply with quote

HI PCM programmer,

thanks a lot for the help.

My code is here and is very basic as i am just testing with Friend Laptop.

Code:

//#include <16F887.H>
#include "C:\Documents and Settings\Administrator\Application Data\PICC\Projects\half-brigde-400hz.h"

void set_deadband(int8 deadband)
   {
      #byte PWM1CON = 0x9B
     
      if(deadband > 127)
         deadband == 127;
         PWM1CON = deadband;
   }

void main()
{
 
   int8 CCP_DELAY = 10;
   int8 value;
   setup_adc_ports(sAN0|VSS_VDD);
   setup_adc(ADC_CLOCK_DIV_8);
   setup_spi(SPI_SS_DISABLED);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DIV_BY_16,255,1);
   //setup_ccp1(CCP_PWM);
   //set_pwm1_duty(0);
   setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
//Setup_Oscillator parameter not selected from Intr Oscillator Config tab
 
 
   setup_ccp1(CCP_PWM, CCP_PWM_HALF_BRIDGE | CCP_PWM_H_L );
   set_deadband(127);
 
   // TODO: USER CODE!!
   value = 0;
 
   delay_us(20);
   while(1)
   {
      value = read_adc();
     
      set_pwm1_duty(value);
   }

}


this code was compiled :P and i will try in a minute. :P
aliaj00



Joined: 11 May 2011
Posts: 24

View user's profile Send private message

PostPosted: Wed May 11, 2011 2:58 pm     Reply with quote

hi i just tested it and the output is only on RC2 and nowhere else. i must be missing something as the code compiled.

PLEASE HELP Smile.
aliaj00



Joined: 11 May 2011
Posts: 24

View user's profile Send private message

PostPosted: Wed May 11, 2011 3:06 pm     Reply with quote

i have found this post here that says the compiler has a bug:

http://www.ccsinfo.com/forum/viewtopic.php?t=44502&highlight=setupccp1+ccppwmhh+ccpdelay

maybe its like this.

should i add the following code:

before main
#define P1B PIN_D5

after
setup_ccp1(CCP_PWM, CCP_PWM_HALF_BRIDGE | CCP_PWM_H_L );
set_deadband(127);

output_low(P1B);

any idea??
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed May 11, 2011 3:07 pm     Reply with quote

You didn't post your compiler version. Yes, try that bug-fix.
It will likely fix the problem.
aliaj00



Joined: 11 May 2011
Posts: 24

View user's profile Send private message

PostPosted: Wed May 11, 2011 3:11 pm     Reply with quote

i tried that not working.


PLEASE HELP:)
aliaj00



Joined: 11 May 2011
Posts: 24

View user's profile Send private message

PostPosted: Wed May 11, 2011 3:14 pm     Reply with quote

PCM 4.093. code is here:

Code:

//#include <16F887.H>
#include "C:\Documents and Settings\Administrator\Application Data\PICC\Projects\half-brigde-400hz.h"
#define P1B PIN_D5

void set_deadband(int8 deadband)
   {
      #byte PWM1CON = 0x9B
     
      if(deadband > 127)
         deadband == 127;
         PWM1CON = deadband;
   }

void main()
{
 
   int8 CCP_DELAY = 10;
   int8 value;
   setup_adc_ports(sAN0|VSS_VDD);
   setup_adc(ADC_CLOCK_DIV_8);
   setup_spi(SPI_SS_DISABLED);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DIV_BY_16,255,1);
   //setup_ccp1(CCP_PWM);
   //set_pwm1_duty(0);
   setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
//Setup_Oscillator parameter not selected from Intr Oscillator Config tab
 
 
   setup_ccp1(CCP_PWM, CCP_PWM_HALF_BRIDGE | CCP_PWM_H_L );
   set_deadband(127);
   output_low(P1B);
 
   // TODO: USER CODE!!
   value = 0;
 
   delay_us(20);
   while(1)
   {
      value = read_adc();
     
      set_pwm1_duty(value);
   }

}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed May 11, 2011 3:16 pm     Reply with quote

I can't test this in hardware today. I can do it tomorrow morning.
I can't do anything more today.
aliaj00



Joined: 11 May 2011
Posts: 24

View user's profile Send private message

PostPosted: Wed May 11, 2011 3:17 pm     Reply with quote

my KIT is PICKIT2 Debugger and on RD5 i have nothing connected. I checked with the scope the other unused pins which are all of them except RC2 P1A, RC6 RC7 serial but unused.
aliaj00



Joined: 11 May 2011
Posts: 24

View user's profile Send private message

PostPosted: Wed May 11, 2011 3:19 pm     Reply with quote

Hey man thanks a lot for taking in consideration testing it for me.
Very kind of you.
Last time i checked the world wouldn't ended this week Very Happy so tomorrow is just perfect.

Thanks again.

BR's

Aliaj00
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu May 12, 2011 1:21 pm     Reply with quote

I tested the code below with vs. 4.093 and it works. I get a squarewave
on pins C2 and D5. The signal on D5 is in-phase with the signal on pin C2.
The frequency of both signals is 244 Hz. The duty cycle appears to be
approximately 50% on my scope. The pulses are high for about 2ms and
low for about 2ms.
The deadband zone is small, compared to the duty cycle. You have to
put the scope on x10 Mag to see it. I measured the deadband at 127us
on the scope. So it's working. This was tested on a PicDem2-Plus board
(non-Rohs version).
Code:

#include <16F887.H>
#fuses INTRC_IO,NOWDT,BROWNOUT,PUT,NOLVP
#use delay(clock=4M)

#define P1B PIN_D5

void set_deadband(int8 deadband)
{
#byte PWM1CON = 0x9B
     
if(deadband > 127)
   deadband == 127;

PWM1CON = deadband;
}

//======================================

void main()
{
setup_timer_2(T2_DIV_BY_16, 255, 1);
setup_ccp1(CCP_PWM_HALF_BRIDGE | CCP_PWM_H_L );
output_low(P1B);

set_pwm1_duty(125);

set_deadband(127);
 
while(1);
}
 
 
aliaj00



Joined: 11 May 2011
Posts: 24

View user's profile Send private message

PostPosted: Sat May 14, 2011 6:29 pm     Reply with quote

HI PCM

i tried this code for testing.

Code:

#include "D:\documents and settings\Administrator\Application Data\PICC\Projects\soft-pwm.h"
//#include <pic.h>



void main()
{
   
   char period;
   char frequency;
   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_CLOCK_DIV_2);
   setup_spi(SPI_SS_DISABLED);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_ccp1(CCP_OFF);
   setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard

   //TODO: User Code
   
   
   
   while (1)
   {
  /* putc("vendos perioden");
   getc(period);
   
   putc("vendos frekuencen");
   getc(frequency);
  */
   output_low(PIN_B6);
   output_low(PIN_B5);
   
  ///
   output_high(PIN_B5);
   delay_ms (15);
   output_low(PIN_B5);
   delay_ms (2);
   //
   output_high(PIN_B6);
   delay_ms(15);
   output_low(PIN_B6);
   delay_ms(2);
   
   delay_ms(5);
   
   }
   

}


it does the job as i need half bridge so dead time just a delay between turning on the pins. also this way i can set the time between repetitive strokes much bigger on the last command delay_ms(5);

i am having a issue. with the scope i am checking the off voltage on both pins and is not zero but 850mV. i am using darlington as driver so it is not big deal but still confusing me enough to ask. i have the darlington's with common ground with the PIC and there is not more than 4mV on the supply line.

Any idea???

thanks a lot for testing
aliaj00



Joined: 11 May 2011
Posts: 24

View user's profile Send private message

PostPosted: Sat May 14, 2011 6:52 pm     Reply with quote

:P found it was the reverse diode at the 7805. :P. i should have seen it.
aliaj00



Joined: 11 May 2011
Posts: 24

View user's profile Send private message

PostPosted: Sat May 14, 2011 6:56 pm     Reply with quote

also cleaned the code now it looks now:

Code:

#include "D:\documents and settings\Administrator\Application Data\PICC\Projects\soft-pwm.h"
//#include <pic.h>



void main()
{
   
   char period;
   char frequency;
   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_CLOCK_DIV_2);
   setup_spi(SPI_SS_DISABLED);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_ccp1(CCP_OFF);
   setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard

   //TODO: User Code
   
    output_low(PIN_B1);
    output_low(PIN_B3);
   
   while (1)
   {
  /* putc("vendos perioden");
   getc(period);
   
   putc("vendos frekuencen");
   getc(frequency);
  */
   //output_low(PIN_B6);
   //output_low(PIN_B5);
   
  ///
   output_high(PIN_B1);
   delay_us (50);
   output_low(PIN_B1);
   delay_us (5);
   //
   output_high(PIN_B3);
   delay_us(50);
   output_low(PIN_B3);
   //delay_us(2);
   
   delay_us(75);
   
   }
   

}


signal attached have some interference from both channels :(
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2, 3  Next
Page 1 of 3

 
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