Vhdl Parallel or Serial-in/ Parallel-out register - vhdl

I want to build a n bits register which can take both serial or parallel input depending of a bit SERIAL. And always parallel output. See my code below. My issue is that I need to use a If statement to choose my input (parallel or serial) (which must be inside a process) and I also need a for generate statement because I work with generic n bit register (which cannot be done inside a process) to build the n D-Flipflop.
I was thinking to use for loop instead of for i ..generate but I need to use that i as index.
Does anyone know how to fix my code? The main issue is that using serial input, the flipflop are connected in series while parallel input, the flipflops are independent. And I don't know how to model that proprely.
Thank you
-- Parallel or Serial-in / Parallel-out n bits register
library ieee;
use ieee.std_logic_1164.all;
entity PSIPOreg is
generic(n: integer);
port(RST, Clk_reg, enable, SERIAL: in std_logic;
Din_P: in std_logic_vector(n-1 downto 0);
Din_S: in std_logic;
Qout: out std_logic_vector(n-1 downto 0));
end PSIPOreg;
architecture bhv of PSIPOreg is
component D_FlipFlop
port(D, Clk, reset, EN : in std_logic;
Q : out std_logic);
end component;
signal parallel_data : std_logic_vector(0 to n-1) := (others =>'0');
signal temp_input: std_logic_vector(0 to n-1) := (others =>'0');
begin
Qout <= parallel_data;
process(SERIAL, Clk_reg, enable, RST)
begin
if(SERIAL = '0') then -- PIPO register
temp_input <= Din_P;
gen_reg: for i in 0 to n-1 generate
regx: D_FlipFlop port map(D => temp_input(i), Clk => Clk_reg, reset => RST, EN => enable, Q => Qout(i));
end generate gen_reg;
elsif(SERIAL = '1') then -- SIPO register
temp_input(0) <= Din_S;
shift_reg: for i in 0 to n-1 generate
begin
dff_lsb: if i = 0 generate
begin
dff: D_FlipFlop port map(D => temp_input(0), Clk => Clk_reg, reset => RST, EN => enable, Q => parallel_data(i));
--Qout(i) <= parallel_data(i);
end generate dff_lsb;
dff_mid: if((i>0) and (i<(n-1))) generate
begin
dff: D_FlipFlop port map(D => parallel_data(i-1), Clk => Clk_reg, reset => RST, EN => enable, Q => parallel_data(i));
--Qout(i) <= parallel_data(i);
end generate dff_mid;
dff_msb: if i = n-1 generate
begin
dff: D_FlipFlop port map(D => parallel_data(i-1), Clk => Clk_reg, reset => RST, EN => enable, Q => Qout(i));
end generate dff_msb;
end generate shift_reg;
end if;
end process;
end bhv;

Related

VHDL Components work perfectly separately; having issues connecting them in an upper entity

