{"id":736,"date":"2021-03-25T15:43:42","date_gmt":"2021-03-25T15:43:42","guid":{"rendered":"https:\/\/imperix.com\/doc\/?p=736"},"modified":"2025-05-07T08:59:04","modified_gmt":"2025-05-07T08:59:04","slug":"s-functions-c-code-simulink-integration","status":"publish","type":"post","link":"https:\/\/imperix.com\/doc\/help\/s-functions-c-code-simulink-integration","title":{"rendered":"Integration of C code in Simulink via S-Functions"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 ez-toc-wrap-right-text counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/imperix.com\/doc\/help\/s-functions-c-code-simulink-integration\/#Creating-an-S-function\" >Creating an S-function<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/imperix.com\/doc\/help\/s-functions-c-code-simulink-integration\/#Good-to-know-about-S-Functions\" >Good to know about S-Functions<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/imperix.com\/doc\/help\/s-functions-c-code-simulink-integration\/#Auxiliary-functions\" >Auxiliary functions<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/imperix.com\/doc\/help\/s-functions-c-code-simulink-integration\/#Arrays-as-arguments\" >Arrays as arguments<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/imperix.com\/doc\/help\/s-functions-c-code-simulink-integration\/#Path-issues-with-the-mat-file\" >Path issues with the .mat file<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/imperix.com\/doc\/help\/s-functions-c-code-simulink-integration\/#Reuse-the-S-Function\" >Reuse the S-Function<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/imperix.com\/doc\/help\/s-functions-c-code-simulink-integration\/#Example\" >Example<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/imperix.com\/doc\/help\/s-functions-c-code-simulink-integration\/#C-code-on-PLECS\" >C code on PLECS<\/a><\/li><\/ul><\/nav><\/div>\n\n<p>This note provides instructions for integrating C code into a control algorithm developed using the ACG SDK via <a href=\"https:\/\/mathworks.com\/help\/simulink\/sfg\/what-is-an-s-function.html\" target=\"_blank\" rel=\"noreferrer noopener\">S-Functions<\/a>, which is probably the best way to include C code into a Simulink model.<\/p>\n\n\n\n<p>With S-Functions, users can create a custom Simulink block, whose behavior is defined by code (C, C++, Fortran or MATLAB), and thus implement advanced algorithms that would be complex to develop with the graphical approach. However, S-Functions have specificities that are good to have in mind, several are discussed in this article.<\/p>\n\n\n\n<p>The integration of C code in PLECS is straightforward and thus briefly discussed at the end.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Creating-an-S-function\"><\/span>Creating an S-function<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Simulink provides an&nbsp;<a href=\"https:\/\/mathworks.com\/help\/simulink\/sfg\/s-function-builder-dialog-box.html\" target=\"_blank\" rel=\"noreferrer noopener\">S-function Builder<\/a>&nbsp;block that generates the necessary files and helps define the inputs, outputs and parameters of the S-function.<\/p>\n\n\n\n<p>The inputs, outputs and parameters can be defined in the Data Properties tab:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"836\" height=\"665\" src=\"https:\/\/imperix.com\/doc\/wp-content\/uploads\/2021\/03\/image-112.png\" alt=\"S-function builder input\/output configuration\" class=\"wp-image-737\" title=\"Product notes &gt; PN153: Integrating custom C or MATLAB code into ACG SDK &gt; s-function_builder_inputs.PNG\" srcset=\"https:\/\/imperix.com\/doc\/wp-content\/uploads\/2021\/03\/image-112.png 836w, https:\/\/imperix.com\/doc\/wp-content\/uploads\/2021\/03\/image-112-300x239.png 300w, https:\/\/imperix.com\/doc\/wp-content\/uploads\/2021\/03\/image-112-768x611.png 768w\" sizes=\"auto, (max-width: 836px) 100vw, 836px\" \/><figcaption>S-function builder input\/output configuration<\/figcaption><\/figure><\/div>\n\n\n\n<p>Then, your C code can be written in the Outputs tab.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"836\" height=\"665\" src=\"https:\/\/imperix.com\/doc\/wp-content\/uploads\/2021\/03\/image-113.png\" alt=\"S-function builder output code\" class=\"wp-image-738\" title=\"Product notes &gt; PN153: Integrating custom C or MATLAB code into ACG SDK &gt; s-function_builder_code.PNG\" srcset=\"https:\/\/imperix.com\/doc\/wp-content\/uploads\/2021\/03\/image-113.png 836w, https:\/\/imperix.com\/doc\/wp-content\/uploads\/2021\/03\/image-113-300x239.png 300w, https:\/\/imperix.com\/doc\/wp-content\/uploads\/2021\/03\/image-113-768x611.png 768w\" sizes=\"auto, (max-width: 836px) 100vw, 836px\" \/><figcaption>S-function builder output code<\/figcaption><\/figure><\/div>\n\n\n\n<p>Finally, the following build options can be configured in the Build Info tab:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"836\" height=\"665\" src=\"https:\/\/imperix.com\/doc\/wp-content\/uploads\/2021\/03\/image-114.png\" alt=\"S-function build options\" class=\"wp-image-739\" title=\"Product notes &gt; PN153: Integrating custom C or MATLAB code into ACG SDK &gt; s-function_builder_build.PNG\" srcset=\"https:\/\/imperix.com\/doc\/wp-content\/uploads\/2021\/03\/image-114.png 836w, https:\/\/imperix.com\/doc\/wp-content\/uploads\/2021\/03\/image-114-300x239.png 300w, https:\/\/imperix.com\/doc\/wp-content\/uploads\/2021\/03\/image-114-768x611.png 768w\" sizes=\"auto, (max-width: 836px) 100vw, 836px\" \/><figcaption>S-function build options<\/figcaption><\/figure><\/div>\n\n\n\n<p>When finished, the Build button on the top right corner generates the necessary files. These include:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><em>name<\/em>.cpp<\/td><td>Is the S-function files that define the function inputs, outputs and parameters and call the wrapper function.<\/td><\/tr><tr><td><em>name<\/em>_wrapper.cpp<\/td><td>Is a function that contains the user-written code of the S-function. This file is the only file compiled by the imperix toolchain in code generation.<\/td><\/tr><tr><td><em>name<\/em>.tlc<\/td><td>Is an interface defining how the code should be called by Simulink Coder.<\/td><\/tr><tr><td><em>name<\/em>.mexw64<\/td><td>Is the compiled version of the S-function.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<div class=\"wp-block-simple-alerts-for-gutenberg-alert-boxes sab-alert sab-alert-warning\" role=\"alert\">Make sure that MATLAB is in the same folder as your model when you click the Build button. This ensures that the generated files will have the same path as your model and that the compiler will be able to find them when generating code for the whole model.<\/div>\n\n\n\n<div class=\"wp-block-simple-alerts-for-gutenberg-alert-boxes sab-alert sab-alert-info\" role=\"alert\">A MEX compiler is required to use S-functions. If none is installed, please follow the instructions of the section \u201cMex compiler add-on\u201d from\u00a0<a href=\"https:\/\/imperix.com\/doc\/help\/installation-guide-acg-sdk\">Installation guide for imperix ACG SDK (PN133)<\/a>.<\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Good-to-know-about-S-Functions\"><\/span>Good to know about S-Functions<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Auxiliary-functions\"><\/span>Auxiliary functions<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Auxiliary functions can be placed in the&nbsp;<strong>Includes<\/strong>&nbsp;input box, along with any potential&nbsp;<strong>define&nbsp;<\/strong>directives (as shown with the&nbsp;<em>simulate_state<\/em>&nbsp;function in the figure below).<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"836\" height=\"718\" src=\"https:\/\/imperix.com\/doc\/wp-content\/uploads\/2024\/03\/PN153_s-function_auxiliary_functions_red.png\" alt=\"S-Functions : auxiliary functions via the Includes input box\" class=\"wp-image-26857\" srcset=\"https:\/\/imperix.com\/doc\/wp-content\/uploads\/2024\/03\/PN153_s-function_auxiliary_functions_red.png 836w, https:\/\/imperix.com\/doc\/wp-content\/uploads\/2024\/03\/PN153_s-function_auxiliary_functions_red-300x258.png 300w, https:\/\/imperix.com\/doc\/wp-content\/uploads\/2024\/03\/PN153_s-function_auxiliary_functions_red-768x660.png 768w\" sizes=\"auto, (max-width: 836px) 100vw, 836px\" \/><figcaption>S-Functions : auxiliary functions via the&nbsp;<strong>Includes<\/strong>&nbsp;input box<\/figcaption><\/figure><\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Arrays-as-arguments\"><\/span>Arrays as arguments<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>The S-function supports arrays as arguments. However, arrays of dimension higher than 1 are flattened and must be resized in the C script to recover the desired shape, as in the following example :<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"1000\" height=\"718\" src=\"https:\/\/imperix.com\/doc\/wp-content\/uploads\/2024\/03\/PN153_s-function_arrays_arguments_red.png\" alt=\"Reshaped array arguments in a S-Function\" class=\"wp-image-26858\" srcset=\"https:\/\/imperix.com\/doc\/wp-content\/uploads\/2024\/03\/PN153_s-function_arrays_arguments_red.png 1000w, https:\/\/imperix.com\/doc\/wp-content\/uploads\/2024\/03\/PN153_s-function_arrays_arguments_red-300x215.png 300w, https:\/\/imperix.com\/doc\/wp-content\/uploads\/2024\/03\/PN153_s-function_arrays_arguments_red-768x551.png 768w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><figcaption>Reshaped array arguments in a S-Function<\/figcaption><\/figure><\/div>\n\n\n\n<div class=\"wp-block-simple-alerts-for-gutenberg-alert-boxes sab-alert sab-alert-info\" role=\"alert\">Note that Matlab is based on the\u00a0<a href=\"https:\/\/www.mathworks.com\/help\/coder\/ug\/what-are-column-major-and-row-major-representation-1.html20--%3E\" target=\"_blank\" rel=\"noreferrer noopener\">column-major ordering<\/a>. That means that arrays are transposed compared to the row-major ordering usually used in C, C++ and Python, for example. This explains the position of the terms\u00a0<em>[\u2026]_ptr[1]<\/em>\u00a0and\u00a0<em>[\u2026]_ptr[2]<\/em>\u00a0in the figure above.<\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Path-issues-with-the-mat-file\"><\/span>Path issues with the .mat file<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Path issues can occur when the project is located after the build of the S-function. Those issues can be avoided by removing the&nbsp;<em>SFB__[s-function name]__SFB.mat<\/em>&nbsp;file before transferring the project folder. Removing the .mat file does not affect the simulation or the code generation of the model.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Reuse-the-S-Function\"><\/span>Reuse the S-Function<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>The S-Function Builder block also serves as a wrapper for the generated S-function, which means that it can be used inside a model as any other Simulink block. Alternatively, an&nbsp;<a href=\"https:\/\/mathworks.com\/help\/simulink\/slref\/sfunction.html\" target=\"_blank\" rel=\"noreferrer noopener\">S-function block<\/a>&nbsp;can be used to integrate the generated files into a Simulink model.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"579\" height=\"128\" src=\"https:\/\/imperix.com\/doc\/wp-content\/uploads\/2021\/03\/image-115.png\" alt=\"S-function usage with the builder\" class=\"wp-image-740\" title=\"Product notes &gt; PN153: Integrating custom C or MATLAB code into ACG SDK &gt; s-function_builder_use.PNG\" srcset=\"https:\/\/imperix.com\/doc\/wp-content\/uploads\/2021\/03\/image-115.png 579w, https:\/\/imperix.com\/doc\/wp-content\/uploads\/2021\/03\/image-115-300x66.png 300w\" sizes=\"auto, (max-width: 579px) 100vw, 579px\" \/><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"566\" height=\"115\" src=\"https:\/\/imperix.com\/doc\/wp-content\/uploads\/2021\/03\/image-116.png\" alt=\"S-function usage\" class=\"wp-image-741\" title=\"Product notes &gt; PN153: Integrating custom C or MATLAB code into ACG SDK &gt; s-function_use.PNG\" srcset=\"https:\/\/imperix.com\/doc\/wp-content\/uploads\/2021\/03\/image-116.png 566w, https:\/\/imperix.com\/doc\/wp-content\/uploads\/2021\/03\/image-116-300x61.png 300w\" sizes=\"auto, (max-width: 566px) 100vw, 566px\" \/><\/figure><\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Example\"><\/span>Example<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>A working example is available in the Simulink code (CPU version) of&nbsp;<a href=\"https:\/\/imperix.com\/doc\/implementation\/finite-control-set-mpc\">TN162<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"C-code-on-PLECS\"><\/span>C code on PLECS<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>PLECS provides a handy&nbsp;<a href=\"https:\/\/www.plexim.com\/plecs\/control\/cscripts\" target=\"_blank\" rel=\"noreferrer noopener\">C-Script<\/a>&nbsp;block that lets you write and compile custom C code to integrate it into your model. It works in both simulation and code generation modes.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"300\" height=\"75\" src=\"https:\/\/imperix.com\/doc\/wp-content\/uploads\/2021\/03\/image-119.png\" alt=\"C-script usage in PLECS\" class=\"wp-image-744\"\/><\/figure><\/div>\n","protected":false},"excerpt":{"rendered":"<p>This note provides instructions for integrating C code into a control algorithm developed using the ACG SDK via S-Functions, which is probably the best way&#8230;<\/p>\n","protected":false},"author":2,"featured_media":3020,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","footnotes":""},"categories":[13,3],"tags":[],"software-environments":[103],"provided-results":[],"related-products":[50,31,32,92,166,110],"guidedreadings":[],"tutorials":[],"user-manuals":[135],"coauthors":[63,82],"class_list":["post-736","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-going-further-acg-sdk","category-help","software-environments-matlab","related-products-acg-sdk","related-products-b-board-pro","related-products-b-box-rcp","related-products-b-box-micro","related-products-b-box-rcp-3-0","related-products-tpi","user-manuals-going-further-with-acg-sdk"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Integration of C code in Simulink via S-Functions - imperix<\/title>\n<meta name=\"description\" content=\"This note provides instructions for integrating C code into a control algorithm developed using the ACG SDK on Simulink via S-Functions.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/imperix.com\/doc\/help\/s-functions-c-code-simulink-integration\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Integration of C code in Simulink via S-Functions - imperix\" \/>\n<meta property=\"og:description\" content=\"This note provides instructions for integrating C code into a control algorithm developed using the ACG SDK on Simulink via S-Functions.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/imperix.com\/doc\/help\/s-functions-c-code-simulink-integration\" \/>\n<meta property=\"og:site_name\" content=\"imperix\" \/>\n<meta property=\"article:published_time\" content=\"2021-03-25T15:43:42+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-05-07T08:59:04+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/imperix.com\/doc\/wp-content\/uploads\/2021\/03\/3_2_ratio_PN153.png\" \/>\n\t<meta property=\"og:image:width\" content=\"450\" \/>\n\t<meta property=\"og:image:height\" content=\"300\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Julien Orsinger, Fran\u00e7ois Ledent\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Julien Orsinger, Fran\u00e7ois Ledent\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/imperix.com\\\/doc\\\/help\\\/s-functions-c-code-simulink-integration#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/imperix.com\\\/doc\\\/help\\\/s-functions-c-code-simulink-integration\"},\"author\":{\"name\":\"Julien Orsinger\",\"@id\":\"https:\\\/\\\/imperix.com\\\/doc\\\/#\\\/schema\\\/person\\\/65ef663818eab76f53cc627ab80e0a51\"},\"headline\":\"Integration of C code in Simulink via S-Functions\",\"datePublished\":\"2021-03-25T15:43:42+00:00\",\"dateModified\":\"2025-05-07T08:59:04+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/imperix.com\\\/doc\\\/help\\\/s-functions-c-code-simulink-integration\"},\"wordCount\":643,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/imperix.com\\\/doc\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/imperix.com\\\/doc\\\/help\\\/s-functions-c-code-simulink-integration#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/imperix.com\\\/doc\\\/wp-content\\\/uploads\\\/2021\\\/03\\\/3_2_ratio_PN153.png\",\"articleSection\":[\"Going further with ACG SDK\",\"Product notes\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/imperix.com\\\/doc\\\/help\\\/s-functions-c-code-simulink-integration#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/imperix.com\\\/doc\\\/help\\\/s-functions-c-code-simulink-integration\",\"url\":\"https:\\\/\\\/imperix.com\\\/doc\\\/help\\\/s-functions-c-code-simulink-integration\",\"name\":\"Integration of C code in Simulink via S-Functions - imperix\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/imperix.com\\\/doc\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/imperix.com\\\/doc\\\/help\\\/s-functions-c-code-simulink-integration#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/imperix.com\\\/doc\\\/help\\\/s-functions-c-code-simulink-integration#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/imperix.com\\\/doc\\\/wp-content\\\/uploads\\\/2021\\\/03\\\/3_2_ratio_PN153.png\",\"datePublished\":\"2021-03-25T15:43:42+00:00\",\"dateModified\":\"2025-05-07T08:59:04+00:00\",\"description\":\"This note provides instructions for integrating C code into a control algorithm developed using the ACG SDK on Simulink via S-Functions.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/imperix.com\\\/doc\\\/help\\\/s-functions-c-code-simulink-integration#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/imperix.com\\\/doc\\\/help\\\/s-functions-c-code-simulink-integration\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/imperix.com\\\/doc\\\/help\\\/s-functions-c-code-simulink-integration#primaryimage\",\"url\":\"https:\\\/\\\/imperix.com\\\/doc\\\/wp-content\\\/uploads\\\/2021\\\/03\\\/3_2_ratio_PN153.png\",\"contentUrl\":\"https:\\\/\\\/imperix.com\\\/doc\\\/wp-content\\\/uploads\\\/2021\\\/03\\\/3_2_ratio_PN153.png\",\"width\":450,\"height\":300,\"caption\":\"S-function builder output code\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/imperix.com\\\/doc\\\/help\\\/s-functions-c-code-simulink-integration#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Knowledge base\",\"item\":\"https:\\\/\\\/imperix.com\\\/doc\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Product notes\",\"item\":\"https:\\\/\\\/imperix.com\\\/doc\\\/category\\\/help\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Integration of C code in Simulink via S-Functions\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/imperix.com\\\/doc\\\/#website\",\"url\":\"https:\\\/\\\/imperix.com\\\/doc\\\/\",\"name\":\"imperix\",\"description\":\"power electronics\",\"publisher\":{\"@id\":\"https:\\\/\\\/imperix.com\\\/doc\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/imperix.com\\\/doc\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/imperix.com\\\/doc\\\/#organization\",\"name\":\"imperix\",\"url\":\"https:\\\/\\\/imperix.com\\\/doc\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/imperix.com\\\/doc\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/imperix.com\\\/doc\\\/wp-content\\\/uploads\\\/2021\\\/03\\\/imperix_logo.png\",\"contentUrl\":\"https:\\\/\\\/imperix.com\\\/doc\\\/wp-content\\\/uploads\\\/2021\\\/03\\\/imperix_logo.png\",\"width\":350,\"height\":120,\"caption\":\"imperix\"},\"image\":{\"@id\":\"https:\\\/\\\/imperix.com\\\/doc\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/imperix.com\\\/doc\\\/#\\\/schema\\\/person\\\/65ef663818eab76f53cc627ab80e0a51\",\"name\":\"Julien Orsinger\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0a0328b09c6abe61fa1e263a1066dcb26ea8f3b9e8b1d78056047620947bb388?s=96&d=mm&r=g6545a7220411572e799ad58574cce259\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0a0328b09c6abe61fa1e263a1066dcb26ea8f3b9e8b1d78056047620947bb388?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0a0328b09c6abe61fa1e263a1066dcb26ea8f3b9e8b1d78056047620947bb388?s=96&d=mm&r=g\",\"caption\":\"Julien Orsinger\"},\"description\":\"Julien is a senior power electronics engineer. On the knowledge base, he is acting as the editorial manager and is therefore the co-author of numerous articles on a broad variety of topics.\",\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/julien-orsinger-640ab2129\\\/\"],\"url\":\"https:\\\/\\\/imperix.com\\\/doc\\\/author\\\/orsinger\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Integration of C code in Simulink via S-Functions - imperix","description":"This note provides instructions for integrating C code into a control algorithm developed using the ACG SDK on Simulink via S-Functions.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/imperix.com\/doc\/help\/s-functions-c-code-simulink-integration","og_locale":"en_US","og_type":"article","og_title":"Integration of C code in Simulink via S-Functions - imperix","og_description":"This note provides instructions for integrating C code into a control algorithm developed using the ACG SDK on Simulink via S-Functions.","og_url":"https:\/\/imperix.com\/doc\/help\/s-functions-c-code-simulink-integration","og_site_name":"imperix","article_published_time":"2021-03-25T15:43:42+00:00","article_modified_time":"2025-05-07T08:59:04+00:00","og_image":[{"width":450,"height":300,"url":"https:\/\/imperix.com\/doc\/wp-content\/uploads\/2021\/03\/3_2_ratio_PN153.png","type":"image\/png"}],"author":"Julien Orsinger, Fran\u00e7ois Ledent","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Julien Orsinger, Fran\u00e7ois Ledent","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/imperix.com\/doc\/help\/s-functions-c-code-simulink-integration#article","isPartOf":{"@id":"https:\/\/imperix.com\/doc\/help\/s-functions-c-code-simulink-integration"},"author":{"name":"Julien Orsinger","@id":"https:\/\/imperix.com\/doc\/#\/schema\/person\/65ef663818eab76f53cc627ab80e0a51"},"headline":"Integration of C code in Simulink via S-Functions","datePublished":"2021-03-25T15:43:42+00:00","dateModified":"2025-05-07T08:59:04+00:00","mainEntityOfPage":{"@id":"https:\/\/imperix.com\/doc\/help\/s-functions-c-code-simulink-integration"},"wordCount":643,"commentCount":0,"publisher":{"@id":"https:\/\/imperix.com\/doc\/#organization"},"image":{"@id":"https:\/\/imperix.com\/doc\/help\/s-functions-c-code-simulink-integration#primaryimage"},"thumbnailUrl":"https:\/\/imperix.com\/doc\/wp-content\/uploads\/2021\/03\/3_2_ratio_PN153.png","articleSection":["Going further with ACG SDK","Product notes"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/imperix.com\/doc\/help\/s-functions-c-code-simulink-integration#respond"]}]},{"@type":"WebPage","@id":"https:\/\/imperix.com\/doc\/help\/s-functions-c-code-simulink-integration","url":"https:\/\/imperix.com\/doc\/help\/s-functions-c-code-simulink-integration","name":"Integration of C code in Simulink via S-Functions - imperix","isPartOf":{"@id":"https:\/\/imperix.com\/doc\/#website"},"primaryImageOfPage":{"@id":"https:\/\/imperix.com\/doc\/help\/s-functions-c-code-simulink-integration#primaryimage"},"image":{"@id":"https:\/\/imperix.com\/doc\/help\/s-functions-c-code-simulink-integration#primaryimage"},"thumbnailUrl":"https:\/\/imperix.com\/doc\/wp-content\/uploads\/2021\/03\/3_2_ratio_PN153.png","datePublished":"2021-03-25T15:43:42+00:00","dateModified":"2025-05-07T08:59:04+00:00","description":"This note provides instructions for integrating C code into a control algorithm developed using the ACG SDK on Simulink via S-Functions.","breadcrumb":{"@id":"https:\/\/imperix.com\/doc\/help\/s-functions-c-code-simulink-integration#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/imperix.com\/doc\/help\/s-functions-c-code-simulink-integration"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/imperix.com\/doc\/help\/s-functions-c-code-simulink-integration#primaryimage","url":"https:\/\/imperix.com\/doc\/wp-content\/uploads\/2021\/03\/3_2_ratio_PN153.png","contentUrl":"https:\/\/imperix.com\/doc\/wp-content\/uploads\/2021\/03\/3_2_ratio_PN153.png","width":450,"height":300,"caption":"S-function builder output code"},{"@type":"BreadcrumbList","@id":"https:\/\/imperix.com\/doc\/help\/s-functions-c-code-simulink-integration#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Knowledge base","item":"https:\/\/imperix.com\/doc\/"},{"@type":"ListItem","position":2,"name":"Product notes","item":"https:\/\/imperix.com\/doc\/category\/help"},{"@type":"ListItem","position":3,"name":"Integration of C code in Simulink via S-Functions"}]},{"@type":"WebSite","@id":"https:\/\/imperix.com\/doc\/#website","url":"https:\/\/imperix.com\/doc\/","name":"imperix","description":"power electronics","publisher":{"@id":"https:\/\/imperix.com\/doc\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/imperix.com\/doc\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/imperix.com\/doc\/#organization","name":"imperix","url":"https:\/\/imperix.com\/doc\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/imperix.com\/doc\/#\/schema\/logo\/image\/","url":"https:\/\/imperix.com\/doc\/wp-content\/uploads\/2021\/03\/imperix_logo.png","contentUrl":"https:\/\/imperix.com\/doc\/wp-content\/uploads\/2021\/03\/imperix_logo.png","width":350,"height":120,"caption":"imperix"},"image":{"@id":"https:\/\/imperix.com\/doc\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/imperix.com\/doc\/#\/schema\/person\/65ef663818eab76f53cc627ab80e0a51","name":"Julien Orsinger","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/0a0328b09c6abe61fa1e263a1066dcb26ea8f3b9e8b1d78056047620947bb388?s=96&d=mm&r=g6545a7220411572e799ad58574cce259","url":"https:\/\/secure.gravatar.com\/avatar\/0a0328b09c6abe61fa1e263a1066dcb26ea8f3b9e8b1d78056047620947bb388?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/0a0328b09c6abe61fa1e263a1066dcb26ea8f3b9e8b1d78056047620947bb388?s=96&d=mm&r=g","caption":"Julien Orsinger"},"description":"Julien is a senior power electronics engineer. On the knowledge base, he is acting as the editorial manager and is therefore the co-author of numerous articles on a broad variety of topics.","sameAs":["https:\/\/www.linkedin.com\/in\/julien-orsinger-640ab2129\/"],"url":"https:\/\/imperix.com\/doc\/author\/orsinger"}]}},"_links":{"self":[{"href":"https:\/\/imperix.com\/doc\/wp-json\/wp\/v2\/posts\/736","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/imperix.com\/doc\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/imperix.com\/doc\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/imperix.com\/doc\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/imperix.com\/doc\/wp-json\/wp\/v2\/comments?post=736"}],"version-history":[{"count":38,"href":"https:\/\/imperix.com\/doc\/wp-json\/wp\/v2\/posts\/736\/revisions"}],"predecessor-version":[{"id":26933,"href":"https:\/\/imperix.com\/doc\/wp-json\/wp\/v2\/posts\/736\/revisions\/26933"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/imperix.com\/doc\/wp-json\/wp\/v2\/media\/3020"}],"wp:attachment":[{"href":"https:\/\/imperix.com\/doc\/wp-json\/wp\/v2\/media?parent=736"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/imperix.com\/doc\/wp-json\/wp\/v2\/categories?post=736"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/imperix.com\/doc\/wp-json\/wp\/v2\/tags?post=736"},{"taxonomy":"software-environments","embeddable":true,"href":"https:\/\/imperix.com\/doc\/wp-json\/wp\/v2\/software-environments?post=736"},{"taxonomy":"provided-results","embeddable":true,"href":"https:\/\/imperix.com\/doc\/wp-json\/wp\/v2\/provided-results?post=736"},{"taxonomy":"related-products","embeddable":true,"href":"https:\/\/imperix.com\/doc\/wp-json\/wp\/v2\/related-products?post=736"},{"taxonomy":"guidedreadings","embeddable":true,"href":"https:\/\/imperix.com\/doc\/wp-json\/wp\/v2\/guidedreadings?post=736"},{"taxonomy":"tutorials","embeddable":true,"href":"https:\/\/imperix.com\/doc\/wp-json\/wp\/v2\/tutorials?post=736"},{"taxonomy":"user-manuals","embeddable":true,"href":"https:\/\/imperix.com\/doc\/wp-json\/wp\/v2\/user-manuals?post=736"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/imperix.com\/doc\/wp-json\/wp\/v2\/coauthors?post=736"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}