Home
Welcome
Information


FPGA projects - Basic
Music box
LED displays
Pong game
R/C servos
Text LCD module
Quadrature decoder
PWM and one-bit DAC
Debouncer
Crossing clock domains
The art of counting
External contributions

Interfaces
RS-232
JTAG
I2C
EPP
SPI
PCI
PCI Express
Ethernet
HDMI
SDRAM

Advanced
Digital oscilloscope
Graphic LCD panel
Direct Digital Synthesis
CNC steppers
Spoc CPU core

Hands-on
A simple oscilloscope


FPGA introduction
What are FPGAs?
How FPGAs work
Internal RAM
FPGA pins
Clocks and global lines
Download cables
Configuration
Learn more

FPGA software
Design software
Design-entry
Simulation
Pin assignment
Synthesis and P&R

FPGA electronic
SMD technology
Crystals and oscillators

HDL info
HDL tutorials
Verilog tips
VHDL tips

Quick-start guides
ISE
Quartus-II

Site
FPGA links
HDL tutorials
Forum


VHDL tips and tricks

This page is not really a tutorial, but a list of sample code that you can study and refer to when you start writing VHDL.

Thanks for Timothy Dahlin for his contribution.

Bit operations
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity bitops is
    Port( A :  in std_logic_vector(3 downto 0);
          B :  in std_logic_vector(3 downto 0);
          C : out std_logic_vector(3 downto 0);
          D : out std_logic_vector(3 downto 0);
          E : out std_logic_vector(3 downto 0);
          F : out std_logic_vector(3 downto 0);
          G : out std_logic_vector(3 downto 0);
          H : out std_logic_vector(3 downto 0);
          I : out std_logic_vector(3 downto 0);
          J : out std_logic_vector(3 downto 0);
          K : out std_logic_vector(3 downto 0)
        );
end bitops;

architecture Behavioral of bitops is
begin
    C <= A and B;
    D <= A xor B;
    E <= not A;
    F <= A or B;
    G <= A nor B;
    H <= A nand B;
    I <= A xnor B;
    J <= B(3) & A(1 downto 0) & '1';    -- concatentation
    K <= B(2 downto 1) & B(2 downto 1);    -- replication
end Behavioral;
2-to-1 mux
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity mux2t1 is
    Port ( A : in std_logic;
           B : in std_logic;
           S : in std_logic;
           Y : out std_logic);
end mux2t1;

architecture Behavioral1 of mux2t1 is
begin
    process(A, B, S)
    begin
    if(S = '1') then
        Y <= A;
    else
        Y <= B;
    end if;
    end process;
end Behavioral1;

architecture Behavioral2 of mux2t1 is
begin
    process(A, B, S)
    begin
    case S is
    when '1' =>
        Y <= A;
    when others=>
        Y <= B;
    end case;
    end process;
end Behavioral2;

architecture Behavioral3 of mux2t1 is
begin
    Y <= A when (S = '1') else B;
end Behavioral3;

architecture Behavioral4 of mux2t1 is
begin
with S select
    Y <= A when '1',
         B when others;
end Behavioral4;

Links






This page was last updated on December 26 2007.