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.

有没有F28027或F28069的定时器触发ADC转换的例子的??



有没有F28027或F28069的定时器触发ADC转换的例子的??

  • 你好,

    我这里有个F29069通过Timer触发ADC的例子,下面贴出的是ADC部分配置的代码。这段代码是通过软件触发第一次ADC,然后在ADC中断中将ADC的触发源设置成Timer触发。

    /**********************************************************************
    * File: Adc.c -- File for Lab 6, 7, 8, 9, 10, 12 and 14 (not used in Lab 5)
    * Devices: TMS320F2806x
    * Author: Technical Training Organization (TTO), Texas Instruments
    * History:
    *   06/15/11 - original
    **********************************************************************/

    #include "Lab.h"    // Main include file


    /**********************************************************************
    * Function: InitAdc()
    *
    * Description: Initializes the ADC on the F2806x
    **********************************************************************/
    void InitAdc(void)
    {
     asm(" EALLOW");      // Enable EALLOW protected register access

    //--- Power-up and configure the ADC
     AdcRegs.ADCCTL1.all = 0x00E4;  // Power-up reference and main ADC
    // bit 15        0:      RESET, ADC software reset, 0=no effect, 1=resets the ADC
    // bit 14        0:      ADCENABLE, ADC enable, 0=disabled, 1=enabled
    // bit 13        0:      ADCBSY, ADC busy, read-only
    // bit 12-8      0's:    ADCBSYCHN, ADC busy channel, read-only
    // bit 7         1:      ADCPWDN, ADC power down, 0=powered down, 1=powered up
    // bit 6         1:      ADCBGPWD, ADC bandgap power down, 0=powered down, 1=powered up
    // bit 5         1:      ADCREFPWD, ADC reference power down, 0=powered down, 1=powered up
    // bit 4         0:      reserved
    // bit 3         0:      ADCREFSEL, ADC reference select, 0=internal, 1=external
    // bit 2         1:      INTPULSEPOS, INT pulse generation, 0=start of conversion, 1=end of conversion
    // bit 1         0:      VREFLOCONV, VREFLO convert, 0=VREFLO not connected, 1=VREFLO connected to B5
    // bit 0         0:      TEMPCONV, Temperature sensor convert.  0=ADCINA5 is pin, 1=ADCINA5 is temp sensor

     AdcRegs.ADCCTL2.all = 0x0005;  // ADC clock configuration
    // bit 15-3      0's:    reserved
    // bit 2         0:      CLKDIV4EN, ADC clock divider.  0=no effect, 1=CPUCLK/4 if CLKDIV2EN=1 (else no effect)
    // bit 1         0:      ADCNONOVERLAP, 0=overlap sample and conversion, 1=no overlap
    // bit 0         1:      CLKDIV2EN, ADC clock divider.  0=CPUCLK, 1=CPUCLK/2

     DelayUs(1000);      // Wait 1 ms after power-up before using the ADC

    // Priority Configuration

     AdcRegs.SOCPRICTL.bit.ONESHOT = 0; //One-shoot Mode enabled
     AdcRegs.SOCPRICTL.bit.SOCPRIORITY = 0; //All channels for Round Robin

    // ADC Sample mode configuration
     AdcRegs.ADCSAMPLEMODE.all=0x0000;  //All SOC sample mode configured to Single Sample mode


    // ADC SOC0 configuration

     AdcRegs.ADCSOC0CTL.bit.TRIGSEL = 0x00;   // First for Software Trigger
     AdcRegs.ADCSOC0CTL.bit.CHSEL = 0x01;   // Convert channel at ADC A1
     AdcRegs.ADCSOC0CTL.bit.ACQPS = 0x0F;   // Acquisition window for 9(8+1) system clocks(it can be wrong for 7 system clocks due to silicon problems, have a test!)
     AdcRegs.ADCINTSOCSEL1.bit.SOC0 =0x0;           // ADCINT Triggers disabled first, and will be enabled after the first software trigger

     AdcRegs.ADCSOC1CTL.bit.TRIGSEL = 0x00;   // First for Software Trigger
      //AdcRegs.ADCSOC0CTL.bit.TRIGSEL = 0x01;          //Trigger select for Timer0
     AdcRegs.ADCSOC1CTL.bit.CHSEL = 0x01;   // Convert channel at ADC A1
     AdcRegs.ADCSOC1CTL.bit.ACQPS = 0x0F;   // Acquisition window for 9(8+1) system clocks(it can be wrong for 7 system clocks due to silicon problems, have a test!)
     AdcRegs.ADCINTSOCSEL1.bit.SOC1 =0x0;           // ADCINT Triggers disabled first, and will be enabled after the first software trigger

     AdcRegs.ADCSOC2CTL.bit.TRIGSEL = 0x00;   // First for Software Trigger
       //AdcRegs.ADCSOC0CTL.bit.TRIGSEL = 0x01;          //Trigger select for Timer0
     AdcRegs.ADCSOC2CTL.bit.CHSEL = 0x00;   // Convert channel at ADC A1
     AdcRegs.ADCSOC2CTL.bit.ACQPS = 0x0F;   // Acquisition window for 9(8+1) system clocks(it can be wrong for 7 system clocks due to silicon problems, have a test!)
     AdcRegs.ADCINTSOCSEL1.bit.SOC2 =0x0;           // ADCINT Triggers disabled first, and will be enabled after the first software trigger

    // ADCINT1 configuration
     AdcRegs.INTSEL3N4.bit.INT4CONT = 0;   // ADCINT3 Continues mode disable
     AdcRegs.INTSEL3N4.bit.INT3CONT = 0;
     AdcRegs.INTSEL5N6.bit.INT5CONT = 0;
     AdcRegs.INTSEL3N4.bit.INT4E = 1;   // Enable ADCINT3
     AdcRegs.INTSEL3N4.bit.INT3E = 1;
     AdcRegs.INTSEL5N6.bit.INT5E = 1;
     AdcRegs.INTSEL3N4.bit.INT4SEL = 0;   // EOC0 triggers ADCINT3
     AdcRegs.INTSEL3N4.bit.INT3SEL = 1;
     AdcRegs.INTSEL5N6.bit.INT5SEL = 2;

    //--- Enable the ADC interrupt
                                          // Enable ADCINT1 in PIE group 1
                           // Enable INT1 in IER to enable PIE group

    // Pre-clear all the flags
      //this part needn't be done because of the reset
     AdcRegs.ADCCTL1.bit.ADCENABLE = 1; // Enable the ADC
     asm(" EDIS");      // Disable EALLOW protected register access

    } // end InitAdc()

    /***************************************************************************
     Function SW_Trig Used to Trigger SOCs by Software
     ****************************************************************************/

    void SW_Trig(unsigned short SOCn)
    {
     asm( "EALLOW");
     AdcRegs.ADCSOCFRC1.all = SOCn;
     asm( "EDIS");
    }

    //--- end of file -----------------------------------------------------