C2000系列TMS320F28335如何触发ADC?
[复制链接]
本帖最后由 Aguilera 于 2020-4-12 11:21 编辑
触发方式
三种触发方式可以开始ADC转换,具体如下:
S/W软件立即启动
EPWM SOCA、SOCB转换启动
XINT2 ADC转换开始
1、使用EPWM的SOCA触发;
AdcRegs.ADCTRL2.bit.EPWM_SOCA_SEQ1 = 1;// Enable SOCA from ePWM to start SEQ1
AdcRegs.ADCTRL2.bit.INT_ENA_SEQ1 = 1; // Enable SEQ1 interrupt (every EOS)
2、使能EPWMxSOCA信号的产生,以何种方式何时产生;
EPwm1Regs.ETSEL.bit.SOCAEN = 1; // Enable SOC on A group
EPwm1Regs.ETSEL.bit.SOCASEL = 4; // Select SOC from from CPMA on upcount CTR = CMPA且为向上计数是产生触发事件
EPwm1Regs.ETPS.bit.SOCAPRD = 1; // Generate pulse on 1st event 在第一个事件时产生SOCA信号
EPwm1Regs.CMPA.half.CMPA = 0x0080; // Set compare A value
3、EPWM为up-down模式,触发频率为10K,时钟为150MHz;
EPwm1Regs.TBPRD = 0x1D4C; // Set period for ePWM1 7500 10K
EPwm1Regs.TBCTR = 0x0000U; //
EPwm1Regs.TBCTL.bit.CTRMODE = 2; // up-down模式
EPwm1Regs.TBCTL.bit.HSPCLKDIV = 0x00; // 使用系统时钟
EPwm1Regs.TBCTL.bit.CLKDIV = 0x00;
ADC初始化配置程序如下:
#include "DSP2833x_Device.h" // DSP2833x Headerfile Include File
#include "DSP2833x_Examples.h" // DSP2833x Examples Include File
#include "DSP2833x_Adc.h"
#define ADC_usDELAY 5000L
Uint16 Sample_I = 0U;
float Real_I = 0.0f;
float Base_Current = 3.0f / 4096.0f;
void init_28335ADC_CLK(void)
{
EALLOW;
#define ADC_MODCLK 0x03
SysCtrlRegs.HISPCP.all = ADC_MODCLK;
EDIS;
}
// ADC初始化
void init_adc_config(void)
{
extern void DSP28x_usDelay(Uint32 Count);
EALLOW;
SysCtrlRegs.PCLKCR0.bit.ADCENCLK = 1;
ADC_cal();
EDIS;
AdcRegs.ADCTRL3.all = 0x00E0; // Power up bandgap/reference/ADC circuits
DELAY_US(ADC_usDELAY); // Delay before converting ADC channels
// Configure ADC
AdcRegs.ADCMAXCONV.all = 0x000F; // Setup 1 conv's on SEQ1 16个通道
AdcRegs.ADCTRL1.bit.ACQ_PS = 0x1;
AdcRegs.ADCTRL3.bit.SMODE_SEL = 0; // 顺序采样
AdcRegs.ADCTRL1.bit.CPS = 0; // 对外设时钟HSPCLK不分频
AdcRegs.ADCTRL3.bit.ADCCLKPS = 0x0; // ADC内核时钟不分频 ADCCLK = HSPCLK / (CPS + 1) = 25MHz
AdcRegs.ADCTRL1.bit.SEQ_CASC = 1; // 级联排序模式
AdcRegs.ADCTRL1.bit.CONT_RUN = 1; // 连续模式
AdcRegs.ADCTRL1.bit.SEQ_OVRD = 1; // 排序覆盖
// 转换顺序
AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x00U; // Setup ADCINA0 as 1st SEQ1 conv.
AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0x01U;
AdcRegs.ADCCHSELSEQ1.bit.CONV02 = 0x02U;
AdcRegs.ADCCHSELSEQ1.bit.CONV03 = 0x03U;
AdcRegs.ADCCHSELSEQ2.bit.CONV04 = 0x04U;
AdcRegs.ADCCHSELSEQ2.bit.CONV05 = 0x05U;
AdcRegs.ADCCHSELSEQ2.bit.CONV06 = 0x06U;
AdcRegs.ADCCHSELSEQ2.bit.CONV07 = 0x07U;
AdcRegs.ADCCHSELSEQ3.bit.CONV08 = 0x08U;
AdcRegs.ADCCHSELSEQ3.bit.CONV09 = 0x09U;
AdcRegs.ADCCHSELSEQ3.bit.CONV10 = 0x0AU;
AdcRegs.ADCCHSELSEQ3.bit.CONV11 = 0x0BU;
AdcRegs.ADCCHSELSEQ4.bit.CONV12 = 0x0CU;
AdcRegs.ADCCHSELSEQ4.bit.CONV13 = 0x0DU;
AdcRegs.ADCCHSELSEQ4.bit.CONV14 = 0x0EU;
AdcRegs.ADCCHSELSEQ4.bit.CONV15 = 0x0FU;
AdcRegs.ADCTRL2.bit.EPWM_SOCA_SEQ1 = 1;// Enable SOCA from ePWM to start SEQ1
AdcRegs.ADCTRL2.bit.INT_ENA_SEQ1 = 1; // Enable SEQ1 interrupt (every EOS)
// Assumes ePWM1 clock is already enabled in InitSysCtrl();
EPwm1Regs.ETSEL.bit.SOCAEN = 1; // Enable SOC on A group
EPwm1Regs.ETSEL.bit.SOCASEL = 4; // Select SOC from from CPMA on upcount CTR = CMPA且为向上计数是产生触发事件
EPwm1Regs.ETPS.bit.SOCAPRD = 1; // Generate pulse on 1st event 在第一个事件时产生SOCA信号
EPwm1Regs.CMPA.half.CMPA = 0x0080; // Set compare A value
// 设置EPWM触发源
EPwm1Regs.TBPRD = 0x1D4C; // Set period for ePWM1 7500 10K
EPwm1Regs.TBCTR = 0x0000U; //
EPwm1Regs.TBCTL.bit.CTRMODE = 2; // up-down模式
EPwm1Regs.TBCTL.bit.HSPCLKDIV = 0x00; // 使用系统时钟
EPwm1Regs.TBCTL.bit.CLKDIV = 0x00;
}
// 转换计算
interrupt void adc_isr(void)
{
Sample_I = AdcRegs.ADCRESULT0 >>4; // 采样数据
Real_I = (float)Sample_I * Base_Current;// 实际电流
}
|