0
\$\begingroup\$

I am designing a simple 16 bit adder circuit in Digilent's Xilinx Spartan 6 FPGA. The Verilog design accepts two 16 bit inputs A and B and returns the 16 bit sum C = A+B. I am ignoring carry in and carry out.

I want to send A and B from PC to FPGA using serial port as well send the sum C from FPGA to PC using serial port. I am not sure how to do this. I have googled but could not find something simple. Can i send A and B as decimals like A = 5, B = 3? or do i have to send it as ASCII? How do i distinguish A from B if A = 255 and B = 512 (i.e., both A and B have multiple digits). How does FPGA deal with ASCII.

Some pointers or explanations will be really appreciated

\$\endgroup\$
1
  • \$\begingroup\$ While tbis can be done, SPI is often much easier to integrate into an FPGA design when you want a way to set/get registers. You can use a usb microcontroller or specialized usb chip as a bridge - ideally your bridge will also let you inject the fpga configuration file. \$\endgroup\$ Oct 15, 2014 at 0:37

2 Answers 2

2
\$\begingroup\$

I would suggest either writing a UART module from scratch or finding one online. Then all you would need to do is write a wrapper that interfaces the UART to your registers. Here is one possible open source Verilog UART module that I wrote a while ago:

https://github.com/alexforencich/verilog-uart

This particular module uses the AXI stream interface, so it should not be very difficult to interface with your design.

The AXI stream interface has three signals: tdata, tvalid, and tready. tvalid indicates that tdata contains valid data, and tready indicates that the sink is ready to receive the data. Data bytes are transferred only when tvalid and tready are both high.

What I would recommend doing is defining a simple serial protocol that supports some basic framing. Say, to send A and B to the FPGA, you would send some sort of start indication (e.g. 0 or perhaps ASCII S or W), then the MSB of A, then the LSB of A, then the MSB of B, then the LSB of B. Then you can write a state machine that looks for the start indication, then loads the next four bytes into the appropriate registers. Then once the operation is complete, the state machine can send the result back to the computer. If you want to use ASCII instead of binary, you can do that too, but it's a bit more complicated to convert everything. I would recommend using hex if you want something human readable as it is much easier to divide by 16 than it is to divide by 10 (bit shift/bit slice instead of an actual division operation).

\$\endgroup\$
3
  • \$\begingroup\$ Thanks Alex. I am slightly confused about the last part where you are mentioning both ASCII and binary. Can i send both ASCII and binary from PC. If so how? How can i send Ascii S and then binary value of A (assume A =255) Can you please tell which tool sends binary and ASCII to FPGA. I know of Hypterterminal which only sends ASCII. \$\endgroup\$ Oct 14, 2014 at 23:35
  • \$\begingroup\$ If you want to use binary, you might have to use some sort of a script or other program to send the data to the FPGA. Personally, I am partial to Python and it is very easy to create binary data from there. E.g. if you use PySerial to open a port called sp, then you can do sp.write(struct.pack('c>h>h', 'S', 123, 456)) . This will send an ASCII S followed by 123 and then 456, LSB first (big endian). If you want to use hyperterminal, then converting to hex would be a better idea than converting to decimal. \$\endgroup\$ Oct 15, 2014 at 0:06
  • \$\begingroup\$ Consider hex - fixed record size and easy conversion like binary, but human readable and plenty of codes to reserve for delimiters and terminators. \$\endgroup\$ Oct 15, 2014 at 0:35
0
\$\begingroup\$

Ken Chapman (Xilinx employee) provides a simple and lightweight UART module as an external I/O device for his 8-bit processor (PicoBlaze). These UART modules (RX and TX) can be used on every Xilinx FPGA. Each module has a simple byte interface. This processor and it's periphery comes with a lot of documentation and examples :)

=> Search "PicoBlaze" on the Xilinx website.

For your requested transmission of 2x 16 bit, you will need a simple statemachine which receives 4 bytes in 4 cycles e.g. coded as A0, A1, B0, B1. I would advice to send all bytes already binary encoded to the FPGA, so there is no ascii or BCD to binary decoding need.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.