TI中文支持网
TI专业的中文技术问题搜集分享网站

28335如何AD采样并用PWM输出

新人学习dsp,最近在用AD采样,并用pwm输出波形,编了一个程序,但不知道对不对,现附上程序请大神们指导一下。

#include "DSP2833x_Device.h" // DSP2833x Headerfile Include File
#include "DSP2833x_Examples.h" // DSP2833x Examples Include File

#pragma CODE_SECTION(epwm1_timer_isr, "ramfuncs");

#define Period 37500 // 周期(3750*2*Frequency*2分频=150M)

/*******************************************************
————— 采样函数变量定义————————
********************************************************/
int16 data_A0 = 0;
int16 data_Table[1000] = {0};
int16 countAD = 0;

/*******************************************************
——————函数声明——————————
*******************************************************/
void EPWM_init(void); // EPWM初始化函数
void ADC_init(void); // ADC初始化函数
void AdcSample(void); // ADC采样函数

interrupt void epwm1_timer_isr(void); // 中断函数

/******************************************************
——————主函数——————————-
*******************************************************/

void main(void)
{
// Step 1. Initialize System Control:
InitSysCtrl();

//MemCopy(&RamfuncsLoadStart, &RamfuncsLoadEnd, &RamfuncsRunStart);
//InitFlash();

InitEPwmGpio();

// Step 3. Clear all interrupts and initialize PIE vector table:
DINT;

InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();

EALLOW; PieVectTable.EPWM1_INT = &epwm1_timer_isr;
EDIS;

// Step 4. Initialize all the Device Peripherals: EPWM_init(); ADC_init();

// Step 5. User specific code, enable interrupts
IER |= M_INT3; PieCtrlRegs.PIEIER3.bit.INTx1 = 1; // Enable EPWM1_INT in PIE
EINT; ERTM;

// Step 6. IDLE loop. Just sit and loop forever (optional):
for(;;)
{
asm(" NOP");
}
}

/***************************************************************
———————-中断函数———————————-
***************************************************************/
interrupt void epwm1_timer_isr(void)
{
while(AdcRegs.ADCST.bit.INT_SEQ1 == 0){} // 判断AD转换完成
AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1; //中断标志位清零

data_A0 = AdcRegs.ADCRESULT0 >>4;
data_Table[countAD] = data_A0;

countAD++;
if(countAD>=1000) countAD = 0;

EPwm1Regs.CMPA.half.CMPA = Period*0.5;

EPwm1Regs.ETCLR.bit.INT = 1; PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;}

/************************************************************
——————–EPWM配置函数—————————–
*************************************************************/
void EPWM_init(void){
EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0; // Stop all the TB clocks
EDIS;

/***********************************************
—–EPWM1————————————–
***********************************************/

EPwm1Regs.TBCTL.bit.PRDLD = TB_SHADOW;
EPwm1Regs.TBPRD = Period; EPwm1Regs.TBPHS.half.TBPHS = 0x0000; EPwm1Regs.TBCTR = 0x0000;

// Setup TBCLK
EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP; EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE; EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_IN; EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV4; //2分频 EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1;

EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW; EPwm1Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;
EPwm1Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;

// Set actions
EPwm1Regs.AQCTLA.bit.ZRO =AQ_SET ;
EPwm1Regs.AQCTLA.bit.CAU = AQ_CLEAR;

// Setup Deadband
EPwm1Regs.DBCTL.bit.OUT_MODE = DB_FULL_ENABLE; EPwm1Regs.DBCTL.bit.POLSEL = DB_ACTV_HIC;
EPwm1Regs.DBCTL.bit.IN_MODE = DBA_ALL;
EPwm1Regs.DBRED = Period*0.01;
EPwm1Regs.DBFED = Period*0.01;

// Event-Trigger(interrupt event)
EPwm1Regs.ETSEL.bit.INTSEL = ET_CTR_ZERO; // Select INT on Zero event
EPwm1Regs.ETSEL.bit.INTEN = 1; // Enable INT
EPwm1Regs.ETPS.bit.INTPRD = ET_1ST; // Generate INT on 1st event

EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1; // Start all the timers synced
EDIS;

}

