1

I am looking at an FSM example in a digital design literature book where the idea is to create a simple FSM using a Moore machine for a Manchester encoder.

enter image description here

The FSM takes two inputs. d is the data signal, and v is the data valid signal. d is the signal to be encoded. The output of the FSM is y, the encoded result. The book doesn't specify any relationship between the clock generating the input signal d and the one clk driving the FSM. But, it mentions that the max speed that can be achieved is half the speed of the clock driving d, which is expected. It takes a transition from one level to another (d0 -> d1) to generate one output data (y0).

The state diagram suggested by the book is the following.

enter image description here

Notations: d' <=> (d = '0') and d <=> (d = '1'). Same for v.

The book doesn't explain how the states were derived and what they represent. This is an extract of the text.

enter image description here

I don't understand why the output y is asserted in the s0b state. If d is initially low, the FSM goes to s0a state. At that point, the next state is set to s0b regardless of the input, and the output y is asserted (y <= '1'). But, is this correct? The output should be 0 since we start from d=0 (a transition from low to high). (Update The reason of my confusion here, is that I was trying to solve a different problem. I was making a state diagram for a Decoder.)

I simulated the code implementing this state diagram and I see a strange behaviour in the output y.

library ieee;
use ieee.std_logic_1164.all;

entity manchester_encoder is
    port (
        clk, reset : in std_logic;
        v, d       : in std_logic;
        y          : out std_logic
    );
end manchester_encoder;

architecture moore_arch of manchester_encoder is
    type state_type is (idle, s0a, s0b, s1a, s1b);
    signal state_reg, state_next : state_type;
begin
    -- state register
    process (clk, reset)
    begin
        if (reset = '0') then
            state_reg <= idle;
        elsif (clk'event and clk = '1') then
            state_reg <= state_next;
        end if;
    end process;

    -- next-state logic
    process (state_reg, v, d)
    begin
        case state_reg is
            when idle =>
                if v = '0' then
                    state_next <= idle;
                else
                    if d = '0' then
                        state_next <= s0a;
                    else
                        state_next <= s1a;
                    end if;
                end if;
            when s0a =>
                state_next <= s0b;
            when s1a =>
                state_next <= s1b;
            when s0b =>
                if v = '0' then
                    state_next <= idle;
                else
                    if d = '0' then
                        state_next <= s0a;
                    else
                        state_next <= s1a;
                    end if;
                end if;
            when s1b =>
                if v = '0' then
                    state_next <= idle;
                else
                    if d = '0' then
                        state_next <= s0a;
                    else
                        state_next <= s1a;
                    end if;
                end if;
        end case;
    end process;

    -- Moore output logic
    y <= '1' when state_reg = s1a or state_reg = s0b else
        '0';

end moore_arch;

As expected, the waveforms show that y is asserted erroneously following a transition from 0 to 1 in the input signal d. I am starting to believe that this state diagram is incorrect. Can someone help me figure this out?

Another concern is how to define an FSM clock that allows to sample the transitions of the d correctly as they come.

enter image description here

Update

I re-simulated the DUT using the suggested tips. The waveforms behaves correctly.

enter image description here

Theo
  • 113
  • 4
  • [Finite State Machine: Principle and Practice](http://ebook.pldworld.com/_eBook/FPGA%EF%BC%8FHDL/-Examples-/FSM%20design%20examples.pdf) – user16145658 May 16 '23 at 16:25
  • The IEEE tells us it's part of RTL Hardware Design Using VHDL: Coding for Efficiency, Portability, and Scalability by Pong P. Chu, 2006, Wiley-IEEE – user16145658 May 16 '23 at 18:17
  • @user16145658 The output `y` is included in the waveforms. I can use the pattern provided in the example. I don't think the behaviour will be different. – Theo May 16 '23 at 21:01
  • The sample waveform [can be replicated](https://i.stack.imgur.com/SVT1j.jpg) (7 two clock cells between markers A and H) using the data pattern 0010011 with each bit taking two clocks. This without modifying the VHDL model. – user16145658 May 16 '23 at 22:26
  • @user16145658 Thanks for taking the time. In your waveform, your '0' input data is encoded differently in [A,B] and [C,D] intervals. In [A,B], you have a transition `0->1` and in [C,D] you have a transition `1->0` for the same input. – Theo May 16 '23 at 22:47
  • @user16145658 I understand the reason of my confusion. I was in fact thinking what a decoder does not an encoder hence my question. Thanks for the help mate. – Theo May 17 '23 at 09:31
  • [Old, but Still Useful: The Manchester Code](https://www.digikey.com/en/blog/old-but-still-useful-the-manchester-code). When you consider deriving clock from a 2X rate clock and also re-clocking data in to the 2X rate to line the two up the FSM version and the XOR version are of similar complexity. Which one is easier for the digital designer to express? – user16145658 May 18 '23 at 07:35

1 Answers1

1

You must stimulate the design in a way, that each bit at d, that shall be transfered, is active for 2 clock cycles. So if you want to transfer a 1 you need d=1 for 2 clock cylces, if you want to transfer a 0 you need d=0 for 2 clock cycles.

  • 1
    Precede the pictured text from the book Finite State Machine: Principle and Practice immediately with "The Manchester encoder transforms a regular data stream into a Manchester-coded data stream. Because an encoded bit includes as sequence of "01" or "1O", two clock cycles are needed. Thus, the maximal data rate is only half of the clock rate. There are two input signals. The d signal is the input data stream, and the v signal indicates whether the d" The paragraph was bisected by Figure 10.27. – user16145658 May 16 '23 at 17:06