做了一个stm8的一个测量电压电流的项目,发现adc通道通过一个10k电阻连接VCC,的时候ADC数据出来都是只有200多,按理说,10位adc应该出来1000多才对,由于adc出来的数据是十六位的,怀疑是串口发送数据的时候数据位数不对。于是改为
uint16_t dat_tmp = 0;
// ADC_conf(4);
// dat_tmp = ADC_GetConversionValue();// printf("\r\ndddddddddd\r\n");
// delay(0xffff);
TIM1_SR1 &= ~(1 << 0); //清除中断标志
ms_count++;
if(ms_count > 1000) //1ms*1000=1s
{ms_count = 0;ADC_conf(2);dat_tmp = ADC_GetConversionValue(2);printf("\r\n,ch2 = %hu", dat_tmp);ADC_conf(3);dat_tmp = ADC_GetConversionValue(3);printf("ch3 = %hu", dat_tmp);ADC_conf(4);dat_tmp = ADC_GetConversionValue(4);printf("ch4 = %hu", dat_tmp);if(SWITCH_ON){printf("switch on");}else{printf("switch off");}printf("\r\n");// PE_ODR ^= 1<<5;//LED灯1s翻转一次
}
出来还是只有200多,
,ch2 = 0ch3 = 2ch4 = 211switch on
,ch2 = 1ch3 = 3ch4 = 209switch on
,ch2 = 0ch3 = 2ch4 = 216switch on
,ch2 = 0ch3 = 2ch4 = 225switch on
,ch2 = 0ch3 = 1ch4 = 220switch on
,ch2 = 0ch3 = 1ch4 = 213switch on
,ch2 = 0ch3 = 1ch4 = 0switch on
多方查找,排除掉是芯片虚焊、芯片损坏之后,想到一个问题,就是我的ADC输入前面还有一个LM324的运放
会不会是运放影响了测试呢?于是果断将芯片拔掉,发现出来的数据正常了!
,ch2 = 0ch3 = 536ch4 = 833switch on,ch2 = 0ch3 = 546ch4 = 819switch on,ch2 = 0ch3 = 0ch4 = 265switch on,ch2 = 0ch3 = 0ch4 = 161switch on,ch2 = 0ch3 = 4ch4 = 162switch on,ch2 = 0ch3 = 0ch4 = 195switch on,ch2 = 0ch3 = 0ch4 = 183switch on,ch2 = 0ch3 = 0ch4 = 142switch on,ch2 = 0ch3 = 0ch4 = 946switch on,ch2 = 0ch3 = 0ch4 = 963switch on,ch2 = 0ch3 = 0ch4 = 874switch on,ch2 = 0ch3 = 0ch4 = 922switch on,ch2 = 0ch3 = 0ch4 = 959switch on,ch2 = 536ch3 = 0ch4 = 826switch on,ch2 = 540ch3 = 0ch4 = 851switch on,ch2 = 526ch3 = 0ch4 = 877switch on,ch2 = 0ch3 = 0ch4 = 172switch on,ch2 = 0ch3 = 0ch4 = 176switch on,ch2 = 0ch3 = 0ch4 = 194switch on,ch2 = 0ch3 = 0ch4 = 176switch on