/*******************************************************************
———————–AD采样配置函数——————————–
********************************************************************/
void ADC_init(void)
{
InitAdc();

AdcRegs.ADCTRL1.bit.ACQ_PS = 0xf; // Acquisition window size
AdcRegs.ADCTRL1.bit.CPS = 0; // ADC预分频
AdcRegs.ADCTRL3.bit.ADCCLKPS = 3; // ADCCLK=25MHz
AdcRegs.ADCTRL1.bit.SEQ_CASC = 1; // cascaded sequencer operation
AdcRegs.ADCTRL1.bit.CONT_RUN = 1; // Continue-Run mode AdcRegs.ADCTRL3.bit.SMODE_SEL = 0; // 顺序采样
// AdcRegs.ADCOFFTRIM.bit.OFFSET_TRIM = 120;
AdcRegs.ADCMAXCONV.all = 0x0005; // 6 channels of AD convertion in SEQ

AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x00; AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0x01; AdcRegs.ADCCHSELSEQ1.bit.CONV02 = 0x02; AdcRegs.ADCCHSELSEQ1.bit.CONV03 = 0x03; AdcRegs.ADCCHSELSEQ2.bit.CONV04 = 0x04; AdcRegs.ADCCHSELSEQ2.bit.CONV05 = 0x05; AdcRegs.ADCTRL2.bit.SOC_SEQ1 = 0x1; // 软件强制触发转换
}

mangui zhang:

先分开调试吧      调试成功AD采集   和   PWM输出

然后由PWM触发ADC采集

新人学习dsp,最近在用AD采样,并用pwm输出波形,编了一个程序,但不知道对不对,现附上程序请大神们指导一下。

#include "DSP2833x_Device.h" // DSP2833x Headerfile Include File
#include "DSP2833x_Examples.h" // DSP2833x Examples Include File

#pragma CODE_SECTION(epwm1_timer_isr, "ramfuncs");

#define Period 37500 // 周期(3750*2*Frequency*2分频=150M)

/*******************************************************
————— 采样函数变量定义————————
********************************************************/
int16 data_A0 = 0;
int16 data_Table[1000] = {0};
int16 countAD = 0;

/*******************************************************
——————函数声明——————————
*******************************************************/
void EPWM_init(void); // EPWM初始化函数
void ADC_init(void); // ADC初始化函数
void AdcSample(void); // ADC采样函数

interrupt void epwm1_timer_isr(void); // 中断函数

/******************************************************
——————主函数——————————-
*******************************************************/

void main(void)
{
// Step 1. Initialize System Control:
InitSysCtrl();

//MemCopy(&RamfuncsLoadStart, &RamfuncsLoadEnd, &RamfuncsRunStart);
//InitFlash();

InitEPwmGpio();

// Step 3. Clear all interrupts and initialize PIE vector table:
DINT;

InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();

EALLOW; PieVectTable.EPWM1_INT = &epwm1_timer_isr;
EDIS;

// Step 4. Initialize all the Device Peripherals: EPWM_init(); ADC_init();

// Step 5. User specific code, enable interrupts
IER |= M_INT3; PieCtrlRegs.PIEIER3.bit.INTx1 = 1; // Enable EPWM1_INT in PIE
EINT; ERTM;

// Step 6. IDLE loop. Just sit and loop forever (optional):
for(;;)
{
asm(" NOP");
}
}

/***************************************************************
———————-中断函数———————————-
***************************************************************/
interrupt void epwm1_timer_isr(void)
{
while(AdcRegs.ADCST.bit.INT_SEQ1 == 0){} // 判断AD转换完成
AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1; //中断标志位清零

data_A0 = AdcRegs.ADCRESULT0 >>4;
data_Table[countAD] = data_A0;

countAD++;
if(countAD>=1000) countAD = 0;

EPwm1Regs.CMPA.half.CMPA = Period*0.5;

EPwm1Regs.ETCLR.bit.INT = 1; PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;}

/************************************************************
——————–EPWM配置函数—————————–
*************************************************************/
void EPWM_init(void){
EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0; // Stop all the TB clocks
EDIS;

/***********************************************
—–EPWM1————————————–
***********************************************/

EPwm1Regs.TBCTL.bit.PRDLD = TB_SHADOW;
EPwm1Regs.TBPRD = Period; EPwm1Regs.TBPHS.half.TBPHS = 0x0000; EPwm1Regs.TBCTR = 0x0000;

// Setup TBCLK
EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP; EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE; EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_IN; EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV4; //2分频 EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1;

EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW; EPwm1Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;
EPwm1Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;

// Set actions
EPwm1Regs.AQCTLA.bit.ZRO =AQ_SET ;
EPwm1Regs.AQCTLA.bit.CAU = AQ_CLEAR;

// Setup Deadband
EPwm1Regs.DBCTL.bit.OUT_MODE = DB_FULL_ENABLE; EPwm1Regs.DBCTL.bit.POLSEL = DB_ACTV_HIC;
EPwm1Regs.DBCTL.bit.IN_MODE = DBA_ALL;
EPwm1Regs.DBRED = Period*0.01;
EPwm1Regs.DBFED = Period*0.01;

// Event-Trigger(interrupt event)
EPwm1Regs.ETSEL.bit.INTSEL = ET_CTR_ZERO; // Select INT on Zero event
EPwm1Regs.ETSEL.bit.INTEN = 1; // Enable INT
EPwm1Regs.ETPS.bit.INTPRD = ET_1ST; // Generate INT on 1st event

EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1; // Start all the timers synced
EDIS;

}

