2019-08-17 08:23发布
命运枷锁 发表于 2017-6-9 15:15 请检测一下两个采集引脚是否连接其他东西了,一般是这种情况
yklstudent 发表于 2017-6-9 14:54 夸张了,检测程序初始化是否正确,以及引脚是否正确了哦
xianshasaman 发表于 2017-6-9 16:51 多通道扫描模式(即ScanConvMode被使能)下,不使用DMA是没法用的,因为EOC转换完成标志位只有在整个规则通 ...
最多设置5个标签!
已测试,输入电压为0的时候io与gnd之间的电压确实为0,原理图上也已经确认没有链接其他的东西
这是我的初始化adc的代码,想写的是不用dma的双通道采样,不知道这样子写对不对adc采样初始化:
void Adc_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
ADC_InitTypeDef ADC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_GPIOA, ENABLE);
RCC_ADCCLKConfig(RCC_PCLK2_Div6);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_3;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
ADC_DeInit(ADC1);
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
ADC_InitStructure.ADC_NbrOfChannel = 2;
ADC_InitStructure.ADC_ScanConvMode = ENABLE;
ADC_Init(ADC1, &ADC_InitStructure);
ADC_Cmd(ADC1, ENABLE);
ADC_ResetCalibration(ADC1);
while(ADC_GetResetCalibrationStatus(ADC1));
ADC_StartCalibration(ADC1);
while(ADC_GetCalibrationStatus(ADC1));
}
u16 Get_Adc(u8 ch)
{
ADC_RegularChannelConfig(ADC1, ch, 1, ADC_SampleTime_239Cycles5);
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC));
return ADC_GetConversionValue(ADC1);
}
u16 Get_Adc_Average(u8 ch, u8 times)
{
u32 temp_val = 0;
u8 i = 0;
for(; i < times; i++)
{
temp_val += Get_Adc(ch);
delay_ms(5);
}
return temp_val/times;
}
主函数调用:
while(1)
{
TIM_SetCompare1(TIM1,9999);
adcx1 = Get_Adc_Average(ADC_Channel_1,20);
adcx2 = Get_Adc_Average(ADC_Channel_3,20);
strcpy(n0,"n0.val=");//以下是输出采样值到hmi串口屏,可不管
sprintf(s0,"%d",adcx1);
strcat(n0,s0);
strcpy(n1,"n1.val=");
sprintf(s11,"%d",adcx2);
strcat(n1,s11);
HMISends(n0);
HMISendb(0xff);
HMISends(n1);
HMISendb(0xff);
temp1 = 0.225*pow(adcx1*(3.3/4096),3)-0.6519*pow(adcx1*(3.3/4096),2)+22.088*adcx1*(3.3/4096)+0.589;
sprintf(s1,"t9.txt="%f"",temp1);
HMISends(s1);
HMISendb(0xff);
temp2 = 0.225*pow(adcx2*(3.3/4096),3)-0.6519*pow(adcx2*(3.3/4096),2)+22.088*adcx2*(3.3/4096)+0.589;
sprintf(s2,"t11.txt="%f"",temp2);
HMISends(s2);
HMISendb(0xff);
}
支持楼上的观点
一周热门 更多>