Clear Filters
Clear Filters

App Designer - timer with random interruption

5 views (last 30 days)
Chris
Chris on 20 Jan 2021
Edited: Chris on 5 Feb 2021
Hello, maybe somebody know what is not working correct.
I implanted a timer (replaced a loop) for measurements my motor data. But sometimes if I increase/decrease with a spinner my velocity of the motor, the timer finished before I push the stop bottom. It happen always randomly. I guess something is affecting each other but I don’t know what. Maybe anyone has an idea?
Thanks a lot :)
methods (Access = private)
function MemoryTimerFcn(app,~,~)
% read my data (now I just put two inside=
app.actualVelocity.Value = webread()
app.actualMotorCurrent.Value = webread()
end
% .....a lot of other functions
end
function startupFcn(app)
app.MemoryTimer = timer(...
'ExecutionMode', 'fixedRate', ...
'Period',0.2, ...
'BusyMode', 'drop',...
'TimerFcn', @app.MemoryTimerFcn);
end
function MotorON(app, event)
start(app.MemoryTimer);
end
function MotorOFF(app, event)
stop(app.MemoryTimer);
end
  2 Comments
Geoff Hayes
Geoff Hayes on 26 Jan 2021
Chris - can you show where you call MotorON and MotorOff? Is the second function only called when you want to stop the motor (how do you know when to call this?) and is this function the only way to stop the timer? Also, how do you know that the timer has stopped prematurely - is there some sort of indication in the console (or whatever) output?
Chris
Chris on 5 Feb 2021
Edited: Chris on 5 Feb 2021
Hello Geoff, thanks for helping me, sorry for my late answer.
I called the MotorON, MotorOFF with two Buttons. Yes for e.g. my measurements stop sometime if change my velocity value with a spinner.
I change already a lot of things, but I still have my problems with Timers. I guess they affect each other so they jumped out and worked in another process and than continuous.
Now I have already 4 timers:
  • measurements (is working almost the whole time)
  • live plotting data (Start/Stop - Button)
  • heartbeat (all the time) to check the communication with my motor control is existing
  • profile drive, read data from excel (velocity over time) and send them to my motor controller
The code is just an extract:
methods (Access = private)
function MemoryTimerFcn(app,~,~)
app.actualVelocity.Value = webread()
app.actualMotorCurrent.Value = webread()
end
function MemoryTimerFcn2(app,~,~)
%plotting my acutual data, Start/Stop Buttons
end
% send new velocity data (table) after time delay is over
function MemoryTimerFcn3
app.timerDelaySecs = app.X;
app.MemoryTimer3 = timer(...
'StartDelay',app.timerDelaySecs,...
'ExecutionMode', 'singleShot', ...
'BusyMode', 'queue',...
'TimerFcn', @app.MemoryTimerFcn3);
if (app.count <= size(app.data,1))
start(app.MemoryTimer3);
else
MotorOFFButtonPushed(app)
end
end
end
---------------------------------------------------------------------------
function startupFcn(app)
% measurements
app.MemoryTimer = timer(...
'ExecutionMode', 'fixedRate', ...
'Period',0.2, ...
'BusyMode', 'queue',...
'TimerFcn', @app.MemoryTimerFcn);
% live plotting data
app.MemoryTimer2 = timer(...
'ExecutionMode', 'fixedRate', ...
'Period',0.2, ...
'BusyMode', 'queue',...
'TimerFcn', @app.MemoryTimerFcn2);
% heartbeat, started here
app.MemoryTimer4 = timer(...
'ExecutionMode', 'fixedRate', ...
'Period',3, ...
'BusyMode', 'queue',...
'TimerFcn', @app.MemoryTimerFcn4);
start(app.MemoryTimer4);
end
Thanks for helping :)

Sign in to comment.

Answers (0)

Categories

Find more on Tables in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!