This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

controlsuite例程问题



在HVBLDC_Sensored例程中在主函数有如下变量

现在我想将这几个变量声明为全局变量,即:

extern PWMGEN pwm1;

extern PWMDAC pwmdac1;

extern HALL3 hall1;

将它们也用于其他的.C文件,发现报错,

如提示所示,有重复定义,可我并没有发现重复定义,请问是怎么回事?

  • 这里是定义,建议在别的头文件中使用extern声明为全局看看。

  • 我确实在别的文件里用extern声明了,就出现了上述报错,发现有重复定义,不知道是哪里重复定义了

  • shizhong,

    你的源文件中应该有包含一个头文件,关于这个PWMGEN的定义“ xxxpwm_bldc.h”,在这个头文件中就有这些变量的定义,然后你在别的地方又包含了这个头文件,就导致了这些变量的重复定义。

    Eric

  • Eric:

       我试过,在另一个.C文件中,不包含头文件又提示没有定义,而包含了又提示重复定义,这怎么办

  • shizhong,

    可以把PWMGEN等的typedefine copy到这个c文件的开头,如

    typedef struct {       Uint16 CmtnPointer;     // Input: Commutation (or switching) state pointer input (Q0)      int16 MfuncPeriod;      // Input: Duty ratio of the PWM outputs (Q15)      Uint16 PeriodMax;     // Parameter: Maximum period (Q0)      int16 DutyFunc;        // Input: PWM period modulation input (Q15)      Uint16 PwmActive;      // Parameter: 0 = PWM active low, 1 = PWM active high (0 or 1)

           } PWMGEN;

    extern PWMGEN pwm1;

    Eric