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

📄 dsp281x_adc.c

📁 一个DSP2812的源代码
💻 C
字号:
/*******************************************************************************
  Copyright (c) 2006 北京中盛华旭电子科技有限公司(VSUNTEK, Ltd.)
  FileName: DSP281x_Adc.c
  Author: 王在东
  Date: 2006.9.10
  Version: 1.0
  Description: ADC初始化,配置ad模块上电,配置控制寄存器,及触发方式等.
  History:
    <Author> WANGZD
	<Date>   2006.9.10
	<Ver>    1.0
	<Desc>   无

  Todo:
*******************************************************************************/

#include "DSP281x_Device.h"     // DSP281x Headerfile Include File
#include "DSP281x_Examples.h"   // DSP281x Examples Include File

#define ADC_usDELAY  8000L
#define ADC_usDELAY2 200L
Uint32  ai;
//---------------------------------------------------------------------------
// InitAdc: 
//---------------------------------------------------------------------------
// This function initializes ADC to a known state.
//
void InitAdc(void)
{
//	extern void DSP28x_usDelay(Uint32 Count);
// To powerup the ADC the ADCENCLK bit should be set first to enable
// clocks, followed by powering up the bandgap and reference circuitry.
// After a 5ms delay the rest of the ADC can be powered up. After ADC
// powerup, another 20us delay is required before performing the first
// ADC conversion. Please note that for the delay function below to
// operate correctly the CPU_CLOCK_SPEED define statement in the
// DSP28_Examples.h file must contain the correct CPU clock period in
// nanoseconds. For example:
    
	AdcRegs.ADCTRL3.bit.ADCBGRFDN = 0x3;	// Power up bandgap/reference circuitry
//	DELAY_US(ADC_usDELAY);                  // Delay before powering up rest of ADC
    for(ai=0;ai<180000;ai++)
    {FEED_WATCHDOG;}
	AdcRegs.ADCTRL3.bit.ADCPWDN = 1;		// Power up rest of ADC
//	DELAY_US(ADC_usDELAY2);                 // Delay after powering up ADC
    for(ai=0;ai<3000;ai++)
	{FEED_WATCHDOG;}
// 配置 ADC控制寄存器
    AdcRegs.ADCTRL1.bit.RESET = 0;//ADC module software reset
	asm("   RPT #12 || NOP ");
    AdcRegs.ADCTRL1.bit.SUSMOD = 0x02;
    AdcRegs.ADCTRL1.bit.CPS = 0;//ADCCLK = Fclk/2
    AdcRegs.ADCTRL1.bit.ACQ_PS = 0x07; //S/H_CLK=ADCCLK/ACQ_PS,采样脉冲宽度
    AdcRegs.ADCTRL1.bit.CONT_RUN = 1;//连续运行
    AdcRegs.ADCTRL1.bit.SEQ_CASC = 1;//叠加模式
    AdcRegs.ADCTRL1.bit.SEQ_OVRD = 0;//Sequencer override
//   AdcRegs.ADCTRL1.all=0x0FD0;
    AdcRegs.ADCTRL2.all=0x4900;
//    AdcRegs.ADCTRL2.bit.EVA_SOC_SEQ1 = 1;  // EVASOC 使能SEQ1开始转换
//    AdcRegs.ADCTRL2.bit.INT_MOD_SEQ1 = 0;
//    AdcRegs.ADCTRL2.bit.INT_ENA_SEQ1 = 1;  // EOS结束使能SEQ1中断(every EOS)

    AdcRegs.ADCTRL3.bit.EXTREF = 0; //内部参考电压输出
    AdcRegs.ADCTRL3.bit.ADCCLKPS = 0x2;//Fclk=HSPCLK/ADCCLKPS,ADCLK=HSPCLK/[4*(ADCTRL1[7] + 1)]
    AdcRegs.ADCTRL3.bit.SMODE_SEL = 1; //同时采样模式

//AD通道设置,两路通道同时采样
    AdcRegs.ADCMAXCONV.all = 0x7;       // 设置SEQ1两个8路通道同时转换
    AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x0; // 设置A0与B0为SEQ1第一个转换
    AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0x1; // 设置A1与B1为SEQ1第二个转换
    AdcRegs.ADCCHSELSEQ1.bit.CONV02 = 0x2;
    AdcRegs.ADCCHSELSEQ1.bit.CONV03 = 0x3;
    AdcRegs.ADCCHSELSEQ2.bit.CONV04 = 0x4;
    AdcRegs.ADCCHSELSEQ2.bit.CONV05 = 0x5;
    AdcRegs.ADCCHSELSEQ2.bit.CONV06 = 0x6;
    AdcRegs.ADCCHSELSEQ2.bit.CONV07 = 0x7;
    
}	

//===========================================================================
// No more.
//===========================================================================

⌨️ 快捷键说明

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