DSP學習筆記

一半白一半蓝發表於2024-04-27

DSP學習筆記

EPWM

結構框圖

在這裡插入圖片描述

程式碼分析

程式碼配置

//1.關時基時鐘(配置前一定要這麼做)
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0; 
//2.初始化GPIO引腳(選擇EPWM的輸出IO口)
InitEPwm2Gpio();
//3.設定同步輸入脈衝觸發條件(為了做後續的移相pwm控制)
EPwm2Regs.TBCTL.bit.SYNCOSEL = TB_CTR_ZERO; //在Epwm2的計數器到0的時候就發一次時基同步脈衝
//4.初始化相位暫存器
EPwm2Regs.TBCTL.bit.PHSEN = TB_DISABLE;//Epwm2相位暫存器失能
	EPwm2Regs.TBPHS.half.TBPHS = 0;
	EPwm2Regs.TBCTR = 0x0000;                  // Clear counter
	EPwm2Regs.TBPRD = tbprd;
//5.選擇計數模式(此處選擇向上計數模式)
EPwm2Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP;    // Count up向上計數模式
//6.設定時基時鐘
EPwm2Regs.TBCTL.bit.HSPCLKDIV=TB_DIV1;//0x00
EPwm2Regs.TBCTL.bit.CLKDIV=TB_DIV2;//0x01
// 7.設定暫存器操作模式(緩衝模式)
EPwm2Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
EPwm2Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm2Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;
EPwm2Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;
//8.設定比較點(A和B都是在零點進行比較)
EPwm2Regs.CMPA.half.CMPA = 0;    // Set compare A value
EPwm2Regs.CMPB = 0;              // Set Compare B value
//9.動作模組使用
EPwm2Regs.AQCTLA.bit.ZRO = AQ_CLEAR;            // Set PWM1A on Zero
EPwm2Regs.AQCTLA.bit.CAU = AQ_SET;          // Clear PWM1A on event A, up count
EPwm2Regs.AQCTLB.bit.ZRO = AQ_SET;            // Set PWM1B on Zero
EPwm2Regs.AQCTLB.bit.CBU = AQ_CLEAR;          // Clear PWM1B on event B, up count
//10.最後不要忘記,把時鐘再開啟!!!
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;         // Start all the timers synced

相關文章