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.

TMS320F2835 adc连续采样



我现在想采集adc2的值,用软件触发,连续采样,我的设置如下:

AdcRegs.ADCCTL1.bit.INTPULSEPOS = 0;

AdcRegs.INTSEL1N2.bit.INT2E = 0;//关闭中断
AdcRegs.INTSEL1N2.bit.INT2CONT = 1; //连续模式
AdcRegs.INTSEL1N2.bit.INT2SEL = 0x10; //选择无效
AdcRegs.ADCSOC1CTL.bit.CHSEL = 2; //将ADCINA2映射到通道1
AdcRegs.ADCSOC1CTL.bit.TRIGSEL = 0;//软件触发

//
// set SOC1 S/H Window to 7 ADC Clock Cycles, (6 ACQPS plus 1)
//
AdcRegs.ADCSOC1CTL.bit.ACQPS = 6;
EDIS;
AdcRegs.ADCSOCFRC1.bit.SOC1=1;

然后我每次读的时候:

AdcRegs.ADCSOCFRC1.bit.SOC1=1;//软件触发
adc_tmp=AdcResult.ADCRESULT1;//读值

如果我改成这样:

//AdcRegs.ADCSOCFRC1.bit.SOC1=1;//软件触发

adc_tmp=AdcResult.ADCRESULT1;//读值

