getbetterat.work
DOC_ID: VHDL_02_EXPANDED

What is VHDL?

Most code tells a computer what to do. VHDL tells a computer what to be. It is a language used to build actual, physical computer chips using code.

Normal Code (Python, C)

Reads line by line. Step one finishes, then step two starts. It takes time to move down the list.

1. Read button
2. Wait a second
3. Turn on light

VHDL (Hardware)

Everything happens exactly at the same time. Wires don't wait in line. They work instantly.

Light 1 connects to Button 1
Light 2 connects to Button 2
[BOTH HAPPEN AT ONCE]

The Virtual Playground

Building a real, physical computer chip in a factory costs millions of dollars. If you make one mistake, the chip goes in the trash.

VHDL lets engineers simulate the chip. This means we build a fake, virtual version of the chip on our screen.

We can press fake buttons and watch fake lights turn on. If there is a mistake, we just change the code. It costs zero dollars to fix a mistake on a screen.

Test Before
You Build

Where does VHDL code go?

Target 1: FPGA

FPGA stands for Field Programmable Gate Array.

Think of it as a shape-shifting chip. You plug it into your computer, send your VHDL code to it, and the inside of the chip physically changes to match your code.

If you don't like it, you can erase it and turn it into a completely different chip tomorrow.

Target 2: ASIC

ASIC stands for Application-Specific Integrated Circuit.

This is a permanent chip. Once you test your VHDL code and know it is perfect, you send it to a giant factory.

They print your chip into solid silicon. It can never be changed. It is very fast, very cheap to make millions of them, but you cannot fix a bug later.

The Two Parts of Every VHDL File

1. The Entity (The Box)

The Entity is the outside of the box. It only lists the pins. What goes in? What goes out? It does not know how the math works inside. It only knows the inputs and outputs.

2. The Architecture (The Brains)

The Architecture lives inside the box. This is where you write the rules. If button A and button B are pushed, turn on light C. This is the brain.

Signals: The Invisible Wires

In normal coding, you have "variables" to store data. In VHDL, we use Signals.

A signal is literally a wire. When you write a rule that says Signal_X <= Signal_Y, you are asking the computer to solder a wire from pin Y to pin X.

Vectors: The Data Highway

Sometimes you need to send a large number, like 255. A single wire can only send a 0 or a 1. To send bigger numbers, we tie wires together into bundles.

In VHDL, a bundle of wires is called a Vector.

-- This makes 8 wires tied together (from wire 7 down to wire 0)
DataBus : in std_logic_vector(7 downto 0);

Example: A Simple Light Switch

-- 1. The Box (Inputs and Outputs)

entity LightSwitch is

port (

Switch1 : in bit;

Switch2 : in bit;

LightBulb : out bit

);

end LightSwitch;


-- 2. The Brains (The Rules)

architecture Rules of LightSwitch is

begin

-- The light only turns on if BOTH switches are ON

LightBulb <= Switch1 and Switch2;

end Rules;

Libraries

You don't have to teach the computer how to add numbers or count. Smart engineers already did that. At the top of your file, you "check out" a library to use their tools.

-- Always put this at the top of your file:

library IEEE;

use IEEE.std_logic_1164.all;

use IEEE.numeric_std.all;

The Clock: The Heartbeat

Chips are incredibly fast. If you don't control them, data crashes into other data like cars at an intersection with no traffic lights. To fix this, we use a Clock Signal. It is a master wire that pulses ON and OFF millions of times a second. Rule: The chip is only allowed to take a step and do math when the clock ticks. This keeps the whole city moving in perfect rhythm.

The Vault (Flip-Flops)

Wires do not have memories. When you let go of a button, the wire instantly forgets it was ever pressed.

To remember things, we build a Flip-Flop. It is a tiny vault. When the clock ticks, the vault opens, grabs the data on the wire, and locks it inside. It holds that data safely until the next clock tick.

The Two Types of Hardware Logic

1. Combinational

No clock. No memory. It happens instantly.

Example: If you press "A" and "B", the "C" light turns on right now. If you let go, it turns off right now.

2. Sequential

Uses the clock. Has memory. It waits in line.

Example: Pressing a button changes a saved score, but the score only updates on the screen when the next clock tick happens.

The "Process" Sandbox

We learned earlier that in VHDL, all code happens at the exact same time. But sometimes, humans need code to run in order (Step 1, then Step 2). We can do this using a Process.

A process is a special sandbox. Outside the sandbox, everything happens instantly. Inside the sandbox, the code is read from top to bottom, just like Python or C.

-- The sandbox only wakes up when the Clock ticks
process(Clock)
begin
  if rising_edge(Clock) then
    -- We can write normal step-by-step logic here!
    Counter <= Counter + 1;
  end if;
end process;

State Machines

How does a traffic light know what to do next? It uses a "State Machine." It remembers what state it is currently in, and looks at rules to decide where to go next.

STATE: GREEN
STATE: YELLOW
STATE: RED

The Testbench

To test our chip, we don't buy physical buttons. We write a second VHDL file called a Testbench. It acts as a fake world around our chip. It generates fake button presses and fake clock ticks to see if our chip survives the test.

Generates a fake Clock tick
Fakes a button press for 10ms
Watches the light bulb output

The Worst Mistake: The "Latch"

If you write an `If` rule but forget to write the `Else` rule, the computer panics. It doesn't know what to do.

To save itself, it secretly builds a vault (memory) to hold the old value. This is called a "Latch" and it will usually destroy your chip's timing and break your project. Always write an `Else`!

How a Chip is Made (The Flow)

1

Write the Code

Type your VHDL into a text file. Define your boxes and your rules.

2

Simulate

Run the virtual playground. Send fake inputs to make sure the math is correct.

3

Synthesis

A computer program translates your VHDL words into an actual map of tiny gates and wires.

4

Implementation

The map is locked into an FPGA shape-shifter chip, or sent to a factory for a permanent ASIC.

Inside Synthesis (The City Map)

Grid Blueprint Map

When you hit "compile," it doesn't make a software app. It enters Synthesis.

The compiler looks at your code and physically connects tiny hardware blocks together. It routes wires across the silicon chip like drawing streets on a city map.

If your code is too big or too slow, the "streets" get too long, and data won't arrive before the clock ticks. This is called a timing failure.

Why do we still use it?

VHDL is old, but it is deeply trusted. When a machine cannot afford to crash, engineers use VHDL. You will find VHDL hardware in:

Spacecraft

Satellites run on pure hardware because space radiation crashes normal software.

Medical Gear

A hospital life-support machine cannot afford to "freeze" or wait to load.

Military Radar

It processes millions of radio waves per second instantly, with zero delay.

Ready to build your first chip?

The physical world is waiting for your code.