配置ADC:
1.设置转换通道数
AdcRegs.ADCMAXCONV.all = 0x0001; // SEQ1的通道转换数是(MAXCONV+1)
2.转换通道的选择
AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x3; // Setup ADCINA3 as 1st SEQ1 conv.
AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0x2; // Setup ADCINA2 as 2nd SEQ1 conv.
3.使能ePWM作为触发转换的信号
AdcRegs.ADCTRL2.bit.EPWM_SOCA_SEQ1 = 1;// Enable SOCA from ePWM to start SEQ1
4. 使能SEQ1的中断
AdcRegs.ADCTRL2.bit.INT_ENA_SEQ1 = 1; // Enable SEQ1 interrupt (every EOS)
配置ePWM:
1.使能ePWM作为SOCA触发信号
EPwm1Regs.ETSEL.bit.SOCAEN = 1; // Enable SOC on A group
2.SOCA信号是来自CMPA上升计数
EPwm1Regs.ETSEL.bit.SOCASEL = 4; // Select SOC from CMPA on upcount
3.SOCA周期的选择(每一次/两次/三次 事件触发)
EPwm1Regs.ETPS.bit.SOCAPRD = 1; // Generate pulse on 1st event
00 Disable the SOCA event counter. No EPWMxSOCA pulse will be generated
01 Generate the EPWMxSOCA pulse on the first event: ETPS[SOCACNT] = 0,1
10 Generate the EPWMxSOCA pulse on the second event: ETPS[SOCACNT] = 1,0
11 Generate the EPWMxSOCA pulse on the third event: ETPS[SOCACNT] = 1,1
4.ePWM中时基模块和计数比较模块的设置
EPwm1Regs.CMPA.half.CMPA = 0x0080; // Set compare A value
EPwm1Regs.TBPRD = 0xFFFF; // Set period for ePWM1
EPwm1Regs.TBCTL.bit.CTRMODE = 0; // count up and start
|