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...

Parents
  • 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

Reply Children
No Data
Related