This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
如标题所示,程序调了很久,但死活不行,为毛28031的ADC这么的神奇,
9路模拟信号输入通道是ADCINA0~ADCINA4,ADCINA7,ADCINB0,ADCINB1,ADCINB7 这9路信号,
程序中使用的中断是ADCINT1,使用软件置位触发ADC中断,有关AD的程序全部提取如下:
main
{
DINT;
InitSysCtrl();
asm(" RPT #8 || NOP ");
DINT;
/***************Interrupt****************/
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
EALLOW;
PieVectTable.ADCINT1 = &adc_isr;//使用ADCINT1
EDIS;
InitAdcAio();
InitAdc(void);
IER |= M_INT1;////含有ADCINT1
sw_soc_internal_adc();//软件启动ADC
while(1)
{
while((AdcRegs.ADCSOCFLG1.all & 0x01FF) == 0){}//这一条是我加的测试语句看SOC是否有了(是否开始ADC转换)
internal_adc_operation();//如adc_isr中的internal_adc_interrupt_flag置位,就读出9个ADC通道的数字量
}
}
void InitAdcAio()
{
EALLOW;
/* Configure ADC pins using AIO regs*/
// This specifies which of the possible AIO pins will be Analog input pins.
// NOTE: AIO1,3,5,7-9,11,13,15 are analog inputs in all AIOMUX1 configurations.
// Comment out other unwanted lines.
GpioCtrlRegs.AIOMUX1.bit.AIO2 = 2; // Configure AIO2 for A2 (analog input) operation
GpioCtrlRegs.AIOMUX1.bit.AIO4 = 2; // Configure AIO4 for A4 (analog input) operation
//GpioCtrlRegs.AIOMUX1.bit.AIO6 = 2; // Configure AIO6 for A6 (analog input) operation
//GpioCtrlRegs.AIOMUX1.bit.AIO10 = 2; // Configure AIO10 for B2 (analog input) operation
//GpioCtrlRegs.AIOMUX1.bit.AIO12 = 2; // Configure AIO12 for B4 (analog input) operation
//GpioCtrlRegs.AIOMUX1.bit.AIO14 = 2; // Configure AIO14 for B6 (analog input) operation
EDIS;
}
void InitAdc(void)
{
extern void DSP28x_usDelay(Uint32 Count);
// *IMPORTANT*
// The Device_cal function, which copies the ADC calibration values from TI reserved
// OTP into the ADCREFSEL and ADCOFFTRIM registers, occurs automatically in the
// Boot ROM. If the boot ROM code is bypassed during the debug process, the
// following function MUST be called for the ADC to function according
// to specification. The clocks to the ADC MUST be enabled before calling this
// function.
// See the device data manual and/or thee ADC Reference
// Manual for more informatioon.
EALLOW;
SysCtrlRegs.PCLKCR0.bit.ADCENCLK = 1;//使能ADC时钟
(*Device_cal)();//校正
EDIS;
// To powerup the ADC the ADCENCLK bit should be set first to enable
// clocks, followed by powering up the bandgap, reference circuitry, and ADC core.
// Before the first conversion is performed a 5ms delay must be observed
// after power up to give all analog circuits time to power up and settle
// Please note that for the delay function below to operate correctly the
// CPU_RATE define statement in the DSP2803x_Examples.h file must
// contain the correct CPU clock period in nanoseconds.
EALLOW;
AdcRegs.ADCCTL1.bit.ADCBGPWD = 1; // Power ADC BG
AdcRegs.ADCCTL1.bit.ADCREFPWD = 1; // Power reference
AdcRegs.ADCCTL1.bit.ADCPWDN = 1; // Power ADC
AdcRegs.ADCCTL1.bit.ADCENABLE = 1; // Enable ADC
AdcRegs.ADCCTL1.bit.ADCREFSEL = 0; // Select interal BG
EDIS;
DELAY_US(ADC_usDELAY); // Delay before converting ADC channels
AdcRegs.ADCCTL1.bit.INTPULSEPOS = 1; //INT pulse generation occurs 1 cycle prior to ADC result latching into its result register
AdcRegs.ADCCTL1.bit.TEMPCONV = 0;//ADCINA5不接内部温度传感器
AdcRegs.ADCSAMPLEMODE.all = 0x00;//single sample mode
AdcRegs.ADCSOC0CTL.bit.CHSEL = 0x00; //below is soc channel choose
AdcRegs.ADCSOC1CTL.bit.CHSEL = 0x01;
AdcRegs.ADCSOC2CTL.bit.CHSEL = 0x02;
AdcRegs.ADCSOC3CTL.bit.CHSEL = 0x03;
AdcRegs.ADCSOC4CTL.bit.CHSEL = 0x04;
AdcRegs.ADCSOC5CTL.bit.CHSEL = 0x07;
AdcRegs.ADCSOC6CTL.bit.CHSEL = 0x08;
AdcRegs.ADCSOC7CTL.bit.CHSEL = 0x09;
AdcRegs.ADCSOC8CTL.bit.CHSEL = 0x0F;
AdcRegs.ADCSOC0CTL.bit.ACQPS = 24; //sample time windows
AdcRegs.ADCSOC1CTL.bit.ACQPS = 24;
AdcRegs.ADCSOC2CTL.bit.ACQPS = 24;
AdcRegs.ADCSOC3CTL.bit.ACQPS = 24;
AdcRegs.ADCSOC4CTL.bit.ACQPS = 24;
AdcRegs.ADCSOC5CTL.bit.ACQPS = 24;
AdcRegs.ADCSOC6CTL.bit.ACQPS = 24;
AdcRegs.ADCSOC7CTL.bit.ACQPS = 24;
AdcRegs.ADCSOC8CTL.bit.ACQPS = 24;
AdcRegs.ADCSOC0CTL.bit.TRIGSEL = 0;//software trigger
AdcRegs.ADCSOC1CTL.bit.TRIGSEL = 0;
AdcRegs.ADCSOC2CTL.bit.TRIGSEL = 0;
AdcRegs.ADCSOC3CTL.bit.TRIGSEL = 0;
AdcRegs.ADCSOC4CTL.bit.TRIGSEL = 0;
AdcRegs.ADCSOC5CTL.bit.TRIGSEL = 0;
AdcRegs.ADCSOC6CTL.bit.TRIGSEL = 0;
AdcRegs.ADCSOC7CTL.bit.TRIGSEL = 0;
AdcRegs.ADCSOC8CTL.bit.TRIGSEL = 0;
// Enabled ADCINT1
AdcRegs.INTSEL1N2.bit.INT1E = 1;
// continuous sampling for ADCINT1
AdcRegs.INTSEL1N2.bit.INT1CONT = 1;
// Setup ADCINT1 trigger source
AdcRegs.INTSEL1N2.bit.INT1SEL = 1; //EOC1 triggers ADCINT1
// Setup each SOC's ADCINT trigger source
AdcRegs.ADCINTSOCSEL1.bit.SOC0 = 1; //ADCINT1 starts SOC0-7
AdcRegs.ADCINTSOCSEL1.bit.SOC1 = 1;
AdcRegs.ADCINTSOCSEL1.bit.SOC2 = 1;
AdcRegs.ADCINTSOCSEL1.bit.SOC3 = 1;
AdcRegs.ADCINTSOCSEL1.bit.SOC4 = 1;
AdcRegs.ADCINTSOCSEL1.bit.SOC5 = 1;
AdcRegs.ADCINTSOCSEL1.bit.SOC6 = 1;
AdcRegs.ADCINTSOCSEL1.bit.SOC7 = 1;
AdcRegs.ADCINTSOCSEL2.bit.SOC8 = 1; //ADCINT1 starts SOC8
DELAY_US(ADC_usDELAY); // Delay before converting ADC channels
}
void sw_soc_internal_adc(void)
{
//ADC Conversion
EALLOW;
AdcRegs.ADCSOCFRC1.all = 0x01FF; // Force Start SOC0-8 to begin ping-pong sampling
EDIS;
}
interrupt void adc_isr(void)
{
//ADC Conversion
EALLOW;
AdcRegs.ADCSOCFRC1.all = 0x01FF; // Force Start SOC0-8 to begin ping-pong sampling
EDIS;
while(AdcRegs.ADCINTFLG.bit.ADCINT1 == 0){} //Wait for ADCINT1
internal_adc_interrupt_flag = 1;//置1代表进入了ADC中断
AdcRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; //Clear ADCINT1 flag reinitialize for next SOC
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; // Acknowledge interrupt to PIE
}
有技术支持在吗????