rfid tag reading vhdl code problem

K

Kenneth

Hi,
Does anyone written vhdl code on rfid tag reader, I have problem in
reading the tag values out from the contactless card. It need to
transmit characters of "sl00ff" + enter thru the rs232 to the reader
then it will send a valid authentication character 'L' back. However,
i try many way but still could not get the correct character back,
kept getting '?' back, attached is the code, could anyone help me to
see where i gone wrong. Thank you very much, I really need it to work
urgently.

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

-- Uncomment the following lines to use the declarations that are
-- provided for instantiating Xilinx primitive components.
--library UNISIM;
--use UNISIM.VComponents.all;

entity tophier is
Port (
mclkx16 : IN std_logic;
rxstrobe : IN std_logic;
txstrobe : IN std_logic;
reset : IN std_logic;
-- datain : OUT std_logic_vector(7 downto 0);
pushbutton : IN std_logic_vector(3 downto 0);
buttonmsg : IN std_logic;
Led_wr: out std_logic;
Led_rd : out std_logic;
Led_clk : out std_logic;
leddisplay : out std_logic_vector(7 downto 0);
-- dataout : INOUT std_logic_vector(7 downto 0);
-- receiver input signal, error, and status flags
rx : IN std_logic;
-- rxrdy : OUT std_logic;
parityerr : OUT std_logic;
framingerr: OUT std_logic;
overrun : OUT std_logic;
-- transmitter output signal and status flag
tx : OUT std_logic;
-- txrdy : OUT std_logic

sendstatus : out std_logic;
sendstatus1 : out std_logic;
sendstatus2 : out std_logic;
-----------------------------------------------------------
-- lcd driver pins location.
-----------------------------------------------------------
lcd_data: out std_logic_vector( 7 downto 0 );
lcd_rs: out std_logic;
lcd_rw: out std_logic;
lcd_enable: out std_logic;
led4cnt: out std_logic;
led4lcd: out std_logic
);
end tophier;

architecture Behavioral of tophier is
TYPE STATE_TYPE IS (init,s0,s1,s2,but,s2a,s2b,s2c,s2d,s2e,s2f,s2g,s3);
SIGNAL state : STATE_TYPE;
SIGNAL Link_din_led : std_logic_vector(7 downto 0);
SIGNAL Link_wr : std_logic;
SIGNAL Link_rd : std_logic;
SIGNAL Link_rxrdy : std_logic;
SIGNAL Link_txrdy : std_logic;
SIGNAL Link_txrx : std_logic;
SIGNAL button_clk : std_logic;
SIGNAL databus : std_logic_vector(7 downto 0);
SIGNAL datatxrx :std_logic_vector(7 downto 0);
SIGNAL send_select :std_logic_vector(7 downto 0);
SIGNAL lcdflagen : std_logic;
SIGNAL selparity : std_logic;
SIGNAL button :std_logic_vector(3 downto 0);

component pushbuttons is
PORT( pb1_in : IN std_logic;
pb2_in : IN std_logic;
pb3_in : IN std_logic;
pb4_in : IN std_logic;
clk : IN std_logic;
s1_pb : OUT std_logic;
s2_pb : OUT std_logic;
s3_pb : OUT std_logic;
s4_pb : OUT std_logic
);
end component;

component uart is
PORT (mclkx16 : IN std_logic;
rxstrobe : IN std_logic;
txstrobe : IN std_logic;
reset : IN std_logic;
selparity : IN std_logic;
datain : INOUT std_logic_vector(7 downto 0);
dataout : INOUT std_logic_vector(7 downto 0);
-- receiver input signal, error, and status flags
rx : IN std_logic;
rxrdy : OUT std_logic;
parityerr : OUT std_logic;
framingerr: OUT std_logic;
overrun : OUT std_logic;
-- transmitter output signal and status flag
tx : OUT std_logic;
txrdy : OUT std_logic);
end component;

component lcd_top is
port(
clock: in std_logic;
reset: in std_logic;
txrxmsgflag: in std_logic;
datatxrx : in std_logic_vector(7 downto 0);
lcd_data: out std_logic_vector( 7 downto 0 );
lcd_rs: out std_logic;
lcd_rw: out std_logic;
lcd_enable: out std_logic;
led4cnt: out std_logic;
led4lcd: out std_logic );
end component;

begin
------------------------------------------------------------
-- for debugging purpose only (not required)
led_rd <= Link_rd;
led_wr <= Link_wr;
--datain <= Link_din_led;
datatxrx <= databus;
leddisplay <= send_select;
selparity <= '0';
------------------------------------------------------------
u1 : uart PORT MAP
(
mclkx16 => mclkx16,
reset => reset,
datain => send_select,
dataout => databus,
parityerr => parityerr,
selparity => selparity,
framingerr => framingerr,
overrun => overrun,

-- receiver
rx => rx,
rxrdy => Link_rxrdy,
rxstrobe => Link_rd,

-- transmitter pins
tx => tx,
txrdy=> Link_txrdy,
txstrobe => Link_wr

);

