ADC采样连续正玄波(50Khz~200Khz),液晶显示(400Vpp)是正常的。输入50KHZ波数为1或者其他个数<170个(周期大于5ms)液晶显示为0,实际上ADC可以采到几个值。波数大于170个可以显示(400vpp)。假如采样信号给2khz输入10个波就可以了,正常显示了。之前做过采单个或者几个波是可以正常显示的。这次就不行了,板子基本没变。
采样程序
#include "AD.h"
#include "STM32f10x_it.h"
#include "delay.h"
void ADInit(void) {
ADC_InitTypeDef ADC_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphclockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_ADC1, ENABLE);
RCC_ADCCLKConfig(RCC_PCLK2_Div2);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_Init(GPIOC, &GPIO_InitStructure);
ADC_DeInit(ADC1);
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
ADC_InitStructure.ADC_ScanConvMode = DISABLE;
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfChannel = 1;
ADC_Init(ADC1, &ADC_InitStructure);
ADC_Cmd(ADC1, ENABLE);
ADC_ResetCalibration(ADC1);
while (ADC_GetResetCalibrationStatus(ADC1));
ADC_StartCalibration(ADC1);
while (ADC_GetCalibrationStatus(ADC1));
}
u16 GetAdc(u8 type,u8 ch) {
if (type == 0) {
ADC_RegularChannelConfig(ADC1, ch, 1, ADC_SampleTime_28Cycles5);
} else {
ADC_RegularChannelConfig(ADC1, ch, 1, ADC_SampleTime_7Cycles5);
}
ADC_SoftwareStartConvCmd(ADC1, ENABLE); //ʹ��ָ����ADC1������ת����������
while (!ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC)); //�ȴ�ת������
return ADC_GetConversionValue(ADC1); //�������һ��ADC1�������ת�����
}
void BubbleSort(u16 *arr, u16 size) {
int i, j, tmp;
for (i = 0; i < size - 1; i++) {
for (j = 0; j < size - i - 1; j++) {
if (arr[j] > arr[j + 1]) {
tmp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = tmp;
}
}
}
}
u16 FindAdcMaxValue(u16 *arr, u16 size){
int i = 0;
u16 AdcMaxValue;
AdcMaxValue = arr[0];
for(i = 1; i < size - 1; i++){
if(arr > AdcMaxValue){
AdcMaxValue = arr;
}
}
return AdcMaxValue;
}
u16 GetAdcMaxValue(u8 type,u8 ch) {
u16 i = 0;
u16 j = 0;
u16 admaxValue = 0;
u16 adValue = 0;
static u16 arrayV[200] = {0};
static u16 arrayI[200] = {0};
u16 a = 0;
static u16 timeOutCnt
= 0;
if (type == 0) {
while (i < 200) {
adValue = GetAdc(type,ch);
if (adValue > 200) {
arrayV = adValue;
i++;
timeOutCnt = 0;
} else {
timeOutCnt++;
if (timeOutCnt > 200) {
for (j=0;j<200;j++) {
arrayV[j] = 0;
}
timeOutCnt = 0;
break;
}
}
}
admaxValue = FindAdcMaxValue(arrayV,200);
} else {
while (i < 200) {
adValue = GetAdc(type,ch);
if (adValue > 40) {
arrayI = adValue;
i++;
timeOutCnt = 0;
} else {
timeOutCnt++;
if (timeOutCnt > 200) {
timeOutCnt = 0;
break;
}
}
}
admaxValue = FindAdcMaxValue(arrayI,200);
}
//BubbleSort(array,200);
//return array[199];
timeOutCnt = 0;
if (admaxValue > 1600) {
a = 10;
}
return admaxValue;
}
void ADTest(void)
{
while (1)
{
//UART1SendByte(GetADV());
DelayNmS(200);
}
}
这是50K连续波显示和仿真看到的采样数据
这是50KHZ发送5个正弦波(周期5ms)
|