专家
公告
财富商城
电子网
旗下网站
首页
问题库
专栏
标签库
话题
专家
NEW
门户
发布
提问题
发文章
PIC单片机
关于PIC18Fxx31系列的功率控制PWM模块和CCP模块的使用问题
2020-02-06 10:12
发布
×
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
站内问答
/
51单片机
2729
7
7
最近要使用PIC18F2331做一个逆变器,把蓄电池的110伏电转化为220伏,50Hz的交流电,功率为2000W。一共有两个模块可以用:功率PWM和CCP。功率PWM带有故障输入和死去插入功能,可是我觉得使用很受限制。
逆变器使用SPWM的全桥控制,开关管是IGBT,不知大家有何建议。我网上找了很多也没有关于这方面的资料,郁闷中!
友情提示:
此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
7条回答
cqgxh
2020-02-07 00:54
#include <pic.h>
const unsigned int Sin[100] = {100,100,101,103,105,107,109,112,116,120,124,128,133,139,144,150,157,163,170,178,185,193,202,210,219,229,238,248,258,268,279,289,300,312,323,334,346,358,370,382,394,407,419,432,445,457,470,483,496,509,521,534,547,560,572,585,598,610,623,635,647,659,671,683,694,705,717,728,738,749,759,769,779,788,798,807,815,824,832,839,847,854,860,867,873,878,884,889,893,897,901,905,908,910,912,914,916,917,917,917};
static unsigned int step;
unsigned long int longbuf;
unsigned int tempint;
unsigned char tempchar, datamul;
bit Fbit;
unsigned char adcnt;
void main (void)
{
//-------------------------------------var initlize.
step = 49;
Fbit = 1;
datamul = 255; //must be low 63.
//-------------------------------------initlize.
PORTB = 0xFF;
TRISB = 0x00;
TRISA0 = 1;
TRISC2 = 0; // 883的RC2
TMR2 = 0;
T2CON = 0x08;
PR2 = 251; //100; //频率修改 251-----51.10HZ
TMR2IF = 0;
TMR2IE = 1;
CCP1CON = 0x8F;
PWM1CON = 0x8f; //死区控制 84 ---0.8US 85 ----1US
ECCPAS = 0x05;
TMR2ON = 1;
ADCON0 = 0xC1;
ADCON1 = 0x04;
ADIF = 0;
ADIE = 0;
PEIE = 1;
GIE = 1;
//-------------------------------------main code.
while(1)
{
NOP();
if(adcnt > 32)
{
adcnt = 0;
ADIF = 0;
GODONE = 1;
NOP();
NOP();
NOP();
// if(ADIF == 1) // AD控制
// datamul = ADRES; // AD控制
}
adcnt ++;
}
}
void interrupt ISR (void)
{
if (TMR2IE && TMR2IF)
{
TMR2IF = 0;
// = 1;
if (Fbit)
{
step ++;
if(step == 100)
{
Fbit = 0;
//step --;
}
}
else
{
step --;
if (step == 1)
{
Fbit = 1;
// step ++;
}
}
longbuf = Sin[step -1];
if (step > 50)
{
longbuf = (longbuf - 509) * datamul;
tempint = longbuf >> 8;
tempint += 509;
}
else
{
longbuf = (509 -longbuf) * datamul;
tempint = longbuf >> 8;
tempint = 509 - tempint;
}
//longbuf =longbuf * datamul;
//tempint = longbuf >> 8; //datamul <= 255;
CCPR1L = tempint >> 2;
tempchar = tempint;
tempchar <<= 4;
CCP1CON = (CCP1CON & 0xCF) | (tempchar & 0x30);
RB4 = 0;
}
}
加载中...
查看其它7个回答
一周热门
更多
>
相关问题
PIC单片机不同的IO口驱动74HC573驱动共阴极的数码管,有的段不亮
1 个回答
一种简单精确的pic延时方法
21 个回答
谁熟悉PIC的产品发布时间的,帮看看PIC18F47K40啥版本IDE能开发
12 个回答
求AN1078对应的源代码下载地址
5 个回答
PIC单片机应用技巧
4 个回答
相关文章
一种用PIC单片机主时钟驱动的老式挂钟
0个评论
×
关闭
采纳回答
向帮助了您的知道网友说句感谢的话吧!
非常感谢!
确 认
×
关闭
编辑标签
最多设置5个标签!
PIC单片机
保存
关闭
×
关闭
举报内容
检举类型
检举内容
检举用户
检举原因
广告推广
恶意灌水
回答内容与提问无关
抄袭答案
其他
检举说明(必填)
提交
关闭
×
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
×
付费偷看金额在0.1-10元之间
确定
×
关闭
您已邀请
0
人回答
查看邀请
擅长该话题的人
回答过该话题的人
我关注的人
const unsigned int Sin[100] = {100,100,101,103,105,107,109,112,116,120,124,128,133,139,144,150,157,163,170,178,185,193,202,210,219,229,238,248,258,268,279,289,300,312,323,334,346,358,370,382,394,407,419,432,445,457,470,483,496,509,521,534,547,560,572,585,598,610,623,635,647,659,671,683,694,705,717,728,738,749,759,769,779,788,798,807,815,824,832,839,847,854,860,867,873,878,884,889,893,897,901,905,908,910,912,914,916,917,917,917};
static unsigned int step;
unsigned long int longbuf;
unsigned int tempint;
unsigned char tempchar, datamul;
bit Fbit;
unsigned char adcnt;
void main (void)
{
//-------------------------------------var initlize.
step = 49;
Fbit = 1;
datamul = 255; //must be low 63.
//-------------------------------------initlize.
PORTB = 0xFF;
TRISB = 0x00;
TRISA0 = 1;
TRISC2 = 0; // 883的RC2
TMR2 = 0;
T2CON = 0x08;
PR2 = 251; //100; //频率修改 251-----51.10HZ
TMR2IF = 0;
TMR2IE = 1;
CCP1CON = 0x8F;
PWM1CON = 0x8f; //死区控制 84 ---0.8US 85 ----1US
ECCPAS = 0x05;
TMR2ON = 1;
ADCON0 = 0xC1;
ADCON1 = 0x04;
ADIF = 0;
ADIE = 0;
PEIE = 1;
GIE = 1;
//-------------------------------------main code.
while(1)
{
NOP();
if(adcnt > 32)
{
adcnt = 0;
ADIF = 0;
GODONE = 1;
NOP();
NOP();
NOP();
// if(ADIF == 1) // AD控制
// datamul = ADRES; // AD控制
}
adcnt ++;
}
}
void interrupt ISR (void)
{
if (TMR2IE && TMR2IF)
{
TMR2IF = 0;
// = 1;
if (Fbit)
{
step ++;
if(step == 100)
{
Fbit = 0;
//step --;
}
}
else
{
step --;
if (step == 1)
{
Fbit = 1;
// step ++;
}
}
longbuf = Sin[step -1];
if (step > 50)
{
longbuf = (longbuf - 509) * datamul;
tempint = longbuf >> 8;
tempint += 509;
}
else
{
longbuf = (509 -longbuf) * datamul;
tempint = longbuf >> 8;
tempint = 509 - tempint;
}
//longbuf =longbuf * datamul;
//tempint = longbuf >> 8; //datamul <= 255;
CCPR1L = tempint >> 2;
tempchar = tempint;
tempchar <<= 4;
CCP1CON = (CCP1CON & 0xCF) | (tempchar & 0x30);
RB4 = 0;
}
}
一周热门 更多>