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.
ADC初始化代码如下:
void ADC_Init(void){ EALLOW; SysCtrlRegs.PCLKCR0.bit.ADCENCLK = 1; // Enable ADC clock SysCtrlRegs.HISPCP.all = 3; // ADC: 25MHZ InitAdc(); // provide by TI // AdcRegs.ADCTRL3.all = 0x00E0; AdcRegs.ADCTRL1.bit.ACQ_PS = 0x0F; // sequential sampling AdcRegs.ADCTRL3.bit.ADCCLKPS = 1; // 25Mhz no frequency division AdcRegs.ADCTRL1.bit.SEQ_CASC = 1; // 1: Cascaded sequencer mode 0:double sort mode AdcRegs.ADCTRL3.bit.SMODE_SEL = 0;// 1:Synchronous sampling 0:sequential sampling AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x0; // A0 as the sample channel save data to results0 AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0x1; // A1 as the sample channel save data to results1 AdcRegs.ADCCHSELSEQ1.bit.CONV02 = 0x2; // A2 as the sample channel save data to results2 AdcRegs.ADCCHSELSEQ1.bit.CONV03 = 0x3; // A3 as the sample channel save data to results3 AdcRegs.ADCCHSELSEQ2.bit.CONV04 = 0x4; // A4 as the sample channel save data to results4 AdcRegs.ADCCHSELSEQ2.bit.CONV05 = 0x5; // A4 as the sample channel save data to results4 AdcRegs.ADCCHSELSEQ2.bit.CONV06 = 0x6; // A4 as the sample channel save data to results4 AdcRegs.ADCCHSELSEQ2.bit.CONV07 = 0x7; // A4 as the sample channel save data to results4 AdcRegs.ADCCHSELSEQ3.bit.CONV08 = 0x8; // B0 as the sample channel save data to results5 AdcRegs.ADCCHSELSEQ3.bit.CONV09 = 0x9; // B0 as the sample channel save data to results5 AdcRegs.ADCCHSELSEQ3.bit.CONV10 = 0xA; // B0 as the sample channel save data to results5 AdcRegs.ADCCHSELSEQ3.bit.CONV11 = 0xB; // B0 as the sample channel save data to results5 AdcRegs.ADCCHSELSEQ4.bit.CONV12 = 0xC; // B0 as the sample channel save data to results5 AdcRegs.ADCCHSELSEQ4.bit.CONV13 = 0xD; // B0 as the sample channel save data to results5 AdcRegs.ADCCHSELSEQ4.bit.CONV14 = 0xE; // B0 as the sample channel save data to results5 AdcRegs.ADCCHSELSEQ4.bit.CONV15 = 0xF; // B0 as the sample channel save data to results5 //AdcRegs.ADCCHSELSEQ1.bit.CONV02 = 0x02; // A2 as the sample channel AdcRegs.ADCTRL1.bit.CONT_RUN = 1; // continuous sampling AdcRegs.ADCMAXCONV.bit.MAX_CONV1 = 0xF; // max sample channel, CONV05 have used , so it should be 5. but actully, only two channel working. Cascaded mode max 15, double sort max 7; //AdcRegs.ADCMAXCONV.bit.MAX_CONV2 = 0xf; // max sample channel, case only A0 is used , so 0x0; AdcRegs.ADCTRL2.all = 0x2000; //software trigger EDIS; }
返回ADC读值的代码如下:
Uint16 Read_ADCValueResult0(void){ while(AdcRegs.ADCST.bit.INT_SEQ1 == 0); // wait the end of the translation AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1; //clear interrupt flag return AdcRegs.ADCRESULT0>>4; //return translate results, high 12bits valid, low 4bits invalid }