本帖最后由 halou 于 2015-8-8 20:59 编辑
- <p>#define ADC_CKPS 0xf // ADC module clock = HSPCLK/2*ADC_CKPS = 25.0MHz/(1*2) = 12.5MHz
- #define ADC_SHCLK 0xF // S/H width in ADC module periods = 16 ADC clocks
- #define AVG 1000 // Average sample limit
- #define ZOFFSET 0x00 // Average Zero offset</p><p>
- </p><p>
- </p><p><p> InitSysCtrl();</p><p>
- EALLOW;
- SysCtrlRegs.HISPCP.all = ADC_MODCLK; // HSPCLK = SYSCLKOUT/ADC_MODCLK
- EDIS;
- InitGpio();
- InitCapl();
- InitAdc(); // For this example, init the ADC
- InitEpwm();
- PID_init();
- // Step 3. Clear all interrupts and initialize PIE vector table:
- // Disable CPU interrupts
- DINT;
- InitPieCtrl();
- // Disable CPU interrupts and clear all CPU interrupt flags:
- IER = 0x0000;
- IFR = 0x0000;</p><p>
- InitPieVectTable();
- EALLOW; // This is needed to write to EALLOW protected registers
- //PieVectTable. ECAP1_INT = &ISRCap1;
- //PieVectTable. ECAP2_INT = &ISRCap2;
- //PieVectTable. ECAP3_INT = &ISRCap1;
- //PieVectTable.TINT0 = &ISRTimer0;
-
- PieVectTable.ADCINT = &adc_isr;
-
- //PieVectTable.XINT13 = &cpu_timer1_isr;
- //PieVectTable.TINT2 = &cpu_timer2_isr;
- EDIS;
-
- IER |= M_INT1; // Enable CPU Interrupt 1
- PieCtrlRegs.PIEIER1.bit.INTx6 = 1; //ADCINT</p><p>
- // Enable global Interrupts and higher priority real-time debug events:
- EINT; // Enable Global interrupt INTM
- ERTM; // Enable Global realtime interrupt DBGM</p><p>
- ////////////////////////////////////////////////////////////////////////</p><p><div class="blockcode"><blockquote><p></p><p>void InitAdc(void)
- {
- extern void DSP28x_usDelay(Uint32 Count);</p><p>
- 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
- AdcRegs.ADCTRL1.bit.ACQ_PS = ADC_SHCLK; // Sequential mode: Sample rate = 1/[(2+ACQ_PS)*ADC clock in ns]
- // = 1/(3*40ns) =8.3MHz (for 150 MHz SYSCLKOUT)
- // = 1/(3*80ns) =4.17MHz (for 100 MHz SYSCLKOUT)
- // If Simultaneous mode enabled: Sample rate = 1/[(3+ACQ_PS)*ADC clock in ns]
- AdcRegs.ADCTRL3.bit.ADCCLKPS = ADC_CKPS; </p><p>//AdcRegs.ADCTRL1.bit.CPS=1; //内核时钟预定标器,1为二分频</p><p> AdcRegs.ADCTRL1.bit.SEQ_CASC = 1; // 1 Cascaded mode 级联模式
- AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x0; // Setup ADCINA0 as 1st SEQ1 conv.</p><p>
- //AdcRegs.ADCST.bit.INT_SEQ1_CLR=1;
- //AdcRegs.ADCST.bit.INT_SEQ2_CLR=1;</p><p> AdcRegs.ADCTRL1.bit.CONT_RUN = 1; // Setup continuous run
- AdcRegs.ADCTRL1.bit.SEQ_OVRD = 0; // Enable Sequencer override feature
-
- // Initialize all ADC channel selects to A0
- AdcRegs.ADCCHSELSEQ1.all = 0x0;
- AdcRegs.ADCCHSELSEQ2.all = 0x0;
- AdcRegs.ADCCHSELSEQ3.all = 0x0;
- AdcRegs.ADCCHSELSEQ4.all = 0x0;</p><p> // AdcRegs.ADCTRL3.bit.SMODE_SEL = 1; //0-顺序采样,1-同步采样
- AdcRegs.ADCMAXCONV.all = 0x0000; // Setup ADA0 conv's on SEQ1
- </p><p> AdcRegs.ADCTRL2.bit.INT_ENA_SEQ1 = 1;
- AdcRegs.ADCTRL2.bit.RST_SEQ1 = 1;
- AdcRegs.ADCTRL2.bit.SOC_SEQ1 = 1;
- }
- interrupt void adc_isr(void)
- {
- while (AdcRegs.ADCST.bit.INT_SEQ1 == 0){}</p><p> AdcA[Adc_isrTimes] = ((AdcRegs.ADCRESULT0)>>4);
- Adc_isrTimes++;</p><p> if(Adc_isrTimes==1000)
- {
- Adc_isrTimes = 0;
- }
- // Clear INT flag for this timer
- AdcRegs.ADCTRL2.bit.RST_SEQ1 = 1; // Reset SEQ1
- AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1; // Clear INT SEQ1 bit
- PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; // Acknowledge interrupt to PIE</p><p> return;
- }</p></p></p>
这是主程序中的测试代码</p><p> if(AdcRegs.ADCST.bit.SEQ1_BSY ==1)
flagintadc2 =1;
if(AdcRegs.ADCST.bit.INT_SEQ1 ==1)
flagintadc =1;</p><p>
</p><p>程序执行后
</p>
|