fpga:vhdl
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| fpga:vhdl [2022/01/06 11:07] – [Conversions] utedass | fpga:vhdl [2025/06/13 12:33] (current) – utedass | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== VHDL ====== | ====== VHDL ====== | ||
| + | [[https:// | ||
| - | [[https:// | + | ===== Things is should write down ===== |
| - | [[https://tomverbeure.github.io/2020/11/04/ | + | * Math-functions for determining bit width (IEEE.math_real.all) |
| - | + | * Generic notation | |
| - | + | * natural and conversion to integer and real | |
| - | + | * Defining functions | |
| - | ====== Basics ====== | + | * Entity instantiation |
| - | ===== Time suffixes ===== | + | * State machines using type |
| - | | fs | femtoseconds | | + | * Some simulation specific stuff like after 3ps, assert and until rising_edge(clk) |
| - | | ps | picoseconds | + | * High impedance value of std_logic (' |
| - | | ns | nanoseconds | + | * Naming conventions once I have settled for one |
| - | | us | microseconds | | + | |
| - | | ms | milliseconds | | + | |
| - | | sec | seconds | + | |
| - | | min | minutes | + | |
| - | | hr | hours | | + | |
| ===== Conversions ===== | ===== Conversions ===== | ||
| Line 27: | Line 25: | ||
| -- numbers, math operations allowed | -- numbers, math operations allowed | ||
| signal my_int : integer; -- 32 bit 2-complement | signal my_int : integer; -- 32 bit 2-complement | ||
| + | signal my_int_ranged : integer -1 to 23; -- Limited range. Simulator might enforce, synthesiser might not | ||
| signal my_uint : unsigned (7 downto 0); | signal my_uint : unsigned (7 downto 0); | ||
| - | signal my_sint : signed (7 downto 0); | + | signal my_sint : signed (7 downto 0) := x" |
| -- loose bits, math operations not allowed | -- loose bits, math operations not allowed | ||
| + | signal my_bit : std_logid; | ||
| signal my_bits : std_logic_vector (7 downto 0); | signal my_bits : std_logic_vector (7 downto 0); | ||
| + | |||
| + | -- Integer assignements | ||
| + | my_int <= 1337; -- Decimal | ||
| + | my_int <= 16#beef#; -- Hex (base 16) | ||
| + | my_int <= 2#101010; -- Binary (base 2) | ||
| + | |||
| + | -- std_logic assignement | ||
| + | my_bit <= ' | ||
| + | |||
| + | -- Assignments to std_logic_vector (also works on signed and unsigned) | ||
| + | -- All assignments must match in width | ||
| + | my_bits <= (others => ' | ||
| + | my_bits(3 downto 0) <= (others => ' | ||
| + | my_bits <= " | ||
| + | my_bits <= x" | ||
| + | my_bits <= ' | ||
| -- conversions between integers | -- conversions between integers | ||
| Line 40: | Line 56: | ||
| my_int <= to_integer(my_sint); | my_int <= to_integer(my_sint); | ||
| - | -- casts between binary representations, | + | -- casts between binary representations, |
| my_uint <= unsigned(my_sint); | my_uint <= unsigned(my_sint); | ||
| my_uint <= unsigned(my_bits); | my_uint <= unsigned(my_bits); | ||
| Line 49: | Line 65: | ||
| my_bits <= std_logic_vector(my_uint); | my_bits <= std_logic_vector(my_uint); | ||
| my_bits <= std_logic_vector(my_sint); | my_bits <= std_logic_vector(my_sint); | ||
| + | |||
| + | -- From ASCII code value | ||
| + | my_ascii_code <= std_logic_vector(to_unsigned(character' | ||
| + | |||
| + | -- From number immediate values to std_logic_vector | ||
| + | my_immediate_hex <= std_logic_vector(to_unsigned(16# | ||
| + | my_immediate_dec <= std_logic_vector(to_unsigned(10# | ||
| </ | </ | ||
| + | |||
| + | <code vhdl> | ||
| + | -- Char to unsigned | ||
| + | tx_char <= to_unsigned(character' | ||
| + | </ | ||
| + | |||
| + | ===== Textio ===== | ||
| + | Can be used in simulation. | ||
| + | |||
| + | <code vhdl> | ||
| + | use std.textion.all; | ||
| + | |||
| + | -- Further down... | ||
| + | process is | ||
| + | variable l : line; | ||
| + | begin | ||
| + | write (l, String' | ||
| + | writeline (output, l); | ||
| + | wait; | ||
| + | end process; | ||
| + | </ | ||
| + | |||
| + | ===== Other things ===== | ||
| + | |||
| + | <code vhdl> | ||
| + | report "this is a message"; | ||
| + | -- or: | ||
| + | report "this is a serious message" | ||
| + | </ | ||
fpga/vhdl.1641467265.txt.gz · Last modified: 2022/09/12 00:30 (external edit)
