Hi Brian,
I understand that you want to extract specific parameters from Simulink model like output voltage, temperatures, and ripple current and display them using generated code.
You can follow this official MathWorks Documentation to access outputs in generated code.
I am also attaching an example Simulink model and the steps to create the model. Below are the steps to Access Parameters in Generated Code:
1. Create Simulink Model:
- Open Simulink and create a model (e.g., voltCodeGen).
- Add some components in the model for Simulation.
- Use Outport Blocks for Parameters:
- For each parameter you want to access (e.g., input/output voltage), add an Outport block. Connect these Outport blocks to the relevant signals in your model.
2. Configure Outport Blocks:
- Go to Apps > Simulink Coder > Code Mappings.
- In the Code Mappings Editor, find the Outport blocks you added.
- Set the storage class of each Outport block to ExportedGlobal.
- Assign a unique identifier name to each Outport block. This identifier will be used to access the variable in the generated code.
3. Generate C Code:
- In Simulink Coder Tab, Click on Build to generate C code for your model.
- The generated code will be located in the code generation folder. (voltCodeGen_grt_rtw)
- Access Parameters in Generated Code:
- Open the main generated C file (voltCodeGen.c) in Visual Studio.
- Locate the identifiers you set for the Outport blocks. These will be declared as global variables.
- Use “printf” statements in “voltCodeGen_step” to display the values of these parameters in the terminal window.
printf("Voltage: %f\n", Voltage);
printf("Current: %f\n", Current);
Hope this helps!