打印

DSPIC30F2020单片机查表法实现正弦波驱动全桥逆变电路

[复制链接]
2061|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
红精灵温格|  楼主 | 2017-3-23 15:20 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
毕设的题目,自己编了个程序,但在调试时SIMULATOR提示PWM CLOCK FASTER THAN FOSC,不知道怎么回事,贴一下我的代码,希望大神能指导一下!
#include <p30F2020.h>
_FOSCSEL(FRC_PLL); //使能PLL,FRC晶振
_FOSC(CSW_FSCM_OFF&FRC_HI_RANGE); //禁止时钟切换,高频模式
_FPOR(PWRT_128);//上电复位128MS
_FWDT(FWDTEN_OFF); //禁止看门狗定时器
_FGS(CODE_PROT_OFF);//代码保护关闭

unsigned int const pwmtab[200] = {0,631,1262,1892,2522,3152,3781,4409,5035,5661,6285,6908,7528,8147,8764,9379,
9992,10602,11209,11814,12416,13015,13610,14202,14791,15376,15957,16534,17107,17676,18241,18801,
19356,19907,20453,20993,21529,22059,22584,23103,23617,24124,24626,25122,25611,26094,26571,27041,
27505,27961,28411,28854,29289,29718,30139,30553,30959,31357,31748,32131,32506,32873,33232,33582,
33925,34259,34584,34901,35210,35509,35800,36082,36355,36620,36875,37121,37358,37586,37804,38013,
38213,38403,38584,38755,38917,39069,39212,39345,39468,39581,39685,39779,39863,39937,40001,40056,
40100,40135,40160,40175,40180,40175,40160,40135,40100,40056,40001,39937,39863,39779,39685,39581,
39468,39345,39212,39069,38917,38755,38584,38403,38213,38013,37804,37586,37358,37121,36875,36620,
36355,36082,35800,35509,35210,34901,34584,34259,33925,33582,33232,32873,32506,32131,31748,31357,
30959,30553,30139,29718,29289,28854,28411,27961,27505,27041,26571,26094,25611,25122,24626,24124,
23617,23103,22584,22059,21529,20993,20453,19907,19356,18801,18241,17676,17107,16534,15957,15376,
14791,14202,13610,13015,12416,11814,11209,10602,9992,9379,8764,8147,7528,6908,6285,5661,
5035,4409,3781,3152,2522,1892,1262,631};
unsigned char num; //查表顺序寄存器
unsigned char sign; //正弦表输出标志
float  sin_l;
void PortInit()  
{  
   // LATE= 0x0000;  // E端口清零  
    TRISE = 0x0000; // E端口设为输出, 0: out, 1: in
    TRISB = 0x0000; // E端口设为输出, 0: out, 1: in
    PORTE = 0x0000;  
    PORTB = 0x0000;  
   
    OSCCONbits.TSEQEN=0;//OSCTUN 寄存器中的 TUN<3:0> 位调节 FRC 振荡器
    OSCTUNbits.TUN = 0111; /* FRC时钟为15M */
   
}  

void PWM_Config()
{
   
FCLCON1=0X0003; //禁用电流限制和故障输入


IOCON1bits.PENH = 1; /* PWM1H PWM 模块将控制 PWM输出引脚 */

IOCON1bits.PENL = 1; /* PWM1L PWM 模块将控制 PWM输出引脚 */

IOCON1bits.PMOD = 00; /* 互补输出模式 */

IOCON1bits.POLH = 0; //PWMxH 引脚为高电平有效

IOCON1bits.POLL = 0; //PWMxL 引脚为高电平有效

/* Load PDTR1 and ALTDTR2 register with preset dead time value */
DTR1 = 64; /* 死区时间设置 */

ALTDTR1 = 64; /* 死区时间 */

/* PHASE1 register */
PHASE1 = 0; /* No phase shift */


/* PWM Time Base Control Register */
PTCONbits.PTEN = 1; // 使能PWM模块
PTCONbits.EIPU = 1; //立即更新有效周期寄存器
PWMCON1bits.IUE = 1; //立即对有效的pdc寄存器进行更新

PWMCON1bits.MDCS = 0;//PDC提供占空比


    PTPER = 47620; //30mips为47620 ,周期=(PTPER+1)/120MHZ
    PDC1 = 0; //占空比清零

     _PWM1IE=1;//允许中断请求
_PWM1IF=0;//中断标志清零
  _PWM1IP=6;    //中断优先级设为6
  _IPL=1;//CPU中断优先级为1

}

int main()
{
   
    num = 0;        // 个变量初始化
sign = 0;
PortInit() ;
PWM_Config();
while(1);//一直循环等待中断
}

void __attribute__((interrupt, no_auto_psv)) _PWM1Interrupt(void)
{
      _PWM1IF=0;//中断标记位清零
    if (!num)        //如果num=0,意味着 每一次查表循环完毕标志取反,用以确定正负半周波形
        sign = ~sign; //0变1
    ++num;        // 正弦表顺序取值
  if (num>=200)        //200个点查完后清num
num = 0;
    sin_l= pwmtab[num];
    PDC1=(unsigned char)sin_l;//赋值
    if(sign)
                                          {PORTBbits.RB5=1;}//换向
                                  else
                                      {PORTBbits.RB5=0;}//换向
  

}


相关帖子

沙发
红精灵温格|  楼主 | 2017-3-23 16:53 | 只看该作者
这是具体的提示W0400-PWM:  PWM clock faster than Fosc

使用特权

评论回复
板凳
zhizaibide| | 2019-4-15 14:59 | 只看该作者
楼主请问找出问题了吗?我在simulator仿真调试也碰到了这样的提示,但是输出的PWM波形是正常的耶。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

主题

2

帖子

0

粉丝