Modifications

Sauter à la navigation Sauter à la recherche
2 081 octets ajoutés ,  8 décembre 2022 à 21:50
Ligne 51 : Ligne 51 :  
* The pin 2 (middle one) to the ADC0 analog input.
 
* The pin 2 (middle one) to the ADC0 analog input.
   −
[[Fichier:ENG-CANSAT-PICO-TMP36-01.png|320px]]
+
[[Fichier:ENG-CANSAT-PICO-TMP36-01.jpg|320px]]
    
The TMP36 output voltage would range from 0V @ -50°C to 1.75V @ 125°C. So no risk for our 3V based microcontroler.
 
The TMP36 output voltage would range from 0V @ -50°C to 1.75V @ 125°C. So no risk for our 3V based microcontroler.
Ligne 57 : Ligne 57 :  
== Testing the sensor ==
 
== Testing the sensor ==
   −
The Raspberry-Pico offers a 12 bits resolution ADC (effective 8mV resolution. 3.3V/4095).  
+
The Raspberry-Pico offers a 12 bits resolution ADC (effective 0.8mV resolution. 3.3V/4095).  
    
{{ambox|text=The MicroPython ADC expose an unified reading method named {{fname|read_u16()}} returning a 16 bits integer (between 0 and 65535).<br />
 
{{ambox|text=The MicroPython ADC expose an unified reading method named {{fname|read_u16()}} returning a 16 bits integer (between 0 and 65535).<br />
Ligne 63 : Ligne 63 :     
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
 +
# Read the TMP36 analog temperature sensor
 +
#    sensor wired to ADC0 (GP26)
 +
#
 +
from machine import ADC, Pin
 +
import time
    +
adc = ADC(Pin(26))
 +
while True:
 +
    value = adc.read_u16()
 +
    mv = 3300.0 * value / 65535
 +
    temp = (mv-500)/10
 +
    print( 'Temp: %5.2f °C, Voltage: %4i mV' % (temp,mv) )
 +
    time.sleep( 0.100 )
 +
</syntaxhighlight>
    +
Which produce the following results into the MicroPython REPL/Shell
 +
 +
<nowiki>Temp: 15.19 °C, Voltage:  651 mV
 +
Temp: 14.87 °C, Voltage:  648 mV
 +
Temp: 14.71 °C, Voltage:  647 mV
 +
</nowiki>
 +
 +
== Improving the circuit ==
 +
You may notice some variation in the temperature reading. This is due to the DC/DC regulation using running at lower frequency (to spare power when really few current required by the project). At lower frequency, the voltage regulation is less efficient and 3V3 rail will be more noisy.
 +
 +
As the TMP36 only requires 50µA and RP2040 consume very few current, you may encounter this situation.
 +
 +
The following scope capture show the 3V3 rail at very low current. As shown, je 3V3 contains lot of noise (Saw Waveform).
 +
 +
[[Fichier:Pico-3V3-regulation-at-low-current.png|640px]]
 +
 +
As the analog sensors are very sensitive to unstable power voltage. Variation and noise on power rail may cause important variation on analog output of an analog sensor.
 +
 +
[[Fichier:Pico-TMP36-improved-wiring.png|480px]]
 +
 +
By adding the 2200µF capacitor, the noisy saw waveform will be changed and adding the 10nF will greatly reduce the noise opn the PowerRail.
 +
 +
[[Fichier:Pico-TMP36-improved-wiring-2.png|640px]]
 +
 +
== Improving the code ==
 +
A good way to improve stability in the readings is to preform a means calculation over several reading.
 +
 +
<syntaxhighlight lang="python">
 +
# Mean read the TMP36 analog temperature
 +
#  sensor wired to ADC0 (GP26)
 +
#
 +
from machine import ADC, Pin
 +
import time
 +
 +
adc = ADC(Pin(26))
 +
while True:
 +
    value = 0
 +
    for i in range(10):
 +
        value += adc.read_u16()
 +
    value /= 10
 +
    mv = 3300.0 * value / 65535
 +
    temp = (mv-500)/10
 +
    print( 'Temp: %5.2f °C, Voltage: %4i mV' % (temp,mv) )
 +
    time.sleep(0.100 )
 
</syntaxhighlight>
 
</syntaxhighlight>
    
{{ENG-CANSAT-PICO-TRAILER}}
 
{{ENG-CANSAT-PICO-TRAILER}}
29 917

modifications

Menu de navigation