Closed omkarg closed 3 years ago
Did you run the init_model first? Are you able to simulate the model by pressing play?
Yes, I ran the init_model and it ran successfully. attached screenshot for reference. But if I try to generate code from Simulink it gives that error
These paths are also set in Matlab (attached screenshot)
Hi @EmanuelFeru , Is there something else that needs to be set? Or I checked for few resources online to fix this issue by running the mex command but I am unable to find the .c file for it. If you could help me that would be really great
Are you able to run the model? And yes you need to install a c compiler to run and build the code. See here https://www.mathworks.com/support/requirements/supported-compilers.html I have the first one MinGW.
Also i used Matlab R2017b I am not sure if there are some incompatibility issue. Normally it should be upwards compatible.
Yes the C compiler is already installed and I am able to run the model from Matlab as seen in the above screenshots but if I run it in Simulink it gives me this error.
This is an indication that the s functions are not compatible with the 2019b. I will give a try myself next day, I think I still have the 2019b version installed.
@EmanuelFeru or you can upload the C file for the S functions and I can or anyone else who faces this issue can also generate the S functions.
Is it possible to generate s-functions from C files?
I was assuming this would solve the issue, hence mentioned about the C file https://in.mathworks.com/matlabcentral/answers/146644-error-in-s-funtion-s-function-test-does-not-exist. and they had mentioned it here as well https://stackoverflow.com/questions/8953759/s-function-in-simulink-matlab/33988085
@EmanuelFeru good afternoon. Is it working at your end on 2019b? or any idea on how I can generate the S functions with this version on matlab
Hi, I have the same problem (MATLAB version is: R2021a). Could you upload the .c source for s-functions? Thank you. A.
Hi,
I just opened the model in it's own folder location in Matlab R2019b and pressed Run. It worked without problem and produces same output as in 2017b.
Edit:
If I type mex -setup
I get this compiler:
@omkarg, I see you are using a Mac. I built the s functions on Windows, can that be the problem?
@EmanuelFeru that can be the issue. How are you generating the S functions on your machine? If you can provide the files for S function I can try to generate it on my mac machine and see if that works.
The compiler for mac is also different so may be it is because I am using mac machine it is not working
@asti-softronic are you using a mac machine?
To build i just Right click the block and then, go to Code generation and click make s-function. I forgot to tell you, but the open model is also there, it is the commented block _open, right above the used block _closed. Have you tried with the open one?
@EmanuelFeru Yes even I am using the same process to generate S functions but it does not work on mac machine. Yes i tried with open model , for closed model it is used to give 2 errors for open model it gives one error as per the screenshot. I have attached the open model config and the error screenshots. Can you extract the C code for the S function and provide, may be I can try it that way or if you have any other options I can try that
Inside the PWM_gates block there is also the open model. Try replacing the 6 pwm blocks with the open one. If you still have the error you can delete the 6 pwm blocks and connect line directly inside pwm_gates and try to run.
@EmanuelFeru Yes, it works in open mode. But I will have to get the closed mode working for it to work in FOC right?
No need for that. The closed part is the plant model not the controller. I closed the model just to have faster simulation time and in case someone does not have the Simulink motor model. But for the controller it doesn't matter if you use open or closed plant model.
@omkarg Did you manage to make it run in 2019b?
@EmanuelFeru Apologies for the late response. With the open model I was able to run it in 2019b version
Hi, I am getting the following error when trying to generate code from Simulink model, could you please help me with this? I am using Matlab_R2019b version
Generating code into build folder: /Users/mac15/Downloads/BLDC/Matlab/bldc-motor-control-FOC-master/01_Libraries/02_Plant/BLDCmotor_FOC_R2017b_fixdt_ert_rtw
Build procedure for model: 'BLDCmotor_FOC_R2017b_fixdt' aborted due to an error.
Error in S-function 'BLDCmotor_FOC_R2017b_fixdt/BLDC_model_closed/BLDC_model_sfcn': S-Function 'BLDC_model_sf' does not exist Component:Simulink | Category:Block diagram error Error in S-function 'BLDCmotor_FOC_R2017b_fixdt/PWM_gates/PWM_generator1/PWM_generator_sfcn': S-Function 'PWM_generator_sf' does not exist