電機控制算法FOC-研究英飛凌AP32013i_Inverter_TC27xC_1_22心得(二)

本文首先簡單介紹AP32013i_Inverter_TC27xC的硬件組成,然後說明其軟件框架,數據結構,最後是源碼分析。


一, AP32013i_Inverter_TC27xC屬於Hybrid kit AURIX,即AURIX系列(英飛凌32bit單片機的一個系列)的混合套件。主要應用驅動電機。

其環境如下圖:需要直流電源12V和高壓電源(Vdc),上位機(PC),電機支持。其中電機功率和電流不能超過Hybrid kit AURIX中的功率器件,電機類型:永磁同步電機(表貼,內嵌均可)和異步電機均可。

其主要硬件組件如下圖(如有不全,請原諒)

二,軟件構架

其軟件構架風格是分層構架。採用傳統的三層架構:底層是驅動層(iLLD),中間是服務層,上層是應用層。

軟件主流程:主要流程分成,BOOT,配置載入,硬件初始化,自檢,應用程序初始化,運行。其中配置載入包括:EEPROM中數據:以EFS形式;和用戶通過上位機通訊修改的配置。

其運行的架構風格是前後臺架構,各個前臺和後臺同步如下圖:

爲了支持上述的同步,其硬件配置如下:(原版爲3種PWM源:ATOM,TOM,CCU6,這裏只圖解ATOM)。在ATOM中配置兩個中斷服務函數LB30_Isr_M0_Period和LB30_Isr_M0_Trigger,同時用寄存器直接在Trigger ponint配置成P2.7輸出和VADC採集的輸入源,而主要FOC算法則跑在VADC採集後中斷服務函數LB30_Isr_Adc_M0中,這樣保證在運行FOC算法時,電機的位置速度,電流反饋信號都採集完畢。

三,數據結構:

主要數據結構分成兩塊:硬件相關的數據(g_Lb)和運行相關的數據(g_appLibrary)。如下圖

其中重要的LB30數據結構和Db3x數據結構

typedef struct
{

    LB_FileBoardVersion  *boardVersion;
    LB_FileConfiguration configuration;

    struct
    {
        IfxQspi_SpiMaster         *qspi0;        /**< \brief QSPI0 driver data.  */
        Ifx_Efs                   *efsConfig;    /**< Ifx_At25xxx file system (configuration) */
        IfxAsclin_Asc             asc0;         /**< \brief ASC 0 interface */
        IfxAsclin_Asc             asc1;         /**< \brief ASC 1 interface */
        IfxPort_Pin               asc1Rs232Select;
        IfxMultican_Can           can;          /**< \brief CAN driver */
        IfxMultican_Can_Node      canNodes[2];  /**< \brief CAN nodes */
        IfxPort_Pin               can0ErrN;
        IfxPort_Pin               can0En;
        IfxPort_Pin               can0StbN;
        IfxGtm_Atom_Timer         timerOneMs;          /**< \brief 1ms interrupt */
        IfxGtm_Atom_Timer         timerTenMs;          /**< \brief PWM timer driver */
        IfxQspi_SpiMaster         qspi2;               /**< \brief QSPI2 driver data.  */
        IfxQspi_SpiMaster         qspi3;               /**< \brief QSPI3 driver data.  */
        IfxQspi_SpiMaster_Channel sscAd2s1210;         /**< \brief SSC channel for AD2S1210. */
        IfxGpt12_IncrEnc          encoder;             /**< \brief GPT12-based encoder object */
        Ad2s1210                  ad2s1210;            /**< \brief AD2S1210 based resolver object */
        IfxDsadc_Dsadc            dsadc;
        IfxDsadc_Rdc              dsadcRdc0;           /**< \brief DSADC-based resolver object */
        IfxPort_Pin               Resolver0GainSel[4]; /**< \brief Resolver 0 Gain settings */
        IfxPort_Pin               Resolver1GainSel[4]; /**< \brief Resolver 1 Gain settings */
        IfxPort_Pin               ResolverOutputSel;   /**< \brief Select between AD2S1210 and Resolver 0 */

        IfxTlf35584_Driver               tlf35584;            /**< TLF35584 driver */
        IfxQspi_SpiMaster_Channel sscTlf35584;         /**< \brief SSC channel for TLF35584 */

        IfxVadc_Adc_Group         group[7];
        LB30_Inverter             inverter;
        IfxPort_Pin               digitalInputs[4];     /**< \brief General purpose digital inputs */
        IfxPort_Pin               digitalOutputs[4];    /**< \brief General purpose digital outputs */
    }driver;

    struct
    {
        AppAnalogInput currents[ECU_PHASE_PER_MOTOR_COUNT];
        AppAnalogInput vDc;
        AppAnalogInput igbtTemp[ECU_PHASE_PER_MOTOR_COUNT];

        AppAnalogInput motorTemp;

        AppAnalogInput in[4];
        AppAnalogInput tempBoard;
        AppAnalogInput vAna50;
        AppAnalogInput vRef50;
        AppAnalogInput vDig33;
        AppAnalogInput kl30;
    }analogInput;

    struct
    {
        IfxStdIf_DPipe    asc0;
        IfxStdIf_DPipe    asc1;
        IfxStdIf_Pos      encoder;
        IfxStdIf_Pos      ad2s1210;
        IfxStdIf_Pos      dsadcRdc0;
        IfxStdIf_Inverter inverter;
    }  stdIf;

    AppDbStdIf *driverBoardStdif;

    Ifx_MotorModelConfigF32_File *motorConfiguration;
    boolean disableCurrentSensorCheck;		/**< \brief If TRUE, the current sensors are disable */
    struct
    {
    	boolean pwmEnabled; /** If true, PWM duty cycles will be updated */
    	boolean running;		/** If true, selftest pwm is running */
    	Ifx_TimerValue duty[3]; /** PWM duty cycle values (reference)*/
    	Ifx_TimerValue dutyFaulty[3]; /** PWM duty cycle values (error injection) */
    }selftest;
}LB30
typedef struct
{
    boolean                isBoardVersion;       /**< \Brief TRUE if the driver board version file is loaded */
    boolean                isBoardConfiguration; /**< \Brief TRUE if the driver board configuration file is loaded */

    LB_FileBoardVersion    boardVersion;
    Db3x_FileConfiguration configuration;

    struct
    {
        Ifx1edi2002as_Driver             oneEdi2001as[6]; /**< 1EDI2002AS drivers ={U top, U Bottom, V Top,, V Bottom W Top, W Bottom}*/
        IfxQspi_SpiMaster_Channel sscOneEdi2001as; /**< \brief SSC channel for Edi2001AS */

        IfxQspi_SpiMaster_Channel sscEeprom;       /**< \brief SSC channel for EEPROM */
        Ifx_At25xxx               eeprom;          /**< Ifx_At25xxx driver */
        Ifx_Efs                   efsConfig;       /**< Ifx_At25xxx file system: Configuration */
        Ifx_Efs                   efsBoard;        /**< Ifx_At25xxx file system: Production data */
    }driver;
}Db3x;

 

四,源碼分析:

1. 嵌入式特點:把大量配置和運行變量編成了幾個全局變量,各種跨文件調用。但是一旦抓住主要數據結構可讀性就增加了,更容易理解。

2. 爲了兼容硬件和通用型,大量使用空指針。在初始化時用代碼指向地址(包括變量和函數),往往跳轉3次以上。給閱讀帶來困難。


 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章