time delay in simulink to be used with c code generation
14 个评论
Hi @Sadia,
Please see my response to your comments below.
To address your first query regarding, My problem is whenever I try to include the a C function (using coder.ceval etc) in a Matlab function block, initially it gives errors such as cannot find header files such as "stm32f4xx_hal_conf.h" etc
The error regarding missing header files such as "stm32f4xx_hal_conf.h" indicates that the MATLAB environment cannot locate the necessary STM32 HAL library files. This is often due to incorrect paths or missing configurations in the MATLAB setup.
Now, addressing your second query, operand mismatch for ds, Error: no such instruction: `dmb 0xF etc.
The assembler errors, such as "operand mismatch for ds" and "no such instruction: `dmb 0xF," suggest that the assembly code generated by the C code is not compatible with the target architecture or that the compiler settings are not correctly configured for the STM32 platform.
My suggestion would be at this point would be integrating the C code into MATLAB, test the C code in a standalone environment (e.g., an STM32 IDE) to ensure that it compiles and runs correctly. This can help isolate whether the issue is with the C code itself or the integration with MATLAB.
After reading your comments about “I am not very well versed with C and assembly language so I don't really understand this. I have tried googling it but no luck specifically in Matlab.”
I may suggest how exactly are you compiling code since I have no clue what is going on your side of “ interface a STM32F411RE board with a 4 digital seven segment display via simulink”
So, please provide some detailed instructions and let’s follow a step by step process in order to accomplish your goal. Otherwise, exchanging these ideas back and forth and not knowing how are you interfacing your board with simulink will not help reach your target goal. Hope, you understand.
回答(1 个)
- Open the Model Configuration Parameters dialog box from the Settings. Then, navigate to the Simulation Target tab.
- In the advanced parameters section, uncheck the option labeled Block reduction. This will prevent the code generator from simplifying blocks that are crucial for timing accuracy.
- Go to the Code Generation tab and then select Optimization.
- Consider setting the Optimization levels option to Minimum. This setting reduces the extent to which the code is optimized, preserving your intended logic.
- Alternatively, it can be set to Balanced with readability or Maximum if those settings better suit the needs.
- If either Balanced with readability or Maximum is chosen, enable Specify custom optimization and uncheck the option Eliminate superfluous local variables (expression folding). This prevents the code generator from folding expressions that might interfere with timing logic.
3 个评论
- Create a MATLAB Function Block:
- In your Simulink model, add a MATLAB Function block.
- Double-click the block to open the editor and define the delay function. Use coder.ceval to call a custom C function:
- Create a file named delay.c with the following content:
- Create a delay.h file to declare the function:
- In the Model Settings under Code Generation > Custom Code, specify the delay.c and delay.h files in the appropriate sections for source and header files.
- In the Source files field, enter the name of your custom source file, e.g., delay.c. If the file is not in the current working directory, provide the full path or relative path from the model file location.
- In the Header files field, enter the name of your custom header file, e.g., delay.h. Similar to source files, provide the full path if necessary.
- If you need to include any specific initialization code or additional functions, you can add them in the Include directives field. For example, you might add #include "delay.h" if it is not already included in your code.
另请参阅
类别
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!