Question

I'm a beginner and I need a little help . My "current_s" is changing whenever rising edge of the clock detected. But, I want it to change only once when "Dot" or "Dash" is '1'.

I tried to create a signal like: Go_s<=Dot or Dash; And then tried to use its rising_edge to enable the process, but I've been told that it's not a good idea. But I can't think anything else.

library IEEE;
use IEEE.STD_LOGIC_1164.all;
use IEEE.NUMERIC_STD.all;
-------------------------------------------------------------------------------
Entity Let5 is
Port(
Clk: in std_logic;
Reset: in std_logic;
Dot: in std_logic;
Dash: in std_logic;
one_spc: in std_logic;
three_spc: in std_logic);
END Let5;
-------------------------------------------------------------------------------
Architecture Let5_a of Let5 is
-------------------------------------------------------------------------------
Type state is (Start, A, B, A_1, A_2, B_1, B_2);
Signal current_s: state;
-------------------------------------------------------------------------------
BEGIN
---------------------------------------------------------------------------------
PROCESS(Clk, Reset)
BEGIN
    IF(Reset='1')Then
    current_s<=Start;   
    ELSIF(Clk='1' and Clk'event)Then
    Case current_s is

        When Start =>
            IF(Dot='1')Then
                current_s<=A;               
            ELSIF(Dash='1')Then
                current_s<=B;               
            END IF;         

        When A =>       
            IF(Dot='1')Then
                current_s<=A_1;             
            ELSIF(Dash='1')Then
                current_s<=A_2;             
            END IF;     

        When B =>
            IF(Dot='1')Then
                current_s<=B_1;
            ELSIF(Dash='1')Then
                current_s<=B_2;
            END IF;

        When OTHERS => current_s <= Start;
    END Case;
    END IF;
END PROCESS;
-------------------------------------------------------------------------------
END Let5_a;

Simulation:

enter image description here

Was it helpful?

Solution

Add an conditional update of current_s inside the clocked process, using:

...
elsif (Clk='1' and Clk'event) then
  if (Dot = '1') or (Dash = '1') then
    case current_s is
      ...

Then current_s is updated only when the condition (Dot = '1') or (Dash = '1') is TRUE.

It is correct what you have been told, that you should not make an additional signal Go_s checking for rising edge of this, since this is not the way to implement standard synchronous designs. Instead use a signal clock and make updates on rising edge, for example using rising_edge(Clk) instead of Clk='1' and Clk'event, and then make the updated conditional to whatever signal required. FPGAs and tools are made to implement this kind of design.

OTHER TIPS

Actually it ought to work reading Dot or Dash in the way you do now; I suspect something else is the problem.

If Dot is high for three consecutive clock cycles...

  • in the first, you get to State A.
  • in the second, you get to State A1.
  • in the third, ... there is no handler for State A1 so the "when others" clause takes you back to Start.

I suspect you actually want to remain in State A1 (or even State A) until either :

  • Dot is no longer 1, or:
  • Dash is 1

and to accomplish this (remain in State A1 instead of retriggering) you need:

When A1 =>       
    if Dot = '0' then
        current_s <= Start;             
    elsif Dash = '1' then
        current_s <= A_2;             
    end if;  

Treat states Bn similarly for Dash.

If I'm misinterpreting and you actually want to remain in State A longer, it should now be clear how to make that happen instead.

Your code has a number of problems, and they are NOT related to Dot and Dash, because it is OK to have one with higher priority than the other. The present state changes at every clock cycle because that is exactly what you told the circuit to do when Dot and/or Dash is '1'. Note that in the states start, A, and B the machine changes to a state that is not in this list (start, A, B), so the WHEN OTHERS statement causes it to return to the start state at the next clock edge, with this repeated indefinitely.

My suggestion is that you draw the intended state transition diagram very carefuly, after which re-writing the code should be straightforward, especially because this is a relatively simple problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top