TrickyDicky
Advanced Member level 7
- Joined
- Jun 7, 2010
- Messages
- 7,110
- Helped
- 2,081
- Reputation
- 4,181
- Reaction score
- 2,048
- Trophy points
- 1,393
- Activity points
- 39,769
I made it another go. It compiles, but complains about some signals not being in the sensitivity list. If I don't need the process to be re-evaluated, there is no real need to put every signal that is read inside the sensitivity list, right? I tried uploading it to my DE-2-nano, but it doesn't work. LED(1 DOWNTO 0) are supposed to show me which state it's in, but both leds seem to glow quite dimly so I guess it's switching states with the same frequency as CLOCK_50 (which I don't understand).
.
I made it another go. It compiles, but complains about some signals not being in the sensitivity list. If I don't need the process to be re-evaluated, there is no real need to put every signal that is read inside the sensitivity list, right?
I don't get what the deal about clocks are. I've now limited myself to only using CLOCK_50 as a clock, but then the compiler complains and says "Warning (332060): Node: newClock was determined to be a clock but was found without an associated clock assignment.".
What is really the difference between using rising_edge and having a signal in the sensitivity list? When a rising or falling edge of a signal represents some kind of change, it's called a clock, right? If a signal is present in the sensitivity list it means that something will happen when that signal changes value (rising or falling edge) so I don't understand the difference.
Warning (10631): VHDL Process Statement warning at uart.vhd(53): inferring latch(es) for signal or variable "nextstate", which holds its previous value in one or more paths through the process
Warning (10631): VHDL Process Statement warning at uart.vhd(53): inferring latch(es) for signal or variable "UARTREG", which holds its previous value in one or more paths through the process
Warning (10631): VHDL Process Statement warning at uart.vhd(53): inferring latch(es) for signal or variable "bitnumber", which holds its previous value in one or more paths through the process
Warning: Latch bitnumber[0] has unsafe behavior
Warning: Ports D and ENA on the latch are fed by the same signal state.stop
The difference between a clock and a 'event is that a clock should toggle from '0' to '1' back to '0' in a periodicy frequency. Hence it should create 'events with a fixed period. Using the sensitivity list may mean the process remains inactive for a long period of time. 'events are also created on ANY change in signal, and std_logic has 9 states in simulation ('U', 'X', '0', '1', 'Z'. 'W', 'L', 'H' and '-'). So changing from any of these to any other of these causes a 'event, which is not a clock edge.
library ieee;
use ieee.std_logic_1164.all;
--use ieee.numeric_std.all;
entity RxUnit is
generic (
OVSFAC : INTEGER := 16; -- Oversample
BAUDFAC : INTEGER := 4
);
port (
Clk : in Std_Logic;
Reset : in Std_Logic := '0'; -- Reset input
RxD : in Std_Logic; -- UART data input
RxAv : out Std_Logic; -- Received Data valid
RcvErr : out Std_Logic; -- Error
Frame : out Std_Logic;
DataO : out Std_Logic_Vector(7 downto 0)); -- Received data
end entity;
architecture RTL of RxUnit is
signal RReg : Std_Logic_Vector(7 downto 0); -- Byte receive register
signal SampleCnt: INTEGER range 0 to OVSFAC-1;
signal BitPos : INTEGER range 0 to 11; -- Position of the bit in the byteframe
signal clkcount : INTEGER range 0 to BAUDFAC-1;
signal RxD_S1 : Std_Logic;
signal RxD_S2 : Std_Logic;
begin
process(Clk,Reset)
begin
if Reset = '1' then -- Reset
BitPos <= 0;
clkcount <= 0;
RxAv <= '0';
RcvErr <= '0';
RxD_S1 <= '1';
RxD_S2 <= '1';
elsif Rising_Edge(Clk) then
-- Synchronizer chain
RxD_S1 <= RxD;
RxD_S2 <= RxD_S1;
if BitPos = 0 then
RxAv <= '0';
RcvErr <= '0';
SampleCnt <= 0;
end if;
if clkcount < BAUDFAC-1 then
clkcount <= clkcount + 1;
else
clkcount <= 0;
if BitPos = 0 then
if RxD_S2 = '0' then -- Start Bit
BitPos <= 1;
SampleCnt <= 0;
end if;
else
sampleCnt <= SampleCnt + 1;
if SampleCnt >= OVSFAC-1 then -- Increment BitPos
BitPos <= BitPos + 1;
elsif SampleCnt = (OVSFAC - 1)/2 then
RReg <= RxD_S2 & RReg(7 downto 1); -- Deserialisation LSB first
CASE BitPos is
WHEN 1 =>
if RxD_S2 = '1' then -- Start Bit Error
BitPos <= 0;
end if;
WHEN 10 =>
BitPos <= 0;
if RxD_S2 = '0' then -- Stop Bit Error
RcvErr <= '1';
else
DataO(7 downto 0) <= RReg; -- Store received byte
RxAv <= '1';
end if;
WHEN OTHERS => -- Data bits
END CASE;
end if; -- Sample
end if; -- Bitpos /= 0
end if; -- clkcount
end if; -- RisindEdge(clk)
end process;
Frame <= '1' WHEN BitPos > 0 ELSE
'0';
end RTL;
About my use of "last_value", I have to find some other solution then. What I would like is to use rising_edge so that it executes the commands inside the if-statement only ONCE, but I guess that would be going back to using several clocks.
As Tricky points out the solution isn't how to take advantage of all the VHDL language constructs. Many of them won't synthesize anyways.I think you need to stop looking for a solution via the VHDL. You need to work out the solution in terms of hardware first before you write any VHDL (usually on paper)
Synthesis ignores sensitivity lists, so missing some out will only lead to a difference in behaviour between your simulation and real hardware.
architecture asynchronous of flopr is
begin
process(clk, reset) begin
if reset then
q <= "0000";
elsif rising_edge(clk) then
q <= d;
end if;
end process
end;
architecture synchronous of flopr is
begin
process(clk) begin
if rising_edge(clk) then
if reset then q<="0000";
else q <= d;
end if;
end if;
end process;
end;
Multiple signals in a process sensitivity list are separated with a comma. Notice that reset is in the sensitivity list on the asynchronously resettable flop, but not on the synchronously resettable flop. Thus, the asynchronously resettable flop immediately responds to a rising edge on reset, but the synchronously resettable flop responds to reset only on the rising edge of the clock.
signal UARTREG : STD_LOGIC_VECTOR(9 DOWNTO 0);
signal counter2 : unsigned (4 DOWNTO 0);
begin
RX <= KEY(0);
LED(0) <= EN;
LED(1) <= ((not RX) and (not EN));
LED(3) <= newClock;
LED(4) <= PreviousClock;
test <= (newClock and (not previousClock));
process(CLOCK_50)
variable counter : integer := 0;
begin
if (((not RX) and (not EN)) = '1') then
EN <= '1';
end if;
if (EN = '1') then
if rising_edge(CLOCK_50) then
prescaler_counter <= prescaler_counter + 1;
if(prescaler_counter > prescaler) then
newClock <= not newClock;
prescaler_counter <= (others => '0');
counter := counter + 1;
UARTREG( to_integer(counter) ) <= RX;
end if;
end if;
end if;
The code shows that you are essentially misunderstanding the text book statement.My book gives a great example with a asynchronously triggered flip-flop and a synchronously triggered flip-flop where the only difference is whether RST is in the sensitivity list or not.
The problem with to_integer() is rather trivial. It's an error to apply it to an integer signal or variable, it's defined for signed or unsigned only.
To fix the error, you can writeSo how should I do it then?
UARTREG(counter) <= RX;
UARTREG( to_integer(counter) ) <= RX;
library IEEE;
use IEEE.STD_LOGIC_1164.all;
use IEEE.STD_LOGIC_UNSIGNED.all;
use IEEE.NUMERIC_STD.all;
entity instr_mem is
port (addr, input_instruction : IN STD_LOGIC_VECTOR(31 downto 0);
WE, word_ready : IN STD_LOGIC;
instr: OUT STD_LOGIC_VECTOR(31 downto 0));
end;
architecture instr_mem_beh of instr_mem is
type instruction_array is array (40 DOWNTO 0) of STD_LOGIC_VECTOR(31 DOWNTO 0);
signal instruction_memory : instruction_array;
signal counter2 : unsigned(31 DOWNTO 0);
BEGIN
counter2 <= to_unsigned(addr);
PROCESS (word_ready, addr)
variable counter : integer := 0;
BEGIN
if (WE = '0') then
if rising_edge(word_ready) then
instruction_memory(counter) <= input_instruction;
counter := counter + 1;
end if;
else
counter := 0;
instr <= instruction_memory(to_integer(counter2));
end if;
end process;
end instr_mem_beh;
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?