Skip to content

Commit 487ede5

Browse files
authored
Merge pull request #19 from PaulThbt/main
FMCW Project update and DPS library udpate
2 parents 305efa8 + b3cdaf6 commit 487ede5

File tree

16 files changed

+224
-96
lines changed

16 files changed

+224
-96
lines changed

docs/Projects/FMCWRadar.md

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -141,23 +141,20 @@ For ultrasonic FMCW radars, the max range bottleneck is $$T_c$$. For regular FMC
141141
## Radar Design
142142
{: .text-yellow-300}
143143

144-
{: .WARNING}
145-
Due to mechanical coupling issues on the current SensEdu Shield, this radar implementation will not be able to perform distance measurements with a single SensEdu Shield. The implementation requires two Arduino boards with SensEdu Shields and the radar measures the distance between the two boards.
146-
147144
The following block diagram illustrates the architecture of the FMCW radar :
148145

149-
<img src="{{site.baseurl}}/assets/images/RadarDesign.png" alt="drawing" width="800"/>
146+
<img src="{{site.baseurl}}/assets/images/Radar.png" alt="drawing" width="800"/>
150147
{: .text-center}
151148

152149
FMCW Radar Block Diagram
153150
{: .text-center}
154151

155-
The chirp signal Tx is generated in the transmitter shield and converted to an analog signal with the DAC. Tx is then doubled and follows 2 paths :
152+
The chirp signal Tx is generated and converted to an analog signal with the DAC. Tx is then doubled and follows 2 paths :
156153

157154
- Tx is amplified and sent to the ultrasonic transducer
158-
- Tx is sent to the receiving shield by using a jump wire between the transmitter DAC pin and the receiver ADC1 pin.
155+
- Tx is sent to ADC3 by using a jump wire between the DAC pin and the receiver ADC3 pin (A8).
159156

160-
On the receiver shield, Tx goes through ADC1. The MEMS microphone receives a signal Rx which is amplified with a low noise amplifier (LNA) and goes through ADC2. This method is by no means optimal but it enables to send Tx and Rx signals to MATLAB from the same shield. The Tx and Rx signals are sent from the receiver shield to MATLAB.
157+
The MEMS microphone receives a signal Rx which is amplified with a low noise amplifier (LNA) and goes through ADC1. The digital Tx and Rx signals are both sent to MATLAB.
161158

162159
The following signal processing is performed in MATLAB to measure the distance between the two shields :
163160

@@ -169,74 +166,65 @@ The following signal processing is performed in MATLAB to measure the distance b
169166
## Code Implementation
170167
{: .text-yellow-300}
171168

172-
For this implementation, 2 Arduino with SendEdu boards are required. Follow these steps to get setup :
173-
- Upload the `Chirp_SawtoothMod.ino` sketch from the [Chirp Project]({% link Projects/Chirp.md %}) to the transmitting board
174-
- Upload the `FMCW_Distance_Measurement.ino` sketch to the receiving board
175-
- Wire the DAC output `DAC0` from the transmitting board to the ADC1 of the receiving board. The default script uses analog pin `A7` to connect to ADC1. Check out the [ADC]({% link Library/ADC.md %}) section of the documentation for more details on the available ADCs for each analog pin.
176-
177169
{: .IMPORTANT}
178-
Make sure to wire the DAC output of the transmitting board to the ADC1 of the receiving board !
170+
Make sure to wire the DAC output to ADC3 (analog pin `A8`).
179171

180172

181173
### Sending the ADC data and receiving in MATLAB
182174
{: .text-yellow-100}
183175

184-
On the receiving board :
185-
- ADC1 receives the DAC data
186-
- ADC2 receives microphone #2 data
176+
- ADC3 receives the DAC data
177+
- ADC1 receives the microphone #3 data
187178

188179
A size header `adc_byte_length` is sent to MATLAB to indicate the size of each ADC frame in bytes. Since ADCs are 16-bit, each data is coded with 2 bytes. The data from both ADCs is sent to MATLAB using the `serial_send_array` function.
189180

