File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -39,7 +39,7 @@ void Battery::SaadcInit() {
3939
4040 nrf_saadc_channel_config_t adcChannelConfig = {.resistor_p = NRF_SAADC_RESISTOR_DISABLED,
4141 .resistor_n = NRF_SAADC_RESISTOR_DISABLED,
42- .gain = NRF_SAADC_GAIN1_5 ,
42+ .gain = NRF_SAADC_GAIN1_4 ,
4343 .reference = NRF_SAADC_REFERENCE_INTERNAL,
4444 .acq_time = NRF_SAADC_ACQTIME_40US,
4545 .mode = NRF_SAADC_MODE_SINGLE_ENDED,
@@ -59,11 +59,11 @@ void Battery::SaadcEventHandler(nrfx_saadc_evt_t const* p_event) {
5959 APP_ERROR_CHECK (nrfx_saadc_buffer_convert (&saadc_value, 1 ));
6060
6161 // A hardware voltage divider divides the battery voltage by 2
62- // ADC gain is 1/5
63- // thus adc_voltage = battery_voltage / 2 * gain = battery_voltage / 10
62+ // ADC gain is 1/4
63+ // thus adc_voltage = battery_voltage / 2 * gain = battery_voltage / 8
6464 // reference_voltage is 0.6V
6565 // p_event->data.done.p_buffer[0] = (adc_voltage / reference_voltage) * 1024
66- voltage = p_event->data .done .p_buffer [0 ] * 6000 / 1024 ;
66+ voltage = p_event->data .done .p_buffer [0 ] * ( 0.6 * 8 * 1000 ) / 1024 ;
6767
6868 if (voltage > battery_max) {
6969 percentRemaining = 100 ;
You can’t perform that action at this time.
0 commit comments