How to creating a tune-able sine wave in simulink

6 visualizaciones (últimos 30 días)
Youssef EL ALAOUI
Youssef EL ALAOUI el 22 de En. de 2016
Comentada: Walter Roberson el 28 de En. de 2016
Hi everyone,
I'm trying to create a signal generator, like, tune-able module that could be translated with Embedded Coder for the STM32F429 MCU. Especially for a sine wave with freq = 10hz and 100 sample/Period. If any buddy could help I tried several combinations but no result comes out.
Thank you by advance,

Respuesta aceptada

Jason Moore
Jason Moore el 23 de En. de 2016
This can be solved pretty easily using the Sine Wave block. If you ever want to see which blocks are supported for code generation you can use the command >>showblockdatatypetable . This table will give you a list of every block and its support with Code Generation.
In this case, Sin Wave is supported. So you can use the sin wave block in your model and if you want the parameters to be run time tunable I would use a Simulink.Parameter Object. Simply define >>myParam = Simulink.Paramameter
Goto the workspace double click on myParam and change the value to the initial parameter value and ExportedGlobal. Now use myParam in your block parameters of your Sin Wave block. When you generate code you will end up with a variable called myParam that you can tune. You can do this for all of the settings of the Sin Wave block.
  2 comentarios
Youssef EL ALAOUI
Youssef EL ALAOUI el 25 de En. de 2016
hi Jason,
Thank you for the hint, actually I got registers variables (Freq, Amp, Phase and Bias) that I monitor via USART into a Matlab Function block, in an embedded design into the STM32F4 MCU where I'm generating wave-forms. The M-function block contains the following:
function y = SinWave(Amp, Freq, pi, count)
if coder.target('Sfun')
y = real(0);
t = real(0);
else
t = (2*pi/(Freq-1))*count;
y = Amp*sin(t);
end
end
The DAC is a 12 bits resolution.
Regards,
Walter Roberson
Walter Roberson el 28 de En. de 2016
Youssef commented,
Thanks again to Jason for his answer. Now, since I'm using the UART link to change Simulink's parameters, I have set a "Data Store Memory" for every parameter. The complementary question is how to associate the Simulink.Parameter (SAmp) with "Data store memory" that I'm calling "Amp"? Thanks,

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by