Issues with Generating Variable Frequency (Chirp) Ultrasonic Signal on Nucleo-L432KC
Hello everyone,
I’m currently working on a project where I need to generate an ultrasonic trigger signal using the Nucleo-L432KC board and CubeIDE. I can successfully generate a constant 40 kHz signal, and I am able to control the number of cycles in each burst (8, 10, or 20 cycles) and the duration of the wait time (20 to 50 ms) between bursts based on the distance to be measured. However, I’m facing issues when trying to sweep the frequency from 38 kHz to 42 kHz.
My Setup:
1. Board: Nucleo-L432KC
2. Development Environment: CubeIDE
3. Clock Configuration: 80 MHz system clock
4. Timer Configuration:
•Prescaler: 0
•Period: 1000 - 1 (to generate 40 kHz signal)
•Output Compare Mode: Toggle
•Timer instance is TIM2.
The Problem:
I need to sweep the frequency from 38 kHz to 42 kHz at certain intervals. To achieve this, I attempted to dynamically change the timer period. Here’s what I tried:
Dynamic Period Update:
•Adjust the period and pulse width in the main loop.
•Use HAL functions to stop and start the timer to update the settings.
In my main loop, I start with a period of 900 (for 38 kHz) and increment it by 10 to sweep up to 1100 (for 42 kHz). After reaching 1100, I reset the period back to 900 and repeat the process. However, this approach did not work without adding Hal delay for at least 10-20 ms. Therefore, the signal generated is not as expected. There is a significant difference between the generated signal and the expected one. The updates are not being processed correctly, possibly due to the loop running too quickly or the timer not updating as expected.
What I Need:
- Advice on a more effective approach to dynamically change the frequency.
- Alternative methods or configurations that might work better for generating a variable frequency signal.
If it is possible to achieve this with my current Nucleo-L432KC board, any detailed help and guidance would be greatly appreciated. I am open to suggestions and willing to try different approaches to get this working correctly.
Any help or suggestions would be greatly appreciated!
Thanks in advance for your assistance!
