Thursday, July 18, 2013

Quartus-ModelSim: How to customize the waveforms to facilitate the debug

In a previous blog I described how to customize the waveforms in ModelSim in the Xilinx ISE environment. Due to the request of many of you, I now describe the waveform customization for the Altera Quartus users.  
As you'll read in the application note that I present; when invoking any simulation (functional or gate level) from the Quartus environment, ModelSim is automatically started up, displaying the waveforms resulting from the test bench in the panel called Wave View. Due to the ModelSim's settings (detailed in a script file) by default, only the entity signals are displayed in the waveform viewer, no other signal ... So, once opened this Wave View window if you wish to display internal signals of the design under test, or change the position and / or color of the signals, or add dividers, and many other features offered by ModelSim, you can do it (following certain steps explained later), but once you close ModelSim all modifications are lost!. Hence, when you run the same simulation again, you must start again with the modifications. The problem sound familiar?????

In the 'Application Note' that I present here, I detail the steps to follow, so that when you invoke ModelSim from Quartusthe Wave View will contain all the information you set and saved for proper verification and easy debug.

Here is the link to download the 'Application Note'AN-08 C7T

Until next time!

Wednesday, July 17, 2013

ASCII to HEX - the smart way....

Introduction

In this post I'll present an easy way to convert text in ASCII to Hex. This is useful to save data in memory, pass through data in a particular communication protocol, a data to be displayed on an LCD, etc..

Procedure

The VHDL standard has defined several type of conversion's functions in its standard libraries. Some of this functions will be used for this conversion.
The necessary steps for conversion are as follows:
1 - Declaration of the string, constant and signal counter in the declarative part of the architecture:

 1 architecture beh of test is
 2 .......
 3 constant N : natural := 16;
 4 type tstring is array(natural range<>) of character;
 5 constant msje1 : tstring(0 to N-1) := "Vuelvo en 5 ... ";
 6 .......
 7 -- declaracion de la senal para asignar el Hex correspondiente
 8 signal byte_to_Tx: std_logic_vector(7 downto 0);
 9
10 -- declaracion de contador
11 signal char_cont: natural range 0 to N-1;
12 .......

2 - Using conversion functions to get the Hexadeciaml byte for each character in the string:

byte_to_tx<=std_logic_vector(to_unsigned(character'pos(msje1(char_cont)),8));

Let's consider this last statement piece by piece:
a-
msje1(char_cont);

what makes this part of the instruction is to position in a specific character of the msje1. The position is given by the counter's value char_cont. Of course, this statement must be inside a loop where the counter is incremented once is sent the respective character.

b-
character'pos('character')

in this part 'character' represents the character of msje1 specified by char_cnt. On the other hand, character'pos ('V') (I write 'V' as an example of a character from msje1), what it does is first to return the position number value for the  'V' character in the array defined in the VHDL standard. To refresh a little bit something that your surely saw some time ago, I detail the type character as it's defined in the VHDL standard: 

 1 type character is (
 2     NUL, SOH, STX, ETX, EOT, ENQ, ACK, BEL,
 3     BS, HT, LF, VT, FF, CR, SO, SI,
 4     DEL, DC1, DC2, DC3, DC4, NAK, SYN, ETB,
 5     CAN, EM, SUB, ESC, FSP, GSP, RSP, USP,
 6     ‘ ’,’!’, “”,’#’,’$’,’%’,&,’’’,
 7     ‘(,),*, ‘+, ‘,,-,.,/,
 8     ‘0,1,2,3,4,5,6,7,
 9     ’8,9,:,;,<,=,>,’?’,
10     ‘@’,’A’,’B’,’C’,’D’,’E’,’F’,’G’,
11     ‘H’,’’I’,’J’,’K’,’L’,’M’,’N’,’O’,
12     ‘P’,’Q’,’R’,’S’,’T’,’U’,’V’,’W’,
13     ‘X’,’Y’,’Z’,’[‘,\,’]’,’^’,’_’,
14     ‘`’,’a’,’b’,’c’,’d’,’e’,’f’,’g’,
15     ‘h’,’i’,’j’,’k’,’l’,’m’,’n’,’o’,
16     ‘p’,’q’,’r’,’s’,’t’,’u’,’v’,’w’,
17     ‘x’,’y’,’z’,’{‘,|,’}’,’~’,DEL);
18

as you can see, the character 'V' is positioned in 86th place in the array, so the character'pos ('V') returns the number 86 (as an integer).

c-
So now we have to convert an integer, 86, (which is giving me the position) to std_logic_vector. Using the now 'famous' conversion functions table  we know that we must first pass the integer to unsigned and then to std_logic_vector. That is done by the next part of the statement:

std_logic_vector(to_unsigned(86,8));

where 8 is the number of bits needed to represent the maximum number estimated to be converted (in this case 256).

d-
finally the binary corresponding to the character specified by char_cont signal is assigned to byte_to_Tx

Final ...

I hope you find it useful ... and if you ever use NOTIFY ....

See you soon ....