/*******************************************************************
———————–AD采样配置函数——————————–
********************************************************************/
void ADC_init(void)
{
InitAdc();

AdcRegs.ADCTRL1.bit.ACQ_PS = 0xf; // Acquisition window size
AdcRegs.ADCTRL1.bit.CPS = 0; // ADC预分频
AdcRegs.ADCTRL3.bit.ADCCLKPS = 3; // ADCCLK=25MHz
AdcRegs.ADCTRL1.bit.SEQ_CASC = 1; // cascaded sequencer operation
AdcRegs.ADCTRL1.bit.CONT_RUN = 1; // Continue-Run mode AdcRegs.ADCTRL3.bit.SMODE_SEL = 0; // 顺序采样
// AdcRegs.ADCOFFTRIM.bit.OFFSET_TRIM = 120;
AdcRegs.ADCMAXCONV.all = 0x0005; // 6 channels of AD convertion in SEQ

AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x00; AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0x01; AdcRegs.ADCCHSELSEQ1.bit.CONV02 = 0x02; AdcRegs.ADCCHSELSEQ1.bit.CONV03 = 0x03; AdcRegs.ADCCHSELSEQ2.bit.CONV04 = 0x04; AdcRegs.ADCCHSELSEQ2.bit.CONV05 = 0x05; AdcRegs.ADCTRL2.bit.SOC_SEQ1 = 0x1; // 软件强制触发转换
}

HeiHei:

不明白你的目的,你具体要实现什么功能?可以详细说一下吗?

新人学习dsp,最近在用AD采样,并用pwm输出波形,编了一个程序,但不知道对不对,现附上程序请大神们指导一下。

#include "DSP2833x_Device.h" // DSP2833x Headerfile Include File
#include "DSP2833x_Examples.h" // DSP2833x Examples Include File

#pragma CODE_SECTION(epwm1_timer_isr, "ramfuncs");

#define Period 37500 // 周期(3750*2*Frequency*2分频=150M)

/*******************************************************
————— 采样函数变量定义————————
********************************************************/
int16 data_A0 = 0;
int16 data_Table[1000] = {0};
int16 countAD = 0;

/*******************************************************
——————函数声明——————————
*******************************************************/
void EPWM_init(void); // EPWM初始化函数
void ADC_init(void); // ADC初始化函数
void AdcSample(void); // ADC采样函数

interrupt void epwm1_timer_isr(void); // 中断函数

/******************************************************
——————主函数——————————-
*******************************************************/

void main(void)
{
// Step 1. Initialize System Control:
InitSysCtrl();

//MemCopy(&RamfuncsLoadStart, &RamfuncsLoadEnd, &RamfuncsRunStart);
//InitFlash();

InitEPwmGpio();

// Step 3. Clear all interrupts and initialize PIE vector table:
DINT;

InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();

EALLOW; PieVectTable.EPWM1_INT = &epwm1_timer_isr;
EDIS;

// Step 4. Initialize all the Device Peripherals: EPWM_init(); ADC_init();

// Step 5. User specific code, enable interrupts
IER |= M_INT3; PieCtrlRegs.PIEIER3.bit.INTx1 = 1; // Enable EPWM1_INT in PIE
EINT; ERTM;

// Step 6. IDLE loop. Just sit and loop forever (optional):
for(;;)
{
asm(" NOP");
}
}

/***************************************************************
———————-中断函数———————————-
***************************************************************/
interrupt void epwm1_timer_isr(void)
{
while(AdcRegs.ADCST.bit.INT_SEQ1 == 0){} // 判断AD转换完成
AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1; //中断标志位清零

data_A0 = AdcRegs.ADCRESULT0 >>4;
data_Table[countAD] = data_A0;

countAD++;
if(countAD>=1000) countAD = 0;

EPwm1Regs.CMPA.half.CMPA = Period*0.5;

EPwm1Regs.ETCLR.bit.INT = 1; PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;}

