Tutorial — Practice 6: Stepper motor
Learn by programming: follow each step, write your own code, then validate with the lab questions and exam. Adapt pins and routines to your board when needed.
What you will build
Drive a stepper motor with full-step sequence, ULN2003 driver, and direction control.
-
1 RC0–RC3 outputs to ULN2003
Set PORTC bits 0–3 as outputs. Each line drives a stepper coil via ULN2003 (higher current than the PIC). RA0 as input to reverse direction.CLRF TRISC BSF TRISA, 0 CLRF LATC -
2 Full-step sequence table
Typical unipolar sequence: `0x01, 0x02, 0x04, 0x08` (one coil at a time). Store the table in flash with `DB` and read with TBLRD* or index in RAM. Apply the pattern to LATC.secuencia: DB 0x01, 0x02, 0x04, 0x08 aplicar_fase: ; fase = 0..3 -> LATC = secuencia[fase] RETURN -
3 Advance phase and control direction
Variable `fase` (0–3). Each step: increment or decrement per `sentido` (toggle with RA0). Link to `aplicar_fase` and a delay between steps—that delay sets RPM. -
4 Delay between steps with Timer
Avoid long busy-wait if you also use interrupts. Simple option: calibrated `retardo_paso` loop; better: Timer0 overflow every N ms. Tune speed until rotation is smooth without excessive vibration. -
5 Test CW/CCW rotation in Proteus
Verify sequence on LEDs or virtual motor. Press RA0: direction should reverse without losing steps. Document schematic and phase table in the report.
Before you code — pre-lab
Pre-laboratory — reference research
Pre-lab research for Practice 6 (Stepper motor, UNEXPO).
Q 1 What is a stepper motor and how does it rotate?
A stepper converts electrical pulses into discrete angular steps. Each step turns the shaft a fixed angle (e.g. 5.625°/step on small geared motors).
Coils are energized in sequence (full or half step). The PIC cannot drive coil current directly — a driver (ULN2003) sits between PIC and coils.
Q 2 Full step and half step sequences
Full step: one coil on at a time — 4 states per cycle, more torque, less resolution.
Half step: two coils at intermediate states — double steps per revolution, smoother motion.
Example unipolar sequence (coils A–D):
`1000 → 0100 → 0010 → 0001 → 1000`
Store the sequence in a table and advance an index each step.
Q 3 Role of the ULN2003
The ULN2003 is a Darlington array with protection diodes. It amplifies PIC outputs (~20 mA) to motor coil current (~hundreds of mA). ULN2003 inputs come from the PIC; outputs drive unipolar stepper coil commons.
Review the motor and ULN2003 driver datasheet from the schematic.
Design your solution
Design before coding
The lab sheet asks for pseudocode and a flowchart before the .ASM. Write yours first, then unlock the reference guide.
- 1. Pseudocode
- 2. Flowchart
- 3. Reference
Write your pseudocode
Include: sequence table, phase index, timer delay, direction/speed buttons and ULN2003 driver.
0 characters (minimum 80)
Describe your flowchart
On paper or here: list each symbol in order. Your report needs ovals, rectangles, diamonds and the main loop.
0 characters (minimum 60)
My pseudocode draft
My flowchart draft
Reference pseudocode
START
Config 4 outputs → ULN2003
Config Timer0 for step delay
phase ← 0, direction ← CW
table ← {1000, 0100, 0010, 0001}
REPEAT FOREVER
IF step_button THEN advance_phase()
IF dir_button THEN direction ← toggle
write table[phase] to motor port
wait timer_delay
END REPEAT Reference flowchart
Build and adapt the code
Practica · UNEXPO
Lab Practice 6
Control a stepper motor with coil energization sequences. May combine PWM or timed digital outputs.
Typical elements
Section titled “Typical elements”- Driver (ULN2003 or similar)
- 4 PIC outputs to coils
- Buttons for direction and speed
- Timer for step delay
Reference source code
Section titled “Reference source code”After building — post-lab
Post-laboratory — reference research
Post-lab analysis after controlling the motor in simulation or hardware.
Q 1 How do you control stepper motor speed?
Speed depends on time between steps. Use a Timer or software delay between sequence changes. Shorter delay → more steps per second → higher angular speed. Too short and the motor misses steps.
Q 2 How do you reverse rotation direction?
Reverse the order of the energization sequence: decrement the phase index instead of incrementing, or walk the table backwards. A button can toggle a `direction` variable.
Document the exact bit pattern sent to each coil.
Check what you learned
Exams by difficulty level
Open each level when you are ready. Basic is public; intermediate and UNEXPO levels require a CALETAS account to submit answers.
Basic Basic level — Motor and driver 3 questions
Stepper motor and ULN2003 basics.
0 of 0 answered
Sign in with CALETAS to sync this result across devices.
Sign in with CALETASIntermediate Intermediate level — Sequence and speed 3 questions
Phase table, timer and direction.
0 of 0 answered
Sign in with CALETAS to sync this result across devices.
Sign in with CALETASUNEXPO UNEXPO level — Lab oral 2 questions
Sequences, driver and button control.
0 of 0 answered
Sign in with CALETAS to sync this result across devices.
Sign in with CALETAS