EmbDev.net

Forum: FPGA, VHDL & Verilog Scrolling a text on a 7-seg display


von Giorgia (Guest)


Rate this post
useful
not useful
Hi to everyone! I write because I need help: I have to write a code to 
scroll a text (such as "dE1") on a 7-seg display using four 7-bit 
registers connected in a queue-like fashion, such that the outputs of 
the
first register feed the inputs of the second, the second feeds the 
third, and so on (pipeline). Each register’s outputs should directly 
drive the seven segments of one display. A finite state machine controls 
the pipeline in this way:
1. the FSM inserts the correct characters (d, E or 1) into the first of 
the 7-bit registers in the pipeline.
2. After step 1 is complete, the FSM configures the pipeline into a loop 
that connects the last register back to the first one, so that the 
letters continue to scroll indefinitely.

My code is:
1
library IEEE;
2
use IEEE.STD_LOGIC_1164.ALL;
3
4
entity Scroll is
5
    Port ( clk : in STD_LOGIC;
6
           rst : in STD_LOGIC;
7
           z1 : inout STD_LOGIC_VECTOR (6 downto 0);
8
           z2 : inout STD_LOGIC_VECTOR (6 downto 0);
9
           z3 : inout STD_LOGIC_VECTOR (6 downto 0);
10
           z4 : inout STD_LOGIC_VECTOR (6 downto 0));
11
end Scroll;
12
13
architecture Behavioral of Scroll is
14
15
signal o1: std_logic_vector(6 downto 0) :="0000000";
16
signal o2: std_logic_vector(6 downto 0) :="0000000";
17
signal o3: std_logic_vector(6 downto 0) :="0000000";
18
19
type state_type is (A,B,C,D);
20
signal y: state_type:=A;
21
22
begin
23
24
z1<="111101" when y=B else
25
"1001111" when y=C else
26
"0110000" when y=D else
27
"0000000" when y=A else
28
"XXXXXXX";
29
30
process(rst,clk)
31
    begin
32
    if rst='0' then
33
        y<=A;
34
    elsif(clk'event and clk='1') then
35
    
36
    case y is
37
        when A =>
38
            y<=B;
39
            
40
       
41
        when B =>
42
            y<=C;
43
          
44
         when C =>
45
                y<=D;
46
47
         when D =>
48
            y<=B;
49
             
50
        end case;
51
        
52
        end if;
53
54
end process;
55
56
57
pipeline: process(clk,rst)
58
begin
59
   if rst='0' then
60
   
61
   o1<="0000000";
62
   o2<="0000000";
63
   o3<="0000000";
64
  
65
  for i in 6 downto 0 loop
66
  z2(i)<=o1(i);
67
  z3(i)<=o2(i);
68
  z4(i)<=o3(i);
69
  end loop;
70
   
71
 elsif(clk'event and clk='1') then
72
 --effettuo lo shift
73
for k in 6 downto 0 loop
74
   o1(k)<=z1(k);
75
   o2(k)<=o1(k);
76
   o3(k)<=o2(k);
77
 end loop;
78
 --aggiornamento dei segnali in uscita
79
    
80
  for j in 6 downto 0 loop
81
  z2(j)<=o1(j);
82
  z3(j)<=o2(j);
83
  z4(j)<=o3(j);
84
  end loop;
85
  end if;
86
  end process;
87
88
end Behavioral;
This code doesn't work because the second, the third and the fourth 
display are late compared to the first one of one clock cycle. Could you 
help me please? Thank you very much.

: Edited by Moderator
von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Rate this post
useful
not useful
Giorgia wrote:
> This code doesn't work because the second, the third and the fourth
> display are late compared to the first one of one clock cycle. Could you
> help me please?
Congratulations, you found what's called "latency". The most easy 
solution for that "problem" is, to supply them one clock cycle earlier. 
But in the real world with a 50MHz clock its not problem to have one 
clock cycle latency here, because then the display is delayed by 20ns. 
Your eye will not recognize that...

A few hints beyond that:
1
z1 : inout STD_LOGIC_VECTOR (6 downto 0);
Are those really inout ports? If not: why do you declare it that way? 
Just for laziness? That's no good idea, believe me.
1
for k in 6 downto 0 loop
2
   o1(k)<=z1(k);
3
   o2(k)<=o1(k);
4
   o3(k)<=o2(k);
5
 end loop;
You can skip the loop and cut this down to
1
   o1 <= z1;
2
   o2 <= o1;
3
   o3 <= o2;

Giorgia wrote:
> I have to write a code to scroll a text (such as "dE1") on a 7-seg
> display using four 7-bit registers connected in a queue-like fashion
Why do you do that so complicated with additional FSM and so on?
Why not the easy way?
1
library IEEE;
2
use IEEE.STD_LOGIC_1164.ALL;
3
4
entity Scroll is
5
    Port ( clk : in STD_LOGIC;
6
           rst : in STD_LOGIC;
7
           z1 : out STD_LOGIC_VECTOR (6 downto 0);
8
           z2 : out STD_LOGIC_VECTOR (6 downto 0);
9
           z3 : out STD_LOGIC_VECTOR (6 downto 0);
10
           z4 : out STD_LOGIC_VECTOR (6 downto 0));
11
end Scroll;
12
13
architecture Behavioral of Scroll is
14
15
  signal o1: std_logic_vector(6 downto 0) :="0111101"; -- d
16
  signal o2: std_logic_vector(6 downto 0) :="1001111"; -- E
17
  signal o3: std_logic_vector(6 downto 0) :="0110000"; -- 1
18
  signal o4: std_logic_vector(6 downto 0) :="0000000"; -- blank
19
20
begin
21
22
  pipeline: process(clk,rst)
23
  begin
24
    if rst='0' then
25
      o1<="0111101";
26
      o2<="1001111";
27
      o3<="0110000";
28
      o4<="0000000";   
29
    elsif(clk'event and clk='1') then
30
      o1 <= o2; -- scroll the text (fairly fast at some MHz clock...)
31
      o2 <= o3;
32
      o3 <= o4;
33
      o4 <= o1;
34
    end if;
35
  end process;
36
37
  z1 <= o1;
38
  z2 <= o2;
39
  z3 <= o3;
40
  z4 <= o4;
41
42
end Behavioral;


BTW: pls wrap your VHDL code with the [vhdl] tokens as described a few 
lines over each edit-box.

BTW2: with proper indention your code gets more readable.

: Edited by Moderator
von Giorgia (Guest)


Rate this post
useful
not useful
Now it's working! Thank you very much!
I added a FSM because the exercise requires it. Do you think it's too 
complicated?

von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Rate this post
useful
not useful
Giorgia wrote:
> I added a FSM because the exercise requires it.
Each simple counter is a FSM.

> Do you think it's too complicated?
No, it's a nice exercise.

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.