Beruflich Dokumente
Kultur Dokumente
net/publication/339274858
CITATIONS READS
0 35
4 authors, including:
Radovan Stojanovic
University of Montenegro
147 PUBLICATIONS 653 CITATIONS
SEE PROFILE
Some of the authors of this publication are also working on these related projects:
All content following this page was uploaded by Radovan Stojanovic on 14 February 2020.
Podgorica
Contact: stox@ucg.ac.me
1
Contents
Summary ....................................................................................................................................................... 3
Problem description...................................................................................................................................... 3
Software solution and simulation ................................................................................................................. 3
Steps.......................................................................................................................................................... 3
Examples ....................................................................................................................................................... 7
Example 1. ................................................................................................................................................. 8
MATLAB code ........................................................................................................................................ 8
MATLAB to VHDL code .......................................................................................................................... 8
Our VHDL code ...................................................................................................................................... 8
QUARTUS II testing................................................................................................................................ 8
Example 2. ................................................................................................................................................. 9
MATLAB code ........................................................................................................................................ 9
MATLAB to VHDL code ........................................................................................................................ 10
Our VHDL code .................................................................................................................................... 10
QUARTUS II testing.............................................................................................................................. 11
Conclusion ................................................................................................................................................... 12
2
Summary
This is an exam project, made in MEDEL electronics lab at the University of Montenegro, with
mentoring of prof. Dr. Radovan Stojanović. In further text, the problem is explained in details and
offered an elegant solution. In addition to that, we have enclosed high level design and description of
our solution, alongside with hardware and software structure. The accent is on MATLAB to VHDL code
conversion.
Problem description
Our job is to explain the principle of converting MATLAB code to VHDL code. This project show
that knowledge of Altera QUARTUS program is not necessary, but generating the VHDL code can be
gotten through MATLAB. Will this be a good way for functional VHDL code we are going to show in one
of the following chapters.
Steps
1. Open MATLAB
3
2. Write a function that you want to convert to VHDL
4
5. Add MATLAB function file
6. Go to Workflow Advisor
7. Select Convert to fixed-point at build time because double operation is not suitable for FPGA
5
8. Define input types
6
12. Select Code Generation Target
14. Run
Examples
We will show two different examples, and describe each of them (showing the difference
between the code which is generated using HDL Coder, and the code without converting).
7
Example 1.
Multiplexer 2/1
MATLAB code
y = ((~sel)&a) | (sel&(b));
end
QUARTUS II testing
8
Flow Summary
Simulation:
Our code
In this example, a VHDL code for multiplexer 2/1 is generated from MATLAB code. We got a fully
functional code, and it is ready to be used properly, without any error. There is no difference between
code we got and a code we wrote directly in Altera QUARTUS.
Example 2.
4-bit Counter
MATLAB code
9
persistent count_val; %limit to four bits
if isempty(count_val) if count_val>15
count_val = 0; count_val=0;
end end
%counting up end
if enable_ctr count=count_val;
count_val=count_val+1; end
10
begin brojac:=0;
if(clock_new='1' and end if;
clock_new'event) then end if;
if (enable='1') then end if;
if(brojac<15) then count <=brojac;
brojac:=brojac+1; end process;
else end RTL;
QUARTUS II testing
Flow Summary:
Simulation:
11
Our code
In this second example, it is shown how to make 4 bit counter using two methods
(converting MATLAB code to VHDL code and writing it directly in Altera QUARTUS). Generating VHDL
code from MATLAB, we got also a fully functional code as in the first example, but this time there is
some difference between these two codes. At the first sight from the pictures above, difference is
obvious. In the generated code we have 41 lines of code, but in our VHDL code we have 26 lines of code,
what indicates that we need less lines of the code if we use Altera QUARTUS for making 4-bit counter,
and accordingly we need less memory. Also, using MATLAB for generating code we need more logics
elements as well as totals pins.
Conclusion
From this two examples, we can notice that the knowledge of Altera QUARTUS program for
solving some problems is very useful, but the MATLAB can be used as utility for generating the code for
the same problem. Using Altera program we can save a lot of memory because convertor is working only
to solve problem and make a functional code. It does not take care of how many lines of code it will use
or how much memory it will spend. We made an example for one combinational and one sequential
circuit. For the simple codes, converter is working in accordance with expectations, there is no
difference between two codes obtained in two different ways. But, as the code is more complex,
difference is bigger. It is necessary to use more logic elements, more pins, and for sure a much more
memory.
References:
12