Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:iot-open:practical:hardware:sut:stm32:emb2_1 [2024/04/21 11:20] ktokarzen:iot-open:practical:hardware:sut:stm32:emb2_1 [2024/04/21 11:25] (current) – [Result validation] ktokarz
Line 13: Line 13:
 Reading of the ADC is possible using the regular ''analogRead(pin)'' function. In STM32WB55 there are 16 analogue inputs, and the potentiometer is connected to the pin A4 (PC_3 in Nucleo numbering). Reading of the ADC is possible using the regular ''analogRead(pin)'' function. In STM32WB55 there are 16 analogue inputs, and the potentiometer is connected to the pin A4 (PC_3 in Nucleo numbering).
  
-<note tip>In STM32, ADC has by default a 12-bit resolution, so valid return values are 0...4095;</note>+<note tip>In STM32, ADC has a 12-bit resolution but the AnalogRead() function uses a 10-bit resolution by default, so valid return values are 0...1023. If you want to have full 12-bit resolution use analogReadResolution(12)function call</note>
 ===== Prerequisites ===== ===== Prerequisites =====
 To implement this scenario, it is advised to get familiar with at least one of the following scenarios first: To implement this scenario, it is advised to get familiar with at least one of the following scenarios first:
Line 92: Line 92:
  
 === Step 4 === === Step 4 ===
-Initialise the I2C bus and configure ADC's GPIO as input:+Initialise the I2C bus and configure ADC's GPIO as input. Change the ADC resolution to 12-bits.
 <code c> <code c>
   Wire.begin();   Wire.begin();
   pinMode(POT_ADC, INPUT);   pinMode(POT_ADC, INPUT);
 +  analogReadResolution(12);
 </code> </code>
  
Line 128: Line 129:
 </code> </code>
 ==== Result validation ==== ==== Result validation ====
-A relation between the potentiometer set value and ADC reading should be almost linear from 0V up to about 3V. It becomes horizontal because the ESP32 chip limits the ADC range to 3V, so going beyond 3V (and due to the electronic construction as in figure {{ref>figuredigipot}} it may go to about 3.3V) gives no further increase but rather a reading of the 4096 value (which means the input voltage is over the limit). For this reason, your plot may be finished suddenly with a horizontal instead of linearity decreasing function. It is by design. ADC input of the ESP32 can tolerate values between 3V and 3.3V. The linear correlation mentioned above is never perfect, either because of the devices' implementation imperfection (ESP32's ADC input and digital potentiometer output) or because of the electromagnetic noise. There are many devices in our lab room.+A relation between the potentiometer set value and ADC reading should be almost linear from 0V up to the maximum. The linear correlation is never perfect, either because of the devices' implementation imperfection (STM32's ADC input and digital potentiometer output) or because of the electromagnetic noise. There are many devices in our lab room.
  
 ===== FAQ ===== ===== FAQ =====
en/iot-open/practical/hardware/sut/stm32/emb2_1.1713698410.txt.gz · Last modified: 2024/04/21 11:20 by ktokarz
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0