View previous topic :: View next topic |
Author |
Message |
aliaj00
Joined: 11 May 2011 Posts: 24
|
pic16F887 Half Bridge problem |
Posted: Wed May 11, 2011 1:42 pm |
|
|
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
|
|
|
aliaj00
Joined: 11 May 2011 Posts: 24
|
|
Posted: Wed May 11, 2011 2:53 pm |
|
|
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
|
|
Posted: Wed May 11, 2011 2:58 pm |
|
|
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 . |
|
|
aliaj00
Joined: 11 May 2011 Posts: 24
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed May 11, 2011 3:07 pm |
|
|
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
|
|
Posted: Wed May 11, 2011 3:11 pm |
|
|
i tried that not working.
PLEASE HELP:) |
|
|
aliaj00
Joined: 11 May 2011 Posts: 24
|
|
Posted: Wed May 11, 2011 3:14 pm |
|
|
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
|
|
Posted: Wed May 11, 2011 3:16 pm |
|
|
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
|
|
Posted: Wed May 11, 2011 3:17 pm |
|
|
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
|
|
Posted: Wed May 11, 2011 3:19 pm |
|
|
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 so tomorrow is just perfect.
Thanks again.
BR's
Aliaj00 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu May 12, 2011 1:21 pm |
|
|
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
|
|
Posted: Sat May 14, 2011 6:29 pm |
|
|
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
|
|
Posted: Sat May 14, 2011 6:52 pm |
|
|
:P found it was the reverse diode at the 7805. :P. i should have seen it. |
|
|
aliaj00
Joined: 11 May 2011 Posts: 24
|
|
Posted: Sat May 14, 2011 6:56 pm |
|
|
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 :( |
|
|
|