{"id":1512,"date":"2021-03-25T10:00:47","date_gmt":"2021-03-25T08:00:47","guid":{"rendered":"https:\/\/zen-cori.138-201-132-86.plesk.page\/?p=1512"},"modified":"2023-02-06T12:44:14","modified_gmt":"2023-02-06T10:44:14","slug":"3-reasons-to-consider-using-a-floating-point-model-to-generate-fixed-point-code","status":"publish","type":"post","link":"https:\/\/www.btc-embedded.com\/de\/3-reasons-to-consider-using-a-floating-point-model-to-generate-fixed-point-code\/","title":{"rendered":"3 Reasons to Consider Using a Floating-Point Model to Generate Fixed-Point Code"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-post\" data-elementor-id=\"1512\" class=\"elementor elementor-1512\" data-elementor-post-type=\"post\">\n\t\t\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-3b5f0493 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"3b5f0493\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-559a247a\" data-id=\"559a247a\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-d83c847 elementor-widget elementor-widget-text-editor\" data-id=\"d83c847\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Despite the availability of fast processors with dedicated floating-point support, we still see many projects generating fixed-point code from Simulink. The reason for this is not only the resource usage, but also the more transparent and predictable mathematical behavior. You can read more about this in our previous articles <a href=\"https:\/\/www.btc-embedded.com\/what-you-should-know-about-fixed-point\/\">\u201cWhat you should know about fixed-point\u201d<\/a> and <a href=\"https:\/\/www.btc-embedded.com\/what-you-should-know-about-floating-point\/\">\u201cWhat you should know about floating-point\u201d<\/a>.<\/p><p>Assuming that we want to generate fixed-point production code from a Simulink model, there are basically two choices:<\/p><ul><li>directly create a Simulink model with fixed-point types or<\/li><li>create a floating-point model first<\/li><\/ul><div>\u00a0<\/div><p>The first option might seem natural, but starting with a floating-point model can have several advantages. Let\u2019s try to look at it from three perspectives:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-7c099a8 elementor-widget elementor-widget-heading\" data-id=\"7c099a8\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">1. Development<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-a1ff07f elementor-widget elementor-widget-text-editor\" data-id=\"a1ff07f\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>In the automotive industry, applications in general and software in particular is getting more complex. With this growing complexity, we see many projects which separate the role of the\u00a0<b>function developer<\/b>\u00a0from the role of the\u00a0<b>software developer<\/b>. The function developer might be an engineer with detailed domain knowledge (e.g. about the powertrain) while the software developer has the knowledge about the production code and the implementation details. In such a setting, it makes a lot of sense to allow the function developer to work in a somehow ideal mathematical world of float double types in Simulink, where he can focus on the actual algorithms, maybe do some rapid prototyping, and doesn\u2019t need to think about implementation details like bit sizes or scalings. This would happen in a second step, where the software developer will configure and parametrize the code generator and in particular take care of the fixed-point data types and the scaling.\u00a0<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-30b3c92 elementor-widget elementor-widget-heading\" data-id=\"30b3c92\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">2. Testing and Debugging<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-934b48a elementor-widget elementor-widget-text-editor\" data-id=\"934b48a\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>When test cases fail, we need to start a debugging to find the root cause. But if we directly implement everything in fixed-point the question is: Does the failed test case come from a problem with the algorithm or a problem with the scalings and resolutions of the variables.<\/p><p>If we create a floating-point model first, we can be sure that any errors found during requirements-based testing on model level (MIL) result from the algorithm itself.<\/p><p>In a second step, we can perform a Back-to-Back Test between model (MIL) and code (SIL\/PIL) with suitable tolerances. Any deviations which occur in this second step would be caused by the scaling.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-27e953f elementor-widget elementor-widget-heading\" data-id=\"27e953f\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">3. Reuse<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-6cdaf06 elementor-widget elementor-widget-text-editor\" data-id=\"6cdaf06\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Especially for larger projects, it is recommended to create a hierarchical software architecture where the actual software units are limited in their size. This is also directly mentioned in the ISO 26262 specification, which asks for \u201cAppropriate hierarchical structure of the software components\u201d and \u201cRestricted size and complexity of software components\u201d. We already talked about this topic in context of Model-based Development in our blog article <a href=\"https:\/\/www.btc-embedded.com\/moving-automotive-embedded-software-development-to-the-cloud-5-2\/\">\u201cModular Model-based Software Architecture for Efficient Unit and Integration Test\u201d<\/a>.\u00a0<\/p><p>Another positive effect of small software units is the potential to reuse them in different projects and\/or on different target platforms. But this might require an adaption of the implementation data types. With a \u201cmaster\u201d Simulink model using FLP data types, we have the flexibility to generate different variants of the production code with either FLP data types or 8\/16\/32-bit FXP types. Each variant would require it\u2019s dedicated Back-to-Back Test between model and code, but other test activities like Requirements-based Testing would only happen once at the model level.\u00a0<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-b769b80 elementor-widget elementor-widget-image\" data-id=\"b769b80\" data-element_type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t<figure class=\"wp-caption\">\n\t\t\t\t\t\t\t\t\t\t<img fetchpriority=\"high\" decoding=\"async\" width=\"800\" height=\"246\" src=\"https:\/\/www.btc-embedded.com\/wp-content\/uploads\/2021\/03\/tl_block_flp_fxp-1756x-f94.png\" class=\"attachment-large size-large wp-image-1516\" alt=\"Settings for generating optimized fixed-point code from Simulink models with dSPACE TargetLink\" srcset=\"https:\/\/www.btc-embedded.com\/wp-content\/uploads\/2021\/03\/tl_block_flp_fxp-1756x-f94.png 1756w, https:\/\/www.btc-embedded.com\/wp-content\/uploads\/2021\/03\/tl_block_flp_fxp-1756x-f94-768x237.png 768w, https:\/\/www.btc-embedded.com\/wp-content\/uploads\/2021\/03\/tl_block_flp_fxp-1756x-f94-1536x473.png 1536w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/>\t\t\t\t\t\t\t\t\t\t\t<figcaption class=\"widget-image-caption wp-caption-text\">TargetLink Inport Block with floating-point datatype on model level and fixed-point type in code\n<\/figcaption>\n\t\t\t\t\t\t\t\t\t\t<\/figure>\n\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-8f3060b elementor-widget elementor-widget-heading\" data-id=\"8f3060b\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">Conclusion <\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-6ec190f elementor-widget elementor-widget-text-editor\" data-id=\"6ec190f\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Generating fixed-point code from a floating-point model can bring several benefits to the different stakeholders in a Model-based Development process. Function developers and software developers can efficiently focus on different aspects of the process. Test engineers can independently deal with different error sources. And last but not least, a model which is more independent from the actual implementation is more reusable within different projects and\/or on different targets.<\/p><p>P.S.: Even in a floating-point model,\u00a0it makes sense to use boolean\/integer\/enum types for the variables which do\u00a0not\u00a0represent a continous range of values.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>Despite the availability of fast processors with dedicated floating-point support, we still see many projects generating fixed-point code from Simulink. The reason for this is not only the resource usage, but also the more transparent and predictable mathematical behavior. You can read more about this in our previous articles \u201cWhat you should know about fixed-point\u201d [&hellip;]<\/p>\n","protected":false},"author":16,"featured_media":9023,"comment_status":"open","ping_status":"closed","sticky":false,"template":"elementor_theme","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[1],"tags":[50,49,48,51],"product":[],"use_cases":[],"class_list":["post-1512","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","tag-automatic-code-generation","tag-model-based-development","tag-simulink","tag-targetlink"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.btc-embedded.com\/de\/wp-json\/wp\/v2\/posts\/1512","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.btc-embedded.com\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.btc-embedded.com\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.btc-embedded.com\/de\/wp-json\/wp\/v2\/users\/16"}],"replies":[{"embeddable":true,"href":"https:\/\/www.btc-embedded.com\/de\/wp-json\/wp\/v2\/comments?post=1512"}],"version-history":[{"count":0,"href":"https:\/\/www.btc-embedded.com\/de\/wp-json\/wp\/v2\/posts\/1512\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.btc-embedded.com\/de\/wp-json\/wp\/v2\/media\/9023"}],"wp:attachment":[{"href":"https:\/\/www.btc-embedded.com\/de\/wp-json\/wp\/v2\/media?parent=1512"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.btc-embedded.com\/de\/wp-json\/wp\/v2\/categories?post=1512"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.btc-embedded.com\/de\/wp-json\/wp\/v2\/tags?post=1512"},{"taxonomy":"product","embeddable":true,"href":"https:\/\/www.btc-embedded.com\/de\/wp-json\/wp\/v2\/product?post=1512"},{"taxonomy":"use_cases","embeddable":true,"href":"https:\/\/www.btc-embedded.com\/de\/wp-json\/wp\/v2\/use_cases?post=1512"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}