190181
```c
191182
// Send ADC data (16-bit values, continuously)
192183
uint32_t adc_byte_length = mic_data_size * 2; // ADC data size in bytes
193184
Serial.write((uint8_t*)&adc_byte_length, sizeof(adc_byte_length)); // Send size header
194-
serial_send_array((const uint8_t*)adc_dac_data, adc_byte_length); // Transmit ADC1 data
195-
serial_send_array((const uint8_t*)adc_mic_data, adc_byte_length); // Transmit ADC2 data (Mic2 data)
185+
serial_send_array((const uint8_t*)adc_dac_data, adc_byte_length); // Transmit ADC3 data
186+
serial_send_array((const uint8_t*)adc_mic_data, adc_byte_length); // Transmit ADC1 data (Mic3 data)
196187
```
197188
198189
An important variable is `mic_data_size` which must be a multiple of 32 because `serial_send_array` sends data by chunks of 32-bytes. `mic_data_size` will also define the amount of samples used for the plots in MATLAB.
199190
200191
The bigger the value of `mic_data_size`, the more latency when you run the MATLAB distance measurement script but the more signal will be displayed on the plots.
201192
202-
{: .NOTE}
203-
Increasing `mic_data_size` won't affect distance resolution since the latter only depends on the chirp bandwidth.
204-
205-
In MATLAB, the `read_data` function is used to retrieve the data from both ADCs.
206-
207193
```c
208194
// Retrieve size header for ADC data
209195
adc_byte_length = read_total_length(arduino); // Total length of ADC data in bytes
210196
ADC_DATA_LENGTH = adc_byte_length / 2; // Total number of ADC samples
211197
212198
// Retrieve DAC to ADC data
213-
adc1_data = read_data(arduino, ADC_DATA_LENGTH);
199+
adc3_data = read_data(arduino, ADC_DATA_LENGTH);
214200
215201
// Retrieve Mic ADC data
216-
adc2_data = read_data(arduino, ADC_DATA_LENGTH);
202+
adc1_data = read_data(arduino, ADC_DATA_LENGTH);
217203
```
218204

219205

220206
### Data processing in MATLAB & Distance computation
221207
{: .text-yellow-100}
222208

223209

224-
After sending the data to MATLAB, the data can be processed and the distance is eventually computed. Here are the different steps in order to compute the distance in MATLAB.
210+
After sending the data to MATLAB, the data can be processed and the distance is eventually computed. It is worth noting that a high-pass FIR filter has also been applied to the mixed signal in MATLAB. This is to attenuate low frequencies (15 Hz to 46 Hz) in the spectrum coming from the transducer's signal directly received by the microphone. These frequencies don't correspond to an object's reflection and thus need to be mitigated. This is important to mitigate the right amount of reflections
211+
212+
Here are the different steps in order to compute the distance in MATLAB.
225213

226-
**Step 1**{: .text-blue-000} : High pass filter Tx (`adc1_data`) and Rx (`adc2_data`) to clean up the signals
214+
**Step 1**{: .text-blue-000} : High pass filter Tx (`adc3_data`) and Rx (`adc1_data`) to clean up the signals
227215

228216
```c
217+
adc3_data_filt = highpass(adc3_data, 30000, SAMPLING_RATE);
229218
adc1_data_filt = highpass(adc1_data, 30000, SAMPLING_RATE);
230-
adc2_data_filt = highpass(adc2_data, 30000, SAMPLING_RATE);
231219
```
232220

233-
**Step 2**{: .text-blue-000} : Mix Tx and Rx
221+
**Step 2**{: .text-blue-000} : Mix Tx and Rx using sample-by-sample multiplication
234222

235223
```c
236-
mixed_signal = adc1_data_filt .* adc2_data_filt;
224+
mixed_signal = adc3_data_filt .* adc1_data_filt;
237225
```
238226

239-
**Step 3**{: .text-blue-000} : Lowpass the mixed signal at 5 kHz to only keep the low frequency component
227+
**Step 3**{: .text-blue-000} : Low-pass filter the mixed signal at 5 kHz to remove the unwanted high frequency component
240228