u2 : lcd_top PORT MAP
(
clock => mclkx16,
reset => reset,
datatxrx => datatxrx,
lcd_data => lcd_data,
lcd_rs => lcd_rs,
lcd_rw => lcd_rw,
lcd_enable => lcd_enable,
txrxmsgflag => lcdflagen,
led4cnt => led4cnt,
led4lcd => led4lcd
);

u3 : pushbuttons PORT MAP
(
pb1_in => pushbutton(0),
pb2_in => pushbutton(1),
pb3_in => pushbutton(2),
pb4_in => pushbutton(3),
clk => mclkx16,
s1_pb => button(0),
s2_pb => button(1),
s3_pb => button(2),
s4_pb => button(3)
);

--------------------------------------------------
-- A very long timer delay ( currently not in use).
--------------------------------------------------
clock_divider: process (mclkx16) is
variable c:natural range 0 to 33554432;
begin
if mclkx16'event and mclkx16 = '1' then
if reset ='1' then
c:= 0;
button_clk <= '0';
else
c := (c + 1);
if c = 33554432 then
button_clk <= not button_clk;
c := 0;
end if;

end if;
end if;
end process clock_divider;

--------------------------------------------------
-- Main program running.
--------------------------------------------------
simulation : PROCESS (reset, mclkx16)
constant big: natural := 334455;
constant small: natural := 1;
constant nom: natural := 2;
variable cnt : natural range 0 to nom;
variable cnt1 : natural range 0 to 2;
variable readdelay : natural range 0 to big;
variable flag : boolean := false;

begin

if reset = '1' then
state <= init;
Link_wr <= '1';
cnt := 0;
cnt1 := 0;
readdelay := 0;
sendstatus <= '0';
sendstatus1 <= '0';
sendstatus2 <= '0';
flag := false;

elsif mclkx16'event and mclkx16 = '1' then
case state is
when init =>
if (flag = false) then
send_select <= "01111000"; -- 'x' reset once
-- leddisplay <= send_select;
flag := true;
link_wr <= '0';
else
Link_wr <= '1';
state <= init;
end if;

if (flag = true) then
if (cnt = nom) then
link_wr <= '1';
cnt := 0;
flag := false;
state <= s0;
else
cnt := cnt + 1;
state <= init;
end if;
end if;

when s0 =>
if cnt1 = 2 then
if pushbutton(0) = '1' then
state <= s1;
elsif pushbutton(1) = '1' then
state <= s2a;
elsif pushbutton(2) = '1' then
state <= s3;
elsif pushbutton(3) = '1' then
state <= init;
else
state <= s0;
end if;
cnt1 := 0;
else
cnt1 := cnt1 + 1;
state <= s0;
end if;


when s1 =>
if (flag = false) then
send_select <= "01110011"; -- 's' read serialno.
-- leddisplay <= send_select;
flag := true;
link_wr <= '0';
else
Link_wr <= '1';
state <= s1;
end if;

if (flag = true) then
if (cnt = nom) then
link_wr <= '1';
cnt := 0;
flag := false;
state <= s0;
else
state <= s1;
cnt := cnt + 1;
end if;
end if;
--------------------------------------------------------------

when s2 =>
if readdelay = 0 or flag = true then
sendstatus <= '1';
if (flag = false) then
send_select <= "01110011"; -- 's' login.
-- leddisplay <= send_select;
flag := true;
link_wr <= '0';
else
Link_wr <= '1';
state <= s2;
end if;
readdelay := 1;
if (flag = true) then
if (cnt = nom) then
link_wr <= '1';
cnt := 0;
flag := false;
-- state <= s2a;
else
cnt := cnt + 1;
state <= s2;
end if;
end if;

elsif readdelay < big then
readdelay := readdelay + 1;
state <= s2;
else
state <= s2a;
readdelay := 0;
end if;


when but =>
if (buttonmsg = '1') then
state <= s2a;
else
state <= but;
end if;

when s2a =>
if readdelay = 0 or flag = true then
if (flag = false) then
send_select <= "01101100"; -- 'l' login.
-- leddisplay <= send_select;
flag := true;
link_wr <= '0';
else
Link_wr <= '1';
state <= s2a;
end if;

readdelay := 1;
if (flag = true) then
if (cnt = nom) then
link_wr <= '1';
cnt := 0;
flag := false;
-- state <= s2b;
else
cnt := cnt + 1;
state <= s2a;
end if;
end if;
elsif readdelay < big then
readdelay := readdelay + 1;
state <= s2a;
else
state <= s2b;
readdelay := 0;
end if;

when s2b =>
if readdelay = 0 or flag = true then
if (flag = false) then
send_select <= "00110000"; -- '0' login.
-- leddisplay <= send_select;
flag := true;
link_wr <= '0';
else
Link_wr <= '1';
state <= s2b;
end if;

readdelay := 1;
if (flag = true) then
if (cnt = nom) then
link_wr <= '1';
cnt := 0;
flag := false;
-- state <= s2c;
else
cnt := cnt + 1;
state <= s2b;
end if;
end if;
elsif readdelay < big then
readdelay := readdelay + 1;
state <= s2b;
else
state <= s2c;
readdelay := 0;
end if;

when s2c =>
if readdelay = 0 or flag = true then
if (flag = false) then
send_select <= "00110001"; -- '1' login.
-- leddisplay <= send_select;
flag := true;
link_wr <= '0';
else
Link_wr <= '1';
state <= s2c;
end if;

readdelay := 1;
if (flag = true) then
if (cnt = nom) then
link_wr <= '1';
cnt := 0;
flag := false;
-- state <= s2d;
else
cnt := cnt + 1;
state <= s2c;
end if;
end if;
elsif readdelay < big then
readdelay := readdelay + 1;
state <= s2c;
else
state <= s2d;
readdelay := 0;
end if;

when s2d =>
if readdelay = 0 or flag = true then
if (flag = false) then
send_select <= "01100110"; -- 'F' login.
-- leddisplay <= send_select;
flag := true;
link_wr <= '0';
else
Link_wr <= '1';
state <= s2d;
end if;

readdelay := 1;
if (flag = true) then
if (cnt = nom) then
link_wr <= '1';
cnt := 0;
flag := false;
-- state <= s2e;
else
cnt := cnt + 1;
state <= s2d;
end if;
end if;
elsif readdelay < big then
readdelay := readdelay + 1;
state <= s2d;
else
state <= s2e;
readdelay := 0;
end if;

when s2e =>
if readdelay = 0 or flag = true then
if (flag = false) then
send_select <= "01100110"; -- 'F' login.
-- leddisplay <= send_select;
flag := true;
link_wr <= '0';
else
Link_wr <= '1';
state <= s2e;
end if;

readdelay := 1;
if (flag = true) then
if (cnt = nom) then
link_wr <= '1';
cnt := 0;
flag := false;
-- state <= s2f;
else
cnt := cnt + 1;
state <= s2e;
end if;
end if;
elsif readdelay < big then
readdelay := readdelay + 1;
state <= s2e;
else
state <= s2f;
readdelay := 0;
end if;

when s2f =>
if readdelay = 0 or flag = true then
if (flag = false) then
send_select <= "00001101"; -- 'CR' login.
-- leddisplay <= send_select;
flag := true;
link_wr <= '0';
else
Link_wr <= '1';
state <= s2f;
end if;

readdelay := 1;
if (flag = true) then
if (cnt = nom) then
link_wr <= '1';
cnt := 0;
flag := false;
-- state <= s2g;
else
cnt := cnt + 1;
state <= s2f;
end if;
end if;
elsif readdelay < small then
readdelay := readdelay + 1;
state <= s2f;
else
readdelay := 0;
sendstatus <= '0';
state <= s0;
end if;


when s2g =>
if (flag = false) or flag = true then
send_select <= "01110010"; -- 'r' login.
-- leddisplay <= send_select;
flag := true;
link_wr <= '0';
else
Link_wr <= '1';
end if;

if (flag = true) then
if (cnt = nom) then
link_wr <= '1';
cnt := 0;
flag := false;
else
cnt := cnt + 1;
end if;
end if;

if (flag = false) then
send_select <= "00110000"; -- '0' login.
-- leddisplay <= send_select;
flag := true;
link_wr <= '0';
else
Link_wr <= '1';
end if;

if (flag = true) then
if (cnt = nom) then
link_wr <= '1';
cnt := 0;
flag := false;
else
cnt := cnt + 1;
end if;
end if;

if (flag = false) then
send_select <= "00110100"; -- '4' login.
-- leddisplay <= send_select;
flag := true;
link_wr <= '0';
else
Link_wr <= '1';
end if;

if (flag = true) then
if (cnt = nom) then
link_wr <= '1';
cnt := 0;
flag := false;
else
cnt := cnt + 1;
end if;
end if;

state <= s0;


----------------------------------------------------------------------------------
when s3 =>
if (flag = false) then
send_select <= "01100011"; -- 'c' continuous scanning.
flag := true;
link_wr <= '0';
else
Link_wr <= '1';
end if;

if (flag = true) then
if (cnt = nom) then
link_wr <= '1';
cnt := 0;
flag := false;
else
cnt := cnt + 1;
end if;
end if;
state <= s0;
end case;
end if;

end process simulation;

try : process ( reset,mclkx16 )
begin
if reset = '1' then
Link_rd <= '0';

elsif mclkx16'event and mclkx16 = '1' then
if (Link_rxrdy = '1') then
Link_rd <= '1';
lcdflagen <= '0';
else
Link_rd <= '0';
lcdflagen <= '1';

end if;
end if;
end process;
end Behavioral;



regards
kenneth
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,525
Members
44,997
Latest member
mileyka

Latest Threads

Top