Forum: FPGA, VHDL & Co. Es wird nicht beim Sync_Ram auf "we<='0' geschaltet.


von peter (Gast)


Lesenswert?

Hallo, guten Tag.
Ich habe hier ein Sync_ram erstellt und möchte damit neue Daten 
reinscheiben über RS232.
Es funktioniert soweit, das ich die Datenübertragung an der LED_G sehen 
kann.
Ich fülle Daten von 1-255 rein. Die LED_G zählt hoch.
Hiermit werden die Daten geladen:
------------------------------
if RX_en = '1'  then
we<='1';
address <= conv_std_logic_vector(conv_integer(addr),8);
addr <= addr+1;
datain <= RX_Data;
end if;
------------------------------
Wenn we<='1' ist gesetzt werden Daten übertragen.

Frage: Wie komme ich in den neuen we<='0' Status?
Wenn ich hiermit setze :
---------------------------
if sw(1)='1' then
addr<=0;
we<='0';
end if;
--------------------------
kommt keine Reaktion, auch kann ich weiterhin Daten laden von RS232, es 
ist kein we<='0'.

Wo liegt der Fehler im VHDL ?

Danke.

Gruss

1
library ieee;
2
use ieee.std_logic_1164.all;
3
use ieee.numeric_std.all;
4
use ieee.std_logic_arith.all;
5
6
entity c_sync_ram is 
7
 Generic ( Quarz_Taktfrequenz : integer := 50000000;  
8
           Baudrate           : integer := 19200 
9
          );  
10
11
port(
12
  clock : in  std_logic;
13
  led_g : out STD_LOGIC_VECTOR(7 downto 0);
14
  sw    : in  STD_LOGIC_VECTOR(2 downto 0);
15
  RXD   : in   STD_LOGIC
16
  ); 
17
end c_sync_ram; 
18
            
19
architecture Behavioral of c_sync_ram is
20
21
type rx_state_t is (IDLE, BUSY, READY);
22
signal rx_state : rx_state_t := IDLE;
23
signal rxd_sr   : std_logic_vector (3 downto 0) := "1111";         
24
signal rxsr     : std_logic_vector (7 downto 0) := "00000000";    
25
signal rxbitcnt : integer range 0 to 9 := 9;
26
signal rxcnt    : integer range 0 to (Quarz_Taktfrequenz/Baudrate)-1; 
27
signal rx_en    : STD_LOGIC :='0';
28
signal RX_Data  : STD_LOGIC_VECTOR (7 downto 0);  
29
30
signal we      : STD_LOGIC;
31
signal address : std_logic_vector (7 downto 0);
32
signal datain  :   std_logic_vector (7 downto 0);
33
signal dataout :  std_logic_vector (7 downto 0);
34
35
signal addr : integer range 0 to 255 := 0; 
36
signal data : integer range 0 to 255 := 129; 
37
signal cnt : integer range 0 to 50000000 := 0; 
38
39
component sync_ram port(
40
  we      : in STD_LOGIC; 
41
  address : in std_logic_vector (7 downto 0);
42
  datain  : in std_logic_vector (7 downto 0);
43
  dataout : inout std_logic_vector (7 downto 0);
44
  clock   : in  std_logic
45
 );
46
end component;
47
48
begin
49
io1 : sync_ram  port map(we,address,datain,dataout,clock);
50
51
process
52
begin
53
  wait until rising_edge(clock); 
