STM32

记录常用的ADC应用计算方法(含公式推导)

电压计算

/* * __V__ * | * R1 * |--->ADC * R2 * __|__ * GND * Vadc = R2/(R1+R2) * Vbattery; * * Ref = 3.3V; * 12bit ADC max value = 4095; * * 3.3/4095 = Vbattery * (R2/(R1+R2) / adc_value; * * Vbattery = adc_value * 3.3 / 4095 / (R2/(R1+R2)); * Vbattery = adc_value * 3.3 * (R1+R2) / (R2 * 4095); * * R1 = 470; * R2 = 22; * * Vbattery = adc_value * 3.3 * (470+22) / (22 * 4095); * = adc_value * 3.3 * 492 / 90090; * = adc_value * 1623.6 / 90090; */ /* * @brief convert the adc value to voltage * @param adc_value the adc value result * @retval valtage(mV) */ uint32_t voltage_convert(uint32_t adc_value) { uint32_t voltage; voltage = adc_value * 1623.6 * 1000 / 90090; return voltage; }
INA181电流检测

/* * INA181A2: * * Vo = (Iload * Rsense * GAIN) + Vref * * Vref = 0; * GAIN = 50; // INA181A2 * Rsense = 0.01 Ohm (10mΩ) * Vo = 3.3/4095 * adc_value; * = 3.3 * adc_value / 4095; * * Iload = Vo / Rsense / GAIN * = 3.3 * adc_value / 4095 / 0.01 / 50; * = 3.3 * adc_value / 4095 * 100 / 50; * = adc_value * 330 / (4095 * 50); * = adc_value * 330 / 204750; */ /* * @brief convert adc value to current(mA) * @param adc_value the adc result value * @retval current value(mA) */ uint32_t current_convert(uint32_t adc_value) { uint32_t current; current = adc_value * 330 * 1000 / 204750; return current; }
NTC温度计算

// ToDo