Timer to sample real-time input.

4 views (last 30 days)
Amr
Amr on 30 Dec 2020
Hi,
I am using Simulink to make a model of some sort that is interfaced with an Arduino Uno. The part where I need help in involves a sensor reading that is being stored on startup for purpose of calculating the offset. So I have a MATLAB Function block that does so, the code inside is as follows:
function y = fcn(u)
u_calc = 0;
for i = 1:10
u_calc = u_calc + u;
pause('0.1');
end
u_calc = u_calc/10;
y = u-u_calc;
Now to have ensure that there is a different sample on each loop, typically using the Arduino IDE I will just use a delay() function that has value higher than the sensor sample time - let's say it is 0.1 sec. Now making the code in this manner resulted in a problem where the whole model paused, I attached a display to the input and it shows nothing until (0.1*10) sec has elapsed. Is the offeset calculated right? or is the approach I used to simulate a delay() or for sampleing is wrong?

Answers (0)

Categories

Find more on Arduino Hardware in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!