This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
I am using Simulink Embedded Coder to program my microcontroller. I need to generate a 25kHz sine wave for my speaker.
I am monitoring the signal by connecting an oscilloscope to GPIO pin 70.
When the frequency is 25kHz there is no signal. The result is as follows:
Then I tested the system by reducing the frequency to 250Hz. The result is as follows:
Then I changed the step size from "auto" to 1/(5e5) and the result is as follows:
But as I said this signal disappears in about 100 seconds. In the video below, I captured this weird behaviour.
Why is this signal not continuous and it disappears after a while? Why does it not appear like a proper sine wave when the fixed step size is configured as "auto"?
Finally I will share some screenshots to help with the troubleshooting.
This is my code. First I generate a sine wave with Amplitude 1 and Frequency 250Hz. Then I amplify it by 2047 times and shift it up by 2047 in order to create a sine wave in the range of 0-2^12..
This is the configuration parameters window where I changed the Fixed-step size. Note the solver type is "Fixed-step" and Solver Type is "discrete (no continuous states)".
Hello Canberk,
1) You need to make sure your simulation works before going to HW.
What does the scope in your Simulink model show during simulation (ignoring the DAC block)? Do you get a sine wave with correct frequency? Does your simulation end after 1 second? Do you see a continuous wave, or a discretized wave? Does the gain and offset work like you expect it to be?
2) You may want to directly contact MathWorks Technical Support for assistance, as this looks like a Simulink or maybe Embedded Coder issue.
Cheers,
-Brian
Hello Brian,
Thank you for your response,
What does the scope in your Simulink model show during simulation (ignoring the DAC block)?
Do you get a sine wave with correct frequency?
There are 25 oscillations in 1e-3 seconds hence the frequency is 25kHz as expected.
Does your simulation end after 1 second?
Yes, but that's how long the simulation runs, right? I don't think the period of which the simulation runs can be causing this behaviour.
Do you see a continuous wave, or a discretized wave?
The sine wave that I monitored using my oscilloscope is discretized. You can notice this if you zoom into one of the visuals in my original post.
Does the gain and offset work like you expect it to be?
Yes, as it can be seen in the image above, it is what I expect it to be.
Please let me know what you think,
Best regards,
Canberk
Hi Canberk,
Simulated results look ok to me.
As far as the code running on the board, I cant debug from picture, and I don't have an F28379D to tinker with. Best bet is to contact MathWorks Technical Support for assistance.
Cheers,
-Brian
Hello Brian,
I will contact the support team but first, let me share some new findings. We ran some experiments with different frequencies and recorded the time taken for the signal to vanish. The findings are as follows:
This result shows that the number of oscillations until the signal disappears is more or less the same if we ignore the error due to the latency in the refresh of the oscilloscope. So my idea is that maybe the buffer is getting filled up. Let me know what you think.
Canberk
Hi Canberk,
My guess is that you have a setting somewhere that isn't right - it looks like you are seeing some sort of sampling or memory limitation. Please contact MathWorks Tech Support; they will likely want you to provide a copy of your model that they can investigate.
Thanks,
-Brian