how to control stepper motor speed via USB port
6 views (last 30 days)
i really need some help over here..i have connected and run my stepper motor but how come i cannot control the speed of my motor?..can someone give me some hints?
below are my coding:
function text_speed_m1_Callback(hObject, eventdata, handles)
sliderValue = get(handles.text_speed_m1,'String');
%convert from string to number if possible, otherwise returns empty
sliderValue = str2nm(sliderValue);
%if user inputs something is not a number, or if the input is less than 0
%or greater than 100, then the slider value defaults to 0
if (isempty(sliderValue) || sliderValue < 0 || sliderValue > 256)
% --- Executes during object creation, after setting all properties.
function text_speed_m1_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
% --- Executes on slider movement.
function slider_speed_m1_Callback(hObject, eventdata, handles)
sliderValue = get(handles.slider_speed_m1,'Value');
%puts the slider value into the edit text component
% Update handles structure
% --- Executes on button press in pushbutton_speed_m1.
function pushbutton_speed_m1_Callback(hObject, eventdata, handles)
obj1 = instrfind('Type','serial','Port','COM8','Tag','');
obj1 = serial('COM8');
obj1 = obj1(1)
sv2 = get(handles.text_speed_m1,'String');
please give me some hints on what i do wrong..really need help now..thanks
Walter Roberson on 27 Mar 2011
We can't tell why you cannot control the speed of the motor. You have not described what happens when you try.
Closing and reopening the serial port each time is not advisable. If you find a serial port and it is open, then you should use it.
In your code, if obj1 is empty after the instrfind, then when you associate the serial port with obj1, you have omitted setting anything like port speed. The default probably is not what you want; even if it happens to be, other people reading your code are going to be left wondering and the defaults might change in other versions, so it is better to set port characteristics explicitly.
More Answers (17)
keycamel villegas on 16 Apr 2011
hi fremond khoo..did you used a motor driver for your stepper motor?and may i know what are the connections?thank you!!.. im a newbie in matlab..and my thesis project involves the movement of a bipolar stepper motor. :)
my project involves a bipolar stepper motor and im using L298 motor driver..would it be possible that your code above can be used in our project?
our professor said that our connection would be:
RS232 to serial to parallel converter(using 4 bit shift register) to l298 motor driver connected to bipolar stepper motor,,
would that be possible?or can you suggest other connection for our bipolar stepper motor because i have difficulty analyzing the connections of this components,,
by the way THANK YOU for your reply :)