|
大家好!c8051F的ad采样,帮我看下程序哪里的设置有问题!
[复制链接]
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. ADC0CLK 是调制器时钟分频系数 为获得最佳性能,应选择使调制器时钟等于2.4576 MHz(调制器采样速率= 19.2千赫)的分频系数 系统时钟分按照公式: MDCLK=系统时钟/ (ADC0CLK + 1)
这样的话 速度应该很快啊 ~ 怎么 程序打出来的ADC_VIN 很慢??? 知道大神解释下 为什么呢??? 怎么设置才能最快@!@ Sampling_times=128的话 采样速率应该是 19200 Hz啊 实验结果目测还不到1Hz~ 啊啊啊 啊啊啊
|
|