Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
169 views
in Technique[技术] by (71.8m points)

How to convert a data acquisition Matlab script to Simulink?

The Matlab script which I wrote is going to be used as a feedback for my control system. I have downloaded a library done called "Custom Arduino Library for HX711" by Nicholas Giacoboni.

I want to convert a Matlab script which I wrote Matlab script. I have also tested the script by itself and it works.
HX711 is a load cell amplifier ADC converter.

function data = Loadcell()
eml.extrinsic('arduino','addon','read_HX711')

a = arduino('COM5','Mega2560','libraries','ExampleAddon/HX711');
scale = -338000;
while 1
    LoadCell = addon(a, 'ExampleAddon/HX711',{'D6','D5'});
    data = (read_HX711(LoadCell)-7388092)/scale
    
end
end

the layout of simulink at the moment Simulink function block.

And I run Simulink on Normal mode and simulation stop time at inf it comes up with this error. How do I solve this error and get this working?

Regards,

Allan

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

At a minimum you need to define the size of data at the top of the file. The parser has no idea of what read_HX711 returns and hence cannot allocate memory for data. You probably need to do the same for a and LoadCell.

That is, you need something like,

data = zeros(1,1);
a = zeros(1,1);
LoadCell = zeros(1,1);

at the top of the file.

If that doesn't work, then I would suggest that you put all of your above code into a function in a separate m-file, where that function returns just your data variable. Then in your MATLAB Function block code just have one call to your new function (which will still need to be defined as extrinsic).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...