How to write to a parameter ?

9 views (last 30 days)
John
John on 7 Apr 2025
Answered: Subhajyoti on 27 Jun 2025
I have a control system where a voltage demand (parameter ManualDemand_V) sets a voltage which is sent to a plant model that converts the voltage to a speed in rpm.
There is also a PI controller block which tracks the manual demand voltage for a bumpless transition from manual control to PI control.
The PI controller is enabled by setting a flag (parameter EnablePI). When this flag is set, I have an algorithm to capture the speed output of the plant model, using a rising edge detect and sample and hold.
This captures the speed of the plant model when the PI controller is enabled, so that the PI controller setpoint matches the speed at the time when the PI controller was enabled.
I need the PI controller setpoint (parameter SpeedDemand_rpm) to be updated with this sample and hold value that was captured when the PI controller was enabled, but I don’t know how to do this.
Is it possible to update this parameter and if so how ? I did have a look at the ‘parameter writer’ block but not sure if this is suitable and I don’t know how to implement it.
All these parameters are configured as Simulink parameters, so they appear in the a2l file and can be used with Vector CANape where the Simulink code will be running on a dSpace Micro Auto Box (obviously without the plant model).
When the parameter is updated with the sample and hold value, I would expect to see the value of this parameter change in CANape. Once it has changed, the user should be able to modify the parameter so that the setpoint can be changed for the PI controller.
Below are the Simulink parameters defined in the model shown above…
SpeedDemand_rpm:
EnablePI:
ManualDemand_V:

Answers (1)

Subhajyoti
Subhajyoti on 27 Jun 2025
Hi @John,
To update the SpeedDemand_rpm parameter with the sampled speed when EnablePI is triggered, use the "Parameter Writer" block in Simulink:
1. Configure SpeedDemand_rpm:
Define as a Simulink.Parameter with ExportedGlobal storage class, tunable, and matching data type (e.g., double).
matlab
SpeedDemand_rpm = Simulink.Parameter;
SpeedDemand_rpm.Value = 0;
SpeedDemand_rpm.CoderInfo.StorageClass = 'ExportedGlobal';
SpeedDemand_rpm.DataType = 'double';
2. Add Parameter Writer:
  • Place a "Parameter Writer" block (Simulink/Signal Routing).
  • Connect the Sample and Hold block’s output (captured speed) to the block’s input.
  • Set the block’s Parameter name to SpeedDemand_rpm.
3. Conditional Update:
  • Use a Switch or Enabled Subsystem to write only on the rising edge of EnablePI.
4. dSPACE and CANape:
  • Ensure SpeedDemand_rpm appears in the A2L file (via ExportedGlobal).
  • Deploy to dSPACE MicroAutoBox; verify updates in CANape.
  • Users can modify SpeedDemand_rpm in CANape for PI setpoint adjustments.
5. Validate:
  • Test in Simulink simulation, then on dSPACE.
  • Confirm SpeedDemand_rpm updates in CANape when EnablePI triggers.
Also, ensure matching sample times and dSPACE RTI compatibility. If issues arise, consider a global variable with "Data Store Write" as an alternative.

Categories

Find more on Simulink in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!