| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- /**
- @copyright None
- @file main.c
- @author Comment Vivre
- @date 2025-10-31
- @brief 主函数 初始化 主循环
- */
- #include <Myproject.h>
- bool data IsTick = false;
- bool data isCtrlPowOn = false;
- Curr_Offset_t xdata currOffset;
- Motor_Control_t motorControl;
- CurrentVarible xdata mcCurVarible;
- FOCCTRL xdata mcFocCtrl;
- void HardwareInit(void)
- {
- // 上电等待
- uint16 PowerUpCnt = 0;
-
- while (PowerUpCnt++ < 10000);
-
- // 参考电压初始化
- VREF_Config_Init();
- // 外部中断初始化 预驱故障中断保护
- PreDriver_Falut_Init();
- // IO初始化
- GPIO_Init();
- // ADC端口初始化
- ADC_Init();
- // AMP初始化
- AMP_Init();
- // 驱动初始化
- Driver_Init();
- // 串口初始化
- UART1_Init();
- Set_IRQ_DMA(DMA_IRQ_L1);
- // 系统定时器初始化
- Sys_Tick();
- _nop_(); _nop_();
- EA = 1;
- }
- /* ---------------------------------------------------------------------------------
- Function Name : void SoftwareInit(void)
- Description : 软件初始化,初始化所有定义变量,按键初始化扫描
- Input : 无
- Output : 无
- ----------------------------------------------------------------------------------*/
- void SoftwareInit(void)
- {
- // FaultVarible变量清零
- memset(&mcFaultDect, 0, sizeof(FaultVarible));
- // ProtectVarible保护次数清零
- memset(&mcProtectTime, 0, sizeof(ProtectVarible));
- /// 电流保护的变量清零
- memset(&mcCurVarible, 0, sizeof(CurrentVarible));
- McStaSet.SetMode = 0;
- mcState = mcReady;
- mcFaultSource = 0;
- }
- /**
- @function main
- @brief 主函数 电机驱动主循环 任务循环
- @date 2025-10-31
- */
- void main(void)
- {
- HardwareInit();
- SoftwareInit();
- _nop_(); _nop_(); _nop_();
- WatchDogConfig(600, 1);
-
- while (1)
- {
- if (IsTick)
- {
- Get_ADC_Value();
- // 目标转速设置
- Get_Target_Ref();
- // 环路响应
- Loop_Control();
- // 上电控制
- Power_In_Control();
- // LED灯故障显示
- LED_State_Display(mcFaultSource);
- // 故障保护函数功能
- Fault_Detection();
- Tick_Task();
- // 调试信息上载
- Dabug_Data_Update();
- // 喂狗
- SetBit(WDT_CR, WDTRF);
- IsTick = false;
- }
-
- Motor_Control_State();
- }
- }
|