Forum: FPGA, VHDL & Co. VHDL einfache FSM Implementierung geht nicht


von FSM (Gast)


Lesenswert?

Hallo,

Ich habe Probleme mit einer einfache Implementierung von einem FSM für 
UART-Transmitter in VHDL. Alles funktioniert in der Simulation aber 
nicht in der Hardware. Bitte um jede Hilfe! Ich schaue das Signal mit 
einem kleinem Oszi (DSO QUAD), Das Signal ist immer null.

Board: Xula2- SPARTAN6 - XC6SLX9 - FTG256
Entwickulngsumgebung: Xilinx ISE 14.7, Win7 Pro 32-bit

Ich werde das gleiche für Empfänger auch machen und möchte in der Mitte 
von jedem Bit abtasten deshalb zähle ich bis 16 für jede Bit.

Wo mache ich falsch?
Anbei ist die Code.
Danke.
1
library IEEE;
2
use IEEE.STD_LOGIC_1164.ALL;
3
4
-- Uncomment the following library declaration if using
5
-- arithmetic functions with Signed or Unsigned values
6
use IEEE.NUMERIC_STD.ALL;
7
use IEEE.STD_LOGIC_UNSIGNED.ALL;
8
9
-- Uncomment the following library declaration if instantiating
10
-- any Xilinx primitives in this code.
11
--library UNISIM;
12
--use UNISIM.VComponents.all;
13
14
entity uart_transmitter is
15
    Port ( clk_i : in  STD_LOGIC;
16
           rst_i : in  STD_LOGIC := '0';
17
           ld_i  : in  STD_LOGIC := '1';
18
           din_i : in  STD_LOGIC_VECTOR (7 downto 0) := "01010101"; --test
19
           tx_o  : out  STD_LOGIC);
20
end uart_transmitter;
21
22
architecture Behavioral of uart_transmitter is
23
24
25
type state_t is (idleState, startState, activeState, parityState);
26
27
signal nextState : state_t := idleState;
28
29
signal bitCount   : std_logic_vector(3 downto 0) := (others => '0');
30
signal counter    : std_logic_vector(3 downto 0) := (others => '0');
31
32
signal nrOnes     : std_logic_vector(3 downto 0) := (others => '0');
33
signal load       : std_logic := '0';  
34
signal input      : std_logic_vector(7 downto 0) := (others => '0');
35
36
signal s_tx_o    : std_logic := '1';
37
signal s_tmp     : std_logic_vector(7 downto 0);
38
constant counterEnd : std_logic_vector(4 downto 0) := "10000"; --16
39
40
begin
41
  
42
  pr_state_update: process(clk_i, rst_i)
43
  begin
44
    if rising_edge(clk_i) and clk_i = '1' then
45
      if rst_i = '1' then
46
47
        nextState <= idleState;  
48
      
49
      end if;
50
      
51
      case nextState is
52
        when idleState   => 
53
          
54
          bitCount   <= (others => '0');
55
          counter    <= (others => '0');
56
          nrOnes     <= (others => '0');
57
          s_tx_o <= '1';
58
          if load = '1' then 
59
            input <= din_i;    
60
            nextState <= startState; 
61
          else 
62
            nextState <= idleState; 
63
          end if;
64
          
65
        when startState  => 
66
          s_tx_o <= '0';
67
68
          if counter = (counterEnd-1) then
69
            counter <= (others => '0');
70
            nextState <= activeState;
71
          else
72
            counter <= counter + 1;
73
            nextState <= startState;
74
          end if;
75
          
76
        when activeState => 
77
          s_tx_o <= input(to_integer(unsigned(bitCount)));  
78
79
          if counter = (counterEnd-1) then
80
            counter <= (others => '0');  
81
            bitCount <= bitCount + 1;
82
            
83
            if input(to_integer(unsigned(bitCount))) = '1' then
84
              nrOnes <= nrOnes + 1;
85
             end if;
86
            
87
            if bitCount = "0111" then
88
              bitCount <= (others => '0');
89
90
              nextState <= parityState;              
91
            else
92
              nextState <= activeState;  
93
            end if;
94
          else
95
            counter <= counter + 1;
96
            nextState <= activeState;
97
          end if;  
98
         when parityState =>  
99
          counter <= (others => '0');
100
          if (nrOnes /= "0000") and (to_integer(unsigned(nrOnes)) mod 2 = 0) then
101
            s_tx_o <= '1';
102
          else
103
            s_tx_o <= '0';
104
          end if;        
105
            
106
          if counter = (counterEnd-1) then
107
108
            nextState <= idleState;  
109
          else
110
            counter <= counter + 1;
111
            nextState <= parityState;
112
          end if;
113
          
114
         when others =>  
115
          nextState <= idleState;  
116
    end case;
117
    end if;
118
  end process;
119
      
