Timer to sample real-time input.
4 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Arduino Hardware 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!