54
  rxd_sr <= rxd_sr(rxd_sr'left-1 downto 0) & RXD;
55
  RX_en  <= '0';
56
  
57
  case rx_state is
58
    when IDLE => 
59
      if (rxd_sr(3 downto 2) = "10") then                 
60
        rxcnt    <= ((Quarz_Taktfrequenz/Baudrate)-1)/2; 
61
        rxbitcnt <= 0;
62
        rx_state <= BUSY;
63
      end if;
64
    when BUSY =>
65
      if (rxbitcnt<9) then  
66
        if(rxcnt<(Quarz_Taktfrequenz/Baudrate)-1) then 
67
          rxcnt    <= rxcnt+1;
68
        else
69
          rxcnt    <= 0; 
70
          rxbitcnt <= rxbitcnt+1;
71
          rxsr     <= rxd_sr(rxd_sr'left-1) & rxsr(rxsr'left downto 1); 
72
        end if;
73
      else
74
        rx_state <= READY;
75
      end if;
76
    when READY =>
77
      RX_Data  <= rxsr;
78
      rx_state <= IDLE; 
79
      RX_en    <= '1';           
80
  end case;
81
end process;  
82
83
process(clock)
84
begin
85
  if rising_edge(clock) then
86
    if RX_en = '1'  then 
87
      we<='1';    
88
      address <= conv_std_logic_vector(conv_integer(addr),8);  
89
      addr <= addr+1; 
90
      datain <= RX_Data;
91
    end if;
92
    
93
    if (cnt<20000000 ) and sw(0)='1' then        
94
      cnt <= cnt+1;     
95
    else  
96
      cnt <= 0;
97
      if addr <= 255 then
98
        addr<=addr+1;      
99
        address <= conv_std_logic_vector(conv_integer(addr),8);  
100
      end if;  
101
    end if;  
102
  end if;
103
   
104
  if sw(1)='1' then
105
    addr<=0;
106
    we<='0';
107
  end if; 
108
  
109
end process;  
110
111
led_g<=dataout;
112
end Behavioral;
113
114
115
--------------------------------------------------
116
library IEEE;
117
use IEEE.STD_LOGIC_1164.all;
118
use IEEE.Numeric_Std.all;
119
120
entity sync_ram is
121
  port (
122
    clock   : in  std_logic;
123
    we      : in  std_logic;
124
    address : in  std_logic_vector (7 downto 0);
125
    datain  : in  std_logic_vector (7 downto 0);
126
    dataout : out std_logic_vector (7 downto 0)
127
  );
128
end entity sync_ram;
129
130
architecture RTL of sync_ram is
131
132
type ram_type is array (0 to 255) of std_logic_vector(0 to 7);
133
signal ram : ram_type :=(
134
  x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", 
135
  x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", 
136
  x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", 
137
  x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", 
138
  x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", 
139
  x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", 
140
  x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", 
141
  x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", 
142
  x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", 
143
  x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", 
144
  x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", 
145
  x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", 
146
  x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", 
147
  x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", 
148
  x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", 
149
  x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", 
150
  x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", 
151
  x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", 
152
  x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", 
153
  x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", 
154
  x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", 
155
  x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", 
156
  x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", 
157
  x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", 
158
  x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", x"00", 
159
  x"00", x"00", x"00", x"00", x"00", x"00" );
160
161
signal read_address : std_logic_vector (7 downto 0);
162
  
163
begin
164
165
process(clock) is
166
begin
167
  if rising_edge(clock) then
168
    if we = '1' then
169
      ram(to_integer(unsigned(address))) <= datain;   
170
    end if;   
171
      read_address <=address;    
172
  end if;
173
end process;
174
175
dataout <= ram(to_integer(unsigned(read_address)));
176
end architecture RTL;

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


Lesenswert?

1
  :
2
  end if;
3
   
4
  if sw(1)='1' then
5
    addr<=0;
6
    we<='0';
7
  end if; 
8
  
9
end process;
Huah!
Ein versteckter asynchroner Reset, das hat was. Machs doch wenigstens 
so:
1
  :
2
    if sw(1)='1' then
3
      addr<=0;
4
      we<='0';
5
    end if; 
6
  end if;
7
 
8
end process;
Das wird den Fehler nicht beheben, ergibt aber (abgesehen vom nicht 
einsynchronisierten sw) ein synchrones Design.

zum eigentlichen "Problem":
Hast du dir mal dein we-Signal auf einer LED angezeigt? Wird das 
tatsächlich nicht 0?

von uwe (Gast)


Lesenswert?

Probiers mal mit gemüt.. ner Statemachine.

von Michael A. (michiavelli)


Lesenswert?

peter schrieb:
> kommt keine Reaktion

Hast sw(1) denn im ucf-File überhaupt mit einem Schalter oder Button 
verbunden? Das vergisst man schnell mal...

von peter (Gast)


Lesenswert?

-----------------------
Ein versteckter asynchroner Reset, das hat was. Machs doch wenigstens
----------------------

Danke. Das wars zum Teil. Hatte ich gar nicht gesehen das er ausserhalb 
lag. Jetzt funktioniert es mit dem Schalten auf die 0-Adresse.

Habe jetzt die Abfrage :
"if addr <= 255 then" entfernt und da die "we<='0'" reingesetzt. Jetzt 
funktioniert es das w<='0' angenommen wird.

Danke.

Gruss

von peter (Gast)


Lesenswert?

---------------------------
Jetzt funktioniert es das w<='0' angenommen wird.
--------------------------

Es werden jetzt die Daten gelesen und an der Led_G angezeigt.
Vorher war bei Zählen stillstand.

Gruss

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.