Forum Discussion
inout line undefined
Hello,
Here is the code that is confusing me. This is not the whole program, just a component. ------------------------------------------------------------------------------------------ library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; entity Serial_Communication is Port ( i_CLK, i_CLKx2, i_EN, i_RD : in STD_LOGIC; i_ADDR : in STD_LOGIC_VECTOR(6 downto 0); io_DATA : in STD_LOGIC_VECTOR(15 downto 0); io_SD : inout STD_LOGIC; o_SEN, o_SCLK, o_DONE : out STD_LOGIC); end Serial_Communication; architecture Behavioral of Serial_Communication is component CLK_Interrupt is Port ( i_CLK, i_interrupt, i_idle_state : in STD_LOGIC; o_CLK : out STD_LOGIC); end component; signal clk : std_logic := '0'; signal clkx2 : std_logic := '0'; signal sclk_interrupt : std_logic := '1'; signal clk_e : std_logic := '0'; -- early clk signal clkx2_e : std_logic := '0'; -- early clkx2 signal clkx2_d : std_logic := '0'; -- delayed clkx2 signal sen : std_logic := '0'; signal o_sd : std_logic := '0'; signal i_sd : std_logic := '0'; signal tristate : std_logic := '0'; signal done : std_logic := '0'; begin clk_e<=i_CLK; clkx2_e<=i_CLKx2; clk<=clk_e after 15ns; clkx2<=clkx2_e after 15ns; o_SEN<=sen; o_DONE<=done; V1: CLK_Interrupt port map ( i_CLK => clk, i_interrupt => sclk_interrupt, i_idle_state => '0', o_CLK => o_SCLK); process(clkx2, i_EN) variable count : integer := 0; -- clkx2 counter variable run : boolean := false; begin if clkx2'event and clkx2='1' then if i_EN='1' then run:=true; end if; if run=true then count:=count+1; else done<='1'; count:=0; end if; if count=1 then done<='0'; o_sd<='0'; tristate<='0'; elsif count=2 then o_sd<=i_RD; sen<='1'; elsif count=3 then sclk_interrupt<='0'; elsif count<18 then o_sd<=i_ADDR((17-count-(17-count)mod 2) /2); elsif count<50 then if i_RD='0' then o_sd<=io_DATA((49-count-(49-count)mod 2) /2); else end if; elsif count=50 then if i_RD='0' then o_sd<='0'; else end if; elsif count=51 then sclk_interrupt<='1'; sen<='0'; elsif count=52 then done<='1'; run:=false; count:=0; end if; end if; end process; clkx2_d<=clkx2 after 15ns; -- makes sure the o_sd value is set before it is given out to io_SD process(clkx2_d, tristate) begin if clkx2_d'event and clkx2_d='1' and tristate='0' then io_SD<=o_sd; end if; end process; end Behavioral; ------------------------------------------------------------------------------------------ When I simulate my entire program the io_SD inout line is undefined whenever the i_EN line is '0'. If i_EN='1' then all signals are what they should be. Once the component, that is driving this one, sets i_EN to '0' simulation just ends. Changing the simulation run time does not work, it simply ends after i_EN='0'. If I start off with i_EN='0' then simulation run time is again a constant (15ns) and the io_SD is labeled "U", meaning undefined. I assumed that the simulator was buggy and tried programming the FPGA. The program did not work as expected. Maybe I should also mention that I am using xilinx ise project navigator 10.1.03(nt) for coding in vhdl. The FPGA is Xilinx Spartan XC3S1200E.7 Replies
- Altera_Forum
Honored Contributor
For a start - this is an Altera forum - for Xilinx specific problems you should really go to the Xilinx forum.
But asside from that - I dont know what things should be? having a quick look over this code, the counter wont start counting until i_en = '1', and you have nothing defined for when count = 0. And why is io_SD an inout? you never read it, so it should just be an Out. - Altera_Forum
Honored Contributor
The future plan is to use this component for reading and writing. Right now I am trying to get the writing to work only. That is why the inout is used only as out for now. The i_EN signal comes from a different component. I don't want the counter to count when i_EN is low. i_EN meaning "Enable input signal". The problem is that somehow the io_SD is undefined when i_EN is low.
I know I should be using Xilinx's forums, sorry about that. I tried posting on Xilinx forum but I could not find out how. - Altera_Forum
Honored Contributor
Well this is what a good testbench and simulation are all about - debugging.
- Altera_Forum
Honored Contributor
I should have mentioned this earlier. There is an error when I simulate the program: "ERROR: Simulation:595 - Index 8 out of bound 6 downto 0." "ERROR: In process Serial_Communication.vhd:71"
- Altera_Forum
Honored Contributor
--- Quote Start --- I should have mentioned this earlier. There is an error when I simulate the program: "ERROR: Simulation:595 - Index 8 out of bound 6 downto 0." "ERROR: In process Serial_Communication.vhd:71" --- Quote End --- It means your algorithm for address calculation is wrong as it calculates index 8. - Altera_Forum
Honored Contributor
I can see the process (referred to in the error) working properly in the simulation. All is well until in_EN goes low. Meaning the proper waveform is shown on the proper lines. When in_EN goes low the simulation just does not go further, I can increase simulation run time but simulation it self does not go any further.
If I start the program with in_EN low, the simulation runs for 15ns only and the io_SD line is shown undefined. And same thing occurs, I can increase or decrease simulation time but it does nothing when I increase it past 15ns. - Altera_Forum
Honored Contributor
The problem is when count=0 the wrong elsif statement is entered. I have fixed it already.
Thank you for your help.