parallel to parallal state machine to generate parity

Status
Not open for further replies.

jokester4u

Junior Member level 2
Joined
Nov 26, 2013
Messages
20
Helped
1
Reputation
2
Reaction score
0
Trophy points
1
Visit site
Activity points
124
can someone help me to generate parity with 8 bit of inputs parallel to parallel using state machine using vhdl code?

I have done serial to parallel converter

can someone fix for me ?

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:

You don't say what is wrong, or why you think there is something wrong. Do you have a testbench that shows an error?

I could be wrong but I'd say d_out is going to end up being implemented as a latch as it has to default to holding it's value if temp = '1'.

Most serial to parallel conversions use a shift register+counter instead of a demultiplex+FSM to convert the serial data to parallel.
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…