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.




