Electronics > Microcontrollers
Uni-polar stepper motor shaft rotation inconsistent
newtekuser:
I'm using a cheap 5v uni-polar stepper motor and having issues getting consistent shaft rotations each time I call the function to perform a rotation. Say I rotate by 500 steps in either direction, each time it rotates less than the previous time as if it is missing steps.
I experimented with slow and faster speeds by adjusting the delay each coil is energized to no avail.
There's no load on the motor either and current draw is about 250ma during rotation.
Am I doing something wrong in code, or is this motor just too weak to even sustain its own shaft rotations w/o load?
This is the stepper in use: https://www.digikey.com/en/products/detail/mikroelektronika/MIKROE-1530/5724295
I'm driving it using a ULN2803AFWG and PIC16F887.
--- Code: ---void stepper_rotate_full_drive(char direction, int steps){
for(int i=0;i<steps;i++)
{
if (direction == CW){
PORTA = 0b00000011;
__delay_ms(2);
PORTA = 0b00000110;
__delay_ms(2);
PORTA = 0b00001100;
__delay_ms(2);
PORTA = 0b00001001;
__delay_ms(2);
PORTA = 0b00000011;
__delay_ms(2);
}
if (direction == CCW){
PORTA = 0b00001001;
__delay_ms(2);
PORTA = 0b00001100;
__delay_ms(2);
PORTA = 0b00000110;
__delay_ms(2);
PORTA = 0b00000011;
__delay_ms(2);
PORTA = 0b00001001;
__delay_ms(2);
}
}
PORTAbits.RA0 = 0;
PORTAbits.RA1 = 0;
PORTAbits.RA2 = 0;
PORTAbits.RA3 = 0;
}
--- End code ---
Nominal Animal:
The stepper is the extremely common 28BYJ-48 with a gearbox that results in 4096 steps per turn.
The most likely reason for the behaviour is incorrect wiring.
The red wire is the center tap for both coils. Leave it unconnected. Connect it to 5V. (It is possible to cut a trace on the small board on behind the blue plastic to make the stepper true bipolar one, but it isn't necessary with ULN2803 or ULN2003 Darlington arrays.)
One motor coil is connected between pink and orange, and the other between blue and yellow.
The important bit is that the motor coil wires are interleaved, i.e. blue and yellow are not controlled by consecutive pins on your MCU, nor pink and orange.
pink-yellow-orange-blue and yellow-orange-pink-blue and so on should all work, with the only difference being the direction of rotation.
If your wiring puts blue and yellow and/or pink and orange in consecutive bits in port A, it would explain the weak and inconsistent rotation.
The gearbox itself does have backlash, typically on the order of 20 steps or so. That is, when you rotate the shaft in one direction, it takes about 20 steps or so (but depends a lot on the gearbox and gears, thus does vary between steppers even from the same manufacturer somewhat) in the opposite direction before the shaft starts rotating in the opposite direction. If you gently move the shaft by your fingers, you can feel this 'slop'. It is only a degree or two, but with 4096 steps per rotation, it does end up being quite a few steps.
However, if you keep rotating the shaft a constant number of steps in opposite directions, with say a piece of tape stuck to the shaft, it should not drift: just 'bounce' between two fixed directions.
H.O:
--- Quote ---The red wire is the center tap for both coils. Leave it unconnected.
--- End quote ---
Hmm....am I missing something? How will leaving the center tap disconnected work when driven in unipolar fashion?
The darlington array sinks current, surely you need a way for the current to enter the winding(s) and that'll be thru the center tap(s) of the windings.
(And driving that motor in bipolar mode will not work without first breaking the connection between the two center taps, right?)
In the code there are 5 steps in sequence where the first and the last step contains the same bit pattern. This causes the timing between steps to be erratic, perhaps that's all it is.
Nominal Animal:
--- Quote from: H.O on September 25, 2023, 12:40:35 pm ---How will leaving the center tap disconnected work when driven in unipolar fashion?
--- End quote ---
It won't. (I modify mine to work in bipolar configuration and either actual bipolar stepper drivers like DRV8834, or quad half bridges like L293D.)
Thanks for pointing out the goof; I fixed the post.
--- Quote from: H.O on September 25, 2023, 12:40:35 pm ---(And driving that motor in bipolar mode will not work without first breaking the connection between the two center taps, right?)
--- End quote ---
Correct. The actual winding has six taps, two of which are connected together (and to the red wire) on the small single-sided PCB behind the blue plastic. You only need to cut one trace to convert from unipolar to bipolar; I recommend using a Dremel with a cutting wheel. That way, one can simply ignore the red wire. (It will still be connected to the middle of one of the windings, but as long as it is not connected to anything, it won't do anything. At worst, it might act a bit like an antenna, but the stepper frequencies are so low it should not be an issue.)
Siwastaja:
Also note the sequence (assuming OP wants full step sequence) is one element too long, 0b00000011 repeats twice per cycle, hence the sudden deceleration mid-cycle, it's a sure way to make the stepper miss steps (as is the lack of acceleration/deceleration ramps). However, if you have tested this with very slow speeds / long delays, then the culprit is elsewhere.
It's a good idea nevertheless to slow down stepping even more, like 1 step per second, mount something visible on the axle (like a piece of tape) and carefully look if the motor is taking uniform steps in uniform direction each time. If not, then the sequence is simply wrong.
Navigation
[0] Message Index
[#] Next page
Go to full version