J
john
Guest
Hello All,
I am need for some serious advice. I am trying to synchronize the
passing of the control signal "Reset_counter" between two clocks
namely "clk1x" and clk_b = clk_synch. The clk_b is equal to
"clk_divider (6) and generated by dividing the "clk1x" as you can see
in the following code.
The sequential machine is running on "clk1x" and it generates the
signal called "Reset_counter" to reset the 49 bit counter
"p2s_counter". This counter outputs 49 bit of serial data at the
rising edge of the slower clock "clk_synch". Because "clk_synch" is
slower than the "clk1x", so I tired to pass the signal "Reset_counter"
through atleast three flip flops as you can see in the code clocking
with the slower clock " clk_synch".
Then I used the resultant output signal " synch_reset_2" to Reset the
49 bit counter. The sequential state machine " ser_out_state" checks
running on "clk1x" for p2s counter to get equal to count 49. after the
counter reaches its count the state machine gets into a new state.
Since, "clk1x " is way faster than "clk_synch" thats why it will not
miss the p2s_counter signal.
I am using xess board and foundation code and have all sorts of
problems simulating the code. SO thats why i am testing the code using
Logic Analyzer.
My questions is
Am I synchronizing the clocks in the right way?
I will appreciate any advice!
John
combinatorial : process(err_r, addr_r, dIn, rand, begun, done,
rdPending, doAgain )
begin
case state_r is
when INIT =>
Reset_counter <= '1';
state_x <= Ser_buff_LOAD_1;
when Ser_buff_LOAD_1 =>
Reset_counter <= '1';
state_x <= Ser_buff_LOAD_2;
When Ser_buff_LOAD_2 =>
Reset_counter <='1';
state_x <= Ser_buff_LOAD_3;
When Ser_buff_LOAD_3 =>
Reset_counter <='1';
state_x <= Reset_state;
when Reset_state =>
Reset_counter <='1';
state_x<= Tag_state;
when Tag_state =>
Reset_counter <='1';
state_x <= ser_out_state;
----------------------------------------
when ser_out_state =>
Reset_counter <='1';
if ( p2s_counter /= "110001") then
Reset_counter <='0';
state_x <= ser_out_state;
else
Reset_counter <='1';
state_x <= Ser_buff_LOAD_1;
end if;
---------------------------------------
When EMPTY_PIPE =>
Reset_counter <='1';
if done = YES then
cke <= YES;
end if;
if rdPending = NO then
state_x <= STOP;
end if;
When others =>
end process;
------------------------------------
-- clk1x is the main clock generated by xess's program
update: process (clk1x)
begin
if clk1x'event and clk1x = '1' then
if rst = YES then -- main reset from xess's program
state_r <= INIT;
else
addr_r <= addr_x;
state_r <= state_x;
end if;
end if;
end process;
------------------------------------
clk_synch <= clk_b;
-------------------------------------
-- 49 bits, parallel to serial port conversion--
serial_count : process ( clk_synch)
begin
if rising_edge (clk_synch) then
if ( synch_reset_2 = '0') Then
p2s_counter <= p2s_counter + 1;
ser_out<=ser_buff ( to_integer ( p2s_counter ) );
else
p2s_counter <= ( others =>'0');
end if;
end if;
end process;
------------------------------------
Two_flip_flop_synch: process(clk_synch, Reset_counter)
variable synch_reset_a : std_logic;
variable synch_reset_b: std_logic;
begin
If (Reset_counter = '1') Then
synch_reset_a := '1';
synch_reset_b := '1';
elsif rising_edge (clk_synch) then
synch_reset_a :=synch_reset_b;
synch_reset_b:= '0';
end if;
synch_reset <= synch_reset_a ;
end process;
-----------------------------------
-- Third Synchronizing Flip Flop to sycnhronize the Reset_counter --
third_flip_flop_synch : process (clk_synch,Reset_counter )
variable synch_reset_c: std_logic;
variable synch_reset_d:std_logic;
Begin
if ( Reset_counter ='1') then
synch_reset_c:= '1';
synch_reset_d:='1';
elsif rising_edge (clk_synch) then
synch_reset_c:= synch_reset;
synch_reset_d:='0';
end if;
done_1 <= synch_reset_c;
synch_reset_2<= synch_reset_c;
end process;
----------------------------------
-- Dividing the 100MHz clk1x to 1MHz clk_synch--
div : process ( rst,clk1x)
begin
If ( rst = '1') Then
clk_divider <= "00000000000";
elsIf rising_edge (clk1x) then
clk_divider <= clk_divider + 1;
end if;
end process;
---------------------------------
End arch;
-- End of the VHDL Program --
I am need for some serious advice. I am trying to synchronize the
passing of the control signal "Reset_counter" between two clocks
namely "clk1x" and clk_b = clk_synch. The clk_b is equal to
"clk_divider (6) and generated by dividing the "clk1x" as you can see
in the following code.
The sequential machine is running on "clk1x" and it generates the
signal called "Reset_counter" to reset the 49 bit counter
"p2s_counter". This counter outputs 49 bit of serial data at the
rising edge of the slower clock "clk_synch". Because "clk_synch" is
slower than the "clk1x", so I tired to pass the signal "Reset_counter"
through atleast three flip flops as you can see in the code clocking
with the slower clock " clk_synch".
Then I used the resultant output signal " synch_reset_2" to Reset the
49 bit counter. The sequential state machine " ser_out_state" checks
running on "clk1x" for p2s counter to get equal to count 49. after the
counter reaches its count the state machine gets into a new state.
Since, "clk1x " is way faster than "clk_synch" thats why it will not
miss the p2s_counter signal.
I am using xess board and foundation code and have all sorts of
problems simulating the code. SO thats why i am testing the code using
Logic Analyzer.
My questions is
Am I synchronizing the clocks in the right way?
I will appreciate any advice!
John
combinatorial : process(err_r, addr_r, dIn, rand, begun, done,
rdPending, doAgain )
begin
case state_r is
when INIT =>
Reset_counter <= '1';
state_x <= Ser_buff_LOAD_1;
when Ser_buff_LOAD_1 =>
Reset_counter <= '1';
state_x <= Ser_buff_LOAD_2;
When Ser_buff_LOAD_2 =>
Reset_counter <='1';
state_x <= Ser_buff_LOAD_3;
When Ser_buff_LOAD_3 =>
Reset_counter <='1';
state_x <= Reset_state;
when Reset_state =>
Reset_counter <='1';
state_x<= Tag_state;
when Tag_state =>
Reset_counter <='1';
state_x <= ser_out_state;
----------------------------------------
when ser_out_state =>
Reset_counter <='1';
if ( p2s_counter /= "110001") then
Reset_counter <='0';
state_x <= ser_out_state;
else
Reset_counter <='1';
state_x <= Ser_buff_LOAD_1;
end if;
---------------------------------------
When EMPTY_PIPE =>
Reset_counter <='1';
if done = YES then
cke <= YES;
end if;
if rdPending = NO then
state_x <= STOP;
end if;
When others =>
end process;
------------------------------------
-- clk1x is the main clock generated by xess's program
update: process (clk1x)
begin
if clk1x'event and clk1x = '1' then
if rst = YES then -- main reset from xess's program
state_r <= INIT;
else
addr_r <= addr_x;
state_r <= state_x;
end if;
end if;
end process;
------------------------------------
clk_synch <= clk_b;
-------------------------------------
-- 49 bits, parallel to serial port conversion--
serial_count : process ( clk_synch)
begin
if rising_edge (clk_synch) then
if ( synch_reset_2 = '0') Then
p2s_counter <= p2s_counter + 1;
ser_out<=ser_buff ( to_integer ( p2s_counter ) );
else
p2s_counter <= ( others =>'0');
end if;
end if;
end process;
------------------------------------
Two_flip_flop_synch: process(clk_synch, Reset_counter)
variable synch_reset_a : std_logic;
variable synch_reset_b: std_logic;
begin
If (Reset_counter = '1') Then
synch_reset_a := '1';
synch_reset_b := '1';
elsif rising_edge (clk_synch) then
synch_reset_a :=synch_reset_b;
synch_reset_b:= '0';
end if;
synch_reset <= synch_reset_a ;
end process;
-----------------------------------
-- Third Synchronizing Flip Flop to sycnhronize the Reset_counter --
third_flip_flop_synch : process (clk_synch,Reset_counter )
variable synch_reset_c: std_logic;
variable synch_reset_d:std_logic;
Begin
if ( Reset_counter ='1') then
synch_reset_c:= '1';
synch_reset_d:='1';
elsif rising_edge (clk_synch) then
synch_reset_c:= synch_reset;
synch_reset_d:='0';
end if;
done_1 <= synch_reset_c;
synch_reset_2<= synch_reset_c;
end process;
----------------------------------
-- Dividing the 100MHz clk1x to 1MHz clk_synch--
div : process ( rst,clk1x)
begin
If ( rst = '1') Then
clk_divider <= "00000000000";
elsIf rising_edge (clk1x) then
clk_divider <= clk_divider + 1;
end if;
end process;
---------------------------------
End arch;
-- End of the VHDL Program --