Skip to content
Snippets Groups Projects
Commit ef8ee4e3 authored by Teo Serra's avatar Teo Serra
Browse files

week12 add content

parent 73328142
Branches
No related tags found
No related merge requests found
Pipeline #450007 passed
......@@ -9,6 +9,25 @@ weight = 12
### Summary
This week, I tested the addition of a sensor for my final project. I'm not
sure exactly which sensors will be used, but it's to anticipate the measuring
and setup.
The result is shown below for the VMA320 sensor.
<div class="row">
<div class="col-md-6 align-self-center" markdown="1" >
<img src = "./img/week12/SetupVMA320.jpg" alt = "SetupVMA320"
class="mx-auto d-block">
</div>
<div class="col-md-6 align-self-center" markdown="1" >
<center>
<video width=95% controls muted loop>
<source src="./vid/week12/SensingTemp.mp4" type=video/mp4>
</video>
</center>
</div>
</div>
***
......@@ -26,8 +45,153 @@ that you have designed and read it.
***
## Measuring High Voltage Output
## Probe Input Device
This part was done in group and is accessible on the [group page](https://fabacademy.org/2024/labs/ulb/group-assignments/week12/).
## Adding Input Device to my Board
### Contexte of the Week
This week I want to work on my project. It's more about being able to control
plasma generation. I'll need to measure certain information, such as the
temperature of the plasma reactor, or the amount of CO2 leaving the reactor
(if the reactor is an open system).
So I'm going to try and retrieve temperature information using two different
temperature sensors: VMA320, and VMA324.
These are two analog temperature sensors using a thermistor, a resistor that
varies as a function of temperature.
### Adding Temperature Sensor
Adding one of these sensors is very simple. You need to supply the sensor with a
DC voltage (3.3V or 5V). Then recover the output voltage with a final Pin. A
temperature sensor using a thermistor works like a resistive divider. A schematic
of the divider is shown below, in which we supply the divider with DC voltage Vin,
and recover the output voltage Va, the voltage across the thermistor.
The electronic diagram taken from the documentation is also shown below.
<div class="row">
<div class="col-md-6 align-self-center" markdown="1" >
<img src = "./img/week12/Scheme.jpg" alt = "Oscillo1"
class="mx-auto d-block">
</div>
<div class="col-md-6 align-self-center" markdown="1" >
<img src = "./img/week12/ResistifDiv.jpg" alt = "Oscillo2"
class="mx-auto d-block" >
</div>
</div>
The setup, quite simple, is done separately from the board because it was
a bit complicated to do due to a design problem (I wanted to display the
temperature on an OLED screen but I didn't have enough inputs available).
This setup can be seen below for the two sensors used.
<div class="row">
<div class="col-md-6 align-self-center" markdown="1" >
<img src = "./img/week12/SetupVMA320.jpg" alt = "SetupVMA320"
class="mx-auto d-block">
</div>
<div class="col-md-6 align-self-center" markdown="1" >
<img src = "./img/week12/SetupVMA324.jpg" alt = "SetupVMA324"
class="mx-auto d-block" >
</div>
</div>
### From Analog Signal to Temperature
I'll have to translate the sensor input signal into temperature in the code.
To do this, I need to know how thermistors work. It turns out that by knowing
the resistive value of the thermistor, we can know the temperature. You also
need to know the manufacturer's reference point, in this case 25°C.
The Steinhart-Hart relationship describes the relationship between resistance
and temperature. It is given below.
<img src = "./img/week12/SHlaw.jpg" alt = "SHrelation"
class="mx-auto d-block" width =30% >
This law integrates the parameters A, B and C, which are purely empirical and
depend on each thermistor.
A simpler version is possible and can be used over a smaller temperature range,
incorporating only parameter B and a reference temperature and resistance value.
This is what I'm going to use here.
<img src = "./img/week12/SHlaw_Simplified.jpg" alt = "SHrelationSimple"
class="mx-auto d-block" width =20% >
### Programming Temp Sensor
So I program the sensor using an adc object to read the sensor's analog
value, which I transform directly into a voltage.
With this voltage I can find out the resistance of the thermistor using ohm
law and the reference provided by the sensor datasheet. Then I use the Steinhart-Hart
relationship to obtain the absolute temperature and transform it into °C.
```python
import machine
import ssd1306
import time
import math
# Define the pins used
ANALOG_PIN = 26
# Define ref
vRef = 5
tRef = 25
rRef = 10000
# Define Steinhart-Hart parameters
B = 3950
# Initialize the OLED screen
i2c = machine.I2C(1, scl=machine.Pin(7), sda=machine.Pin(6))
oled = ssd1306.SSD1306_I2C(128, 64, i2c)
# Function to read temperature from analog input
def read_temperature(pin):
# Read analog value
adc = machine.ADC(pin)
value = adc.read_u16()
# Convert analog value to voltage
voltage = value / 65535 * vRef # Voltage in volts
# Use the Steinhart-Hart formula to convert voltage to temperature
resistance = (vRef / (vRef - voltage)) * rRef # Resistance in ohms
temperature_kelvin = tRef + 1 / (1 / (273.15 + tRef) + 1 / B * math.log(resistance / rRef) ) # Temperature in Kelvin
temperature_celsius = temperature_kelvin - 273.15 # Temperature in degrees Celsius
return temperature_celsius
while True:
# Read temperature
temperature = read_temperature(ANALOG_PIN)
# Clear the OLED screen
oled.fill(0)
# Display temperature on the OLED screen
oled.text("Temp: {:.2f} C".format(temperature), 0, 0)
oled.show()
# Wait for a few seconds before measuring again
time.sleep(0.1)
```
### Testing with My PCB
I finally tested the sensors by touching the thermistor to provide heat.
One of these tests can be seen in the video below.
<center>
<video width=50% controls muted loop>
<source src="./vid/week12/SensingTemp.mp4" type=video/mp4>
</video>
</center>
......@@ -440,21 +440,74 @@ Here's what I did:
#### Coding the Python Programm
Now it's time to code the program that will control the MOSFETs using PWMs.
The code is fairly simple and uses only the machine library.
Now it's time to code the program that will control the MOSFETs.
*Add code*
I thought it was going to be simple using the PWM objects in the machine library.
It turned out to be more complicated than expected, as the PWMs work synchronously.
In other words, it's not possible to delay the start of one pwm relative to another
(between two output pins). So I have to go for "manual" control using the
RP2040's PIO.
I therefore work with a state machine, associating it with a function called square,
which generates desynchronized square signs on two output pins. The square
program is an assembler program.
#### Testing & Measuring Signals
```python
from machine import Pin
from rp2 import PIO, StateMachine, asm_pio
For the tests, I decided to take a step-by-step approach, first testing the
microcontroller outputs alone, and then testing the microcontroller on the board
# Parameters
frequency = 30_000
count_TOT = 40
FirstPin = 26
# PIO function - PWM generation
@asm_pio(set_init=(PIO.OUT_LOW,PIO.OUT_LOW))
def square():
set(pins, 0b0000) [1] # Deadtime
set(pins, 0b00001) [19] # HalfPeriod
set(pins, 0b0000) [1] # Deadtime
set(pins, 0b00010) [19] # HalfPeriod
# Création d'une StateMachine pour générer les signaux en phase et en opposition de phase
sm = StateMachine(0, square, freq= count_TOT * frequency, set_base=Pin(FirstPin))
# Activation de la StateMachine
sm.active(1)
```
So there are 4 assembler steps: two outputs off, one on, two off, and the other on.
The frequency at which the state machine must run is that of the signal
frequency multiplied by the number of steps in the square code.
### Testing & Measuring Signals
For the tests, I test the microcontroller on the board
and measuring the signals at various points.
##### Microcontroller Alone
The measurement setup includes an oscilloscope and a test bench.
<img src = "./img/week8/TestSetup.jpg" alt = "TestSetup"
class="mx-auto d-block" width = 50% >
And with the oscilloscope I look at different places to see what the
signal looks like. I get signs that correspond to what is expected.
*Add results*
<div class="row">
<div class="col-md-6 align-self-center" markdown="1" >
<img src = "./img/week8/Oscillo_1.jpg" alt = "Oscillo1"
class="mx-auto d-block">
</div>
<div class="col-md-6 align-self-center" markdown="1" >
<img src = "./img/week8/Oscillo_2.jpg" alt = "Oscillo2"
class="mx-auto d-block" >
</div>
</div>
##### MiconController on Board
Here you can see the two square signs at the microcontroller output, as well as
the signs at the gates driver output (higher voltage). The shape of the gate
driver signal is expected, given that the signal is high-frequency, and the
gate driver rise time is noticeable.
*Add results*
A design error stopped me from testing further. I'll test this again in a
future iteration, as it's for my final project.
static/img/week12/ResistifDiv.jpg

8.77 KiB

static/img/week12/SHlaw.jpg

11.4 KiB

static/img/week12/SHlaw_Simplified.jpg

7.25 KiB

static/img/week12/Scheme.jpg

24.2 KiB

static/img/week12/SetupVMA320.jpg

90.5 KiB

static/img/week12/SetupVMA324.jpg

206 KiB

static/img/week8/Oscillo_1.jpg

185 KiB

static/img/week8/Oscillo_2.jpg

180 KiB

static/img/week8/TestSetup.jpg

98.4 KiB

File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment