Data type error in PMSM closed loop foc

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Data type error in PMSM closed loop foc

Jump to solution
1,473 Views
Sriram
Contributor IV

Hello ,

I am building a pmsm prototype with the s32k144 mcu . i modified the speed and position estimation subsystems as i am going to use sine cosine encoder for position sensing . While building the code , there seems to be some data type errors . I tried converting all the data stores to double but still it is not working .

I have attached my simulink model . Can anyone pls help.

PS the sine cosine encoder setup is working fine and generating code when i run it separately. I shows error only when i try to interface it with the foc model.

Concerned block is in Speed and position estimation subsystem

Thank you

0 Kudos
1 Solution
1,465 Views
adriantudor
NXP Employee
NXP Employee

Hi Sriram,

First thing, in your custom function, that "live" in "Speed_and_Position_Estimator" you declared an output "theta" to feed the "THETA_EST" variable which is used and declared in the model as single. In Matlab function data that are not declared as certain type, are by default declared as double. So the simplest thing to get rid of this error was to make a cast inside of your function where values are assigned to the output. If you make a cast like this one, then the output will automatically be modified as the type that you used in the cast.

adriantudor_0-1658993236402.png

I recommend you avoid the data type as auto for any data in the Simulink model. The better is to know what you want and set the data type as you need. 

Another tip for you is to use the power of the "Information Overlays" from the debug tab in your model.

adriantudor_1-1658994253743.png

In this case, I used "Alias Data Types" which adds a label to the signals that show you the data type. In this way, you can find that the type of eg. "ntc3" data store must be "uint32". 

If you need to store values, let's say "uint32" in a data store that is declared as "single", then you can use the "Data Type Conversion" block and insert this one between the block, which generate some data of certain type, and the destination for that value that uses different data type.

And I found some broken links of "Storage Class" for data stores and signals used in the model. In this case, you must go to "Code Mappings" and in the "Data Stores" tab you have to select "Storage Class" and the "Model default".

Here is your fixed model.

 

Best regards,

Adrian

 

View solution in original post

5 Replies
1,462 Views
Sriram
Contributor IV

Thank you so much . i added a data converter block before THETA_EST and then changed all the unresolved data types to Model default after this i was able to generate the code. Is changing all the unresolved data types to model default a good thing to do? because after that i am not able to view it in free master as those data types are not volatile. But i found those data stores under Dwork in freemaster.

 

0 Kudos
1,466 Views
adriantudor
NXP Employee
NXP Employee

Hi Sriram,

First thing, in your custom function, that "live" in "Speed_and_Position_Estimator" you declared an output "theta" to feed the "THETA_EST" variable which is used and declared in the model as single. In Matlab function data that are not declared as certain type, are by default declared as double. So the simplest thing to get rid of this error was to make a cast inside of your function where values are assigned to the output. If you make a cast like this one, then the output will automatically be modified as the type that you used in the cast.

adriantudor_0-1658993236402.png

I recommend you avoid the data type as auto for any data in the Simulink model. The better is to know what you want and set the data type as you need. 

Another tip for you is to use the power of the "Information Overlays" from the debug tab in your model.

adriantudor_1-1658994253743.png

In this case, I used "Alias Data Types" which adds a label to the signals that show you the data type. In this way, you can find that the type of eg. "ntc3" data store must be "uint32". 

If you need to store values, let's say "uint32" in a data store that is declared as "single", then you can use the "Data Type Conversion" block and insert this one between the block, which generate some data of certain type, and the destination for that value that uses different data type.

And I found some broken links of "Storage Class" for data stores and signals used in the model. In this case, you must go to "Code Mappings" and in the "Data Stores" tab you have to select "Storage Class" and the "Model default".

Here is your fixed model.

 

Best regards,

Adrian

 

1,459 Views
Sriram
Contributor IV

Also when i run this model or my model freemaster shows board is not detected and sometimes stops the connection. I have to press reset button to get the freemaster show the values but it only works for a few seconds and then stops the communication with the board

0 Kudos
1,450 Views
adriantudor
NXP Employee
NXP Employee

Hi Sriram, you are right to have those problems with variables and FreeMaster. If you need to see the variables in FreeMaster then the storage class must be "volatile", but due to some broken links that you had before, you can't find the volatile storage class. I found a solution to restore all available storage classes. 

You must enter in "C code perspective", then click on the "C CODE" tab, click on the "Code Interface" button, then choose "Embedded Coder Dictionary", then in the "Memory" tab click on "Storage Class", then click on "Manage Packages" button and in the small window click on the "Refresh" button or on "Unload" then "Load" button for "Simulink" in the drop-down list.  

adriantudor_0-1659007721743.png

adriantudor_1-1659007741430.png

Then you have to choose "Volatile" in "Storage Class" for all variables you need to watch in FreeMaster.

 

Best regards,

Adrian

 

1,448 Views
Sriram
Contributor IV

Thanks i will try it. i was able to access those variables in freemaster under "modelnameDworkvariables" when the variables were declared as model default.

 

0 Kudos