RTUEE / EC / EEEYr 2022 · Sem 52022

Q3Microprocessor

Question

15 marks

Q.3. With the help of schematic diagram, explain the interfacing of stepper motor with 8051 Microcontroller. Also write ALP to change the speed and direction of motor.

Answer

A stepper motor is interfaced with the 8051 through a ULN2003 driver IC that amplifies the microcontroller's port outputs to drive the motor's winding currents in a defined excitation sequence; direction is reversed by traversing the step-pattern table in reverse order, and speed is controlled by the delay inserted between successive steps.

A stepper motor advances in fixed angular increments each time its winding coils are energized in the next step of a specific excitation sequence; reversing this sequence reverses the direction of rotation, and varying the time delay between successive steps varies the rotational speed.

Interfacing Circuit

Because 8051 I/O pins cannot supply the several-hundred-milliamp current typically needed by stepper motor windings, a ULN2003 Darlington-transistor-array driver IC is connected between an 8051 output port (commonly 4 bits, e.g., P1.0-P1.3) and the stepper motor's coil terminals; the ULN2003 amplifies the low-current logic-level signals from the 8051 into the higher current needed to actually energize the motor windings, and includes internal flyback diodes protecting the circuit from the inductive voltage spikes generated as each winding is switched off.

8051 - ULN2003 - Stepper Motor8051 P1.0-P1.3ULN2003Stepper Motor

Assembly Language Program

asm
        MOV DPTR, #STEPTAB
        MOV R1, #00           ; table index (0-3)
CLOOP:  MOV A, R1
        MOVC A, @A+DPTR       ; fetch step-pattern byte
        MOV P1, A             ; energize windings per pattern
        ACALL DELAY           ; delay sets rotation speed
        INC R1                ; forward index = clockwise direction
        CJNE R1, #04, CLOOP   ; loop through all 4 steps
        MOV R1, #00
        SJMP CLOOP
STEPTAB: DB 01H, 02H, 04H, 08H  ; clockwise 4-step sequence
; Counter-clockwise: use DEC R1 instead of INC R1 (with wraparound
; handling), or store/traverse the reverse-order table 08H,04H,02H,01H.

Direction control: the program advances through the 4-entry step-pattern table in forward order (using INC R1) to rotate the motor in one direction (e.g., clockwise); to reverse the direction, the program instead traverses the same table in reverse order (using DEC R1 with appropriate wraparound handling from index 0 back to index 3), or equivalently uses a separately stored, reverse-ordered version of the step table — either approach reverses the sequence in which the motor's winding coils are energized, which directly reverses its physical direction of rotation.

Speed control: the rotational speed of the stepper motor is controlled entirely by the duration of the DELAY subroutine called between successive steps in the excitation sequence — since each step corresponds to a fixed, small angular rotation of the motor shaft, a shorter inter-step delay causes the motor to complete more steps per second (faster rotation, up to the motor's maximum reliable stepping rate, beyond which it risks losing synchronization and stalling), while a longer inter-step delay causes correspondingly slower rotation; this DELAY subroutine is typically implemented using a nested register-based counting loop (similar to the timing-delay subroutines discussed elsewhere in this paper), whose duration can be precisely calculated or empirically adjusted to achieve the specific desired stepping rate/motor speed for a given application.

Why a single-coil-at-a-time excitation sequence is used here: the four bit patterns 01H, 02H, 04H, 08H each energize exactly one of the four stator winding phases at a time, corresponding to the simplest ('wave drive' or 'single-phase') stepper excitation scheme; this gives the lowest possible power consumption per step (only one winding drawing current at any instant) at the cost of somewhat lower torque than alternative excitation schemes. An alternative, commonly used 'two-phase-on' full-step sequence instead energizes two adjacent windings simultaneously at each step (e.g., 03H, 06H, 0CH, 09H), producing higher holding and running torque (since two windings' magnetic fields combine) at roughly double the power consumption; and a further 'half-step' sequence alternates between single-winding and two-winding excitation patterns across eight steps per full electrical cycle (rather than four), halving the effective step angle and giving smoother, more precise rotation at the cost of a more complex, longer step-pattern table and generally reduced torque per step compared to full two-phase excitation. The choice among these excitation schemes for a given application depends on the required balance between torque, smoothness, resolution, and power consumption/heat dissipation.

Role of CJNE in the direction/index logic: the CJNE R1, #04, CLOOP instruction compares the current table index in R1 against the constant 4 (one past the last valid index 3), and branches back to CLOOP if they are not equal — since this comparison instruction does not itself modify R1, the loop correctly continues incrementing and using R1 as the table index for each of the four steps (0,1,2,3) before falling through (once R1 reaches 4) to the code that resets R1 back to 0 and restarts the cycle; this CJNE-based approach is functionally equivalent to using DJNZ with a downward-counting index, but is written here as an upward count to match the natural forward (ascending) order in which the STEPTAB entries are intended to be accessed for the chosen (clockwise) direction of rotation, illustrating that either counting direction can be used for the loop-control logic as long as it is kept consistent with the actual order in which the step-pattern table entries are meant to be traversed.

Practical hardware note on flyback protection: each stepper motor winding is inductive, so abruptly switching off the drive current to a winding (as happens at every step transition) induces a sudden, large reverse voltage spike across that winding (V=L·di/dt) that, if not safely absorbed, could exceed the voltage rating of the ULN2003's internal Darlington transistors and destroy them; this is precisely why the ULN2003 IC includes built-in flyback (freewheeling) diodes connected internally across each of its output Darlington pairs, providing a safe path for this inductive spike current to circulate and decay harmlessly rather than damaging the driver transistors, which is one of the key practical reasons the ULN2003 (or a similar Darlington-array driver with built-in flyback protection) is specifically chosen for this interfacing task rather than attempting to drive the stepper motor windings directly from simple, unprotected transistor switches.

Torque and stalling considerations at high step rates: as the inter-step delay is progressively reduced to increase rotational speed, the motor eventually reaches its maximum reliable stepping rate (the pull-out/slew rate), beyond which the winding current cannot rise fast enough (limited by the winding's own L/R electrical time constant) to develop adequate torque before the next step command arrives, causing the rotor to fall out of synchronism with the applied step sequence — a condition known as stalling, in which the motor either stops rotating entirely or rotates at an incorrect, uncontrolled speed unrelated to the commanded step rate. Well-designed stepper motor control programs therefore often incorporate acceleration/deceleration ramping (gradually reducing the inter-step delay over a series of initial steps when starting from rest, and gradually increasing it again before stopping) rather than commanding the final desired high step rate abruptly from a standstill, since a stepper motor can typically be accelerated to a higher step rate than it could reliably start directly from rest at that same rate, owing to the beneficial effect of the rotor's own mechanical inertia and momentum once already in motion.

Back to Paper