Junus2012
Advanced Member level 5
- Joined
- Jan 9, 2012
- Messages
- 1,552
- Helped
- 47
- Reputation
- 98
- Reaction score
- 53
- Trophy points
- 1,328
- Location
- Italy
- Activity points
- 15,235
Dear friends
I writing a code for serial to parallel converter, the serial data consist of 10 bits, (start bit, 7 data bits, parity bit, end bit).. the conversion starts when the start bit is one and ended with end bit.
I used the state machine for reading the data in sequence and at the end put all them together in a register and show them at the output.
The problem I getting is that my state machine stop at state seven (which is related to data seven of the input), after that the state machine goes to the first state which i named it idle and ignores the state eight, nine.
if you look on to my code you will see im clearly put the condition to go state eight after seven or nine after eight,, but I cant find any reason that makes those states doesnt appear.
Please I need your kind help and any suggestion will be very appreciated.
thank you very much;
below is my code
*********************************************
I writing a code for serial to parallel converter, the serial data consist of 10 bits, (start bit, 7 data bits, parity bit, end bit).. the conversion starts when the start bit is one and ended with end bit.
I used the state machine for reading the data in sequence and at the end put all them together in a register and show them at the output.
The problem I getting is that my state machine stop at state seven (which is related to data seven of the input), after that the state machine goes to the first state which i named it idle and ignores the state eight, nine.
if you look on to my code you will see im clearly put the condition to go state eight after seven or nine after eight,, but I cant find any reason that makes those states doesnt appear.
Please I need your kind help and any suggestion will be very appreciated.
thank you very much;
below is my code
*********************************************
Code VHDL - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; entity spc_state is Port ( clk : in STD_LOGIC; rst : in STD_LOGIC; d_in : in STD_LOGIC; ready : out STD_LOGIC:='0'; err : out STD_LOGIC:='0'; d_out : out STD_LOGIC_VECTOR (6 downto 0):="0000000"); end spc_state; architecture Behavioral of spc_state is type state is (idle, one, two, three, four, five, six, seven, eight, nine); signal pres_state, next_state : state; signal reg : std_logic_vector (9 downto 1); begin process (clk, rst) begin if (rst = '1')then pres_state <= idle; elsif (clk' event and clk = '1') then pres_state <= next_state; end if; end process; process (pres_state, d_in) begin next_state <= pres_state; case pres_state is when idle => if d_in = '1' then next_state <= one; else next_state <= idle; end if; when one => reg(1)<= d_in; next_state <= two; when two => reg(2)<= d_in; next_state <= three; when three => reg(3)<= d_in; next_state <= four; when four => reg(4)<= d_in; next_state <= five; when five => reg(5)<= d_in; next_state <= six; when six => reg(6)<= d_in; next_state <= seven; when seven => reg(7) <= d_in; next_state <= eight; when eight => reg(8) <= d_in; next_state <= nine; when nine => reg(9) <= d_in; next_state <= idle; when others => next_state <= idle; end case; end process; process (pres_state) variable temp : std_logic:='0'; variable temp2: std_logic_vector(7 downto 1):="0000000"; begin case pres_state is when idle => temp := reg(1) xor reg(2) xor reg(3) xor reg(4) xor reg(5) xor reg(6) xor reg(7) xor reg(8) xor reg(9); err <= temp; if temp = '0' then ready <= '1'; d_out <= reg(7 downto 1); temp2 := reg(7 downto 1); end if; when others => d_out <= temp2; end case; end process; end Behavioral;
Last edited by a moderator: