User Tools

Site Tools


fpga:vhdl

This is an old revision of the document!


VHDL

opencores – Mostly verilog? Might find something useful

Things is should write down

  • Math-functions for determining bit width (IEEE.math_real.all)
  • Generic notation
  • natural and conversion to integer and real
  • Defining functions
  • Entity instantiation Stack overflow
  • State machines using type
  • Some simulation specific stuff like after 3ps and assert
  • High impedance value of std_logic ('Z')
  • Naming conventions once I have settled for one

Conversions

library ieee;
use ieee.std_logic_1164.all; -- std_logic_vector
use ieee.numeric_std.all; -- signed and unsigned
 
-- numbers, math operations allowed
signal my_int : integer; -- 32 bit 2-complement
signal my_uint : unsigned (7 downto 0);
signal my_sint : signed (7 downto 0);
 
-- loose bits, math operations not allowed
signal my_bits : std_logic_vector (7 downto 0);
 
-- conversions between integers
my_uint <= to_unsigned(my_int, 8); -- Must specify bit length
my_sint <= to_signed(my_int, 8);
 
my_int <= to_integer(my_uint);
my_int <= to_integer(my_sint);
 
-- casts between binary representations, number of bits must match
my_uint <= unsigned(my_sint);
my_uint <= unsigned(my_bits);
 
my_sint <= signed(my_uint);
my_sint <= signed(my_bits);
 
my_bits <= std_logic_vector(my_uint);
my_bits <= std_logic_vector(my_sint);
 
-- From ASCII code value
my_ascii_code <= std_logic_vector(to_unsigned(character'pos('A'), my_ascii_code'length));
 
-- From number immediate values to std_logic_vector
my_immediate_hex <= std_logic_vector(to_unsigned(16#150#, my_immediate_hex'length));
my_immediate_dec <= std_logic_vector(to_unsigned(10#150#, my_immediate_dec'length));
 
-- std_logic constant assignement
my_bit <= '0';
 
-- std_logic_vector constant assignment
my_bits <= x"ab"; -- Using hex string
my_bits <= "10010110"; -- Using bit string
-- Char to unsigned
tx_char <= to_unsigned(character'pos('a'), 8);

Textio

Can be used in simulation.

use std.textion.all;
 
-- Further down...
  process is
    variable l : line;
  begin
    write (l, String'("Hello world!"));
    writeline (output, l);
    wait;
  end process;
fpga/vhdl.1748241980.txt.gz · Last modified: 2025/05/26 06:46 by utedass

Except where otherwise noted, content on this wiki is licensed under the following license: CC0 1.0 Universal
CC0 1.0 Universal Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki