EmbDev.net

Forum: FPGA, VHDL & Verilog lower case to upper case and vice versa


von Junior H. (Company: University) (junior_hpc)


Rate this post
useful
not useful
Hello.
I want to develop a VHDL application that given a text file, it converts 
all the lower case to upper case and vice versa. E.g., if the the input 
text is "Hello", then the VHDL should output "hELLO". The application 
passes the input text file stored on local machine to signal 
user_w_write_8_data which contains the characters of the input text 
file.
I don't know why, my VHDL code only convert one every two characters. 
E.g., if my input text is "Hello", my code outputs "HeLlO". I don't know 
whether it is a problem of clock cycle or something else. The algorithm 
should be ok, because the signal user_w_write_8_data contains the 8 bits 
of the character, e.g. "H" is represented in user_w_write_8_data as 
"01001000" and in order to convert "H" into "h" I only swap the fifth 
bit from 0 to 1 or from 1 to 0.

This is my VHDL code, do you have any idea where I am wrong?

Thanks.
1
library ieee;
2
use ieee.std_logic_1164.all;
3
use ieee.std_logic_unsigned.all;
4
use ieee.numeric_std.all;
5
6
entity xillydemo is
7
  port (
8
     PCIE_PERST_B_LS : IN std_logic;
9
     PCIE_REFCLK_N : IN std_logic;
10
     PCIE_REFCLK_P : IN std_logic;
11
     PCIE_RX_N : IN std_logic_vector(3 DOWNTO 0);
12
     PCIE_RX_P : IN std_logic_vector(3 DOWNTO 0);
13
     GPIO_LED : OUT std_logic_vector(3 DOWNTO 0);
14
     PCIE_TX_N : OUT std_logic_vector(3 DOWNTO 0);
15
     PCIE_TX_P : OUT std_logic_vector(3 DOWNTO 0));
16
end xillydemo;
17
18
architecture sample_arch of xillydemo is
19
    signal tmp :  std_logic_vector(7 DOWNTO 0);
20
  
21
22
  component xillybus
23
    port (
24
      PCIE_PERST_B_LS : IN std_logic;
25
      PCIE_REFCLK_N : IN std_logic;
26
      PCIE_REFCLK_P : IN std_logic;
27
      PCIE_RX_N : IN std_logic_vector(3 DOWNTO 0);
28
      PCIE_RX_P : IN std_logic_vector(3 DOWNTO 0);
29
      GPIO_LED : OUT std_logic_vector(3 DOWNTO 0);
30
      PCIE_TX_N : OUT std_logic_vector(3 DOWNTO 0);
31
      PCIE_TX_P : OUT std_logic_vector(3 DOWNTO 0);
32
      bus_clk : OUT std_logic;
33
      quiesce : OUT std_logic;
34
      
35
      user_r_read_8_rden : OUT std_logic;
36
      user_r_read_8_empty : IN std_logic;
37
      user_r_read_8_data : IN std_logic_vector(7 DOWNTO 0);
38
      user_r_read_8_eof : IN std_logic;
39
      user_r_read_8_open : OUT std_logic;
40
      user_w_write_8_wren : OUT std_logic;
41
      user_w_write_8_full : IN std_logic;
42
      user_w_write_8_data : OUT std_logic_vector(7 DOWNTO 0);
43
      user_w_write_8_open : OUT std_logic);
44
  end component;
45
46
  component fifo_8x2048
47
    port (
48
      clk: IN std_logic;
49
      srst: IN std_logic;
50
      din: IN std_logic_VECTOR(7 downto 0);
51
      wr_en: IN std_logic;
52
      rd_en: IN std_logic;
53
      dout: OUT std_logic_VECTOR(7 downto 0);
54
      full: OUT std_logic;
55
      empty: OUT std_logic);
56
  end component;
57
58
59
-- Synplicity black box declaration
60
  attribute syn_black_box : boolean;
61
  attribute syn_black_box of fifo_8x2048: component is true;
62
  
63
  signal bus_clk :  std_logic;
64
  signal quiesce : std_logic;
65
66
  signal reset_8 : std_logic;
67
68
  signal ram_addr : integer range 0 to 31;
69
 
70
  signal user_r_read_8_rden  :  std_logic;
71
  signal user_r_read_8_empty :  std_logic;
72
  signal user_r_read_8_data  :  std_logic_vector(7 DOWNTO 0);
73
  signal user_r_read_8_eof   :  std_logic;
74
  signal user_r_read_8_open  :  std_logic;
75
  signal user_w_write_8_wren :  std_logic;
76
  signal user_w_write_8_full :  std_logic;
77
  signal user_w_write_8_data :  std_logic_vector(7 DOWNTO 0);
78
  signal user_w_write_8_open :  std_logic;
79
  signal wr_en               :  std_logic := '0';
