How to modify variables during Simulink simulation

24 ビュー (過去 30 日間)
Tommaso
Tommaso 2025 年 11 月 14 日 9:13
回答済み: Leepakshi 2025 年 11 月 20 日 5:15
Hi everyone, I am quite new to MATLAB and Simulink.
I am developing an high level simulation of a PLL and the input signal is being simulated with a sawtooth voltage source (pulse voltage control where the rise time and fall time are identical and the hold time is infinitely smaller than the latters) which is used as base signal for a PWM of a square wave (based on the sawtooth values, the duty cycle of the PWM changes).
I need to change the frequency of this sawtooth at a certain point during the simulation to measure how fast the PLL settles to the new frequency value.
The ideal way would be to change the frequency parameter in the model workspace during simulation, but this would mean that I need to generate the signal using a MATLAB Function Block (plus, I don't know why, but assignin doesn't allow me to change the model workspace when I put caller instead of base: the output says "For C/C++ code generation, the value of input workspace must be 'base'.").
I tried to do so, but multiple errors occur (e.g. the square pulse duration is not what the duty cycle should impose). You can try yourself to substitute the Frequency Changer block in the first implementation (pulse voltage source) with the constant square_freq and see how the pulses are 50ps shorter.
I attached the model for the generation and the base workspace that makes it work.

回答 (1 件)

Leepakshi
Leepakshi 2025 年 11 月 20 日 5:15
Hi Tommaso,
The error you are encountering in MATLAB regarding the square pulse duration not matching the duty cycle is likely due to incorrect settings or parameters in your duty cycle calculation.
Refer to this Mathworks documentation for dutycycle:
For assignin issue, assignin('caller',...) does not work inside MATLAB Function Blocks for code generation because the workspace must be base.
Refer to this Mathworks documentation for assignin:
If this doesn't solve the issue, you can contact Mathworks Support using below link:
Hope it helps!

カテゴリ

Help Center および File ExchangeSpectral Measurements についてさらに検索

製品


リリース

R2025b

Community Treasure Hunt

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

Start Hunting!

Translated by