就读不出数来,也就是说,我把软件触发关闭,adc值就读不出来,那么这个AdcRegs.INTSEL1N2.bit.INT2CONT = 1; //连续模式有什么意义呢?如果每次我读取都需要软件触发的话,这个连续方式作用不大啊,我的理解是我把连续模式打开后,我只要软件触发一次后,我读取adc_tmp=AdcResult.ADCRESULT1;的值都会成功,因为我把连续模式打开了,如果不是这么理解的话,那么这个连续模式是怎么理解的呢?在什么情况下才有用呢?

  • 参考用户指南,该位设置后会强制给通道产生SOC信号,从而实现连续采样

  • 按照这个回答,那不就是我只要设置一次AdcRegs.ADCSOCFRC1.bit.SOC1=1;然后我每次adc_tmp=AdcResult.ADCRESULT1;读取数据,都应该有数据的,但是实际情况却是如果我只设置一次AdcRegs.ADCSOCFRC1.bit.SOC1=1;后,只能读取一次adc_tmp=AdcResult.ADCRESULT1;这个值,当我的ADC端口电压变化后,adc_tmp=AdcResult.ADCRESULT1并没有改变。这是为什么呢?
  • 您现在是使用软件触发+中断的方式?那您在中断void adc_isr(void)中进行:

    EALLOW;

    AdcRegs.ADCSOCFRC1.bit.SOC1=1;//软件触发

    EDIS;

    就可以了
  • 其实我是不想用中断,因为中断会打断主程序,所以我才尝试用连续转换方式,我在设置里进行了这样的初始化:AdcRegs.INTSEL1N2.bit.INT2E = 0;//关闭中断
    AdcRegs.INTSEL1N2.bit.INT2CONT = 1; //连续模式
    我想问的是:dsp有那种adc开启后就自动连续转换,不需要其他触发源了的配置么?,之前在arm里面有用这种模式,看了dsp的相关资料,好像应该也支持,但是实际使用却不是这样,好像adc如果要读到他的值,必须有触发源,那么这个连续转换对于dsp来说,好像没有起到相应的作用

  • 若是不想使用中断的话,我们有一个温度传感器连续转换的例程

    也有一些比较好的分享资料,您可以参考一下(中文版便于阅读)

    https://blog.csdn.net/LGM_1874/article/details/108140543 

    //###########################################################################
    //
    // FILE:   Example_2803xAdc_TempSensorConv.c
    //
    // TITLE:  ADC Temperature Sensor Conversion example
    //
    //! \addtogroup f2803x_example_list
    //! <h1> ADC Temperature Sensor Conversion (adc_temp_sensor_conv)</h1>
    //!
    //! This example shows how to convert a raw ADC temperature sensor reading
    //! into deg. C and deg. K. Internal temperature is sampled continuously
    //! through ADCINA5. The coefficients required to compensate for temperature
    //! offset are read from TI OTP.
    //!
    //! \note
    //! THIS EXAMPLE USES VARIABLES STORED IN OTP DURING FACTORY TEST. THESE OTP
    //! LOCATIONS ,0x3D7E90 to 0x3D7EA4, MAY NOT BE POPULATED. ENSURE THAT THESE
    //! MEMORY LOCATIONS IN TI OTP ARE POPULATED WITH VALUES DIFFERENT FROM
    //! 0XFFFF
    //!
    //! \b Watch \b Variables \n
    //!  - temp
    //!  - degC
    //!  - degK
    //
    //###########################################################################
    // $TI Release: F2803x Support Library v2.02.00.00 $
    // $Release Date: Tue May 26 17:11:32 IST 2020 $
    // $Copyright:
    // Copyright (C) 2009-2020 Texas Instruments Incorporated - http://www.ti.com/
    //
    // Redistribution and use in source and binary forms, with or without 
    // modification, are permitted provided that the following conditions 
    // are met:
    // 
    //   Redistributions of source code must retain the above copyright 
    //   notice, this list of conditions and the following disclaimer.
    // 
    //   Redistributions in binary form must reproduce the above copyright
    //   notice, this list of conditions and the following disclaimer in the 
    //   documentation and/or other materials provided with the   
    //   distribution.
    // 
    //   Neither the name of Texas Instruments Incorporated nor the names of
    //   its contributors may be used to endorse or promote products derived
    //   from this software without specific prior written permission.
    // 
    // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
    // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
    // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
    // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
    // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
    // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
    // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
    // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    // $
    //###########################################################################
    
    //
    // Included Files
    //
    #include "DSP28x_Project.h"     // DSP28x Headerfile
    
    //
    // Defines
    //
    #define CONV_WAIT 1L //Micro-seconds to wait for ADC conversion.
                         //Longer than necessary.
    
    //
    // Globals
    //
    int16 temp; //raw temperature sensor reading
    int16 degC; //temperature in deg. C
    int16 degK; //temperature in deg. K
    
    //
    // Main
    //
    void main(void)
    {
        //
        // Step 1. Initialize System Control:
        // PLL, WatchDog, enable Peripheral Clocks
        // This example function is found in the DSP2803x_SysCtrl.c file.
        //
        InitSysCtrl();
    
        //
        // Step 2. Initialize GPIO:
        // Enable XCLOCKOUT to allow monitoring of oscillator 1
        //
        EALLOW;
        GpioCtrlRegs.GPAMUX2.bit.GPIO18 = 3; //enable XCLOCKOUT through GPIO mux
        SysCtrlRegs.XCLK.bit.XCLKOUTDIV = 2; //XCLOCKOUT = SYSCLK
    
        //
        // Step 3. Clear all interrupts and initialize PIE vector table:
        // Disable CPU interrupts
        //
        DINT;
    
        //
        // Initialize PIE control registers to their default state.
        // The default state is all PIE interrupts disabled and flags
        // are cleared.
        // This function is found in the DSP2803x_PieCtrl.c file.
        //
        InitPieCtrl();
    
        //
        // Disable CPU interrupts and clear all CPU interrupt flags:
        //
        IER = 0x0000;
        IFR = 0x0000;
    
        //
        // Initialize the PIE vector table with pointers to the shell Interrupt
        // Service Routines (ISR).
        // This will populate the entire table, even if the interrupt
        // is not used in this example.  This is useful for debug purposes.
        // The shell ISR routines are found in DSP2803x_DefaultIsr.c.
        // This function is found in DSP2803x_PieVect.c.
        //
        InitPieVectTable();
    
        //
        // Step 4. Initialize all the Device Peripherals:
        // Configure and Initialize  the ADC:
        //
        InitAdc();
        AdcOffsetSelfCal();
    
        EALLOW;
        
        //
        // Connect channel A5 internally to the temperature sensor
        //
        AdcRegs.ADCCTL1.bit.TEMPCONV  = 1;  
        
        AdcRegs.ADCSOC0CTL.bit.CHSEL  = 5;  //Set SOC0 channel select to ADCINA5
        AdcRegs.ADCSOC1CTL.bit.CHSEL  = 5;  //Set SOC1 channel select to ADCINA5
        
        //
        // Set SOC0 acquisition period to 37 ADCCLK
        //
        AdcRegs.ADCSOC0CTL.bit.ACQPS  = 36; 
        
        //
        // Set SOC1 acquisition period to 37 ADCCLK
        //
        AdcRegs.ADCSOC1CTL.bit.ACQPS  = 36; 
        
        AdcRegs.INTSEL1N2.bit.INT1SEL = 1;  //Connect ADCINT1 to EOC1
        AdcRegs.INTSEL1N2.bit.INT1E  =  1;  //Enable ADCINT1
    
        //
        // Note: two channels have been connected to the temp sensor
        // so that the first sample can be discarded to avoid the
        // ADC first sample issue.  See the device errata.
        //
    
        //
        // Set the flash OTP wait-states to minimum. This is important
        // for the performance of the temperature conversion function.
        //
        FlashRegs.FOTPWAIT.bit.OTPWAIT = 1;
    
        //
        // Main program loop - continually sample temperature
        //
        for(;;)
        {
            //
            // Sample the temp sensor
            //
    
            //
            // Force start of conversion on SOC0 and SOC1
            //
            AdcRegs.ADCSOCFRC1.all = 0x03;
    
            //
            // Wait for end of conversion.
            //
            while(AdcRegs.ADCINTFLG.bit.ADCINT1 == 0){}  //Wait for ADCINT1
            AdcRegs.ADCINTFLGCLR.bit.ADCINT1 = 1;        //Clear ADCINT1
    
            //
            // Get temp sensor sample result from SOC1
            //
            temp = AdcResult.ADCRESULT1;
    
            //
            // Convert the raw temperature sensor measurement into temperature
            //
            degC = GetTemperatureC(temp);
            degK = GetTemperatureK(temp);
        }
    }
    
    //
    // End of File
    //