library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity main is
Port ( txd : out STD_LOGIC := '1';
data: inout STD_LOGIC_VECTOR (9 downto 0);
clk: in STD_LOGIC;
act: inout STD_LOGIC;
do: inout STD_LOGIC;
swt: in STD_LOGIC_VECTOR (7 downto 0);
btn: in STD_LOGIC;
led: out STD_LOGIC_VECTOR (7 downto 0));
end main;
architecture Behavioral of main is
begin
led <= swt;
data <= '1' & swt & '0'; --Data Vector
activar: process (clk,btn)
variable cont: integer range 0 to 5000000;
begin
if (rising_edge (clk)) then
if btn = '1' and cont < 5000000 and do = '0' then
cont := cont + 1;
act <= '0';
elsif btn = '1' and cont >= 5000000 and do = '0' then
act <= '0';
elsif btn = '0' and cont < 5000000 and do = '0' then
cont := 0;
act <= '0';
elsif btn = '0' and cont >= 5000000 and do = '0' then
act <= '1';
cont := 0;
end if;
end if;
end process; --Fin Activar
envia: process (act,clk)
variable cont: integer range 0 to 16:=0;
variable cont2: integer range 0 to 8192 := 0;
begin
if (rising_edge (clk)) then
if (cont2 < 5208) then--Counter for 9600 bauds
cont2 := cont2 + 1;
else
if (act = '1') then
if (cont = 0) then
do <= '1';
txd <= data (cont);
cont := cont + 1;
elsif (cont < 9) then
txd <= data(cont);
cont := cont + 1;
else
txd <= data(cont);
cont := 0;
do <= '0';
end if;
end if;
cont2 :=0;
end if;
end if;
end process;
end Behavioral;
If you short pin 2 and 3 in the DSUB, all characters you type should be echoed back to the screen. Without the short - no echo.Well, thanks for your advice, I'm actually using a USB to Serial adaptor, since my computer does not have a Serial Port, is there any way to test if it's working all right? Or at least know if it is a Null or Direct Cable?
So, I was thinking, maybe I'm calculating the counter, the wrong way, I'm not really sure, I have a 50 Mhz clock, so if I want a 9600 bps, I have to divide (50 Mhz /9600 Hz) - 1 right?
When you release btn and cont >= 5000000 registred act goes "1"...elsif btn = '0' and cont >= 5000000 and do = '0' then
act <= '1';
cont := 0;
... but the probability that cont2 will have 5208 when act = 1 is very very small ... so at the next clock edge..if (cont2 < 5208) then--Counter for 9600 bauds
cont2 := cont2 + 1;
else
if (act = '1') then
if (cont = 0) then
do <= '1';
txd <= data (cont);
cont := cont + 1;
...act returns to 0.. so nothing work?elsif btn = '0' and cont < 5000000 and do = '0' then
cont := 0;
act <= '0';
Well thanks for all your replies, they all have been helpful, I was able to complete de Serial Transmitter, finally, so, now I'm going with the receiver, my teacher said it was optional, but I want to try, I've been reading some examples, so it says the oversampling should be done, with a clock signal 8 times faster, besides some documents says 16, I guess it's better using 16, well my question comes, from the part when I have to sync signals, I'm not really clear with that. Could someone help me, to figure out how to start?
receptor:
process (rxclk)
variable cont1: integer range 0 to 8;
variable cont2: integer range 0 to 16;
variable busy : STD_LOGIC;
--variable exito: STD_LOGIC;
begin
if rising_edge (rxclk) then
if (falling_edge (rx_in) and busy ='0') then
busy := '1';
end if;
if (cont2 = 0) then
if (cont1 = 0 AND busy = '1') then
cont1 := cont1 + 1;
elsif (cont1 /= 3) then
cont1 := cont1 +1;
elsif (cont1 = 3) then
if rx_in = '0' then
cont2 := cont2 + 1;
cont1 := 0;
else
busy := '0';
cont1 := 0;
cont2 := 0;
end if;
elsif (cont2 > 0 AND cont2 < 9) then
if (cont1 < 7) then
cont1 := cont1 + 1;
else
rx_reg (cont2 - 1) <= rx_in;
cont2 := cont2 + 1;
cont1 := 0;
end if;
elsif (cont2 = 9) then
if (cont1 < 7) then
cont1 := cont1 + 1;
else
--if (rx_in = '1') then
led <= rx_reg;
busy := '0';
end if;
end if;
end if;
rx_in_d <= rx_in;
if(rx_in_d = '1' and rx_in = '0') then
-- falling edge detected
Here is an example for "clock enable":
[VHDL] -- here is our clock enable module. We will take the incoming clock, lets say 1 - Pastebin.com
rx_reg (cont2 - 1) <= rx_in;
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?