• 回复
  • 收藏
  • 点赞
  • 分享
  • 发新帖

pic16f716在spwm半桥输出

pic16f716单片机spwm输出模式半桥状态,可是有相波形的第一个脉宽不对啊(如图一),图二是另外一相波形,这个是我想要的,不明白第一个为什么,

  图一

 

还有一个问题为什么我设置的死去时间的一个单位时间是:SPWM的周期时间啊,而不是datasheet上讲的是Fosc/4

全部回复(4)
正序查看
倒序查看
wubaoxue
LV.1
2
2013-10-12 15:32

这个是我的半桥程序,有哪位大侠能帮我看看啊!!!,这波形怎么会是上面这个样子,还有死去时间,我实在无语了!!

//spwm调制,逆变器,

#include

#define uchar unsigned char

#define uint unsigned int

__CONFIG(0X3F32);

const uchar sinTab[200]={   //调制度M=0.9;正弦波代码数组

0,1,2,3,4,5,6,7,8,10,

11,12,13,14,15,16,17,18,19,20,

21,22,23,24,25,26,27,28,29,30,

31,32,33,33,34,35,36,37,38,39,

40,41,41,42,43,44,45,45,46,47,

48,48,49,50,51,51,52,53,53,54,

55,55,56,56,57,58,58,59,59,60,

60,61,61,62,62,62,63,63,64,64,

64,65,65,65,65,66,66,66,66,66,

67,67,67,67,67,67,67,67,67,67,

67,67,67,67,67,67,67,67,67,

67,66,66,66,66,66,65,65,65,65,

64,64,64,63,63,62,62,62,61,61,

60,60,59,59,58,58,57,56,56,55,

55,54,53,53,52,51,51,50,49,48,

48,47,46,45,45,44,43,42,41,41,

40,39,38,37,36,35,34,33,33,32,

31,30,29,28,27,26,25,24,23,22,

21,20,19,18,17,16,15,14,13,12,

11,10,8,7,6,5,4,3,2,1,0

};

/*基波50Hz,载波20KHz,半周期内的采样点数为100,则pwm的周期=1/20ms=50us*/

/*SPWM初始化*/

uchar B_D=0,i;

void init()

{

TRISB=0X28; //

PR2=149; //SPWM为50uS=150*4*(1/12)

CCP1CON=0XBd;   //spwm模式选择,半桥1011,1101,A、c高有效,b、d低有效

CCPR1L=0; //占空比为0

PWM1CON=0X00; //


TMR2IF=0;

T2CON=0X04; //不分频,使能TMR2

}

void  tmr2()

{

if(TMR2IF)

{

if(i==200)

{

i=0;

B_D=!B_D;

}

if(B_D)

{

TRISB=0X20; //B...C


}

else

{

TRISB=0X08; //D...A

}


PR2=149; //SPWM为50uS=150*4*(1/12)

CCPR1L=sinTab[i];

TMR2IF=0;


i++;

}

}

void main ()

{

init();

while(1)

{

 tmr2();

}

}


0
回复
2013-10-21 14:57
@wubaoxue
这个是我的半桥程序,有哪位大侠能帮我看看啊!!!,这波形怎么会是上面这个样子,还有死去时间,我实在无语了!!//spwm调制,逆变器,#include#defineucharunsignedchar#defineuintunsignedint__CONFIG(0X3F32);constucharsinTab[200]={ //调制度M=0.9;正弦波代码数组0,1,2,3,4,5,6,7,8,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,33,34,35,36,37,38,39,40,41,41,42,43,44,45,45,46,47,48,48,49,50,51,51,52,53,53,54,55,55,56,56,57,58,58,59,59,60,60,61,61,62,62,62,63,63,64,64,64,65,65,65,65,66,66,66,66,66,67,67,67,67,67,67,67,67,67,67,67,67,67,67,67,67,67,67,67,67,66,66,66,66,66,65,65,65,65,64,64,64,63,63,62,62,62,61,61,60,60,59,59,58,58,57,56,56,55,55,54,53,53,52,51,51,50,49,48,48,47,46,45,45,44,43,42,41,41,40,39,38,37,36,35,34,33,33,32,31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,8,7,6,5,4,3,2,1,0};/*基波50Hz,载波20KHz,半周期内的采样点数为100,则pwm的周期=1/20ms=50us*//*SPWM初始化*/ucharB_D=0,i;voidinit(){TRISB=0X28;//PR2=149;//SPWM为50uS=150*4*(1/12)CCP1CON=0XBd; //spwm模式选择,半桥1011,1101,A、c高有效,b、d低有效CCPR1L=0;//占空比为0PWM1CON=0X00;//TMR2IF=0;T2CON=0X04;//不分频,使能TMR2}void tmr2(){if(TMR2IF){if(i==200){i=0;B_D=!B_D;}if(B_D){TRISB=0X20;//B...C}else{TRISB=0X08;//D...A}PR2=149;//SPWM为50uS=150*4*(1/12)CCPR1L=sinTab[i];TMR2IF=0;i++;}}voidmain(){init();while(1){ tmr2();}}
半桥SPWM上下桥臂的驱动应该是互补的吧....
0
回复
zy_eric
LV.3
4
2013-10-21 20:19
你是公司做产品否?如果是我这边可以帮你解答 Q1723549569
0
回复
daihui713
LV.6
5
2013-10-29 17:25
@wubaoxue
这个是我的半桥程序,有哪位大侠能帮我看看啊!!!,这波形怎么会是上面这个样子,还有死去时间,我实在无语了!!//spwm调制,逆变器,#include#defineucharunsignedchar#defineuintunsignedint__CONFIG(0X3F32);constucharsinTab[200]={ //调制度M=0.9;正弦波代码数组0,1,2,3,4,5,6,7,8,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,33,34,35,36,37,38,39,40,41,41,42,43,44,45,45,46,47,48,48,49,50,51,51,52,53,53,54,55,55,56,56,57,58,58,59,59,60,60,61,61,62,62,62,63,63,64,64,64,65,65,65,65,66,66,66,66,66,67,67,67,67,67,67,67,67,67,67,67,67,67,67,67,67,67,67,67,67,66,66,66,66,66,65,65,65,65,64,64,64,63,63,62,62,62,61,61,60,60,59,59,58,58,57,56,56,55,55,54,53,53,52,51,51,50,49,48,48,47,46,45,45,44,43,42,41,41,40,39,38,37,36,35,34,33,33,32,31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,8,7,6,5,4,3,2,1,0};/*基波50Hz,载波20KHz,半周期内的采样点数为100,则pwm的周期=1/20ms=50us*//*SPWM初始化*/ucharB_D=0,i;voidinit(){TRISB=0X28;//PR2=149;//SPWM为50uS=150*4*(1/12)CCP1CON=0XBd; //spwm模式选择,半桥1011,1101,A、c高有效,b、d低有效CCPR1L=0;//占空比为0PWM1CON=0X00;//TMR2IF=0;T2CON=0X04;//不分频,使能TMR2}void tmr2(){if(TMR2IF){if(i==200){i=0;B_D=!B_D;}if(B_D){TRISB=0X20;//B...C}else{TRISB=0X08;//D...A}PR2=149;//SPWM为50uS=150*4*(1/12)CCPR1L=sinTab[i];TMR2IF=0;i++;}}voidmain(){init();while(1){ tmr2();}}

增强型的CCP PWM,16F690好像也可以

0
回复