This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Voltage divider/thermistor: GPIO high, ADC read, get temperature, GPIO low

Hello,

I have a voltage divider/thermistor circuit where R1 is an NTC thermistor of 100kOhm at 25°C. R2 is 100kOhm right now.

I took peripheral_saadc example for SDK15 and modified it to get the temperature readings in saadc_callback(); Temperature conversion algorithm is equal to the ones used in:

learn.adafruit.com/.../using-a-thermistor

www.jameco.com/.../temperature-measurement-ntc-thermistors.html

https://devzone.nordicsemi.com/f/nordic-q-a/14583/nrf52832-saadc-sampling

The current during my normal measurement should not exceed ~0.4mA (102kOhm over 3.6V) and I was thinking to use a GPIO as the Vin for the divider circuit.

I would like to: Set GPIO high -> get ADC value -> Clear GPIO -> Calculate temperature - > repeat minimum every 1 second;

How to do it? I am able to power the voltage divider from GPIO but I am unsure where should I make the switch? I cannot make it in the saadc_callback() because if I understand correctly, ADC conversion is already done at that point. Switching GPIO high needs to occur probably some time before ADC sample...

  • Hi,

    Setup an app_timer to run at 1 second interval, you should find examples that show how to use app_timer in the SDK (for instance the BLE examples).

    The app_timer timeout handler (callback) can set the GPIO high and start the saadc conversion.

    The saadc handler (callback) can calculate the temperature and set the GPIO low again.

    Best regards,
    Kenneth

  • Thank you for your response, I managed to implement this solution by calling "nrf_drv_saadc_sample();" from my app_timer function and using other example pieces.

    The problem is with switching the GPIO for ADC measurement... When voltage divider is powered by GPIO pin then I am getting correct ADC readings for my application. However, if I:

    toggle GPIO HIGH->perform ADC->toggle GPIO LOW then the values I am getting are very low (multimeter shows the voltage of 0.37V).

    I suspect that the GPIO does not reach the ultimate "HIGH" state when the measurements are already taken and pin toggled low again. I do not have an oscilloscope right now to confirm it but I will keep tweaking it. In case of any suggestions, ideas, please let me know Slight smile

    Cheers!

  • It make sense, try to #include "nrf_delay.h" in your project and add a small delay, e.g:

    toggle GPIO HIGH->nrf_delay_us(100);->perform ADC

  • Problem solved. The trick was to place a small delay after the ADC measurement and then clear the GPIO. If the delay was placed after toggling GPIO high, taking the measurement and toggling low, the measurements were wrong. I could place in there a 1000us delay without any success while 10us after sampling is enough.

    I guess placing the delay after the ADC sampling made sure that the samples were taken before unpowering the sensor but I can not prove the fact as I do not have an oscilloscope at hand.

    If anybody has a good explanation before closing this thread, it would be nice. How does delay help to get the measurement? Isn't the processor "not doing anything" during the delay?

    void saadc_thermistor_get_adc(){
        ret_code_t err_code;
        nrf_gpio_pin_set(PIN);
        err_code = nrf_drv_saadc_sample();
        APP_ERROR_CHECK(err_code);
        nrf_delay_us(10);
        nrf_gpio_pin_clear(PIN);
    }

  • I though you had implemented it differently, where you would clear the pin after the measurement was ready, not after starting the measurement. In your case you should have a delay equal TACQ:
    http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/saadc.html?cp=2_1_0_36_8#concept_qh3_spp_qr 

Related