Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

UART Receiver in VHDL

Status
Not open for further replies.

arve9066

Member level 2
Joined
Jan 21, 2016
Messages
48
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
446
Code:
--UART RX

PROCESS(clk)
  BEGIN		
	IF(clk'EVENT AND clk='1')THEN
--	
		if (RX_FLG = '0' AND RX_LINE='1') then
			uart_ack <= '0';
		end if;
--			
		IF(RX_FLG='0' AND RX_LINE='0')THEN
			RX_INDEX<=0;
			RX_PRSCL<=0;
			RX_BUSY<='1';
			TX_START <= '0';
			RX_FLG<='1';			
		END IF;
 
		IF(RX_FLG='1')THEN
			RX_DATAFLL(RX_INDEX)<=RX_LINE;
			IF(RX_PRSCL<868)THEN
				RX_PRSCL<=RX_PRSCL+1;
			ELSE
				RX_PRSCL<=0;
			END IF;
			IF(RX_PRSCL=434)THEN
				IF(RX_INDEX<9)THEN
					RX_INDEX<=RX_INDEX+1;
				ELSE
					IF(RX_DATAFLL(0)='0'AND RX_DATAFLL(9)='1')THEN
						DATA<=RX_DATAFLL(8 DOWNTO 1);
						LOOPDATA(7 DOWNTO 0) <= DATA;
						uart_data(7 DOWNTO 0) <= DATA;
						uart_ack <= '1';
					ELSE
						DATA<=(OTHERS=>'0');
					END IF;
					RX_FLG<='0';
					RX_BUSY<='0';
				--	uart_ack <= '0';
				END IF;
			END IF;
		END IF;				
	END IF;
END PROCESS;


I am using a Spartan 6 FPGA with clock signal 100Mhz receiving serial data at 115200 baud. I need an acknowledge signal uart_ack that goes high only when the valid data is received and all other times till the 8 bits are completely received, it should remain 0. Do you think the above code will work? I am particularly interested in the location of the uart_ack signal in the code to satisfy my requirements. There are other data being sampled every 10 ns by the clock and this one byte of UART data should be only one sample in the stream of data which I am trying to ensure by checking the status of the uart_ack signal
 

Code:
Do you think the above code will work? 
[/QUOTE]
Forecasters on vacation. You can simulate this code in Modelsim or another HDL simulator and you will see - work or not.
 

No. I am pretty new to VHDL. I am still learning my way around the Xilinx ISE and VHDL as such. I am in the process. In the mean time if someone could comment on the query it ll be helpful
 

FYI, You are writing code for HARDWARE....

Stuff like this for a shift register is a certain indication you've only written software before this.

Code:
RX_DATAFLL(RX_INDEX)<=RX_LINE;

By inspection I don't think your code will work. I'm not going to write a testbench for you to verify you're code.

BTW, it appears you need to learn how to count (from 0)....you are trying to pre-scale for the 115200 baud rate by dividing 100,000,000/869 = 115,075 instead of 100,000,000/868 = 115,207 (note the second prescaling value of 868 is more accurate).

- - - Updated - - -

No you aren't

IF(RX_PRSCL<868)THEN
RX_PRSCL<=RX_PRSCL+1;
ELSE
RX_PRSCL<=0;
END IF;


When RX_PRSCL is 0-867 the THEN clause is executed (0_thru_867 < 868)
on 867 the THEN clause causes RX_PRSCL to become 868
when RX_PRSCL is 868 that forces the ELSE clause to be taken
which then causes RX_PRSCL to become 0

In summary...RX_PRSCL counts from 0 to 868 back to 0, which means you just divided by 869 not 868. Maybe that is still unclear so a simpler example...

count to 3.
(0-1-2-3-0-1-2-3-...) is a divide by 4 not a divide by three: (0-1-2-0-1-2-...)

- - - Updated - - -

Hmmm looks like I added a reply to a deleted message :-?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top