STM32F103CB,用AD采样,输入电压到了57mv才能读出数据00000001。57mv以下都是00000000。
用寄存器方式写的程序,
初始化:
ADC1->SR = 0x0000; //初始化 ADC1->CR1 = 0x00000000; // ADC1->CR2 = 0x00000000; //ADC1 关闭 //ADC1->CR2 |= ADC_CR2_TSVREFE; //ADC1->CR2 |= ADC_CR2_CONT; //连续转换模式 //ADC1->CR2 |= ADC_CR2_DMA; //使用DMA ADC1->SMPR1 = 0x00000000; //1.5周期 ADC1->SMPR1 |= ADC_SMPR1_SMP10; //239.5周期 ADC1->SMPR2 = 0x00000000; //1.5周期 ADC1->JOFR1 = 0x00000000; //数据偏移 ADC1->JOFR2 = 0x00000000; //数据偏移 ADC1->JOFR3 = 0x00000000; //数据偏移 ADC1->JOFR4 = 0x00000000; //数据偏移 ADC1->HTR = 0x00000000; //高阈值 ADC1->LTR = 0x00000000; //低阈值 ADC1->SQR1 = 0x00000000; //ADC1转换1个通道 ADC1->SQR2 = 0x00000000; // ADC1->SQR3 = 0x00000000; //ADC1 选择通道,瞬时电流
读AD程序:
uint16_t i = 0x0000;
ADC1->SR = 0x0000; ADC1->SQR3 = 0x00000000; ADC1->SQR3 |= ADC_SQR3_SQ1_1; //ADC1 ADC1->SQR3 |= ADC_SQR3_SQ1_3; //ADC1 第一个转换通道AN10 Delay(200); ADC1->CR2 |= ADC_CR2_ADON; //启动A/D 1转换 Delay(200); while((~ADC1->SR) & ADC_SR_EOC){Delay(1);} i = ADC1->DR;
AD时钟频率8MHz
Delay(1) 是延迟加清看门狗
输入是电位器中心抽头,用万用表检测的输入电压 |