Plecto
Full Member level 5
- Joined
- Jan 4, 2012
- Messages
- 315
- Helped
- 1
- Reputation
- 2
- Reaction score
- 1
- Trophy points
- 1,298
- Activity points
- 4,979
signal bitnumber : STD_LOGIC_VECTOR(4 DOWNTO 0);
signal D_OUT : STD_LOGIC_VECTOR(31 DOWNTO 0);
signal RX : ST_LOGIC;
process (clock)
begin
if rising_edge (clock) then
bitnumber <= bitnumber + 1;
D_OUT(bitnumber) <= RX;
end if;
end process;
Code VHDL - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 use ieee.numeric_std.all; ... signal bitnumber : unsigned(4 downto 0) := (others => '0'); --otherwise simulation wont work. Alternativly, use a reset signal D_OUT : STD_LOGIC_VECTOR(31 DOWNTO 0); signal RX : ST_LOGIC; process (clock) begin if rising_edge (clock) then D_OUT( to_integer(bitnumber) ) <= RX; bitnumber <= bitnumber + 1; end if; end process;
if (integer = '1') then
something = something_else + 1;
integer = '0';
end if;
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_unsigned.all;
use ieee.numeric_std.all;
ENTITY UART IS
PORT (CLOCK_50 : IN STD_LOGIC;
KEY : IN STD_LOGIC_VECTOR(0 DOWNTO 0);
--LEDR : OUT STD_LOGIC_VECTOR(9 DOWNTO 0);
LED : OUT STD_LOGIC_VECTOR(7 DOWNTO 0);
TX : OUT STD_LOGIC);
END UART;
architecture UART_beh of UART is
signal UARTREG : STD_LOGIC_VECTOR(8 DOWNTO 0);
signal RX : STD_LOGIC;
signal prescaler: STD_LOGIC_VECTOR(24 downto 0) := "1101111101011110000100000"; -- 12,500,000 in binary
signal prescaler_counter: STD_LOGIC_VECTOR(24 downto 0) := (others => '0');
signal newClock : STD_LOGIC;
signal TRANSMISSION : STD_LOGIC;
signal bitnumber : UNSIGNED(4 downto 0) := (others => '0');
begin
LED <= UARTREG(8 DOWNTO 1);
--RX <= KEY(0);
process(CLOCK_50, RX)
begin
if rising_edge(CLOCK_50) then
prescaler_counter <= prescaler_counter + 1;
if(prescaler_counter > prescaler) then
newClock <= not newClock;
prescaler_counter <= (others => '0');
end if;
end if;
if (RX = '0') then
if (TRANSMISSION = '0') then
prescaler_counter <= "0101111101011110000100000";
newClock <= '0';
TRANSMISSION <= '1';
end if;
end if;
if rising_edge(newClock) then
if (TRANSMISSION = '1') then
UARTREG(to_integer(bitnumber)) <= RX;
bitnumber <= bitnumber + 1;
end if;
if (bitnumber = 8) then
bitnumber <= "00000";
TRANSMISSION <= '0';
end if;
end if;
end process;
end UART_beh;
There has to be something basic that I don't understand about VHDL because I feel clueless about what actually compiles and what refuses to compile.
I'm also curious about what the difference between "hello <= '0' " and "hello <= 0 " or even "hello <= "0" ". I also don't understand why I sometimes see := used instead of <=
hello <= "0"
This assigns the STRING "0" to a signal "hello" defined as a CHARACTER. Only useful in synthesis.
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_unsigned.all;
use ieee.numeric_std.all;
ENTITY UART IS
PORT( CLOCK_50 : IN STD_LOGIC;
KEY : IN STD_LOGIC_VECTOR(0 DOWNTO 0);
--LEDR : OUT STD_LOGIC_VECTOR(9 DOWNTO 0);
LED : OUT STD_LOGIC_VECTOR(7 DOWNTO 0);
TX : OUT STD_LOGIC);
END UART;
architecture UART_beh of UART is
signal UARTREG : STD_LOGIC_VECTOR(8 DOWNTO 0);
signal RX : STD_LOGIC;
signal prescaler: STD_LOGIC_VECTOR(24 downto 0) := "1101111101011110000100000"; -- 12,500,000 in binary
signal prescaler_counter: STD_LOGIC_VECTOR(24 downto 0) := (others => '0');
signal newClock : STD_LOGIC;
signal TRANSMISSION : STD_LOGIC;
signal bitnumber : UNSIGNED(4 downto 0) := (others => '0');
begin
LED <= UARTREG(8 DOWNTO 1);
RX <= KEY(0);
process(CLOCK_50)
begin
if rising_edge(CLOCK_50) then
if (TRANSMISSION = '1') then
prescaler_counter <= prescaler_counter + 1;
if(prescaler_counter > prescaler) then
newClock <= not newClock;
prescaler_counter <= (others => '0');
end if;
end if;
end if;
end process;
process(RX)
begin
if falling_edge(RX) then
TRANSMISSION <= '1';
elsif (bitnumber = 10) then
if (RX = '1') then
TRANSMISSION <= '0';
end if;
end if;
end process;
process(newClock)
begin
if rising_edge(newClock) then
UARTREG(to_integer(bitnumber)) <= RX;
bitnumber <= bitnumber + 1;
end if;
end process;
end UART_beh;
process(KEY(0))
begin
if (SW(3) = '1') then
LED(0) <= SW(1);
else
LED(0) <= SW(0);
end if;
end process;
I took a look at that and that isn't a very good tutorial.Thanks for the replies. I read the gmvhdl.com guide which shed some light at certain aspects,
Hmmm, sounds like your uni isn't very good at the practical side of engineering. Heavy on the theory, with no practical usage of the theory (until you get to the exam). Seems like a lot of the students aren't adept at digital hardware design, and are more like software engineers.This is a uni exam, pity that we haven't had a single lecture about VHDL. I see most of us are trying to treat it as a programming language, raging about how they would rather use C than 'this shit'.
You probably should have a state machine but not some 35 state monster... Something along the lines of IDLE-START-DATA (loop 8 times here)-STOP-IDLE as the sequence it traverses.I gave my UART another go (code below), but I just can't get there. I was thinking of making a state machine with something like 35 states, but that seems tedious (it might work though).
Changes on falling edge of RX (which shouldn't be used as a clock)It says that it can't infer register for TRANSMISSION because it changes value on both rising and falling edge of the clock. I'm not sure what it means to infer a register.
if falling_edge(RX) then
elsif (bitnumber = 10) then
if (RX = '1') then
Code VHDL - [expand] 1 2 3 4 5 6 7 8 9 10 11 process (clk, rst) begin if rst = '1' then q <= '0'; elsif rising_edge (clk) then -- the stuff in here can have multiple nested if statements and/or case statements if en = '1' then q <= d; end if; -- end if; end process;
process(KEY(1))
begin
if rising_edge(KEY(0)) then
if (SW(3) = '1') then
LED(0) <= '1';
else
LED(0) <= '0';
end if;
if SW(2) = '1' then
LED(1) <= '1';
else
LED(1) <= '0';
end if;
end if;
end process;
Because KEY(1) is in the sensitivity list and KEY(0) is in the rising_edge statement.LED(1) changes value regardless of whether KEY(1) changes value, how is that possible? I thought nothing in that process could change unless something happens in the sensitivity list?
Because KEY(1) is in the sensitivity list and KEY(0) is in the rising_edge statement.
The signal sensitivity list is used to specify which signals should cause the process to be re-evaluated. Whenever any event occurs on one of the signals in the sensitivity list, the process is re-evaluated. A process is evaluated by performing each statement that it contains.
I think that's basically possible, if you have some experience with digital logic.I assumed that VHDL was easy enough to just learn by reading a little bit online combined with trial and error.
architecture UART_beh of UART is
signal UARTREG : STD_LOGIC_VECTOR(8 DOWNTO 0);
signal RX : STD_LOGIC;
signal prescaler: STD_LOGIC_VECTOR(24 downto 0) := "1101111101011110000100000"; -- 12,500,000 in binary
signal prescaler_counter: STD_LOGIC_VECTOR(24 downto 0) := (others => '0');
signal newClock : STD_LOGIC;
signal bitnumber : UNSIGNED(4 downto 0) := (others => '0');
type statetype is (idle, start, transfer, stop);
signal state,nextstate: statetype;
begin
--LED <= UARTREG(8 DOWNTO 1);
RX <= KEY(0);
--LED(0) <= newClock;
process(CLOCK_50)
begin
if rising_edge(CLOCK_50) then
state <= nextstate;
prescaler_counter <= prescaler_counter + 1;
if(prescaler_counter > prescaler) then
newClock <= not newClock;
prescaler_counter <= (others => '0');
elsif (state = idle) then
newClock <= '0';
prescaler_counter <= (others => '0');
end if;
end if;
end process;
process(state, RX, newClock)
begin
case state is
when idle =>
if (RX = '0') then
nextstate <= start;
end if;
led(1 DOWNTO 0) <= "00";
when start =>
if (newClock='1' and newClock'last_value='0') then
nextstate <= transfer;
end if;
led(1 DOWNTO 0) <= "01";
when transfer =>
if (bitnumber = 8) then
nextstate <= stop;
elsif (newClock='1' and newClock'last_value='0') then
UARTREG(to_integer(bitnumber)) <= RX;
bitnumber <= bitnumber + 1;
end if;
led(1 DOWNTO 0) <= "10";
when stop =>
bitnumber <= "00000";
if (RX = '1') then
nextstate <= idle;
end if;
led(1 DOWNTO 0) <= "11";
when others => nextstate <= idle;
end case;
end process;
end UART_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?