📄 f2407adc.c
字号:
/*=====================================================================================================================
/* File name: F2407ADC.C
/* This file contains source for the ADC Driver control module
/* Applicability of these functions is indicated in the Table 1
/*================================================================================ */
#include <regs240x.h>
#include <F2407ADC.h>
void inline F2407_ADC_Init(ADCVALS *p)
{
SCSR1=SCSR1|0x0080; /* Turn on the clocks to the ADC module*/
CALIBRATION=CALIBRATION_CONSTANT;
ADCTRL1=ADC_RESET_FLAG; /* Reset the ADC Module */
ADCTRL1=ADCTRL1_INIT_STATE; /* Set up ADCTRL1 register */
ADCTRL2=ADCTRL2_INIT_STATE; /* Set up ADCTRL2 register */
MAXCONV=3; /* Specify four conversions */
CHSELSEQ1=p->ChSelect; /* Configure channel selection */
}
void F2407_ADC_Read(ADCVALS *p)
{
int DatQ15;
long Tmp;
DatQ15 = (RESULT0>>1)&0x7FFF; // Convert result0 to Q15 (unipolar signal)
Tmp = (long)(p->Ch1Gain*DatQ15); //Tmp= gain*dat => Q28 = Q13*Q15
p->Ch1Out = (int)(Tmp>>13); //Convert Q28 to Q15
DatQ15 = (RESULT1>>1)&0x7FFF; // Convert result0 to Q15 (unipolar signal)
Tmp = (long)(p->Ch2Gain*DatQ15); //Tmp= gain*dat => Q28 = Q13*Q15
p->Ch2Out = (int)(Tmp>>13); //Convert Q28 to Q15
DatQ15 = (RESULT2>>1)&0x7FFF; // Convert result0 to Q15 (unipolar signal)
Tmp = (long)(p->Ch3Gain*DatQ15); //Tmp= gain*dat => Q28 = Q13*Q15
p->Ch3Out = (int)(Tmp>>13); //Convert Q28 to Q15
DatQ15 = (RESULT3>>1)&0x7FFF; // Convert result0 to Q15 (unipolar signal)
Tmp = (long)(p->Ch4Gain*DatQ15); //Tmp= gain*dat => Q28 = Q13*Q15
p->Ch4Out = (int)(Tmp>>13); //Convert Q28 to Q15
ADCTRL2 |= 0x6000; // Reset the sequence
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -