Monthly Archives: January 2014

VHDL Constructions

Altera VHDL Examples
Die Hardwarebeschreibungssprache VHDL
OpenCores open source hardware IP-cores

RegEx Look-around assertions

Diese Konstrukte erweitern die regulären Ausdrücke um die Möglichkeit, kontextsensitive Bedingungen zu formulieren, ohne den Kontext selbst zu matchen.
Das heißt, möchte man alle Zeichenfolgen „Sport“ matchen, denen die Zeichenfolge „verein“ folgt, ohne dass jedoch die gematchte Zeichenfolge die Zeichenfolge „verein“ selbst enthält, wäre dies mit einer look-ahead assertion möglich: Sport(?=verein)

(?<=(\s|^))entity(?=(\s|$))

(?<=Ausdruck) = positive look-behind assertion
(?=Ausdruck)  = positive look-ahead assertion

Alt (nicht verwenden!):
([^a-z]*|^)entity([^a-z]*|\w|$)
([^a-z ]+|^)entity([^a-z ]+|\w|$)

VHDL

VHDL Design Units and Subprograms
VHDL Coding Style Guidelines

Package

package <PACKAGE_NAME> is
    [...]
end package <PACKAGE_NAME>;

package body <PACKAGE_NAME> is
    [...]
end package body <PACKAGE_NAME>;

“Use” and “Library” in VHDL
Libraries and Packages in VHDL
VHDL: Component vs Entity
VHDL Packages
WORK is not a VHDL Library

Function

function function_name (parameter_list) return type is  
begin
    [...]
end function_name;
function shift_rows (
    X : std_logic;
    Y : std_logic;
    Z : std_logic
) return std_logic is  
begin
    [...]
end shift_rows;

encrypt_block : process(reset_50_n,clock_50_i)
        variable temp_state;

Procedure

procedure <PROCEDURE_NAME> (    
    X : std_logic;
    Y : std_logic;
    Z : std_logic
) is
	declarations
begin
	sequential statements
end procedure_name;

type path_record_i is record
data : std_logic_vector((PATH_DATA_WIDTH_IN_BITS-1) downto 0);
clk : std_logic;
dv : std_logic;
err : std_logic;
end record;

Self-Made EDA Tool

– Analoge Schaltungen
– Digitale Schaltungen
– Simulation (wie TINA oder Proteus)
  o Analog / Digital / Mixed Mode
  o FPGA Devices
    x CPU Interpreter (PIC16, AVR, 8051, HC11, ARM Cortex-M3) mit gcc Integration
  o Oszilloskop / Logik Analyzer / Multimeter
– Peripherals Library
  o Strukturiert / Suchfunktion
  o Symbole selber erstellen mit Makrosprache
  o Analog (Widerstand, Kondensator) / Digital (AND-Gatter, D-FF) / Mixed Übergang (boundry, transitionbzw. Fehlermeldung
  o mit/ohne VCC/GND
  o Bauteile
    x Gleiches Bauteil anders dargestellt: IEC, ANSI, DIN, Graphisch (LED, Taster, Anzeige, Schrittmotoren)
    x Mikrocontroller
    x Ethernet mit Kodierung (Manchesterkodierung, 4B5B-Code) / Modulationsverfahren [Analog, Digital, Puls, Frequenzspreizend] (DSQ, QAM)
    x el. mag. Wellen
    x Schrittmotoren / Treiber
    x Bus-Systeme / Protokolle (SPI, I2C, 1-Wire, RS-232, USB)
    x Taster
    x Anzeige (LED, LCD)
    x FPGA (?)

Proteus VSM Peripherals Library

VHDL Types

Standard

library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_textio.all;
use IEEE.std_logic_arith.all;
use IEEE.numeric_bit.all;
use IEEE.numeric_std.all;
use IEEE.std_logic_signed.all;
use IEEE.std_logic_unsigned.all;
use IEEE.math_real.all;
use IEEE.math_complex.all;

library STD;
use STD.textio;

VHDL standard packages and types

  • ‘X’ usually is caused by two statements driving the same signal in opposite directions,i.e., ‘0’ and ‘1’
  • ‘Z’ is used to build a tri stated output/input
  • ‘L’ and ‘H’ are used to model a pulldown or pullup respectively
  • ‘-‘ is used in comparisons when you don’t care about certain bits in a vector

stackoverflow: std_logic in VHDL

Wikipedia

VHDL
Four-valued logic (en)
IEEE 1164 (en)
Dataflow programming (en)

QuestaSim ModelSim VHDL Simulation from MentorGraphics

General

Simple ModelSim Tutorial

VHDL

VHDL Design Examples

  • Design Unit
  • Entity
  • Architecture
  • Package
  • Delta Delay
VSIM 13> cd hdl/simulation/questa
VSIM 13> pwd
hdl/simulation/questa
VSIM 13> do ../scripts/do_all.do
questasim_flow

Summary: History of VHDL

1981 Initiated by US DoD to address hardware life-cycle crisis
1983-85 Development of baseline language by Intermetrics, IBM and TI
1986 All rights transferred to IEEE
1987 Publication of IEEE Standard
1987 Mil Std 454 requires comprehensive VHDL descriptions to be delivered with ASICs
1994 Revised standard (named VHDL 1076-1993)
2000 Revised standard (named VHDL 1076 2000, Edition)
2002 Revised standard (named VHDL 1076-2002)
2007 VHDL Procedural Language Application Interface standard (VHDL 1076c-2007)
2009 Revised Standard (named VHDL 1076-2008)

modelsim.ini Variables

Explicit

This variable enables the resolving of ambiguous function overloading in favor of the “explicit” function declaration (not the one automatically created by the compiler for each type declaration). Using this variable makes QuestaSim compatible with common industry practice.

You can override this variable by specifying vcom -explicit.

Specifying Resource Libraries

Note that the library clause is not used to specify the working library into which the design unit is placed after compilation. The vcom command adds compiled design units to the current working library. By default, this is the library named work. To change the current working library, you can use vcom -work and specify the name of the desired target library.

Compiling a VeriLog Design

VSIM 13> vlog [...]

Compiling a VHDL Design

For VHDL, the order of compilation is important. You must compile any entities or configurations before an architecture that references them.

VSIM 13> vcom -2002 -explicit -work ../questa/work ../source/top_tb.vhd
-2002              Revision VHDL 1076-2002
-explicit          Enables the resolving of ambiguous function overloading
-work <directory>  Specify the name of the desired target library
<source>           VHDL source

Built-in Libraries and Packages

In most vhdl programs you have already seen examples of packages and libraries. Here are two:

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_signed.all;

The packages are std_logic_1164 and std_logic_signed and the library is ieee. Since the scope of the library statement extends over the entire file, it is not necessary to repeat that for the second package.
It’s instructive to show where the packages are physically located. For Altera Max+2 and Xilinx Foundation these locations typically are:

Altera: ~\maxplus2\vhdl93\ieee\std1164.vhd
Xilinx: ~\fndtn\synth\lib\packages\ieee\src\std_logic_1164.vhd

It is thus tempting to come to the conclusion that the “library ieee;” statement indicates the “directory” in which the std_logic_1164 package is located. Note, however, where it is in Synplicity:

Synplicty: ~\synplcty\LIB\vhd\std1164.vhd

In the latter there is no mention of ieee at all. It is thus more appropriate to think of ieee as a pointer to the location of the package. The directory structure shown in those three examples depicts the directories where the packages are loaded when the software is installed. The pointer ieee is hardcoded in the compilers and thus there is no need for the user to associate that pointer with the directory structure, nor is it possible to put the packages anywhere else after the software has been loaded.

User Libraries and Packages

User libraries and packages are setup very similarly to the built-in ones. However, in that case, the user is responsible for the directory structure, the contents of the files, etc. Note that the user must then also set up the pointer to the package. The following shows a complete example of this arrangement. There are two ways to do this: 1) with the “work” directory; 2) with a user library.

Libraries and Packages in VHDL

WORK is not a VHDL Library

WORK is not the name of a VHDL library. This may surprise some (or even most) VHDL designers, even experienced engineers. Most of the time, nobody gets bothered by this. But on occasion, it can cause great confusion and waste of time.

All knowledge about VHDL starts with the IEEE Standard VHDL Language Reference Manual. LRM for short. Not much is said about “WORK”, but in section 11.2 (in the LRM 1076-2000) you can read the following:

Every design unit [...] is assumed to contain the following implicit context items [...]:
library STD, WORK; use STD.STANDARD.all;
[...] Library logical name WORK denotes the current working library during a given analysis.

Let me repeat: WORK denotes the current working library.

This means that there is no library named WORK. Instead, the identifier WORK just refers to the current library. You can compare WORK with the Java concept of this. In Java this refers to this object, which obviously is different for each object. This makes me think of a silly joke of man who asks: “is this the second street to the right?”

Enough silliness. Much confusion comes from the fact that VHDL tools allow you to give the name “WORK” to a library:

vlib work
vcom -work work myfile.vhd

That is as crazy as having a street address of John Doe, Ourstreet, MyHomeTown. How will your mail ever get there? And that is exactly the problem with using WORK as a library name. Other libraries cannot refer to you. If another library (say alex) they would refer to work.yourpackage.all, the VHDL analyser would read this as the alex.yourpackage.all.

It would have been better if VHDL tools would refuse the explicit name of WORK for a library. It would have been better if WORK were a reserved keyword in VHDL. But hey, there is no way to change that now. The best you can do is be aware of this idiosyncrasy in VHDL and live with it. Preferably by avoiding WORK all together.

WORK is not a VHDL Library

Simulating a VHDL Design

A VHDL design is ready for simulation after it has been compiled with vcom and possibly optimized with vopt. You can then use the vsim command to invoke the simulator with the name of the configuration or entity/architecture pair or the name you assigned to the optimized version of the design.

VSIM 13> vsim -novopt -t 1ps -lib work work.top_tb
-novopt     Simulate without Optimization
-t <time>   Override Resolution Limit
-lib 

Simulator Resolution Limit

vsim -t 10ps topmod

In the example above, a delay of 4 ps would be rounded down to 0 ps, and a delay of 6 ps would be rounded up to 10 ps.

Examining and Setting Signals and Variables with commands

VSIM> examine -time 13710 ns -radix hex /top_tb/DUT/ata_block_i
# 0EEDFA9A994350F07214CA6151823A08

VSIM> change /top_tb/DUT/ata_block_i 00000000000000000000000000040002

ModelSim Tutorial

FAQ

Question

# ** Error: (vcom-11) Could not find work.aes_tb_package.
# ** Error: ../tb/aes_tester.vhd(54): (vcom-1195) Cannot find expanded name "work.aes_tb_package".
# ** Error: ../tb/aes_tester.vhd(54): Unknown expanded name.
# ** Error: ../tb/aes_tester.vhd(56): VHDL Compiler exiting
# ** Error: /opt/questasim_10.1d/questasim/linux/vcom failed.

Answer

Compile other VHDL file first!

Question

# vsim -lib work -t 1ns -novopt work.aes_tester 
# ** Error: (vsim-19) Failed to access library 'work' at "work".
# No such file or directory. (errno = ENOENT)
# Error loading design
# Error: Error loading design 
#        Pausing macro execution 

Answer

Change to questa directory or map it like this:

vlib ../questa/work
vmap work ../questa/work

Longs Motor / Rattm Motor

Model

Step Angle(deg)

Motor Length(mm)

Rated Current(A)

Phase Resistance(Ohm)

Phase Inductance(mH)

Holding Torque(N.cm)

Detent Torque(N.cm)

Rotor Inertia(g.cm2)

Lead Wire(No)

Motor Weight(g)

17HS2408

1.8

28

0.6

8

10

12

1.6

34

4

150

17HS3401

1.8

34

1.3

2.4

2.8

28

1.6

34

4

220

17HS3410

1.8

34

1.7

1.2

1.8

28

1.6

34

4

220

17HS3430

1.8

34

0.4

30

35

28

1.6

34

4

220

17HS3630

1.8

34

0.4

30

18

21

1.6

34

6

220

17HS3616

1.8

34

0.16

75

40

14

1.6

34

6

220

17HS4401

1.8

40

1.7

1.5

2.8

40

2.2

54

4

280

17HS4402

1.8

40

1.3

2.5

5

40

2.2

54

4

280

17HS4602

1.8

40

1.2

3.2

2.8

28

2.2

54

6

280

17HS4630

1.8

40

0.4

30

28

28

2.2

54

6

280

17HS8401

1.8

48

1.8

1.8

3.2

52

2.6

68

4

400

17HS8402

1.8

48

1.3

3.2

5.5

52

2.6

68

4

400

17HS8403

1.8

48

2.3

1.2

1.6

46

2.6

68

4

400

17HS8630

1.8

48

0.4

30

38

34

2.6

68

6

400

Note:We can manufacture products according to customer’s requirements.