Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
15 years ago

Read from a text file

Hello,

I'm trying to read a text file with VHDL to generate some automatic input codes.

I made a project just to test this entity, but my output is always with value 'Z'.

my text file contains only one line and the line contains this

"11111111"

Observation : the cod.txt was created with QuartusII and is included to the project!

i think quartus can't open or read the file or something like that

thanks in advance

library std;
library ieee;
use std.textio.all;
use ieee.std_logic_1164.all;
entity readfile is
 
    port(clock : in std_logic;
         --output : out std_logic_vector(7 downto 0);
         output : out std_logic
         );
end readfile;
architecture logic of readfile is
--signal aux: std_logic_vector(7 downto 0);
begin
    process(clock)
        variable inline:line;
        variable character_variable:character;
        variable end_of_line:boolean;
        file myfile:text is "cod.txt";
    begin
    
        
        
        if(clock'event and clock = '1') then
            
            readline(myfile,inline);
            
            read(inline,character_variable,end_of_line);
            
            for i in 0 to 7 loop
                read(inline,character_variable,end_of_line);
                
                case character_variable is
                
                    when '0' =>
                        output <= '0';
                        
                    when '1' =>
                        output  <= '1';
                        
                    when others  =>
                        output  <= 'Z';
            
            
                end case;
                
            end loop;
            
        
            --output <= aux;
    
        end if;
    end process;
end logic;

23 Replies