Home / Learn Verilog / Project 7: PWM LED Fader and Servo Controller
Project 7: PWM LED Fader and Servo Controller
Breathing LED and a servo sweeping 0 to 180 degrees.
How to think about this
In plain terms
Use PWM to fade an LED smoothly (a breathing effect) and to position a hobby servo with a button or a potentiometer value.
Why we use it
Projects turn knowledge into skill: you design, simulate, debug and finally see real hardware react.
Under the hood
Simulate in the browser, then build for your board following the steps.
Real-world use
- Portfolio
- Interviews
- Learning by doing
What you will build
Use PWM to fade an LED smoothly (a breathing effect) and to position a hobby servo with a button or a potentiometer value.
| Level | Time | Works in simulation only? |
|---|---|---|
| Beginner | 3 hours | No: simulate first, then run on the board |
What you need (equipment and tools)
Read this table once and you will know exactly what to buy or prepare. You can do the simulation part with only a computer and the free tools.
| Item | What it is (in simple words) | Why you need it | Approx. cost |
|---|---|---|---|
| Computer (Windows, Linux or macOS) | Your normal laptop or desktop. You write Verilog here and run the free tools. | Simulator, synthesis and programmer all run on it. | you have it |
| Free software: Icarus Verilog + GTKWave (simulation), Yosys + nextpnr or the vendor IDE (build), openFPGALoader (program) | The programs that compile and simulate your design. | Everything in this course can be simulated with only these free tools. | free |
| FPGA development board (e.g. Tang Nano 9K, Basys 3, iCEBreaker, Arty A7) | A small circuit board with an FPGA chip, an oscillator (clock), LEDs, buttons and a USB port. The FPGA is the "blank hardware" that your Verilog turns into a real circuit. | This is where your design actually runs. Without it you can only simulate. | about $15 (Tang Nano 9K) to $150 (Arty A7) |
| LEDs (5 mm) + 330 ohm resistors | An LED lights when current flows through it. The resistor limits that current so the LED and the FPGA pin do not burn. | Visible output. Many boards already have LEDs built in; external ones are for bigger demos. | $2 for a pack |
| Hobby servo (SG90) | A small motor that moves to an angle set by a pulse width (1 ms to 2 ms every 20 ms). | Real mechanical output for the PWM project. | $3 |
| Breadboard + jumper wires | A plastic board with holes connected in rows; wires plug in without soldering. | Connect the FPGA pins to buttons, LEDs and modules quickly and safely. | $5 |
| Push buttons (tactile switches) | A small switch that connects two pins while pressed. | Your input to the design. They bounce, so the design needs a debouncer. | $1 |
| Multimeter | Measures voltage, resistance and continuity. | Check that a pin is 3.3 V, that wires connect, and that power is correct. | $10 |
| External 5 V supply or USB 5 V pin (for the servo) | Servos draw more current than a pin can give. | Power the servo from 5 V, not from a pin. Connect its GND to the board GND. | USB power is usually enough for one SG90 |
Connections
| Signal | Direction | Goes to | Note |
|---|---|---|---|
| led_pwm | output | LED with resistor | |
| servo_pwm | output | servo signal (orange wire) | 3.3 V logic is accepted by SG90 |
| servo VCC / GND | - | 5 V and GND | red and brown wires |
Step 1: simulate the design
Brightness (duty cycle) rises, then falls: a breathing effect. For a servo use a 20 ms period and a 1-2 ms pulse.
Step by step
- Simulate the fader and watch the duty value.
- Choose PWM frequency above 200 Hz (no flicker).
- Servo: 50 Hz period, width = 1 ms + position x 1 ms.
- Connect servo power separately; share GND.
- Move the servo with two buttons (left/right) in small steps.
If it does not work
| Symptom | Likely cause | Fix |
|---|---|---|
| Board not detected by the PC | Charge-only USB cable or missing driver | Try another data cable; install the vendor/FTDI driver; check dmesg or Device Manager |
| Nothing happens after programming | Wrong clock pin or wrong pin constraints | Compare every pin with the board schematic; first test with a blinking LED |
| Servo jitters | Weak power supply | Use 5 V from USB, add 100 uF capacitor across servo power |
| LED flickers | PWM too slow | Use at least 1 kHz |
Quick quiz
1. Servo pulse for the centre position?
Standard servo.