打印
[开发工具]

PIC单片机PWM功能程序出错

[复制链接]
1723|1
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
wolf_heart|  楼主 | 2014-7-30 15:18 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
简述:对DSPIC33FJ128JC804的两个PWM模块进行初始化(调用PIC自带的库),编译时报错,错误信息如下:D:/workstation/test_space/R2/XY/mio.c:36:21: error: 'PWM2_INT_DIS' undeclared (first use in this function)
D:/workstation/test_space/R2/XY/mio.c:36:21: note: each undeclared identifier is reported only once for each function it appears in
D:/workstation/test_space/R2/XY/mio.c:36:34: error: 'PWM2_FLTA_DIS_INT' undeclared (first use in this function)
D:/workstation/test_space/R2/XY/mio.c:37:13: error: 'PWM2_EN' undeclared (first use in this function)
D:/workstation/test_space/R2/XY/mio.c:37:21: error: 'PWM2_IDLE_CON' undeclared (first use in this function)
D:/workstation/test_space/R2/XY/mio.c:37:35: error: 'PWM2_OP_SCALE1' undeclared (first use in this function)
D:/workstation/test_space/R2/XY/mio.c:37:50: error: 'PWM2_IPCLK_SCALE4' undeclared (first use in this function)
D:/workstation/test_space/R2/XY/mio.c:37:68: error: 'PWM2_MOD_FREE' undeclared (first use in this function)
D:/workstation/test_space/R2/XY/mio.c:44:16: error: 'PWM2_MOD1_IND' undeclared (first use in this function)
D:/workstation/test_space/R2/XY/mio.c:44:30: error: 'PWM2_PEN1L' undeclared (first use in this function)
D:/workstation/test_space/R2/XY/mio.c:44:41: error: 'PWM2_PDIS1H' undeclared (first use in this function)
D:/workstation/test_space/R2/XY/mio.c:45:16: error: 'PWM2_SEVOPS1' undeclared (first use in this function)
D:/workstation/test_space/R2/XY/mio.c:45:29: error: 'PWM2_OSYNC_PWM' undeclared (first use in this function)
D:/workstation/test_space/R2/XY/mio.c:45:44: error: 'PWM2_UEN' undeclared (first use in this function)
源码如下:
void init_pwm1()
{
    UINT16 period;
    UINT16 config1;
    CloseMCPWM1();
    ConfigIntMCPWM1(PWM1_INT_DIS&PWM1_FLTA_DIS_INT);
    config1=PWM1_EN&PWM1_IDLE_CON&PWM1_OP_SCALE1&PWM1_IPCLK_SCALE4&PWM1_MOD_FREE;
    period=FCY/(FPWM1*4)-1;
    MAX_DUTY_PWM1=period<<1;
    OpenMCPWM1(period ,
               0,
               config1,
               PWM1_MOD1_IND&PWM1_MOD2_IND&PWM1_MOD2_IND&
               PWM1_PEN1L&PWM1_PDIS1H&PWM1_PDIS2H&PWM1_PDIS2L&PWM1_PDIS3H&PWM1_PDIS3L,
               PWM1_SEVOPS1&PWM1_OSYNC_PWM&PWM1_UEN);

    P1DC1= MAX_DUTY_PWM1;
}
//*/

void init_pwm2(void)
{
    //*
    UINT16 period;
    UINT16 config1;

    CloseMCPWM2();
    ConfigIntMCPWM2(PWM2_INT_DIS&PWM2_FLTA_DIS_INT);
    config1=PWM2_EN&PWM2_IDLE_CON&PWM2_OP_SCALE1&PWM2_IPCLK_SCALE4&PWM2_MOD_FREE;
    period=FCY/(FPWM2*4)-1;
    OpenMCPWM2(period ,
               0,
               config1,
             //  PWM2_MOD1_IND&PWM2_MOD2_IND&PWM2_MOD2_IND&PWM2_PEN1H&PWM2_PDIS1L&PWM2_PDIS2H&PWM2_PDIS2L&PWM2_PDIS3H&PWM2_PDIS3L,
             //  PWM2_SEVOPS1&PWM2_OSYNC_PWM&PWM2_UEN);
               PWM2_MOD1_IND&PWM2_PEN1L&PWM2_PDIS1H,
               PWM2_SEVOPS1&PWM2_OSYNC_PWM&PWM2_UEN);

    MAX_DUTY_PWM2=period<<1;
    P2DC1= MAX_DUTY_PWM2;
    //*/
}

我尝试将void init_pwm2(void)中的代码注销,编译就能通过。问题是PWM1和PWM2都是在PWM12.H中定义的,为什么void init_pwm1(void)就编译无误,PWM2就会出问题。
沙发
hlhfootbal| | 2015-1-24 00:18 | 只看该作者
打开PWM12.H看看里面具体的定义

使用特权

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

本版积分规则

62

主题

337

帖子

0

粉丝