⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 f28xadc04u.c

📁 dsp2812的ad转换的程序
💻 C
字号:
/* ==================================================================================
File name:       F28XADC04U.C
                    
Originator:	Digital Control Systems Group
			Texas Instruments

Description: This file contains source for the F28X general purpose 
4 conversions ADC driver for unipolar signals

=====================================================================================
History:
-------------------------------------------------------------------------------------
 11-04-2003	Release	Rev 1.0                                     
----------------------------------------------------------------------------------*/
#include "IQmathLib.h"
#include "DSP28_Device.h"
#include "f28xadc04u.h"
#include "f28xbmsk.h"

#define CPU_CLOCK_SPEED      6.6667L   // for a 150MHz CPU clock speed
#define ADC_usDELAY 5000L
#define DELAY_US(A)  DSP28x_usDelay(((((long double) A * 1000.0L) / (long double)CPU_CLOCK_SPEED) - 9.0L) / 5.0L)

extern void DSP28x_usDelay(unsigned long Count);



void F28X_adc04u_drv_init(ADCVALS *p)
{
    DELAY_US(ADC_usDELAY);	
    
    AdcRegs.ADCTRL1.all = ADC_RESET_FLAG; 		/* Reset the ADC Module    				*/  
	asm(" NOP ");
	asm(" NOP ");    

    AdcRegs.ADCTRL3.bit.ADCBGRFDN = 0x3;		/* Power up bandgap/reference circuitry */
	DELAY_US(ADC_usDELAY);			    		/* Delay before powering up rest of ADC */
    
    AdcRegs.ADCTRL3.bit.ADCPWDN = 1;	   		/* Power up rest of ADC 				*/
    AdcRegs.ADCTRL3.bit.ADCCLKPS = 6;     		//ADCCLK=HSPCLK/[(ADCCTRL1[7]+1)]/* Set up ADCTRL3 register 				*/
	DELAY_US(ADC_usDELAY);	
   
    AdcRegs.ADCTRL1.all = 0x0110;	/* Set up ADCTRL1 register 	0x0110		级联模式	*/
    AdcRegs.ADCTRL2.all = 0x0100; 	/* Set up ADCTRL2 register 	0x0100 EVA启动转换			*/
	AdcRegs.ADCMAXCONV.bit.MAX_CONV = 3;        /* Specify four conversions  			*/
    AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x0;    //IU
    AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0x4;    //地
    AdcRegs.ADCCHSELSEQ1.bit.CONV02 = 0x8;    //IV    
    AdcRegs.ADCCHSELSEQ1.bit.CONV03 = 0xC;    //VREF1.5V
    
	
	EvaRegs.EXTCON.bit.EVSOCE = 1;               //Enable SOC
	EvaRegs.GPTCONA.bit.T1TOADC = 1;      		/* Set up EV Trigger with Timer1 UF 	*/
}  


       unsigned int tempz1;
       _iq tempz2;
       _iq tempz3;
       _iq tempz4;
       _iq tempz5;
void F28X_adc04u_drv_read(ADCVALS *p)
{
       //int offset;
       //long tmp;

        /* Wait until ADC conversion is completed */
        while (AdcRegs.ADCST.bit.SEQ1_BSY == 1)
        {};
        //offset = (int)(p->c1_out - 32767);
        
        tempz3 = AdcRegs.ADCRESULT0-AdcRegs.ADCRESULT1;    //IU-地
        tempz4 = AdcRegs.ADCRESULT3-AdcRegs.ADCRESULT1;    //VREF1.5V-地
        tempz5 = AdcRegs.ADCRESULT3-tempz4;                //IU-tempz4
        tempz2 = (AdcRegs.ADCRESULT1 + 0x8000);/*Ibase=4,IQ14*/
        tempz2 = _IQmpy(_IQ(20),tempz2);
        tempz1 = (int)((tempz2 & 0x8000)>>15);
        if (tempz1==1)
        { 
          p->c1_out = ((long)( tempz2 + 0xFFFF0000));
          p->c1_out = _IQmpy(_IQ(32),p->c1_out);                           
        }
        else
        {
          p->c1_out = ((long)( tempz2 + 0x00000000));
          p->c1_out = _IQmpy(_IQ(32),p->c1_out);//IQ20
        }
       // tempz3 = AdcRegs.ADCRESULT0;
        //temp3 = _IQmpy(temp2,_IQ(10));/* IQ15 */
        //tempz3 = ((long)(AdcRegs.ADCRESULT1 - 0x5652 + 0x8022)<<16)>>10;
        

        //dat_q15 = (>>1)&0x7FFF;   	/* Convert result to Q15 (unipolar signal) 	*/
        //tmp = (long)p->c1_gain*(long)dat_q15;
//        p->c1_out =AdcRegs.ADCRESULT0 - offset; //(int)(tmp>>13);

        //dat_q15 = (AdcRegs.ADCRESULT1>>1)&0x7FFF;   	/* Convert result to Q15 (unipolar signal) 	*/
       // tmp = (long)p->c2_gain*(long)dat_q15;
        
//        p->c2_out = AdcRegs.ADCRESULT1 - offset;
        
        //dat_q15 = (AdcRegs.ADCRESULT2>>1)&0x7FFF;   	/* Convert result to Q15 (unipolar signal) 	*/
        //tmp = (long)p->c3_gain*(long)dat_q15;
//        p->c3_out = AdcRegs.ADCRESULT2;


        AdcRegs.ADCTRL2.all |= 0x4040;       		/* reset the seq 							*/

}            
          

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -