📄 adc.dsp
字号:
/****************************************************************************************
* *
* Library: Configuration of ADC block for simulataneous sampling *
* *
* File: adc.dsp *
* *
* Description: adc code file *
* Purpose : Library routines for ADC block operation *
* *
* Author : JC *
* Version : 1.0 *
* Date : Mar 2002 *
* Modification History: none *
* *
* Embedded Control Systems *
* Analog Devices Inc. *
****************************************************************************************/
#include <main.h>;
/***************************************************************************************
* Calculate Configuration Register Contents from Parameters *
***************************************************************************************/
/*None*/
/***************************************************************************************
* Constants Defined in the Module *
***************************************************************************************/
#define ADC_SF 32768/ADC_Number_of_samples/4 // value of (1/ADC_NUmber_of_samples/4)
/***************************************************************************************
* Routines Defined in this Module *
***************************************************************************************/
.global ADC_Init_;
.global ADC_Scale_;
/***************************************************************************************
* Global Variables Defined in this Module *
***************************************************************************************/
.section/data seg_dmdata;
.VAR Offset_0to3 =0;
.VAR Offset_4to7 =0;
.global Offset_0to3;
.global Offset_4to7;
/***************************************************************************************
* Local Variables Defined in this Module *
***************************************************************************************/
/* None*/
/***************************************************************************************
* *
* Type: Routine *
* *
* Call: call ADC_Init_; *
* *
* Initialises the ADC block and calculate the offsets and set into simultaneous sampling*
* *
* Inputs : ADC_Number_of_samples *
* *
* Ouputs : mr1:Offset_0to3
* sr1:Offset_4to7
* *
* Modified: ar, af, ax0, ay0, ay1, mr, mx0, my0, sr, px, I4 *
* *
***************************************************************************************/
.section/pm seg_pmcode;
ADC_Init_: // Initialise ADC block
iopg = IntCtrl_Page;
ar = IO(IPR3);
ay0 = 0x0fff;
ar = ar and ay0;
ay0= 0x2000; /*assign ADC EOC ISR to USR2*/
ar = ar or ay0;
IO(IPR3) = ar;
iopg = ADC_Page;
ar=0x0227; //set up ADC as SW conv start and offset calibration mode
IO(ADC_CTRL)=ar;
sr=0;
mr=0;
my0=ADC_SF; //load the scaling factor for averaging samples
ay1=0x000F; //use to check if all channels are converted bit 0-3 of ADCSTAT
CNTR=ADC_Number_of_samples;
do offset_loop until CE;
ar=0x0001;
IO(ADC_SOFTCONVST)=ar; //start ADC by software conv start
wait_loop: ar=IO(ADC_STAT);
ar=ar and ay1;
ar=ar-ay1; //ay1=0x000F
if NE jump wait_loop;// check if all chanenels are converted
mx0=IO(ADC_DATA0);
mr=mr+mx0*my0(ss);
mx0=IO(ADC_DATA1);
mr=mr+mx0*my0(ss);
mx0=IO(ADC_DATA2);
mr=mr+mx0*my0(ss);
mx0=IO(ADC_DATA3);
mr=mr+mx0*my0(ss);//calculate Offset_0to3
mx0=IO(ADC_DATA4);
sr=sr+mx0*my0(ss);
mx0=IO(ADC_DATA5);
sr=sr+mx0*my0(ss);
mx0=IO(ADC_DATA6);
sr=sr+mx0*my0(ss);
mx0=IO(ADC_DATA7);
offset_loop: sr=sr+mx0*my0(ss);//calculate Offset_4to7
sat mr;
sat sr;
DM(Offset_0to3)=mr1;//store average of VIN0 to VIN3
DM(Offset_4to7)=sr1;//store average of VIN4 to VIN7
ar=0x0200;
IO(ADC_CTRL)=ar; //set ADC to simultaneous sampling and PWMSync conv start
rts;
/**************************************************************************************
* *
* Type: Routine *
* *
* Call: ADC_Scale_; *
* *
* Used to compensate for offset in the ADC *
* *
* Inputs : None *
* *
* Ouputs : ar- ADC channel value after offset *
* *
* Modified: ar, ay0 *
* *
**************************************************************************************/
ADC_Scale_:
ena ar_sat;
ar = ar - ay0; //The Offset voltage is taken in consideration
dis ar_sat;
rts;
////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -