单相和三相SPWM
全部回复(30)
正序查看
倒序查看
现在还没有回复呢,说说你的想法
PIC16F877SPWM程序:
#include__CONFIG(HS&WDTDIS&LVPDIS); bit sin_f;//换向标志位 const unsigned char sin_[]={0,3,7,11,15,19,23,27,31,35,39,42,46,50,54,58, 62,65,69,73,77,80,84,88,92,95,99,102,106,109,113,116, 120,123,127,130,133,137,140,143,146,150,153,156,159,162,165,168, 171,173,176,179,182,184,187,190,192,195,197,199,202,204,206,208, 211,213,215,217,219,220,222,224,226,227,229,230,232,233,235,236, 237,238,240,241,242,243,243,244,245,246,246,247,248,248,248,249, 249,249,249,249,250,249,249,249,249,249,248,248,248,247,246,246, 245,244,243,243,242,241,240,238,237,236,235,233,232,230,229,227, 226,224,222,220,219,217,215,213,211,208,206,204,202,199,197,195, 192,190,187,184,182,179,176,173,171,168,165,162,159,156,153,150, 146,143,140,137,133,130,127,123,120,116,113,109,106,102,99,95, 92,88,84,80,77,73,69,65,62,58,54,50,46,42,39,35, 31,27,23,19,15,11,7,3}; unsigned char sin_num;//SIN函数表查表变量指针 //------------------------------------- void main(void) { TRISC1=1; TRISC2=1; PORTC=0; TOUTPS0=0; //1:1后分频比,TOUTPS0=0 TOUTPS1=0; //1:1后分频比,TOUTPS1=0 TOUTPS2=0; //1:1后分频比,TOUTPS2=0 TOUTPS3=0; //1:1后分频比,TOUTPS3=0 TMR2ON=1; //启动定时器T2 TMR2IF=0; //清除T2的中断标志 TMR2IE=1; //T2中断允许 PEIE=1; //外设中断允许,TMR2属于外设中断范围 GIE=1; PR2=0xf9; //装载PR2寄存器设置PWM周期,频率为20khz CCP1CON=0x0C; //CCP1模块工作在PWM模式 CCPR1L=0x00; //装载CCPR1L寄存器设置PWM占空比,为0% TMR2IF=0; //清零PIR1寄存器中的TMR2IF中断标志位 T2CKPS0=0; //定时器TMR2设置1:1预分频比,T2CKPS0=0 T2CKPS1=0; //定时器TMR2设置1:1预分频比,T2CKPS1=0 TMR2ON=1; //T2CON寄存器中的TMR2ON位置1使能Timer2 TRISC2=0; //清零TRISC2位,使能CCP1引脚输出驱动器 CCP2CON=0x0C; //CCP2模块工作在PWM模式 CCPR2L=0x00; //装载CCPR2L寄存器设置PWM占空比,为0% TRISC1=0; //清零TRISC1位,使能CCP2引脚输出驱动器 sin_f=1; sin_num=0; while(1) { } } void interrupt ISR(void) { if(TMR2IF==1) { TMR2IF=0; if(sin_num==199) { sin_num=0; sin_f=!sin_f; } if(sin_f) { CCPR2L=sin_[sin_num]; CCPR1L=0; } else { CCPR1L=sin_[sin_num]; CCPR2L=0; } sin_num++; } }
0
回复
提示
帖子已被设置为头条,恭喜楼主可添加电源网私人官网微信(dianyuan_com)为好友,领取现金红包(备注信息:头条红包)
注:现金红包仅限当日领取
活动介绍:http://www.dianyuan.com/bbs/1531738.html
0
回复
提示
@空军通信兵
主要是现在制造业很难混,大家都忙所以没时间来电源网了。还有就是有些人离开逆变器这个行业,转行做其他产品了。所以不来了,我去年也是做逆变器的,现在转行做多普勒雷达产品。中国老板只想着赚钱,不考虑产品质量。中国的很多老板认为技术不值钱,中国的工程师遍地都是。中国老板喜欢过河拆桥,中国拿高工资的都是老板,大家崇拜的都是马云,王健林,还有就是歌星影星,这些人每一个是玩高科技的,而美国崇拜的是科技人员,特斯拉,乔布斯等科技研发人员。中国玩虚的都赚钱了,搞实业的很难生存。为了生存很多实业家转行玩虚的。所以人少了。再过一两年我也去玩虚的,赚钱养家。
现实击垮了多少人的梦想,还是坚守自己的信念吧。还能有梦想的时间不多了。
0
回复
提示
@zcq760622
PIC16F877SPWM程序:#include__CONFIG(HS&WDTDIS&LVPDIS);bitsin_f;//换向标志位constunsignedcharsin_[]={0,3,7,11,15,19,23,27,31,35,39,42,46,50,54,58,62,65,69,73,77,80,84,88,92,95,99,102,106,109,113,116,120,123,127,130,133,137,140,143,146,150,153,156,159,162,165,168,171,173,176,179,182,184,187,190,192,195,197,199,202,204,206,208,211,213,215,217,219,220,222,224,226,227,229,230,232,233,235,236,237,238,240,241,242,243,243,244,245,246,246,247,248,248,248,249,249,249,249,249,250,249,249,249,249,249,248,248,248,247,246,246,245,244,243,243,242,241,240,238,237,236,235,233,232,230,229,227,226,224,222,220,219,217,215,213,211,208,206,204,202,199,197,195,192,190,187,184,182,179,176,173,171,168,165,162,159,156,153,150,146,143,140,137,133,130,127,123,120,116,113,109,106,102,99,95,92,88,84,80,77,73,69,65,62,58,54,50,46,42,39,35,31,27,23,19,15,11,7,3};unsignedcharsin_num;//SIN函数表查表变量指针//-------------------------------------voidmain(void){TRISC1=1;TRISC2=1;PORTC=0;TOUTPS0=0;//1:1后分频比,TOUTPS0=0TOUTPS1=0;//1:1后分频比,TOUTPS1=0TOUTPS2=0;//1:1后分频比,TOUTPS2=0TOUTPS3=0;//1:1后分频比,TOUTPS3=0TMR2ON=1;//启动定时器T2TMR2IF=0;//清除T2的中断标志TMR2IE=1;//T2中断允许PEIE=1;//外设中断允许,TMR2属于外设中断范围GIE=1;PR2=0xf9;//装载PR2寄存器设置PWM周期,频率为20khzCCP1CON=0x0C;//CCP1模块工作在PWM模式CCPR1L=0x00;//装载CCPR1L寄存器设置PWM占空比,为0%TMR2IF=0;//清零PIR1寄存器中的TMR2IF中断标志位T2CKPS0=0;//定时器TMR2设置1:1预分频比,T2CKPS0=0T2CKPS1=0;//定时器TMR2设置1:1预分频比,T2CKPS1=0TMR2ON=1;//T2CON寄存器中的TMR2ON位置1使能Timer2TRISC2=0;//清零TRISC2位,使能CCP1引脚输出驱动器CCP2CON=0x0C;//CCP2模块工作在PWM模式CCPR2L=0x00;//装载CCPR2L寄存器设置PWM占空比,为0%TRISC1=0;//清零TRISC1位,使能CCP2引脚输出驱动器sin_f=1;sin_num=0;while(1){}}voidinterruptISR(void){if(TMR2IF==1){TMR2IF=0;if(sin_num==199){sin_num=0;sin_f=!sin_f;}if(sin_f){CCPR2L=sin_[sin_num];CCPR1L=0;}else{CCPR1L=sin_[sin_num];CCPR2L=0;}sin_num++;}}
请问这是三想spwm代码吗
0
回复
提示