make smaller global variables in code generation

조회 수: 4 (최근 30일)
진회 김
진회 김 2023년 8월 9일
댓글: 진회 김 2023년 8월 11일
Hello im embedded code user. when i do code generation, A total size of global variables is exceed the limited size of our hardware.
so, to diminish the total size of gloval variables, is there anyway which i can do in my simulink model??
Thank you.

답변 (2개)

recent works
recent works 2023년 8월 10일
If you're dealing with limited memory resources in embedded systems and the total size of global variables is a concern during code generation from Simulink, there are several strategies you can use to reduce the memory footprint. Here are some tips to help you minimize the size of global variables:
  1. Reduce Data Types Size: Use smaller data types (e.g., uint8, int16) instead of larger ones (e.g., double) when appropriate. Choose the smallest data type that can represent your data accurately.
  2. Use Local Variables: Minimize the use of global variables. Whenever possible, use local variables within functions or blocks. Local variables have a smaller memory footprint because they only exist within the scope of the function or block.
  3. Optimize Memory Usage in Simulink Blocks:
  • Use fixed-point data types when suitable, as they can reduce the memory required compared to floating-point types.
  • Configure block data types to match the smallest required data type.
  • Use signal ranges to constrain data, allowing more aggressive data type optimization.
  1. Use Memory Block: Consider using Memory blocks to allocate memory in a controlled manner. This allows you to manage memory explicitly and can help prevent overallocation.
  2. Data Decomposition: If you have large arrays, consider decomposing them into smaller chunks or optimizing the data layout to reduce memory fragmentation.
  3. Check Library Block Parameters: If you're using custom library blocks, check their parameters. Some blocks may have configuration options that impact memory usage.
  4. Analyze Code Generation Reports: Enable and review the code generation reports in Simulink. These reports can provide insights into memory usage and suggest optimizations.
  5. Limit Sample Rates: Reducing the sample rates of your signals can help reduce memory usage in embedded systems.
By applying these strategies and being mindful of data types and memory usage throughout your Simulink model, you can work towards reducing the total size of global variables and better fit your embedded hardware constraints.
  댓글 수: 1
진회 김
진회 김 2023년 8월 11일
Thank you for your good recomendation. im going to revise my model by following your suggestion. Thank yon

댓글을 달려면 로그인하십시오.


Jongil Lee
Jongil Lee 2023년 8월 10일
  댓글 수: 3
Song-Hyun Ji
Song-Hyun Ji 2023년 8월 10일
만약 모델 내에 Bus Structure 를 사용한다면, 구조체의 크기에 따라 전역 변수 생성 여부가 결정됩니다. 변수가 전역 데이터(Global data)로 생성되는 최대 스택 크기에 대한 임계 값이 있습니다. 이 임계 값은 모델의 "Configuration Parameters" 옵션 내에 "Maximum stack size" 를 통해 액세스하고 수정할 수 있습니다.
진회 김
진회 김 2023년 8월 10일
답변 감사합니다. 혹시 Maximum stack size 보다 작으면 글로벌 메모리로 잡힌다는 말씀이 맞을까요 ??
추가로 하나만 더 여쭤보겠습니다! Maximum stack size 를 늘리게 되면 init stack 에 대한 값들이 증가하게 되던데 이 두값이 트레이드오프 관계인걸까요 ? 하드웨어에서 동작하기에 init stack 사이즈가 너무 크게 되면 오동작 할수 있어서 Maximum stack size를 늘리면서 init stack 사이즈를 줄일수 있는 방법이 있을까 궁금합니다.

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by