This document describes a student project to design a function generator using VHDL. The function generator can generate sine, square, sawtooth, and triangular waveforms in both low and high frequencies using a lookup table method. Lookup tables storing the waveform values are implemented as arrays in VHDL. Test waveforms are generated and displayed to verify the design works as intended.
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
478 views
Function Generator Using VHDL
This document describes a student project to design a function generator using VHDL. The function generator can generate sine, square, sawtooth, and triangular waveforms in both low and high frequencies using a lookup table method. Lookup tables storing the waveform values are implemented as arrays in VHDL. Test waveforms are generated and displayed to verify the design works as intended.
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 20
Advanced Digital Hardware Design
Function Generator using VHDL
Sailesh Kumar G Electronics and Communication Engineering AAA0188 sailesh-ece15@snu.edu.in
Declaration
Abstract A function generator is a useful machine which is used in electronics and communication, mechanics and various fields. It allows one to generate a range of electrical signals and waveforms for testing and diagnostic purposes. In this project I designed a function generator which is capable of synthesising various waveforms such as sine, square, saw tooth or ramp and triangular waves. These waveforms can be of low frequency or high frequency depending upon the user preference.
Description Here the Lookup Table Method is used to create all the waveforms. This method is done by, first, generating all the required values of the particular waveform for n samples and store it in a memory. In this whole project I have taken the fundamental time period of each waveform to be 2*pi. This method gives very less error and therefore the accuracy in the values of the wave function in a particular angle will be higher. I have also included the input option of using whether a low frequency waveform or a high frequency waveform. This module gives the data output of integer values of the wave from the look up table. For this purpose, I have declared an array of size 50 byte, which stores the value of each waveform at various angles. The more values that we use in the code from the table, the more accurate is the measurement of the waves. But if we just keep on increase the values more accuracy, then the more bits gets used. So the memory requirement will be more and results in the costs. Here the 50 byte array is used for storing the values from the look up table; this automatically results in a low frequency waveform. Therefore another 10 byte array is initialised for generating the same waveform but in higher frequency. This is done by the same Look up table method but taking the appropriate values for a high frequency waveform. This program can be further synthesised and interfaced in a Field Programmable Gate Array (FPGA) board using a Digital to Analog Convertor (DAC), by connecting the output of DAC to an oscilloscope. This can be well explained by seeing the following waveforms generated in MATLAB. The same values are used in the program for generating the waves. This program is more understandable and also very less chance of getting an error since the values is directly taken from the look up table which is generated by MATLAB. The left column waveforms are a low frequency waveform and hence the values obtained are mare whereas in the right column there are high frequency waveforms and so the values are less.
SAWTOOTH:
TRIANGULAR:
SQUARE:
SINE:
VHDL Code library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.NUMERIC_STD.ALL;
entity waves is port (clk :in std_logic; wavegen :in std_logic_vector(1 downto 0); freq: in std_logic; output : out integer range -128 to 127); end waves;
architecture signals of waves is signal i : integer range 0 to 50:=0; signal j : integer range 0 to 10:=0; type memory_type1 is array (0 to 49) of integer range -128 to 127; type memory_type2 is array (0 to 9) of integer range -128 to 127;
signal sine : memory_type1 :=(0,10,19,29,38,46,53,60,66,71,74,77,78,78,77,74,71,66,60,53,46,38,29,19,10,0, -10,-19,-29,-38,-46,-53,-60,-66,-71,-74,-77,-78,-78,-77,-74,-71,-66,-60,-53,-46,-38,-29,-19,- 10);
signal saw : memory_type1 :=(-78,-75,-72,-69,-66,-63,-59,-56,-53,-50,-47,-44,-41,-38,-34,- 31,-28,-25,-22,-19,-16, -12,-9,-6,-3,0,3,6,9,12,16,19,22,25,28,31,34,38,41,44,47,50,53,56,59,63,66,69,72,75);
signal square : memory_type1 :=(78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78, -78,-78,-78,-78,-78,-78,-78,-78,-78,-78,-78,-78,-78,-78,-78,-78,-78,-78,-78,-78,-78,-78,-78,- 78,-78);
signal triangle : memory_type1 :=(-78,-72,-66,-59,-53,-47,-41,-34,-28,-22,-16,-9,- 3,3,9,16,22,28,34,41,47,53,59, 66,72,78,72,66,59,53,47,41,34,28,22,16,9,3,-3,-9,-16,-22,-28,-34,-41,-47,-53,-59,-66,-72);
signal sine_high : memory_type2 :=(0,46,74,74,46,0,-46,-74,-74,-46);
signal saw_high : memory_type2 :=(-78,-63,-47,-31,-16,0,16,31,47,63);
signal square_high : memory_type2 :=(78,78,78,78,78,-78,-78,-78,-78,-78);
signal triangle_high : memory_type2 :=(-78,-47,-16,16,47,78,47,16,-16,-47);
begin
process(clk,wavegen)
begin
if(rising_edge(clk)) then case wavegen is
when "00" => if(freq = '0') then output <= sine(i); i <= i+ 1; if(i = 49) then i <= 0; end if; else output <= sine_high(j); j <= j+ 1; if(i = 9) then j <= 0; end if; end if;
when "01" => if(freq = '0') then output <= saw(i); i <= i+ 1; if(i = 49) then i <= 0; end if; else output <= saw_high(j); j <= j+ 1; if(i = 9) then j <= 0; end if; end if;
when "10" => if(freq = '0') then output <= square(i); i <= i+ 1; if(i = 49) then i <= 0; end if; else output <= square_high(j); j <= j+ 1; if(i = 9) then j <= 0; end if; end if;
when "11" => if(freq = '0') then output <= triangle(i); i <= i+ 1; if(i = 49) then i <= 0; end if; else output <= triangle_high(j); j <= j+ 1; if(i = 9) then j <= 0; end if; end if;
when others => null; end case; end if;
end process; end signals; Waveforms
SINE:
SAW TOOTH:
SQUARE:
TRIANGULAR:
All the output waveforms which include both low frequency and high frequency waves both are generated and have been displayed.
Testbench LIBRARY ieee; USE ieee.std_logic_1164.ALL;
ENTITY wavesfinale IS END wavesfinale;
ARCHITECTURE behavior OF wavesfinale IS
COMPONENT waves PORT( clk : IN std_logic; wavegen : IN std_logic_vector(1 downto 0); freq : IN std_logic; output : out integer range -128 to 127 ); END COMPONENT;
signal clk : std_logic := '0'; signal wavegen : std_logic_vector(1 downto 0) := (others => '0'); signal freq : std_logic := '0';