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

📄 adc.c

📁 基于dsp2812的温控 带AD校准和PWM输出
💻 C
字号:
/**********************************************************************
* File: Adc.c -- File for Labs 4, 5, and 6
* Devices: TMS320F2812, TMS320F2811, TMS320F2810
* Author: Technical Training Organization (TTO), Texas Instruments
* History:
*   07/01/04 - original (based on DSP281x header files v1.00)
**********************************************************************/

#include "DSP281x_Device.h"
//#include "lab.h"


void DelayUs(volatile Uint16);			//function prototype


/**********************************************************************
* Function: InitAdc()
*
* Description: Initializes the ADC on the F2812
**********************************************************************/
void InitAdc(void)
{

/*** Reset the ADC module ***/
	AdcRegs.ADCTRL1.bit.RESET = 1;		// Reset the ADC module
	asm(" RPT #10 || NOP");				// Must wait 12-cycles (worst-case) for ADC reset to take effect
	
/*** Must follow the proper ADC power-up sequence ***/
	AdcRegs.ADCTRL3.all = 0x00D9;		// first power-up ref and bandgap circuits
/*
 bit 15-8      0's:    reserved
 bit 7         1:      ADCRFDN, reference power, 1=power on
 bit 6         1:      ADCBGDN, bandgap power, 1=power on
 bit 5         0:      ADCPWDN, main ADC power, 1=power on
 bit 4-1       0100:   ADCCLKPS, clock prescaler, ADCLK=HSPCLK/(2*ADCCLKPS)
 bit 0         1:      SMODE_SEL, 0=sequential sampling, 1=simultaneous sampling 1并发采样
*/

	DelayUs(5000);						// Wait 5ms before setting ADCPWDN
	AdcRegs.ADCTRL3.bit.ADCPWDN = 1;	// Set ADCPWDN=1 to power main ADC
	DelayUs(20);						// Wait 20us before using the ADC

/*** Configure the other ADC register ***/
	AdcRegs.ADCMAXCONV.all = 0x0001; //转换8次 过采样通道A0
/*
 bit 15-7      0's:    reserved
 bit 6-4       000:    MAX_CONV2 value
 bit 3-0       0000:   MAX_CONV1 value (0 means 1 conversion)
*/

	AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x0;	// Convert Channel 0
//  AdcRegs.ADCCHSELSEQ1.all = 0x8080;  // convert channel adcinA0 and adcinB0
//  AdcRegs.ADCCHSELSEQ2.all = 0x8080;
//  AdcRegs.ADCCHSELSEQ3.all = 0x8080;
//  AdcRegs.ADCCHSELSEQ4.all = 0x8080;

	AdcRegs.ADCTRL1.all = 0x0790; // try a lower ADCclk
/*
 bit 15        0:      reserved
 bit 14        0:      RESET, 0=no action, 1=reset ADC
 bit 13-12     10:     SUSMOD, 10=stop after current conversion on emulator suspend SUSMOD, 00=do not stop on emulator suspend
 bit 11-8      0111:   ACQ_PS (Acquisition), 0111 = 8 x Fclk
 bit 7         1:      CPS (Core clock), 0: Fclk=CLK/1, 1: Fclk=CLK/2
 bit 6         0:      CONT_RUN, 0=start/stop mode, 1=continuous run
 bit 5         0:      SEQ_OVRD, 0=disabled, 1=enabled
 bit 4         1:      SEQ_CASC, 0=dual sequencer, 1=cascaded sequencer
 bit 3-0       0000:   reserved
*/

	AdcRegs.ADCTRL2.all = 0x0900;
/*
 bit 15        0:      EVB_SOC_SEQ, 0=no action
 bit 14        0:      RST_SEQ1, 0=no action
 bit 13        0:      SOC_SEQ1, 0=clear any pending SOCs
 bit 12        0:      reserved
 bit 11        1:      INT_ENA_SEQ1, 1=enable interrupt
 bit 10        0:      INT_MOD_SEQ1, 0=int on every SEQ1 conv
 bit 9         0:      reserved
 bit 8         1:      EVA_SOC_SEQ1, 1=SEQ1 start from EVA
 bit 7         0:      EXT_SOC_SEQ1, 1=SEQ1 start from ADCSOC pin
 bit 6         0:      RST_SEQ2, 0=no action
 bit 5         0:      SOC_SEQ2, no effect in cascaded mode
 bit 4         0:      reserved
 bit 3         0:      INT_ENA_SEQ2, 0=int disabled
 bit 2         0:      INT_MOD_SEQ2, 0=int on every other SEQ2 conv
 bit 1         0:      reserved
 bit 0         0:      EVB_SOC_SEQ2, 1=SEQ2 started by EVB
*/

/*** Enable the ADC interrupt ***/
	PieCtrlRegs.PIEIER1.bit.INTx6 = 1;	// Enable ADCINT in PIE group 1
	IER |= 0x0001;						// Enable INT1 in IER to enable PIE group 1

} // end AdcInit()


/*********************************************************************
* Function: DelayUs()                                                *
* Description: Implements a time delay.                              *
* DSP: TMS320F2812                                                   *
* Last Modified: 06/28/02                                            *
* Include files: none                                                *
* Function Prototype: void DelayUs(volatile Uint16)                  *
* Useage: DelayUs(Usec);                                             *
* Input Parameters: Uint16 Usec = time delay in microseconds         *
* Return Value: none                                                 *
* Notes: The execution time of this routine is rough, based upon a   *
*        150MHz CPUCLK.  It has been tested using all optimization   *
*        levels of the compiler to give approximately a 1us inner    *
*        loop.                                                       *   
*********************************************************************/

void DelayUs( volatile Uint16 Usec )
{
    while( Usec-- )					// 1us loop at 150MHz CPUCLK
	{
		asm(" RPT #139 || NOP");
	}

} // end DelayUs()

/*interrupt void adc_isr(void)
{
	
	ResultA0 = AdcRegs.ADCRESULT0 >> 4; //右移4位得到12为结果
	ResultB0 = AdcRegs.ADCRESULT1 >> 4;
	ResultA0 += AdcRegs.ADCRESULT2 >> 4;
	ResultB0 += AdcRegs.ADCRESULT3 >> 4;
	ResultA0 += AdcRegs.ADCRESULT4 >> 4;
	ResultB0 += AdcRegs.ADCRESULT5 >> 4;
	ResultA0 += AdcRegs.ADCRESULT6 >> 4;
	ResultB0 += AdcRegs.ADCRESULT7 >> 4;


	ResultA0 = ResultA0/8;
	ResultB0 = ResultB0/8;

    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
	return;

 }
 */
/*** end of file *****************************************************/

⌨️ 快捷键说明

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