# Digital to Analog conversion

Status
Not open for further replies.

#### divsec

##### Newbie level 4 how to convert a 8 bit input signal into analog using digital to analog converter(DAC)?
This is normal DAC program which takes clock and reset as input and produces square wave output.

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity square_wave is
Port ( clk : in std_logic;
rst : in std_logic;
dac_out : out std_logic_vector(0 to 7));
end square_wave;

architecture Behavioral of square_wave is
signal temp : std_logic_vector(3 downto 0):="0000";
signal counter : std_logic_vector(0 to 7):="00000000";
signal en :std_logic;
begin
process(clk)
begin
if rising_edge(clk) then temp <= temp + '1' ;
end if;
end process;
process(temp(3))
begin
if rst='1' then counter <= "00000000";
elsif rising_edge(temp(3)) then
if counter<150 and en='0' then
counter <= counter +1 ;
en<='0';
dac_out <="00000000";
elsif counter=0 then en<='0';
else en<='1';
counter <= counter-1;
dac_out <="11111111";
end if;
end if;
end process;

end Behavioral;
can i use this program itself to covert 8 bit input into analog?if so where i should modify?

#### pavan.ps

##### Newbie level 5 the code provided by you gives only digital output. DAC_OUT(8-bit).

If u need the analog signal, u need to feed this digital output to a digital-to-analog converter to give analog signal.

So, If u hav a 8-bit signal, interface the FPGA to DAC such that you get the analog output.

Hope this helps..

#### xtcx To generate a variable analog voltage in an 8-bit DAC, just calculate the step-size for every input. For example, if DAC is capable of generating 0V to 5V, and if it's 8-bit resolution, then for every increase in count will add an output voltage of 19mv(5/255). You can easily calculate the corresponding analog voltage for a given dgital data easily

Status
Not open for further replies.