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.

Quick summaryBreathing LED and a servo sweeping 0 to 180 degrees.

How to think about this

PWMpwm 25%pwm 75%
PWM

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.

LevelTimeWorks in simulation only?
Beginner3 hoursNo: 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.

ItemWhat it is (in simple words)Why you need itApprox. 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 resistorsAn 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 wiresA 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
MultimeterMeasures 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

SignalDirectionGoes toNote
led_pwmoutputLED with resistor
servo_pwmoutputservo signal (orange wire)3.3 V logic is accepted by SG90
servo VCC / GND-5 V and GNDred and brown wires

Step 1: simulate the design

Breathing PWM and servo pulse (scaled)Verilog: edit and run

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

  1. Simulate the fader and watch the duty value.
  2. Choose PWM frequency above 200 Hz (no flicker).
  3. Servo: 50 Hz period, width = 1 ms + position x 1 ms.
  4. Connect servo power separately; share GND.
  5. Move the servo with two buttons (left/right) in small steps.

If it does not work

SymptomLikely causeFix
Board not detected by the PCCharge-only USB cable or missing driverTry another data cable; install the vendor/FTDI driver; check dmesg or Device Manager
Nothing happens after programmingWrong clock pin or wrong pin constraintsCompare every pin with the board schematic; first test with a blinking LED
Servo jittersWeak power supplyUse 5 V from USB, add 100 uF capacitor across servo power
LED flickersPWM too slowUse at least 1 kHz
Tip:Keep your first board test tiny: if the LED blinks, the toolchain, cable and clock are fine. Then add your project piece by piece.

Quick quiz

1. Servo pulse for the centre position?