TimerFcn to start and stop automatic update of static text field - "Not enough input arguments"

1 view (last 30 days)
Milos Krsmanovic
Milos Krsmanovic on 18 Oct 2019
Edited: Milos Krsmanovic on 18 Oct 2019
I have two buttons (ON and OFF) and two static text fileds created in GUIDE. I'm using buttons to start and stop a DC motor. I'm reading encoder signals from the encoder and I want to write/display those readings continuously by updating to two static text fields.
After tryign so many different things, I'm trying a timer function now. The error I'm getting is Error while evaluating TimerFcn for timer 'timer-1' Not enough input arguments.
Please can someone let me know where I'm making the mistake?
This is the function I call with TimerFcn:
function updateEncoderReadings(hObject, eventdata, handles)
global encoder;
[count,time]=readCount(encoder);
rpm=readSpeed(encoder);
set(handles.encoderCountValue,'String',num2str(count)); % change static text to show encoder count
set(handles.encoderRPMValue,'String',num2str(rpm)); % change static text to show encoder RPM
encoderCountValue and encoderRPMValue are set in GUIDE as two text fields' tags.
I'm declaring and initializing my timer once the ON button has been pressed:
function startButton_Callback(hObject, eventdata, handles)
% hObject handle to startButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% (...some other code...)
global encoder;
resetCount(encoder);
global t;
writeDigitalPin(a,'D11',1); % set PWMA pin voltage to HIGH to start the motor
t = timer('ExecutionMode','fixedRate','TasksToExecute',inf,'TimerFcn',@updateEncoderReadings);
start(t);
set(handles.motorRunStatusText,'String','Motor is running'); % change static text to show motor run status
And the stop function, for when the OFF button is pressed:
function stopButton_Callback(hObject, eventdata, handles)
% hObject handle to stopButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% (...some other code...)
global encoder;
resetCount(encoder);
global t;
stop(t); % stop the timer function, i.e. update of the text fields
writeDigitalPin(a,'D11',0); % set PWMA pin voltage to LOW to stop the motor
set(handles.motorRunStatusText,'String','Motor is not running'); % change static text to show motor run status
So I'm not quite sure which other arguments I should pass between the functions, and why the text fields are not being updated.
Also, I know the use of global variables is frowned upon but I don't know how else to do this. Any tips would also be appreciated.
Thanks.

Answers (0)

Community Treasure Hunt

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

Start Hunting!