/************************************************************
——————–EPWM配置函数—————————–
*************************************************************/
void EPWM_init(void){
EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0; // Stop all the TB clocks
EDIS;

/***********************************************
—–EPWM1————————————–
***********************************************/

EPwm1Regs.TBCTL.bit.PRDLD = TB_SHADOW;
EPwm1Regs.TBPRD = Period; EPwm1Regs.TBPHS.half.TBPHS = 0x0000; EPwm1Regs.TBCTR = 0x0000;

// Setup TBCLK
EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP; EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE; EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_IN; EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV4; //2分频 EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1;

EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW; EPwm1Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;
EPwm1Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;

// Set actions
EPwm1Regs.AQCTLA.bit.ZRO =AQ_SET ;
EPwm1Regs.AQCTLA.bit.CAU = AQ_CLEAR;

// Setup Deadband
EPwm1Regs.DBCTL.bit.OUT_MODE = DB_FULL_ENABLE; EPwm1Regs.DBCTL.bit.POLSEL = DB_ACTV_HIC;
EPwm1Regs.DBCTL.bit.IN_MODE = DBA_ALL;
EPwm1Regs.DBRED = Period*0.01;
EPwm1Regs.DBFED = Period*0.01;

// Event-Trigger(interrupt event)
EPwm1Regs.ETSEL.bit.INTSEL = ET_CTR_ZERO; // Select INT on Zero event
EPwm1Regs.ETSEL.bit.INTEN = 1; // Enable INT
EPwm1Regs.ETPS.bit.INTPRD = ET_1ST; // Generate INT on 1st event

EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1; // Start all the timers synced
EDIS;

}

/*******************************************************************
———————–AD采样配置函数——————————–
********************************************************************/
void ADC_init(void)
{
InitAdc();

AdcRegs.ADCTRL1.bit.ACQ_PS = 0xf; // Acquisition window size
AdcRegs.ADCTRL1.bit.CPS = 0; // ADC预分频
AdcRegs.ADCTRL3.bit.ADCCLKPS = 3; // ADCCLK=25MHz
AdcRegs.ADCTRL1.bit.SEQ_CASC = 1; // cascaded sequencer operation
AdcRegs.ADCTRL1.bit.CONT_RUN = 1; // Continue-Run mode AdcRegs.ADCTRL3.bit.SMODE_SEL = 0; // 顺序采样
// AdcRegs.ADCOFFTRIM.bit.OFFSET_TRIM = 120;
AdcRegs.ADCMAXCONV.all = 0x0005; // 6 channels of AD convertion in SEQ

AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x00; AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0x01; AdcRegs.ADCCHSELSEQ1.bit.CONV02 = 0x02; AdcRegs.ADCCHSELSEQ1.bit.CONV03 = 0x03; AdcRegs.ADCCHSELSEQ2.bit.CONV04 = 0x04; AdcRegs.ADCCHSELSEQ2.bit.CONV05 = 0x05; AdcRegs.ADCTRL2.bit.SOC_SEQ1 = 0x1; // 软件强制触发转换
}

youqin guo:

回复 HeiHei:

主要是想通过28335的ADC采集模拟量,并输出能够控制pwm波的一个程序

新人学习dsp,最近在用AD采样,并用pwm输出波形,编了一个程序,但不知道对不对,现附上程序请大神们指导一下。

#include "DSP2833x_Device.h" // DSP2833x Headerfile Include File
#include "DSP2833x_Examples.h" // DSP2833x Examples Include File

#pragma CODE_SECTION(epwm1_timer_isr, "ramfuncs");

#define Period 37500 // 周期(3750*2*Frequency*2分频=150M)

/*******************************************************
————— 采样函数变量定义————————
********************************************************/
int16 data_A0 = 0;
int16 data_Table[1000] = {0};
int16 countAD = 0;

/*******************************************************
——————函数声明——————————
*******************************************************/
void EPWM_init(void); // EPWM初始化函数
void ADC_init(void); // ADC初始化函数
void AdcSample(void); // ADC采样函数

interrupt void epwm1_timer_isr(void); // 中断函数

/******************************************************
——————主函数——————————-
*******************************************************/

