How do you feel about this article? Help us to provide better content for you.
Dave from DesignSpark
Thank you! Your feedback has been received.
Dave from DesignSpark
There was a problem submitting your feedback, please try again later.
Dave from DesignSpark
What do you think of this article?
The STM32L476 Discovery board (896-7724)
from ST Microelectronics is the latest in the Discovery series of microprocessor evaluation boards. A key feature of the STM32L4 range of devices is their very low power consumption.
At its heart is an STM32L476 ARM 32-bit Cortex-M4 CPU with FPU running at up to 80MHz. It has 1MB Flash and 128kB RAM in a 100 pin LQFP package. In low power modes the device consumes microamps while standby currents are of the order of nanoamps.
The firmware shipped with the device includes current measurement functions to demonstrate the device’s power consumption under various system configurations as well as some other demos:
Sound level meter
Two rows of headers are provided on the rear of the board for interfacing with your own projects.
Further details, including key features and peripherals and Data Sheet can be found here.
Application: Radar speed detector
To demonstrate the board I decided to build a radar speed detector using an off the shelf motion detector module. These are available from the internet for a few pounds and use the Doppler effect to detect nearby moving objects.
Here's a video about the project -
The Doppler effect is the change in frequency of a wave perceived by an observer moving relative to its source. This is most commonly experienced in daily life when we hear a siren passing us in the street. The pitch of the siren appears higher when its moving towards us and lower when moving away. The change in frequency is proportional to the speed of object and so by measuring the frequency shift we can determine its speed.
The motion detector works by emitting radio waves that bounce off nearby objects, some of which are reflected back to the sensor. If any of those objects are moving then the reflected wave will be shifted in frequency. The motion detector determines this shift by mixing the reflected signal with the unshifted signal to obtain the sum and difference frequencies. This is then low pass filtered to extract the difference (Doppler) frequency. The figure below shows a typical detector together with a diagram of the system:
According to the Doppler equation the ratio of the frequency shift and the wave frequency is equal to the ratio of the object’s speed and the speed of the wave:
As you can see from the equation, given that the speed of light is pretty quick compared to the speed of most objects we encounter on a daily basis, we need to use a very high frequency wave in order to get a frequency shift of a convenient value for measurement. In this case we’re using about 10GHz (1010Hz) which gives us a frequency shift of a few hundred hertz for speeds commonly exhibited by people and cars.
By measuring this difference frequency and using the rearranged Doppler equation below we can determine the speed, V, of the object:
Where C is the speed of light, ΔF is the Doppler frequency shift and Fw is the frequency of the transmitted wave.
You’ll notice that a division by two has crept in. This is because the wave is shifted twice; once on the way out and again on the return trip. The moving object will see the radar frequency shifted by an amount due to the relative motion of the object and the radar, then that shifted signal is reflected back to the radar, acquiring a second shift. This leads to a detected Doppler shift of twice the amount than if the object itself was the source of the wave. This double shift is corrected by the division by two.
For even large targets a few metres away the output signal from the radar is at a very low level, the order of microvolts, so it needs amplifying before it can be sampled. I used a simple circuit based around the LM358 opamp to provide a gain of a few thousand that could then be connected to an ADC on the STM32L476. The power supply for this amplifier was taken from the +5V supply of the Discovery board but contained a lot of noise from all the digital devices. Some supply filtering was implemented to fix this and I also added a simple level converter to make sure the signal input to the ADC didn’t exceed the 3.3V supply of the STM32 and was centered around 3.3/2 volts. To help with debugging I configured the USB port as a serial device so I could display the sampled signal and other data on a computer. This was invaluable during development to quickly spot any problems and was also used to capture the waveforms shown in this article. Another useful development tool was a small fan which was used to provide a ‘moving’ test target for the radar. Much more convenient than waving your hand in front of the sensor!
The final hardware is shown below. The green PCB is the motion detector with the two pairs of rectangular microstrip transmitting and receiving antennas visible. The chip and surrounding parts form the amplifier while the board hanging off and attached by wires is the supply filter and level converter. Hooray for prototyping!
To measure the frequency of the signal from the motion detector we could use a comparator (the STM32L465 comes with 2) and simply count the number of times the radar signal crosses the zero line in a set time. This is simple and for signals like the one below we can get good results:
However the signals from the radar can be quite noisy, with returns from multiple targets and noise from the amplifiers. The returned signals can also be very weak, often barely visible on the waveform display:
To solve this problem we can take advantage of the STM32L476’s floating point unit and the DSP functions supplied with the SDK to perform an FFT on the radar output to obtain its spectrum. This makes it much easier to separate all the different returns detected by the radar and we can pick the one we’re interested in. For example the waveform above has the spectrum shown below:
It’s now very easy to identify the moving object in the received signal as the peak on the left of the display.
The choice of FFT length for calculating the spectrum is a trade off between time resolution and frequency resolution. With a long FFT we can get a very accurate estimate of the peak frequency but it would take longer to capture and calculate than if we used a short FFT. We can perform more short FFTs per second but they would give us a less accurate frequency estimate. For this application I was aiming for an accuracy of ±1km/h (about 0.3m/s) so I needed a frequency resolution better than 20Hz. In the end I chose an FFT length of 512 which at a sampling rate of 8kHz gives a frequency resolution of about 15Hz. I later added a menu item to the device to allow the FFT size to be changed on the fly so I could see the difference in performance.
For this demo I selected the largest peak in the spectrum as the primary signal and calculated the output for the speed display based on that. Once calculated, the object speed was displayed on the board’s LCD display.
To listen to the radar output I sent the sampled data over the SAI to the audio DAC. From there it could be heard on headphones or speakers.
If this was intended as a bike/vehicle radar then we could improve performance by ignoring objects moving below a certain speed. This can be done by high pass filtering the output from the radar. Most signals below 50Hz are just caused by the person operating the radar moving around. This movement occurs near the sensor and so is of very high amplitude and often exceeds the range of the ADCs. By filtering this before sampling we could improve the performance of the radar considerably.
Once we have the signal in the frequency domain we can do all sorts of things with it. To increase sensitivity and reduce the effects of noise we could average the spectrum over time. Any random noise now gets averaged out leaving the weak signals clearly visible in the spectrum display. As it turned out for this application it didn’t have to be that complicated - the radar could already detect cars tens of metres away with just the simple setup described here.
During development I used a small fan to simulate a moving target for the radar. I noticed that rather than a pure tone, the fan produced a characteristic pattern of lines in the spectrum view:
I’m speculating that the different spectral lines are caused by the the fan blades presenting strong reflections when they are at different angles to the radar at different points in their rotation. This could be unique to the shape and arrangement of the blades in this particular model of fan. This demonstrates the way that military radar might identify different aircraft types from the characteristic Doppler signature of the engines and other external moving parts.
It was a lot of fun to build this radar and there are still lots of things I’d like to experiment with to develop it further. The STM32L476 Discovery board is a powerful platform to do this on.
Want to continue reading articles from DesignSpark?
Become a member to get unlimited access to all DesignSpark content for free!