Labfans是一个针对大学生、工程师和科研工作者的技术社区。 | 论坛首页 | 联系我们(Contact Us) |
![]() |
![]() |
#1 |
游客
帖子: n/a
|
![]()
Techniques for Creating Models and Generating Optimized Code for Fixed-Point Designs Using Simulink 6
by Tom Erkkinen and Vinod Reddy Creating and implementing fixed-point designs is challenging because we live (and think) in a floating-point world. For example, my outside thermometer currently reads 33°F, not 100001°F. Yet thousands of engineers use Simulink every day to design fixed-point embedded systems and will continue to do so for as long as fixed-point processors perform calculations faster and are less expensive than their floating-point counterparts. Simulink Fixed Point helps engineers transition from floating- to fixed-point by providing automatic scaling tools and intrinsic fixed-point data types. Real-Time Workshop Embedded Coder automatically generates code from fixed-point designs that will run in mass-production embedded systems. A popular article describing tips and techniques for quickly creating fixed-point models and generating optimized fixed-point code using MathWorks products appeared in the November 2002 issue of MATLAB Digest. It was prepared by MathWorks developers and based on Simulink 5. We have updated this article based on Simulink 6 and it is now available on MATLAB Central. The update provides an overview of fixed-point, key definitions, design considerations, and a generalized design process. The majority of the article, however, and its most heavily referenced section, is the rich collection of tips about modeling style and code generation options for designing and implementing fixed-point designs optimized for:
Not sure if the article update is worth reading? Take this quiz.
The following tip describes the importance of using the Stateflow operator C per question (1) above, but you will have the read the updated article to learn about question (2) and many others. Example Tip – Use Stateflow Operator “C” Use the C qualifier after literal constants in Stateflow to make the code generator automatically consider the usage context of the constant. This causes the code generator to use the optimal data type for that constant. Figure 1 shows a Stateflow chart in a Simulink model. The content of this Stateflow chart allows us to compare not using the C qualifier with using it. Notice that the first equation, called “simple” in the figure, does not use the C qualifier with the constant 4.5. The second, called “better,” does. (The “c” is not case-sensitive.) Figure 1 also shows the generated code. In the first equation (simple), the addition operation occurs in floating-point because the C qualifier was not specified in the Stateflow chart for the constant 4.5. In contrast, because the C qualifier was specified in the second equation (better), the code generator converted the 4.5 constant to its equivalent fixed-point value (36). It did so based on context. “Context” refers to the data type and scaling of the other operands in the expression. You can also explicitly specify parameter objects in the base workspace and not rely on context. In this example, the data type and scaling of the constant is that of the variable “x,” namely sfix16_En3. Therefore, using the C qualifier automatically selects the appropriate data type and scaling of the constant, based on the context, and the addition occurs with integer mathematics. As a result, ROM consumption and execution time decrease compared with the first equation. ![]() 更多... |
![]() |