# Papilio to papilio
## Problem

The goal is to connect two papilio's and test their ability to send data back and forth as fast as possible.
The project goal is to get high speed data from one Spartan 3E FPGA to another by using wires (LVDS) pair and this is also done without the use of a common clock between the two papiilio's.

## Conceive

The starting point is to replicate this project.

## Setup

* The first step is to download the Xilinx project file. This file can be found on Hamsters web page high speed link.
* Next upload the test_signal bit file onto both papilio's.
* Now you need to connect the three wires to both papilio's.

## Wire Setup

In order to do this you need three wires with exposed cable along with three attachment pins for the second papilio. You leave enough space in between the megawing and the papilio (#1) to wrap the three wires around the ports 8, 13, and 14, those wires are then attached to the pins in papilio (#2) which should be inserted into ports 8, 10,and 11. I have also found that you do not have to have the second papilio in my case the 250k plugged in via usb. By being connected through the wires it will still recieve power and data, the LED lights still come on. Below under demo is a modification to this project a slightly different setup with the wiring in order to include the papilio megawing shield.

## Framing/Clock

The papilio one has a 32MHz oscillating clock. When using two pailio's one as a transmitter and one as a receiver you have to account for an offset in timing. Meaning that they run at slightly different clock cycles causing the bits transmitted and received to be off for example bits 6 and 7 will not match the bits 6 and 7 that are received from the transmitter. To counter this problem Hamster adjusted the received data to align with the sender's clock. This is referred to as the sample offset. This is done in the VHDL code. There are three signals associated with the speed of the transmission, clk_slow, clk_fast,clk_fast_n these signals are linked to instantiations verify signal, serial_rx, and test_signal. This portion of the code is adjusting the data that is received through transmission so that it matches the speed of the transmitting papilio's clock. Once the data is received the "Frame Alignment" begins. The frame alignment is used to verify that the transmitted data is in sync this is done by using a "syncword" (in bits). The syncword is attached to the very beginning of the data bit stream, the way this works is two subframes go into a single ten bit frame. According to Hamster ten bit frames are ideal for this type of transmission because they can be passed through a 8bit/10bit decoder in order to recover the data. When the receiver gets a signal that is toggled it is informing it that a new frame has arrived. That is the importance of the toggle feature in the signal transmission.

## Implement

It is a zip file containing the entire program, it includes the VHDL code for the main project file and the bit file to program your Papilio. I uploaded the bit files individually using a usb cable to each papilio. The next step is to setup the wiring in between the two papilio's. You will need three jumper cables to accomplish the wiring for this project.
In this project I am using a 500k papilio board and a 250k papilio board, because of the configuration logic block (CLB) on the papilio 500k it will always be the transmitter and the 250k papilio will always be the receiver. I discovered this by trail and error, I later contacted Michael Filed who originally created this project and I have quoted the information he provided below. This is why if you disconnect a wire from the 500k papilio the program stops transmitting completely. In comparison to disconnecting a wire from the 250k papilio it will simply disrupt the signal and the connection is de-synchronized but when the cable is reconnected it is immediately synchronized again.
"One thing I am sure of is that for you the 500K must be the transmitter, and the 250K must be the receiver, as the project is super-sensitive to where the CLBs are on the physical die. On the 500K they are put in the bottom half of the die" Michael Field.

## Demo

This is a link to sample video of the papilio's transmitting data. http://youtu.be/0rG6nM75n2U http://youtu.be/8FBj1fFjwK0

## Verification

The above video link is a demonstration of the project working from hamster's original project with the modification of using a papilio 500k board instead of two 250k papilio's. Through the wire connection I successfully transmitted data from the 500k papilio to the 250k papilio which is the receiver. The LED's on the megawing shield display one led light which represents that the data transmission is 'synced' correctly. When a wire is loose you the connection is disrupted you get two led lights on, on my megawing shield it was led's 5 and 6 that would come on and stay on.

## Next Steps

Repeat with two 500K and two 250K papilio's to see if can get bidirectional working.