c51F350 部分程序:
#define SYSCLK 49000000 // SYSCLK frequency (Hz)
#define BAUDRATE 57600 // UART0 Baudrate (bps)
#define MDCLK 2457600 // Modulator Clock (Hz)
void ADC_Buffered(void)
{
unsigned int i;
float average;
for (i = 0; i < Sampling_times; i++)
{
while(!AD0INT);
AD0INT = 0;
ADC_OutputVal = ADC0H;
ADC_OutputVal =ADC_OutputVal<< 16;
ADC_OutputVal += (long)ADC0L + ((long)ADC0M << 8);
sample_array = ADC_OutputVal;
}
for(i=0;i<Sampling_times;i++)
{
average=average+(float)sample_array;
}
average=average/(Sampling_times);
average=average/256/256/256;
average=average*VREF;
average=average*2;
average=average;
ADC_VIN= (int)average;
}
void ADC0_Init (void)
{
unsigned ADC0_decimation;
REF0CN &= ~0x01; // disable internal vref
// REF0CN |= 0x01; // (enable if using internal vref)
// ADC0CN = 0x00; // unipolar output codes, GAIN=1
ADC0CN = 0x10; // Bipolar output codes, GAIN=1
//ADC0CF = 0x00; // interrupts upon SINC3 filter output
// and uses internal VREF
ADC0CF = 0x04; // interrupts upon SINC3 filter output
// and ʹÓÃÍⲿVREF
ADC0CLK = (SYSCLK/MDCLK)-1; // Ideally, MDCLK =2.457MHz
// Generate MDCLK for modulator.
// program decimation rate for desired OWR
ADC0_decimation = (unsigned long) SYSCLK/ (unsigned long) OWR /
(unsigned long) (ADC0CLK+1)/(unsigned long)128;
ADC0_decimation--;
ADC0DEC = ADC0_decimation;
ADC0BUF = 0x00; // ¹Ø±ÕÊäÈ뻺³å
ADC0MUX = 0x0b; // ²î·ÖÊäÈë
// AIN+ => AIN0.0
ADC0DAC = 0x00;
ADC0STA = 0x00; // AIN- => AIN0.1
// ADC0MUX = 0x08;
ADC0MD |= 0x80; // ʹÄÜ(IDLE Mode)
}
输入信号进行采样调制器在频率的MDCLK / 128.
为获得最佳性能,应选择分,使得时钟调制器
等于2.4576 MHz(调制器采样速率= 19.2千赫).
系统时钟分按照公式:
MDCLK=系统时钟/ (ADC0CLK + 1)
这样的话 速度应该很快啊 ~ 怎么 程序打出来的ADC_VIN 很慢???
知道大神解释下 为什么呢??? |