120
load <= ld_i;
121
tx_o <= s_tx_o;
122
end Behavioral;
123
----------------------------UCF Datei:-------------------------------------
124
125
net clk_i  loc = a9 | CLOCK_DEDICATED_ROUTE = FALSE;  # ohne diese Parameter bekkome ich eine Fehler bei der Syntheze.
126
net tx_o   loc = r7 | IOSTANDARD=LVTTL | DRIVE=24 | SLEW=SLOW;

Ich habe eine kleine Testprogram zum Blinken einer LED gemacht und 
funktioneiert die HW.

von Micha (Gast)


Lesenswert?

---> if rising_edge(clk_i) and clk_i = '1' then <---

von Micha (Gast)


Lesenswert?

if rst_i = '1' then
  nextState <= idleState;
---> else <---

.... Rest vom Code ....

end if;

von Lothar M. (Firma: Titel) (lkmiller) (Moderator) Benutzerseite


Lesenswert?

Mal von den ganzen Kleinigkeiten abgesehen: Woher kommt der clk_i? Wie 
wird der erzeugt, und warum verwendest du keinen Takteingang?

von FSM (Gast)


Lesenswert?

Micha schrieb:
> ---> if rising_edge(clk_i) and clk_i = '1' then <---

Micha schrieb:
> if rst_i = '1' then
>   nextState <= idleState;
> ---> else <---
>
> .... Rest vom Code ....
>
> end if;

Danke für die Antworten.
Ich habe einfach übersehen. Jetzt sieht es so aus:
1
                ....
2
    if rising_edge(clk_i) then
3
      if rst_i = '1' then
4
        nextState <= idleState;  
5
      else  
6
             ....

Aber gleiche Ergebnis...Ich sehe keine Signaländerung, immer null.

von Micha (Gast)


Lesenswert?

Lothar Miller schrieb:
> Woher kommt der clk_i?

Du brauchst noch eine Testbench dazu.

von FSM (Gast)


Lesenswert?

Lothar Miller schrieb:
> Mal von den ganzen Kleinigkeiten abgesehen: Woher kommt der clk_i?
> Wie
> wird der erzeugt, und warum verwendest du keinen Takteingang?

clk_i kommt von einem µC, und der beträgt 12MHz (Seite 17 
http://www.xess.com/static/media/manuals/XuLA2-manual.pdf). Zuerst 
möchte ich sicherstellen dass tx_o richtige Signale erzeugt, egal mit 
welcher Frequenz. Danach werde ich mit einer standarde Baudrate testen.

Wie gesagt, Ich habe einen einfachen Test zum Blinken einer LED gemacht 
und funktioniert.

von Micha (Gast)


Lesenswert?

... und ld_i ?

von FSM (Gast)


Lesenswert?

Die Ports clk_i und tx_o zu den Aussenwelt verbunden. Die andere nicht, 
daher habe ich Initialwerte verwendet.

von Micha (Gast)


Lesenswert?

dann schau dir mal die Synthese und Translate Ausgaben an, ob ld_i 
danach noch auf '1' liegt und rst_i noch auf '0' und din_i noch auf 
X"55"

von FSM (Gast)


Lesenswert?

Micha schrieb:
> dann schau dir mal die Synthese und Translate Ausgaben an, ob ld_i
> danach noch auf '1' liegt und rst_i noch auf '0' und din_i noch auf
> X"55"

Diese Signalen sind schon richtig nach der Synthese, aber trotzdem habe 
ich diese Ports deaktiviert und als interne Signale verwendet:
1
entity uart_transmitter is
2
    Port ( clk_i : in  STD_LOGIC;
3
 --          rst_i : in  STD_LOGIC := '0';
4
 --          ld_i  : in  STD_LOGIC := '1';
5
 --          din_i : in  STD_LOGIC_VECTOR (7 downto 0) := "01010101";
6
           tx_o  : out  STD_LOGIC);
7
end uart_transmitter;
8
....
9
signal rst_i : STD_LOGIC := '0';
10
signal ld_i  : STD_LOGIC := '1';
11
signal din_i : STD_LOGIC_VECTOR (7 downto 0) := "01010101";
12
...
Immer noch gleiche.

von Micha (Gast)


Lesenswert?

FSM schrieb:
> when parityState =>
>           counter <= (others => '0');
>
>           ...
>
>           if counter = (counterEnd-1) then
>
>             nextState <= idleState;
>           else
>             counter <= counter + 1;
>             nextState <= parityState;
>           end if;

und du sagst die Simulation funktioniert ?! Soweit ich das sehe hängt 
die FSM bei parityState fest?

von FSM (Gast)


Lesenswert?

Ich habe den Fehler gefunden, der liegt nicht in der Code, sondern in 
der Projekteinstellungen :)
Die UCF-Datei war unter der Projecktname nicht unter der "Top Module", 
ich habe die UCF-Datei unter der Top Module hinzugefügt und jetz 
funktioniert :)
Also zur Ver­an­schau­li­chung:
1
 + ProjektName
2
 |
3
 +-- SoruceCode.vhd
4
 |
5
 +-- Pins.ucf
----->
1
 + ProjektName
2
 |
3
 +-+ SoruceCode.vhd
4
   |
5
   +-- Pins.ucf

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.