void main(void)
{
// Step 1. Initialize System Control:
InitSysCtrl();

//MemCopy(&RamfuncsLoadStart, &RamfuncsLoadEnd, &RamfuncsRunStart);
//InitFlash();

InitEPwmGpio();

// Step 3. Clear all interrupts and initialize PIE vector table:
DINT;

InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();

EALLOW; PieVectTable.EPWM1_INT = &epwm1_timer_isr;
EDIS;

// Step 4. Initialize all the Device Peripherals: EPWM_init(); ADC_init();

// Step 5. User specific code, enable interrupts
IER |= M_INT3; PieCtrlRegs.PIEIER3.bit.INTx1 = 1; // Enable EPWM1_INT in PIE
EINT; ERTM;

// Step 6. IDLE loop. Just sit and loop forever (optional):
for(;;)
{
asm(" NOP");
}
}

/***************************************************************
———————-中断函数———————————-
***************************************************************/
interrupt void epwm1_timer_isr(void)
{
while(AdcRegs.ADCST.bit.INT_SEQ1 == 0){} // 判断AD转换完成
AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1; //中断标志位清零

data_A0 = AdcRegs.ADCRESULT0 >>4;
data_Table[countAD] = data_A0;

countAD++;
if(countAD>=1000) countAD = 0;

EPwm1Regs.CMPA.half.CMPA = Period*0.5;

EPwm1Regs.ETCLR.bit.INT = 1; PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;}

/************************************************************
——————–EPWM配置函数—————————–
*************************************************************/
void EPWM_init(void){
EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0; // Stop all the TB clocks
EDIS;

/***********************************************
—–EPWM1————————————–
***********************************************/

EPwm1Regs.TBCTL.bit.PRDLD = TB_SHADOW;
EPwm1Regs.TBPRD = Period; EPwm1Regs.TBPHS.half.TBPHS = 0x0000; EPwm1Regs.TBCTR = 0x0000;

// Setup TBCLK
EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP; EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE; EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_IN; EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV4; //2分频 EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1;

EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW; EPwm1Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;
EPwm1Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;

// Set actions
EPwm1Regs.AQCTLA.bit.ZRO =AQ_SET ;
EPwm1Regs.AQCTLA.bit.CAU = AQ_CLEAR;

// Setup Deadband
EPwm1Regs.DBCTL.bit.OUT_MODE = DB_FULL_ENABLE; EPwm1Regs.DBCTL.bit.POLSEL = DB_ACTV_HIC;
EPwm1Regs.DBCTL.bit.IN_MODE = DBA_ALL;
EPwm1Regs.DBRED = Period*0.01;
EPwm1Regs.DBFED = Period*0.01;

// Event-Trigger(interrupt event)
EPwm1Regs.ETSEL.bit.INTSEL = ET_CTR_ZERO; // Select INT on Zero event
EPwm1Regs.ETSEL.bit.INTEN = 1; // Enable INT
EPwm1Regs.ETPS.bit.INTPRD = ET_1ST; // Generate INT on 1st event

EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1; // Start all the timers synced
EDIS;

}

/*******************************************************************
———————–AD采样配置函数——————————–
********************************************************************/
void ADC_init(void)
{
InitAdc();

AdcRegs.ADCTRL1.bit.ACQ_PS = 0xf; // Acquisition window size
AdcRegs.ADCTRL1.bit.CPS = 0; // ADC预分频
AdcRegs.ADCTRL3.bit.ADCCLKPS = 3; // ADCCLK=25MHz
AdcRegs.ADCTRL1.bit.SEQ_CASC = 1; // cascaded sequencer operation
AdcRegs.ADCTRL1.bit.CONT_RUN = 1; // Continue-Run mode AdcRegs.ADCTRL3.bit.SMODE_SEL = 0; // 顺序采样
// AdcRegs.ADCOFFTRIM.bit.OFFSET_TRIM = 120;
AdcRegs.ADCMAXCONV.all = 0x0005; // 6 channels of AD convertion in SEQ

AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x00; AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0x01; AdcRegs.ADCCHSELSEQ1.bit.CONV02 = 0x02; AdcRegs.ADCCHSELSEQ1.bit.CONV03 = 0x03; AdcRegs.ADCCHSELSEQ2.bit.CONV04 = 0x04; AdcRegs.ADCCHSELSEQ2.bit.CONV05 = 0x05; AdcRegs.ADCTRL2.bit.SOC_SEQ1 = 0x1; // 软件强制触发转换
}

youqin guo:

回复 mangui zhang:

这个我都调试过了,用的是  AdcRegs.ADCTRL2.bit.EPWM_SOCA_SEQ1=1;触发,但发现采样到的电压值跟pwm波形没有关系,我在想这个是要在主函数里面编写一个adc控制pwm占空比的程序吗还是怎么的,请您支个招

赞(0)
未经允许不得转载:TI中文支持网 » 28335如何AD采样并用PWM输出
分享到: 更多 (0)