{"id":1099,"date":"2012-07-11T05:31:13","date_gmt":"2012-07-11T10:31:13","guid":{"rendered":"https:\/\/blogs.mathworks.com\/seth\/?p=1099"},"modified":"2012-07-11T05:31:13","modified_gmt":"2012-07-11T10:31:13","slug":"my-first-debugging-steps","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/simulink\/2012\/07\/11\/my-first-debugging-steps\/","title":{"rendered":"My First Debugging Steps"},"content":{"rendered":"<p>Seth sometimes tells me: <em>Grab the low hanging fruit.<\/em> When debugging Simulink models, this means looking at the information easily available.<\/p>\r\n\r\n<p>Here are the first three things I usually look at when I see unexpected results in a model.<\/p>\r\n\r\n<p><strong>Signal Dimensions<\/strong><\/p>\r\n\r\n<p>When dealing with matrices and vectors, I like to enable Port\/Signal Displays of <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2012a\/toolbox\/simulink\/ug\/f15-90106.html\">Signal Dimensions<\/a> and <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2012a\/toolbox\/simulink\/ug\/f15-90106.html\">Wide Nonscalar Lines<\/a><\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2012Q3\/ShowSignalDimensions.png\" alt=\"Displaying signal dimensions\"><\/p>\r\n\r\n<p>With those options enabled, I can easily identify that the following state-space system has 2 inputs, 3 outputs and 4 states.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2012Q3\/StateSpaceMatrix.png\" alt=\"Example model showing signal dimensions\"><\/p>\r\n\r\n<p><strong>Data Types<\/strong><\/p>\r\n\r\n<p>In Simulink, you do not need to specify the data type of each signal. In most cases, you specify the data types of a few sources and the Simulink engine propagates it to other blocks. When a model gives unexpected results, it is always a good idea to display the <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2012a\/toolbox\/simulink\/ug\/f15-90106.html\">Port Data Types<\/a><\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2012Q3\/ShowPortDataType.png\" alt=\"Displaying port data types\"><\/p>\r\n\r\n<p>For example, how could someone explain that Simulink thinks that 5 is equal to 1?  Take a look at this model:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2012Q3\/dataTypePropagation.png\" alt=\"Displaying port data types, two Boolean signals are compared\"><\/p>\r\n\r\n<p><strong>Sample Time Colors and Legend<\/strong><\/p>\r\n\r\n<p>You always want to confirm that your signals are at the rate you expect. For that, turn on the <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2012a\/toolbox\/simulink\/ug\/f4-93620.html\">Sample Time Colors<\/a> and look at the <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2012a\/toolbox\/simulink\/ug\/bry66ow.html\">Sample Time Legend<\/a>:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2012Q3\/sampletimeColors.png\" alt=\"Sample Time Colors\"><\/p>\r\n\r\n<p>I have seen too many cases like the following model, where the user designs a position controller to run at 4ms, but forgot to set the sample time of the driver block reading the position of the motor:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2012Q3\/wrongTSColors.png\" alt=\"Color showing unexpected sample times.\"><\/p>\r\n\r\n<p><strong>Now it's your turn<\/strong><\/p>\r\n\r\n<p>What are the things you usually look at when debugging a model? Leave a <a href=\"https:\/\/blogs.mathworks.com\/seth\/?p=1099&#comment\">comment here<\/a>.<\/p>","protected":false},"excerpt":{"rendered":"<p>Seth sometimes tells me: Grab the low hanging fruit. When debugging Simulink models, this means looking at the information easily available.\r\n\r\nHere are the first three things I usually look at when... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/simulink\/2012\/07\/11\/my-first-debugging-steps\/\">read more >><\/a><\/p>","protected":false},"author":41,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[43,33],"tags":[276,277,60,278],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/1099"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/comments?post=1099"}],"version-history":[{"count":23,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/1099\/revisions"}],"predecessor-version":[{"id":1123,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/1099\/revisions\/1123"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/media?parent=1099"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/categories?post=1099"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/tags?post=1099"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}