80
  signal din                 :  std_logic_vector(user_w_write_8_data'range) := (others => '0');
81
82
begin
83
  xillybus_ins : xillybus
84
    port map (
85
      -- Ports related to /dev/xillybus_read_8
86
      -- FPGA to CPU signals:
87
      user_r_read_8_rden => user_r_read_8_rden,
88
      user_r_read_8_empty => user_r_read_8_empty,
89
      user_r_read_8_data => user_r_read_8_data,
90
      user_r_read_8_eof => user_r_read_8_eof,
91
      user_r_read_8_open => user_r_read_8_open,
92
93
      -- Ports related to /dev/xillybus_write_8
94
      -- CPU to FPGA signals:
95
      user_w_write_8_wren => user_w_write_8_wren,
96
      user_w_write_8_full => user_w_write_8_full,
97
      user_w_write_8_data => user_w_write_8_data,
98
      user_w_write_8_open => user_w_write_8_open,
99
100
      -- General signals
101
      PCIE_PERST_B_LS => PCIE_PERST_B_LS,
102
      PCIE_REFCLK_N => PCIE_REFCLK_N,
103
      PCIE_REFCLK_P => PCIE_REFCLK_P,
104
      PCIE_RX_N => PCIE_RX_N,
105
      PCIE_RX_P => PCIE_RX_P,
106
      GPIO_LED => GPIO_LED,
107
      PCIE_TX_N => PCIE_TX_N,
108
      PCIE_TX_P => PCIE_TX_P,
109
      bus_clk => bus_clk,
110
      quiesce => quiesce
111
   );
112
113
  process (bus_clk)
114
  
115
  begin
116
  
117
     if (bus_clk'event and bus_clk = '1') then
118
        wr_en <= user_w_write_8_wren;
119
        if (user_w_write_8_wren = '1') then 
120
            din <= user_w_write_8_data;
121
            if (din(5)='1') then
122
                din(5)<='0';
123
            elsif (din(5)='0') then
124
                din(5)<='1';
125
            end if;
126
        end if;
127
     end if; 
128
129
  end process;
130
131
--  8-bit loopback
132
133
  fifo_8 : fifo_8x2048
134
    port map(
135
          clk        => bus_clk,
136
          srst       => reset_8,
137
          din        => din,
138
          wr_en      => wr_en,
139
          rd_en      => user_r_read_8_rden,
140
          dout       => user_r_read_8_data,
141
          full       => user_w_write_8_full,
142
          empty      => user_r_read_8_empty
143
      );
144
145
    reset_8 <= not (user_w_write_8_open or user_r_read_8_open);
146
147
    user_r_read_8_eof <= '0';
148
  
149
end sample_arch;

von Ben (Guest)


Rate this post
useful
not useful
Hi,

the error occurs because you use synchronous pilelines of different 
lengths on the same data.

Your actions on the clock cycles for one date look like this:
1. user_w_write_8_wren = '1'
2. wr_en = '1', din = user_w_write_8_data
3. din(5) = not din(5), wr_en = '0'


This is such a trivial problem that you can easily do it in an 
asynchronous statement:
1
wr_en <= user_w_write_8_wren;
2
din <= user_w_write_8_data;
3
din(5) <= not user_w_write_8_data(5);

von Junior H. (Company: University) (junior_hpc)


Rate this post
useful
not useful
Wow it works... but I did not really understand why the following code 
did not work... The data is in the FIFO only when bus_clk'event and 
bus_clk = '1', isn't it?? Maybe I am wrong...
1
if (bus_clk'event and bus_clk = '1') then
2
   wr_en <= user_w_write_8_wren;
3
   din <= user_w_write_8_data;
4
   din(5) <= not user_w_write_8_data(5);
5
end if;

Thanks.

von Ben (Guest)


Rate this post
useful
not useful
I have no idea why the code you posted should not work. It looks 
alright.

von Lattice User (Guest)


Rate this post
useful
not useful
Junior H. wrote:
> Wow it works... but I did not really understand why the following code
> did not work... The data is in the FIFO only when bus_clk'event and
> bus_clk = '1', isn't it?? Maybe I am wrong...
>
1
if (bus_clk'event and bus_clk = '1') then
2
   wr_en <= user_w_write_8_wren;
3
   din <= user_w_write_8_data;
4
   din(5) <= not user_w_write_8_data(5);
5
end if;
>

this is not your original code.

You original not working code ist equivalent to this:
1
if (bus_clk'event and bus_clk = '1') then
2
   wr_en <= user_w_write_8_wren;
3
   din <= user_w_write_8_data;
4
   din(5) <= not din(5);
5
end if;

which introduces an extra cycle delay only to bit 5.

von Lattice User (Guest)


Rate this post
useful
not useful
Lattice User wrote:
>
> which introduces an extra cycle delay only to bit 5.

Correction:
It just toggles bit 5 -> alternatnating lower and upper case.

von Junior H. (Company: University) (junior_hpc)


Rate this post
useful
not useful
Hello, I have some question about the following code line:
1
 din <= user_w_write_8_data;

By reading xillybus documentation, user_w_write_8_data contains the data 
arriving from write_device_file but I don't understand what is din. 
Since the data output is represented by dout, how it is possible that by 
executing this line code:
1
 din <= user_w_write_8_data;
the data goes into read_device_file?

von asdf (Guest)


Rate this post
useful
not useful
As you can see in the code, din is connected to the fifo write port, 
which is a buffer the component can read from.

There is no referecne in this thread about "read_device_file" and if you 
provide no context to your problem, no one will be able to help you with 
it.

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.