Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

serial to parallel converter using state machine

Status
Not open for further replies.

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

*********************************************


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:

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.
I can't confirm the observation. The present code goes through all nine states after a '1' data input.

If the code is intended as an UART design, it's missing a number of things.
 
The "rst" input can send the state machine back to idle at any time if it is active. (If the rst code is correct). Anything going on with rst?
 
Dear Fvm

nice to see you again, its been long time :)

First thank you for your response

logically, there is no obvious or clear reason so the machine doesnt go to the eight or nine state,,, I got another confermation of the mistake,,, in the reset I have assigned the state to nine, but again it doesnt show nine, directly show idle rather..

As you said, im trying to use code in UART, kindly could you tell me please what is missing,, if you have some material about it with vhdl then plz it also help

many thanx :)

I can't confirm the observation. The present code goes through all nine states after a '1' data input.

If the code is intended as an UART design, it's missing a number of things.

- - - Updated - - -

The "rst" input can send the state machine back to idle at any time if it is active. (If the rst code is correct). Anything going on with rst?

hii

no no, the rst is not working well if i assign it to states from one to seven but eight and nine doesnt work with rst
 

Dear Fvm

nice to see you again, its been long time :)

First thank you for your response

logically, there is no obvious or clear reason so the machine doesnt go to the eight or nine state,,, I got another confermation of the mistake,,, in the reset I have assigned the state to nine, but again it doesnt show nine, directly show idle rather..

As you said, im trying to use code in UART, kindly could you tell me please what is missing,, if you have some material about it with vhdl then plz it also help

many thanx :)





- - - Updated - - -



hii

no no, the rst is not working well if i assign it to states from one to seven but eight and nine doesnt work with rst



sorry for the dumb question, but how do you know what states are taken ?
are you doing some simulation or using chipscope or logic analyser ?
mabee it actually works ...
 
sorry for the dumb question, but how do you know what states are taken ?
are you doing some simulation or using chipscope or logic analyser ?
mabee it actually works ...

im checking it by simulation

your suggestion is not dump, because sometimes i see some of my design work practically but not by simulation,, hope this will be the same case
 

I believe that you simulated a different code than that in post #1, because I don't see the said problem.

For a full operational UART design you need a baud rate generator, oversampling of input data, check for valid start bit after a half bit period.
 
im checking it by simulation

your suggestion is not dump, because sometimes i see some of my design work practically but not by simulation,, hope this will be the same case

mabe your simulation time resolution is too low ?

if you have modelsim you need to :
vsim -t ps
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top