# Rs232 MAXSONAR to de2

module testc (CLOCK_50, KEY, UART_RXD, LEDR);

parameter IDLE = 1'b0;
parameter RECEIVING = 1'b1;

input CLOCK_50, UART_RXD;
input [0:0] KEY;
output [7:0] LEDR;
wire [7:0] RxData;

reg shift;
reg [1:0] state, nextstate;
reg [3:0] bitcounter;
reg [3:0] samplecounter;
reg [12:0] counter;
reg [10:0] rxshiftreg;
reg clear_bitcounter, inc_bitcounter, inc_samplecounter, clear_samplecounter;

wire reset;

assign reset = KEY[0];
assign RxData = rxshiftreg[8:1];
assign LEDR = RxData;

always @ (posedge CLOCK_50)
begin
if (!reset)
begin
state <= IDLE;
bitcounter <= 0; counter <= 0;
samplecounter <= 0;
end
else
begin
counter <= counter+1;
if (counter>=1736)
begin
counter<=0;
state<=nextstate;
if (shift)
rxshiftreg<={UART_RXD, rxshiftreg[10:1]};
if (clear_samplecounter)
samplecounter<=0;
else if (inc_samplecounter)
samplecounter<=samplecounter+1;
if (clear_bitcounter)
bitcounter <=0;
if (inc_bitcounter)
bitcounter<=bitcounter+1;
end
end
end

always @ (state or UART_RXD or bitcounter or samplecounter)
begin
shift = 0;
clear_samplecounter = 0;
inc_samplecounter = 0;
clear_bitcounter = 0;
inc_bitcounter = 0;

case (state)
IDLE:begin
if (UART_RXD)
nextstate = IDLE;
else begin
nextstate = RECEIVING;
clear_bitcounter = 1;
clear_samplecounter = 1;
end
end
RECEIVING:begin
if (samplecounter == 1) shift = 1;
if (samplecounter == 3) begin
if (bitcounter == 10) begin
nextstate = IDLE;
end
inc_bitcounter = 1;
clear_samplecounter = 1;
end
else inc_samplecounter = 1;
end
endcase
end
endmodule


This is the verilog module i am using to get my rxdata ... When i connect the tx pin of the sensor to the rx pin of the de2 the leds just keep blinking without pattern and also the rxd led on the de2 keeps blinking which means it is getting the data. I give a outside 5v source to the sensor and ground the 5th pin of the rs232

If anyone can help it qould be great

-
If you've connect true RS232 voltages directly to your FPGA (as your mention of pin 5 suggests you may have), you will probably kill it. And it won't work anyway, since the polarity of RS232 is opposite that of logic-level decoders. You need a level shifter circuit which will include an inverter. You may also want to do your debugging using a PC terminal program as the data source instead of the sensor. Do your have you clock rates and baud rates worked out? – Chris Stratton Nov 17 '11 at 17:53
I don't think the sensor is true RS232, more like 0-to-VCC RS232 (see i.stack.imgur.com/YnVGu.jpg), so 5V in this. But still, the I/O pins on Cyclone II FPGA probably aren't 5V tolerant. The DE2 does have 47-ohm resistors in-line between the expansion headers and the FPGA I/O pins, so that might be helping somewhat. – Craig Nov 17 '11 at 18:22
i have connected the sensors to an outside 5v voltage i just connect the tx of the sensor to the rx of the fpga. The gnd actually does not matter it gives me the same output anyways. I am still not sure if they are compatible. If there is anyother way i can achieve this please let me know – user591124 Nov 17 '11 at 19:15
it is running on 9600 baud, 8bit no parity and 1 stop bit the sensor gives .. R (Ascii) and a binary for 0-255 – user591124 Nov 17 '11 at 19:21