Background
The goal is to design a watchdog timer (WDT) using structural modeling using Xilinx. The WDT received a Start trigger which initiates the counter, counts for 59 clock cycles, produces a one-clock interval pulse to signal Reset condition and resets to 0. So I made the following diagram in photoshop to illustrate the components and how they should be connected. WDT is the upper entity.
Schematic and Overall Concept
CLKN is a negative edge clock shared across the SR-ff and the WDT (as well as the counter and the T-ffs in the counter)
Counter is a 6bit binary counter made out of T-FF
Six T-FFs cascaded where the input to the first ff's clock line is the system clock and the clock input for the remaining ffs is the Q from the previous T-ff so the ffs toggle at every 2i where i = 0, 1, 2, 3, 4, 5 so it creates a binary counter
The 6 fan-in and gate is a custom and gate made so that the output is 1 only when the sequence 111010 is the input (111010 = 58; 0->58 = 59 clock cycles)
When the output = 1, it resets the SR ff which resets the counter and the WDT
The 2 fan-in and gate ensures that the counter runs only when Q = 1 and the CLKN is asserted
Q = 1 when S = 1 when the Start trigger is asserted. The trigger stays high until the WDT resets
The outer thicker frame represents the WDT
START maps to Start
CLKN maps to CLKN
Reset_Signal maps to Send_Reset
What I have tried
I have tested every component separately and they work accordingly (code for them listed in the end)
Have tried switching std_logic to bit to avoid values other than 0 and 1 -- didn't work; switched back to std_logic
Initialized every port and signal possible to avoid uninitialized values issues -- worked some times for a certain combination but I could never duplicate it
I have debugged the components and the signals in the ISim waveform screen
Screenshot of Simulation
Disregard the first 100 ns
The SR ff is not producing a q or qnot output even though it shows a constant value of 1 and 0; notice there are no wave forms for those two outputs as well as R
This issue propagates to the 2 fan-in AND gate which produces a constant output of 1 even when the inputs are not 11; it does not read the Q output from the SR ff; since the output is a constant 1, there is no transition thus no clock into the counter
The issue seems to be due to portmapping but I don't really see what I'm doing wrong. I mean, it must be because I've tried everything else (as far as code is concerned) and I've isolated it to the portmapping.
There are no syntax errors
I honestly don't know what to do anymore. I've been stuck on this for about 7 hours now and I'm honestly going crazy (the lack of sleep doesn't help).
Code (essential sections)
SR FF
entity SR_FF is
Port ( S : in std_logic;
R : in std_logic;
CLKN : in std_logic;
QNOT : out std_logic := '1';
Q : out std_logic := '0');
end SR_FF;
architecture Behavioral of SR_FF is
begin
process(CLKN)
variable imm: std_logic := '0';
begin
if (falling_edge(CLKN)) then
if (S = '0' AND R = '0') then
imm := imm; --no change
elsif (S = '0' AND R = '1') then
imm := '0';
elsif (S = '1' AND R = '0') then
imm := '1';
else
NULL;
end if;
end if;
Q <= imm;
QNOT <= not imm;
end process;
T FF
entity T_FF is
Port ( T : in STD_LOGIC;
CLKN : in STD_LOGIC;
Reset : in STD_LOGIC;
Q : out STD_LOGIC := '0';
Qnot : out STD_LOGIC := '1');
end T_FF;
architecture Behavioral of T_FF is
begin
process(CLKN, Reset)
variable imm: std_logic := '0';
begin
if (Reset = '0') then
if (falling_edge(CLKN)) then
if (T = '0') then
imm := imm; --no change
elsif (T = '1') then
imm := not imm; --toggle
else
NULL;
end if;
end if;
else
imm := '0';
end if;
Q <= imm;
Qnot <= not imm;
end process;
end Behavioral;
SIX BIT COUNTER
entity six_bit_counter is
Port ( CLKN : in STD_LOGIC;
RESET : in STD_LOGIC;
COUNT : out STD_LOGIC_VECTOR (5 downto 0) := "000000");
end six_bit_counter;
architecture Structural of six_bit_counter is
component T_FF
Port ( T : in STD_LOGIC;
CLKN : in STD_LOGIC;
Reset : in STD_LOGIC;
Q : out STD_LOGIC;
Qnot : out STD_LOGIC);
end component;
component OR_two
Port ( A : in STD_LOGIC;
B : in STD_LOGIC;
C : out STD_LOGIC);
end component;
signal clk_trigger : std_logic_vector (4 downto 0) := "00000";
signal temp_count : std_logic_vector (5 downto 0) := "000000";
begin
T0: T_FF port map (T => '1', Reset => RESET, CLKN => CLKN, Q => temp_count(0), Qnot => open);
T1: T_FF port map (T => '1', Reset => RESET, CLKN => clk_trigger(0), Q => temp_count(1), Qnot => open);
T2: T_FF port map (T => '1', Reset => RESET, CLKN => clk_trigger(1), Q => temp_count(2), Qnot => open);
T3: T_FF port map (T => '1', Reset => RESET, CLKN => clk_trigger(2), Q => temp_count(3), Qnot => open);
T4: T_FF port map (T => '1', Reset => RESET, CLKN => clk_trigger(3), Q => temp_count(4), Qnot => open);
T5: T_FF port map (T => '1', Reset => RESET, CLKN => clk_trigger(4), Q => temp_count(5), Qnot => open);
//used to duplicate signals; same signal is applied to the clock_input of the flip flops as well as the counter output value
O0: OR_two port map (A => '0', B => temp_count(0), C => clk_trigger(0));
O1: OR_two port map (A => '0', B => temp_count(1), C => clk_trigger(1));
O2: OR_two port map (A => '0', B => temp_count(2), C => clk_trigger(2));
O3: OR_two port map (A => '0', B => temp_count(3), C => clk_trigger(3));
O4: OR_two port map (A => '0', B => temp_count(4), C => clk_trigger(4));
//signal mapped to counter output
O5: OR_two port map (A => '0', B => temp_count(0), C => COUNT(0));
O6: OR_two port map (A => '0', B => temp_count(1), C => COUNT(1));
O7: OR_two port map (A => '0', B => temp_count(2), C => COUNT(2));
O8: OR_two port map (A => '0', B => temp_count(3), C => COUNT(3));
O9: OR_two port map (A => '0', B => temp_count(4), C => COUNT(4));
OA: OR_two port map (A => '0', B => temp_count(5), C => COUNT(5));
end Structural;
WDT
entity WDT is
Port ( CLKN : in STD_LOGIC;
Start : in STD_LOGIC;
Reset_Signal : out STD_LOGIC);
end WDT;
architecture Structural of WDT is
component SR_FF is
Port ( S : in std_logic;
R : in std_logic;
CLKN : in std_logic;
QNOT : out std_logic;
Q : out std_logic);
end component;
component six_bit_counter
Port ( CLKN : in STD_LOGIC;
RESET : in STD_LOGIC;
COUNT : out STD_LOGIC_VECTOR (5 downto 0));
end component;
component AND_six
Port ( A_IN : in STD_LOGIC_VECTOR (5 downto 0);
A_OUT : out STD_LOGIC);
end component;
component AND_two
Port ( A_IN : in STD_LOGIC_VECTOR (1 downto 0);
A_OUT : out STD_LOGIC);
end component;
component OR_two
Port ( A : in STD_LOGIC;
B : in STD_LOGIC;
C : out STD_LOGIC);
end component;
signal temp_count : std_logic_vector (5 downto 0) := "000000";
signal send_reset : std_logic := '0'; --coming out of and_six
signal q_temp : std_logic := '0';
signal clk_counter : std_logic := '0';
signal q_not_temp : std_logic := '0';
begin
--58 = 111010
SRFF1: SR_FF port map (S => Start, R =>send_reset, CLKN => CLKN, Q => q_temp, QNOT => q_not_temp);
A1: AND_two port map (A_IN(0) => CLKN, A_IN(1) => q_temp, A_OUT => clk_counter);
C1: six_bit_counter port map (CLKN => clk_counter, Reset => send_reset, COUNT => temp_count);
A2: AND_six port map (A_IN => temp_count, A_OUT => send_reset);
//used to duplicate Reset signal which is mapped to the interal reset signal to reset the counter and SR ff as well as mapped to the WDT output to demonstrate the counter reached its threshold
OR1: OR_two port map (A => '0', B => send_reset, C => Reset_Signal);
end Structural;
I appreciate any help/ideas/suggestions. I'd rather not start over because I have already invested so much time into this but I will if I have to.
Thank you in advance!