241229
```c
242230
mixed_signal_filt = lowpass(mixed_signal, 5000, SAMPLING_RATE);
@@ -257,11 +245,19 @@ After sending the data to MATLAB, the data can be processed and the distance is
257245
**Step 6**{: .text-blue-000} : Compute the distance
258246

259247
```c
260-
d = (fbeat * Tc * c) / (f_end - f_start);
248+
d = (fbeat * Tc * c) / (2*(f_end - f_start));
261249
```
262250

263-
{: .NOTE}
264-
The distance formula used in this configuration is for a one-way and not roundtrip because the signal travels between the two board. The usual formula differs by a factor of 2.
265-
266251
{: .IMPORTANT}
267-
Make sure the parameters in MATLAB match the parameters of the chirp you are sending (f_start, f_end, Tc, etc...).
252+
Make sure the parameters in MATLAB match the parameters of the chirp you are sending (f_start, f_end, Tc, etc...).
253+
254+
After running the MATLAB code, you should see the following display. This example is with an object placed at 50 cm from the board and using the following radar parameters :
255+
- f_start = 30.5 kHz
256+
- f_end = 35.5 kHz
257+
- Tc = 40 ms
258+
259+
<img src="{{site.baseurl}}/assets/images/Measurement.png" alt="drawing" width="800"/>
260+
{: .text-center}
261+
262+
Measurement display in MATLAB
263+
{: .text-center}

docs/assets/images/Measurement.png

142 KB
Loading

docs/assets/images/Radar.png

129 KB
Loading

docs/assets/images/RadarDesign.png

-130 KB
Binary file not shown.

libraries/XENSIV_Digital_Pressure_Sensor/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
[![Compile examples](https://github.com/Infineon/arduino-xensiv-dps3xx/actions/workflows/compile_examples.yml/badge.svg)](https://github.com/Infineon/arduino-xensiv-dps3xx/actions/workflows/compile_examples.yml)
2+
13
# XENSIV™ Digital Pressure Sensor Arduino Library
24

35
Arduino library of Infineon's [**XENSIV™ Digital Pressure Sensors (DPS3xx)**](https://www.infineon.com/cms/en/product/sensor/pressure-sensors/pressure-sensors-for-iot/).
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
include:
2+
- fqbn: esp32:esp32:featheresp32
3+
4+
additional_urls:
5+
- core: esp32:esp32
6+
url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
7+
8+
exclude:
9+
# Disabled SPI these SPI examples for specific boards until setDataMode is replaced in the library
10+
- sketch:
11+
- examples/spi_command/spi_command.ino
12+
- examples/spi_background/spi_background.ino
13+
fqbn:
14+
- arduino:renesas_uno:minima
15+
- arduino:renesas_uno:unor4wifi
16+
- arduino:samd:mkrzero

libraries/XENSIV_Digital_Pressure_Sensor/examples/i2c_command/i2c_command.ino

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
// Dps3xx Object
1111
Dps3xx Dps3xxPressureSensor = Dps3xx();
1212

13-
float T_offset=0; //temperature offset
14-
1513
void setup()
1614
{
1715
Serial.begin(9600);
@@ -25,7 +23,7 @@ void setup()
2523
* Use the line below instead of the one above to use the default I2C address.
2624
* if you are using the Pressure 3 click Board, you need 0x76
2725
*/
28-
Dps3xxPressureSensor.begin(Wire1);
26+
Dps3xxPressureSensor.begin(Wire);
2927

3028
Serial.println("Init complete!");
3129
}
@@ -34,7 +32,7 @@ void loop()
3432
{
3533
float temperature;
3634
float pressure;
37-
uint8_t oversampling = 0;
35+
uint8_t oversampling = 7;
3836
int16_t ret;
3937
Serial.println();
4038

@@ -61,8 +59,8 @@ void loop()
6159
else
6260
{
6361
Serial.print("Temperature: ");
64-
Serial.print(temperature+T_offset);
65-
Serial.println("°C");
62+
Serial.print(temperature);
63+
Serial.println(" degrees of Celsius");
6664
}
6765

6866
/*
@@ -85,5 +83,5 @@ void loop()
8583
}
8684

8785
// Wait some time
88-
delay(5000);
86+
delay(500);
8987
}

libraries/XENSIV_Digital_Pressure_Sensor/library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=XENSIV Digital Pressure Sensor
2-
version=1.0.1
2+
version=1.0.2
33
author=Infineon Technologies
44
maintainer=Infineon Technologies <www.infineon.com>
55
sentence=Arduino library for the Infineon XENSIV(TM) Digital Pressure Sensors (DPS3xx).

libraries/XENSIV_Digital_Pressure_Sensor/src/DpsClass.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ void DpsClass::begin(SPIClass &bus, int32_t chipSelect, uint8_t threeWire)
7575
m_spibus->endTransaction();
7676

7777
// Switch to 3-wire mode if necessary
78+
// do not use writeByteBitfield or check option to set SPI mode!
79+
// Reading is not possible until SPI-mode is valid
7880
if (threeWire)
7981
{
8082
m_threeWire = 1U;

libraries/XENSIV_Digital_Pressure_Sensor/src/DpsClass.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include <Arduino.h>
1818

1919
// Disable SPI for currently not supported platforms.
20-
#if defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_PSOC6) || defined(ARDUINO_ARCH_RENESAS)
20+
#if defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_RENESAS)
2121
#define DPS_DISABLESPI
2222
#endif
2323

0 commit comments

Comments
 (0)