【DSP】TMS320F28035 ADC例程(ePWM+查询)

#include "DSP28x_Project.h"

Uint16 LoopCount;
Uint16 ConversionCount;
Uint16 Voltage1[10];
Uint16 Voltage2[10];


main()
{
    InitSysCtrl();

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

    InitAdc();

    ConversionCount = 0;

    EALLOW;
    AdcRegs.ADCCTL1.bit.INTPULSEPOS = 1;    //转换完成前一个ADC时钟周期产生EOC
    AdcRegs.INTSEL1N2.bit.INT1E     = 1;    //使能ADCINT1
    AdcRegs.INTSEL1N2.bit.INT1CONT  = 0;    //关闭连续模式
    AdcRegs.INTSEL1N2.bit.INT1SEL   = 1;    //将ADCINT1映射到EOC1
    AdcRegs.ADCSOC0CTL.bit.CHSEL    = 0;    //将ADCINA0映射到通道0
    AdcRegs.ADCSOC1CTL.bit.CHSEL    = 1;    //将ADCINA1映射到通道1
    AdcRegs.ADCSOC0CTL.bit.TRIGSEL  = 5;    //ePWM1A触发SOC0
    AdcRegs.ADCSOC1CTL.bit.TRIGSEL  = 5;    //ePWM1A触发SOC1
    AdcRegs.ADCSOC0CTL.bit.ACQPS    = 6;    //设置窗口采样次数
    AdcRegs.ADCSOC1CTL.bit.ACQPS    = 6;    //设置窗口采样次数
    EDIS;

    //还没开始研究ePWM
    EPwm1Regs.ETSEL.bit.SOCAEN  = 1;        // Enable SOC on A group
    EPwm1Regs.ETSEL.bit.SOCASEL = 4;        // Select SOC from from CPMA on upcount
    EPwm1Regs.ETPS.bit.SOCAPRD  = 1;        // Generate pulse on 1st event
    EPwm1Regs.CMPA.half.CMPA    = 0x0080;   // Set compare A value
    EPwm1Regs.TBPRD             = 0xFFFF;   // Set period for ePWM1
    EPwm1Regs.TBCTL.bit.CTRMODE = 0;        // count up and start

   for(;;)
   {
      while(AdcRegs.ADCINTFLG.bit.ADCINT1 == 0){}    //等待EOC1信号(ADCINT1)
      AdcRegs.ADCINTFLGCLR.bit.ADCINT1 = 1;        //清除EOC1信号(ADCINT1)

      if(ConversionCount == 9)
      {
          ConversionCount = 0;
      }
      else ConversionCount++;

      Voltage1[ConversionCount] = AdcResult.ADCRESULT0;
      Voltage2[ConversionCount] = AdcResult.ADCRESULT1;
   }

}

你可能感兴趣的:(嵌入式)