Writing a code for a CRC using D-FlipFlop in VHDL

I'm learning VHDL for a university project. The goal is to write a CRC circuit given a certain polynomial. I found online solution that uses register but I wanted to do it by using actual D-FlipFlop.
So I created the D-FlipFlop and put in my main file several instances of them using generate to be more flexible and be able to add or remove flipflop easily.
library IEEE;
use IEEE.std_logic_1164.all;
entity LFSR is
generic (NBit : positive := 8);
port(
clk :in std_logic;
reset :in std_logic;
din :in std_logic;
dout :out std_logic_vector(Nbit-1 downto 0)
);
end LFSR;
architecture rtl of LFSR is
component DFC
port(
clk :in std_logic;
reset :in std_logic;
d :in std_logic;
crc :out std_logic;
q :out std_logic
);
end component DFC;
signal q_s : std_logic_vector (NBit-1 downto 0):= (others => '0');
signal crc_t : std_logic_vector (NBit-1 downto 0):= (others => '0'); --registro temporaneo su cui fare le operazioni
signal int_0 :std_logic := '0';
signal int_2 :std_logic := '0';
signal int_4 :std_logic := '0';
signal int_8 :std_logic := '0';
begin
int_0<= din xor q_s(7);
int_2<= q_s(1) xor q_s(7);
int_4<= q_s(3) xor q_s(7);
GEN: for i in 0 to Nbit-1 generate
FIRST: if i=0 generate
FF1: DFC port map (
clk => clk,
reset => reset,
d => int_0,
crc => crc_t(i), --funziona benissimo se metto dout(i)
q => q_s(i)
);
end generate FIRST;
THIRD: if i=2 generate
FF2: DFC port map (
clk => clk,
reset => reset,
d => int_2,
crc => crc_t(i),
q => q_s(i)
);
end generate THIRD;
FIFTH: if i=4 generate
FF4: DFC port map (
clk => clk,
reset => reset,
d => int_4,
crc => crc_t(i),
q => q_s(i)
);
end generate FIFTH;
INTERNAL: if i>0 and i<Nbit-1 and i/= 2 and i/=4 generate
FFI: DFC port map (
clk => clk,
reset => reset,
d => q_s(i-1),
crc => crc_t(i),
q => q_s(i)
);
end generate INTERNAL;
LAST: if i=Nbit-1 generate
FFN: DFC port map (
clk => clk,
reset => reset,
d => q_s(i-1),
crc => crc_t(i),
q => q_s(i)
);
end generate LAST;
end generate GEN;
variable t : natural := 0;
begin
if(rising_edge(clk)) then
t:= t+1;
if t=24 then
dout <= crc_t;
end if;
end if;
end process;
end rtl;
Of course on line 35, where I put "d => din xor q_s(Nbit-1)", the compiler gives me an error. How can I obtain the result I want to get?
I tried putting intermediary signal to pass this problem, but I can't understand why this is not working as expected.
This is the code of the DFC component:
library IEEE;
use IEEE.std_logic_1164.all;
entity DFC is
port(
clk :in std_logic;
reset :in std_logic;
d :in std_logic;
crc :out std_logic;
q :out std_logic
);
end DFC;
architecture rtl of DFC is
begin
process(clk, reset, d)
begin
if(reset = '1')then
q <= '0';
crc<= '0';
elsif (clk'event and clk='1') then
q <= d;
crc <= d;
end if;
end process;
end rtl;
Thanks all for the aswers.
Gabriele.
Edit: I added all the LFSR code and the DFC code.
Your question is incomplete because it does not have a minimal reproductible code. In other word, it is hard to help you.
Prior to VHDL-2008:
You cannot perform such action : d => din xor q_s(Nbit-1) because this line is seen as an operation and that is not possible in an instantiation of an entity or a component.
(like in this post for example: https://electronics.stackexchange.com/questions/184893/warning-actual-for-formal-port-a-is-neither-a-static-name-nor-a-globally-stati)
However, there is a way to work around that, you have to create a new signal
Notice that when you use your code, the error should be something like: Actual for formal port a is neither a static name nor a globally static expression
With VHDL-2008:
If look in the norm: http://www.fis.agh.edu.pl/~skoczen/hdl/ieee_std/ieee1076-2008.pdf
You can find on paragraph 6.5.6.3 Port clauses:
If a formal port of mode in is associated with an expression that is not globally static (see 9.4.1) and the
formal is of an unconstrained or partially constrained composite type requiring determination of index
ranges from the actual according to the rules of 5.3.2.2, then the expression shall be one of the following:
The name of an object whose subtype is globally static
An indexed name whose prefix is one of the members of this list
A slice name whose prefix is one of the members of this list and whose discrete range is a globally static discrete range
An aggregate, provided all choices are locally static and all expressions in element associations are expressions described in this list
A function call whose return type mark denotes a globally static subtype
A qualified expression or type conversion whose type mark denotes a globally static subtype
An expression described in this list and enclosed in parentheses
In other word, in VHDL-2008, the code you provided should work.
About your initialization problem, it is unclear, what signals/varibles are not initialized ? The best you can do is, if your first question is well answered by this post, then accept it has a solution or edit your question for more clarity. Then ask an other question in an other thread about the initialization problem. You can also post your question on Electronics Stackexchange

How to delay the reset signal in a counter build with D flip-flops in VHDL?

I'm trying to build a modulo 25 counter using sn7493 counters. I've modeled my own D flip-flops and used them to recreate the internal structure of the counter. It works until it needs to reset. After '24' I get '2' instead of '0'. I guess the reset signal is to short to properly reset it, but I have no idea how to make it longer.
--DFF model
LIBRARY ieee;
USE ieee.std_logic_1164.all;
ENTITY D IS
PORT(
Din, CLK, RES :IN std_logic;
Q :OUT std_logic
);
END D;
ARCHITECTURE behavior of D IS
begin
PROCESS(CLK)
begin
if rising_edge(CLK) then
Q <= Din;
end if;
if (RES='0') then
Q <= '0';
end if;
end PROCESS;
END behavior;
--SN7493 counter model
LIBRARY ieee;
USE ieee.std_logic_1164.all;
ENTITY c7493 IS
PORT (
CLKA,CLKB,R1,R2: IN std_logic;
Q: INOUT std_logic_vector(0 to 3)
);
END c7493;
ARCHITECTURE behavior of c7493 IS
COMPONENT D IS
PORT(
Din, CLK, RES :IN std_logic;
Q :OUT std_logic
);
END COMPONENT D;
signal A_out,B_out,C_out,D_out: std_logic;
BEGIN
DA: D PORT MAP(
Din => not A_out,
CLK => not CLKA,
RES =>R1 nand R2,
Q => A_out
);
DB: D PORT MAP(
Din => not B_out,
CLK => not CLKB,
RES => R1 nand R2,
Q => B_out
);
DC: D PORT MAP(
Din => B_out xor C_out,
CLK => not CLKB,
RES =>R1 nand R2,
Q => C_out
);
DD: D PORT MAP(
Din => (B_out and C_out) xor D_out,
CLK => not CLKB,
RES =>R1 nand R2,
Q => D_out
);
Q(0) <=A_out;
Q(1) <=B_out;
Q(2) <=C_out;
Q(3) <=D_out;
END behavior;
--main program
LIBRARY ieee;
USE ieee.std_logic_1164.all;
ENTITY plytka IS
PORT(
SW: IN std_logic_vector(0 to 0);
LEDR: OUT std_logic_vector (4 downto 0)
);
END plytka;
ARCHITECTURE projekt OF plytka IS
COMPONENT c7493 IS
PORT(
CLKA,CLKB,R1,R2: IN std_logic;
Q: INOUT std_logic_vector(0 to 3)
);
END COMPONENT c7493;
signal A_out,B_out,C_out,D_out,E_out: std_logic;
BEGIN
c7493A: c7493 PORT MAP(
CLKA => SW(0),
CLKB => A_out,
R1 => (A_out and D_out and E_out),
R2 => (A_out and D_out and E_out),
Q(0) => A_out,
Q(1) => B_out,
Q(2) => C_out,
Q(3) => D_out
);
c7493B: c7493 PORT MAP(
CLKA => A_out and B_out and C_out and D_out,
CLKB => '0',
R1 => (A_out and D_out and E_out),
R2 => (A_out and D_out and E_out),
Q(0) => E_out
);
LEDR <= (E_out,D_out,C_out,B_out,A_out);
END projekt;
One simple way would be too create a small vector and clock in the reset signal (assuming synchronous reset!) and then check if its all zero or not...
std_logic_vector reset_vec : std_logic_vector(3 downto 0) := (others => '0');
-- Then in architecture body
reset_vec <= reset_vec(2 downto 0) & reset when rising_edge(clk);
elong_reset <= '1' when reset_vec /= "0000" OR reset = '1' else '0';
Good luck!

Shift Right Register-ParallelLoad

I have to create an n bit shift right register(used 4 bits here) with parallel load. For this purpose i used a Mux 2 in 1 and d flip flops. If load is '1' then the register is loaded with a value(DataIn), otherwise the register starts to shift.
The code for the Multiplexer is:
entity Mux2in1onebit is
Port ( A : in STD_LOGIC;
B : in STD_LOGIC;
Q : out STD_LOGIC;
sel : in STD_LOGIC);
end Mux2in1onebit;
architecture Behavioral of Mux2in1onebit is
begin
Q <= A when sel = '0' else
B;
end Behavioral
The code for the flip flop:
entity FlipFlop is
Port ( Din : in STD_LOGIC;
Q : out STD_LOGIC;
Enable : in STD_LOGIC;
Clk : in STD_LOGIC;
Reset : in STD_LOGIC);
end FlipFlop;
architecture Behavioral of FlipFlop is
signal Qtemp : std_logic;
begin
process(clk)
begin
if(rising_edge(clk)) then
if(reset = '1') then
Qtemp <= '0';
else
if (enable = '1') then
Qtemp <= Din;
else
Qtemp <= Qtemp;
end if;
end if;
end if;
end process ;
Q <= Qtemp;
end Behavioral;
Now in a top level module i have connected the muxs and the flip flops as following:
entity ShiftRegister is
Port ( DataIn : in STD_LOGIC_VECTOR (3 downto 0);
DataOut : out STD_LOGIC_VECTOR (3 downto 0);
Enable : in STD_LOGIC;
Load :in STD_LOGIC;
BitIn : in STD_LOGIC;
Bitout : out STD_LOGIC;
Reset : in STD_LOGIC;
Clk : in STD_LOGIC);
end ShiftRegister;
architecture Structural of ShiftRegister is
COMPONENT FlipFlop
PORT(
Din : IN std_logic;
Enable : IN std_logic;
Clk : IN std_logic;
Reset : IN std_logic;
Q : OUT std_logic
);
END COMPONENT;
COMPONENT Mux2in1onebit
PORT(
A : IN std_logic;
B : IN std_logic;
sel : IN std_logic;
Q : OUT std_logic
);
END COMPONENT;
signal sigdin, sigq : std_logic_vector(3 downto 0);
begin
MBIT3: Mux2in1onebit PORT MAP(
A => BitIn,
B => DataIn(3),
Q => sigdin(3),
sel => Load
);
BIT3: FlipFlop PORT MAP(
Din => sigdin(3),
Q => sigq(3),
Enable => Enable,
Clk => Clk,
Reset => Reset
);
MBIT2: Mux2in1onebit PORT MAP(
A => sigq(3),
B => DataIn(2),
Q => sigdin(2),
sel => Load
);
BIT2: FlipFlop PORT MAP(
Din => sigdin(2),
Q => sigq(2),
Enable => Enable,
Clk => Clk,
Reset => Reset
);
MBIT1: Mux2in1onebit PORT MAP(
A => sigq(2),
B => DataIn(1),
Q => sigdin(1),
sel => Load
);
BIT1: FlipFlop PORT MAP(
Din => sigdin(1),
Q => sigq(1),
Enable => Enable,
Clk => Clk,
Reset => Reset
);
MBIT0: Mux2in1onebit PORT MAP(
A => sigq(1),
B => DataIn(0),
Q => sigdin(0),
sel => Load
);
BIT0: FlipFlop PORT MAP(
Din => sigdin(0),
Q => sigq(0),
Enable => Enable,
Clk => Clk,
Reset => Reset
);
BitOut <= sigq(0);
DataOut <= sigdin;
end Structural;
Now when i simulate the above code, for reset = '1' the flip flops are set to 0 and when load = '1' then the DataIn is loaded, as expected. But when enable = '1' the register does not shift, but i get "0000" as a result. Thanks.
Your question isn't quite a Minimal, Complete, and Verifiable example, missing the stimuli and actual results.
All three entity and architecture pairs were missing context clauses (library ieee; use ieee.std_logic_1164.all;) and the architecture for Mux2in1onebit was missing a semicolon after end Behavioral.
After fixing those I wrote a simple testbench:
library ieee;
use ieee.std_logic_1164.all;
entity sr_tb is
end entity;
architecture fum of sr_tb is
signal datain: std_logic_vector (3 downto 0) := "1011"; -- load value
signal dataout: std_logic_vector (3 downto 0);
signal enable: std_logic := '0';
signal load: std_logic := '0';
signal bitin: std_logic;
signal bitout: std_logic;
signal reset: std_logic := '0';
signal clk: std_logic := '0';
begin
DUT:
entity work.shiftregister
port map (
datain => datain,
dataout => dataout,
enable => enable,
load => load,
bitin => bitin,
bitout => bitout,
reset => reset,
clk => clk
);
CLOCK:
process
begin
wait for 5 ns;
clk <= not clk;
if now > 160 ns then
wait;
end if;
end process;
STIMULI:
process
begin
wait for 6 ns;
reset <= '0';
wait for 10 ns;
reset <= '1';
wait for 10 ns;
reset <= '0';
wait for 10 ns;
load <= '1';
enable <= '1';
wait for 10 ns;
load <= '0';
enable <= '0';
wait for 10 ns;
bitin <= '0';
wait for 10 ns;
enable <= '1';
wait for 10 ns;
bitin <= '1';
wait for 10 ns;
bitin <= '0';
wait for 10 ns;
wait for 10 ns;
bitin <= '1';
wait for 10 ns;
wait;
end process;
end architecture;
And that produced:
Which shows sigq outputs of the four flip flops are correct and points out DataOut should be assigned from sigq instead of sigdin:
dataout <= sigdin; -- should be sigq
end architecture structural;
If you follow sigq(0) in the waveform you'll see it's values are consisted with the stimuli.
From your comment to your question you were also missing Enable being a '1' when loading.

control icap in Partial Reconfiguration

I'm going to implement partial reconfiguration on virtex5 Xilinx Board. I've written 3 modules(top module and up-counter and down-counter) and created bit streams by Plan-ahead.The result is shown by 2 LEDs(up or down count). My problem is how to exchange counter partitions? or how to control icap by time or an external signal?
I prefer to don't use Microblaze so write state machine for icap as below:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_arith.ALL;
use IEEE.STD_LOGIC_unsigned.ALL;
library UNISIM;
use UNISIM.VComponents.all;
Library UNIMACRO;
use UNIMACRO.vcomponents.all;
entity Main is
port(
Clk: in std_logic;
Output: out std_logic_vector(2 downto 0)
);
end Main;
architecture Behavioral of Main is
signal Q: std_logic_vector(47 downto 0);
signal Load, Clk1hz, Clk1 : std_logic;
signal Local : std_logic_vector(1 downto 0);
component ROM ------------------------------ ROM Component Decleration
port (
Clka: in std_logic;
Addra: in std_logic_vector(11 downto 0);
Douta: out std_logic_vector(31 downto 0));
end component; -------------------------------------------------------End
signal ROM_Address, ROM_Address_Init : std_logic_vector(11 downto 0); -------- ROM and ICAP Signals Decleration
signal ROM_Data : std_logic_vector(31 downto 0);
signal ICAP_Din, ICAP_Dout : std_logic_vector(31 downto 0);
signal ICAP_CE, ICAP_Clk, ICAP_Clk1, En, ROM_Clk, ROM_Clk1, ICAP_WR : std_logic; --------------------------------------End
begin
Clk1Hz <= Clk1;
process(clk)
begin
if (rising_edge(Clk)) then
if (Q=x"000005F5E100") then
Load <= '1';
Clk1 <= not Clk1;
else
Load <= '0';
end if;
end if;
end process;
Output(0) <= not(En);
Output(2 downto 1) <= not(Local);
----------------------------------------------------
----------------------------------------------------
U_UpDown: entity work.Counter
port map(
Clk => Clk1Hz, En => '1', Output => Local
);
----------------------------------------------------
----------------------------------------------------
U1 : COUNTER_LOAD_MACRO
generic map (
COUNT_BY => X"000000000001", -- Count by value
DEVICE => "VIRTEX5", -- Target Device: "VIRTEX5", "VIRTEX6", "SPARTAN6"
WIDTH_DATA => 48) -- Counter output bus width, 1-48
port map (
Q => Q, -- Counter output, width determined by WIDTH_DATA generic
CLK => CLK, -- 1-bit clock input
CE => '1', -- 1-bit clock enable input
DIRECTION => '1', -- 1-bit up/down count direction input, high is count up
LOAD => LOAD, -- 1-bit active high load input
LOAD_DATA => x"000000000000", -- Counter load data, width determined by WIDTH_DATA generic
RST => '0' -- 1-bit active high synchronous reset
);
--------------------------------------------
--------------------------------------------
process(Clk1Hz) -------------------------------------------- ROM and ICAP Modules and Related Codes
variable Count : integer range 0 to 6:=0;
begin
if (rising_edge(Clk1Hz)) then
Count := Count + 1;
if (Count = 2) then
En <= '1';
ROM_Address_Init <= conv_std_logic_vector(0,12);
else
En <= '0';
end if;
end if;
end process;
--------------------------------------------
--------------------------------------------
U_ROM: ROM
port map (Clka => ROM_Clk1, Addra => ROM_Address, Douta => ROM_Data);
BUFG_inst : BUFG
port map (
O => ROM_Clk1, -- Clock buffer output
I => ROM_Clk -- Clock buffer input
);
BUFG_inst1 : BUFG
port map (
O => ICAP_Clk1, -- Clock buffer output
I => ICAP_Clk -- Clock buffer input
);
ICAP_VIRTEX5_inst : ICAP_VIRTEX5
generic map (
ICAP_WIDTH => "X32") -- "X8", "X16" or "X32"
port map (
BUSY => open, -- Busy output
O => ICAP_Dout, -- 32-bit data output
CE => ICAP_CE, -- Clock enable input
CLK => ICAP_Clk1, -- Clock input
I => ICAP_Din, -- 32-bit data input
WRITE => ICAP_WR -- Write input
);
-- ICAP_Din(31 downto 8) <= x"000000"; -------------------------------End
U_ICAP_SM: block -------------------------------------
type State_Type is (State0, State00, State1, State2, State3, State4, State5, State6);
signal Pr_State, Nx_State : State_Type;
begin
Process(En,Clk)
begin
if (En = '0') then
Pr_State <= State0;
elsif (rising_edge(Clk)) then
Pr_State <= Nx_State;
end if;
end process;
process(Pr_State)
begin
case Pr_State is --*****
when State0 =>
Nx_State <= State00;
ROM_Address <= x"000";
ICAP_WR <= '1';
ROM_Clk <= '0';
ICAP_Clk <= '0';
ICAP_CE <= '1';
when State00 =>
Nx_State <= State1;
ICAP_WR <= '0';
when State1 =>
Nx_State <= State2;
ICAP_CE <= '0';
ROM_Clk <= '1';
when State2 =>
Nx_State <= State3;
ICAP_Din <= ROM_Data;
ROM_Clk <= '0';
when State3 =>
Nx_State <= State4;
ICAP_Clk <= '1';
when State4 =>
Nx_State <= State5;
ICAP_Clk <= '0';
when State5 =>
if (ROM_Address = conv_std_logic_vector(3134,12)) then
Nx_State <= State6;
ICAP_CE <= '1';
ROM_Address <= X"000";
else
Nx_State <= State1;
ROM_Address <= (ROM_Address + 1);
end if;
when State6 =>
ICAP_WR <= '1';
end case;
end process;
end Block U_ICAP_SM; -----------------------------------
end Behavioral;
I saved the bit stream (.coe file) of one of the counter (for example up-counter) in ROM. By default circuit is down counting, but when I exchange bit stream by icap (load .coe file of up-counter from ROM) nothing happens and circuit is counting down. (***** in the code)
how can I fix it?

Resources