vishy71
Full Member level 2
- Joined
- Dec 16, 2010
- Messages
- 126
- Helped
- 3
- Reputation
- 6
- Reaction score
- 3
- Trophy points
- 1,298
- Location
- Iran
- Activity points
- 2,296
Hi.I am so sorry because of my poor English speaking!
I am trying to write a simple code in VHDL for RS232 to receive data through a wire as you know.here is my code!
something is wrong! please help me to solve this challenge!thanks
as you can see,bit_cnt pulsed twice!!!!!why? and number of "get" state must be 8 not 4!!!!
here is my code:
also I try to make new state with "plus" name to increase bit_cnt but when I do that,it increased twice!!! for example : bit_cnt<="0000" and after bit_cnt<=bit_cnt+1 it was "0010"!!!!!!
thanks.
I am trying to write a simple code in VHDL for RS232 to receive data through a wire as you know.here is my code!
something is wrong! please help me to solve this challenge!thanks
as you can see,bit_cnt pulsed twice!!!!!why? and number of "get" state must be 8 not 4!!!!
here is my code:
Code:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity rcv is
port(din,clk:in std_logic;dout:out std_logic_vector(7 downto 0);ready:out std_logic);
end entity;
architecture arch_rcv of rcv is
type rcv_state is (idle,start,wt,plus,get,stop);
signal curr_state,next_state:rcv_state;
signal bit_cnt:unsigned(3 downto 0):="0000";
signal clk_cnt:unsigned(15 downto 0):=x"0000";
begin
process(curr_state,din,clk)is
begin
if(clk'event and clk='1') then
curr_state<=next_state;
elsif(din'event and din='0' and curr_state=idle)then
next_state<=start;
elsif(curr_state=idle)then
bit_cnt<="0000";
clk_cnt<=x"0000";
ready<='1';
elsif(curr_state=start)then
ready<='0';
if(clk_cnt=2600)then
next_state<=wt;
clk_cnt<=x"0000";
else
clk_cnt<=clk_cnt+1;
end if;
elsif(curr_state=wt)then
if(clk_cnt=5200)then
clk_cnt<=x"0000";
next_state<=get;
else
clk_cnt<=clk_cnt+1;
end if;
elsif(curr_state=get)then
if(bit_cnt=8)then
next_state<=stop;
else
dout(to_integer(bit_cnt))<=din;
bit_cnt<=bit_cnt+1;
next_state<=wt;
end if;
elsif(curr_state=plus)then
elsif(curr_state=stop)then
if(clk_cnt=5200)then
next_state<=idle;
else
clk_cnt<=clk_cnt+1;
end if;
end if;
end process;
end arch_rcv;
also I try to make new state with "plus" name to increase bit_cnt but when I do that,it increased twice!!! for example : bit_cnt<="0000" and after bit_cnt<=bit_cnt+1 it was "0010"!!!!!!
thanks.