上次问的问题 关于 f350的采样慢的问题 解决了~ 谢谢ayb_ice等几位大神~跟输出字的速度也有关系 最近又遇到了新问题
正弦波的周期是20ms!我想把他采样下来,显示波形。但是不管我如何设置采样周期 始终是一条直线~最奇怪的是 ad输入引脚 如果接电压用滑动变阻器调节 采样的ad或者电压是对的。这是什么原因呢 ???
部分程序
#define MDCLK 128000 // Modulator Clock (Hz)
int ADC_Buffered(void)
{
unsigned int i, Sampling_times=1000;
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=(float)sample_array;
average=average/256/256/256;
average=average*VREF;
average=average*2;
average=average;
ADC_VIN= (int)average;
Uart0_Send232(ADC_VIN);
Uart0_SendString("\n");
}
}
ADC_VIN采样出的波形如下
void SYSCLK_Init (void)
{
unsigned i;
OSCICN = 0x80; // enable intosc
CLKSEL = 0x00; // select intosc as sysclk source
// INTOSC configure
OSCICN = 0x83;
// PLL configure
CLKMUL = 0x00; // Reset Clock Multiplier
CLKMUL &= ~0x03; // select INTOSC / 2 as PLL source
CLKMUL |= 0x80; // Enable 4x Multipler (MULEN = 1)
for (i = 0; i < 125; i++); // Delay for at least 5us
CLKMUL |= 0xC0; // Initialize Multiplier
while (!(CLKMUL & 0x20)); // Poll for Multiply Ready
// SYSCLK configure
VDM0CN = 0x80; // enable VDD monitor
RSTSRC = 0x06; // enable missing clock detector
// and VDD monitor reset sources
CLKSEL = 0x02; // select PLL as clock source
}
//-----------------------------------------------------------------------------
// PORT_Init
//-----------------------------------------------------------------------------
//
// Configure the Crossbar and GPIO ports.
// P0.4 - TX0 (push-pull)
// P0.5 - RX0
void PORT7_Init (void)
{
XBR0 |= 0x01; // UART0 Selected
XBR1 |= 0x40; // Enable crossbar and weak pull-ups
P0MDOUT |= 0xD0; // TX, LEDs = Push-pull
P1MDOUT |= 0xFF;
}
//-----------------------------------------------------------------------------
// ADC0_Init extVREF Bipolar AIN0.1-AIN0.0
//-----------------------------------------------------------------------------
//
// This function initializes the ADC to measure across AIN0.1 and AIN0.0
// on the Target Board (Differential measurements, Bipolar codes)
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.4576 MHz
// 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)
} |