Possibly the most exciting feature of the Papilio is the ability to shift peripheral functionality to any pin at any time, completely on the fly. Shifting SPI pins allows you to easily connect up to 12 SPI devices at once! Or control multiple stepper motors by shifting PWM outputs! Finally, shifting functionality means you never need to worry about where to connect Wings. Every I/O pin is equal, so go ahead and connect your Wing to any open Wing Slot, the FPGA can shift to accommodate the Wing!
Shifting the location of the SPI master pins (MOSI, MISO, CS, and SCK) gives you the ability to connect up to 12 SPI slaves without worrying about loading down a SPI bus. If, for example, you had twelve SD cards attached to the Papilio you would be able to communicate with them all by simply changing where the SPI peripheral pins connect. Read from one SD card, them programmatically change the pin location to read from the next and so on. Shifting pins is very easy to accomplish since it is already built into the AVR8 "Shifty" Soft Processor. If you need more performance you can always add more SPI masters to the AVR8 Soft Processor but that is outside the scope of this article.
Similarly, the PWM outputs from the timers can be shifted on the fly. The AVR8 is patterned after the AtMega103 and it implements the same timers that the AtMega103 does. However, unlike the AtMega103, the PWM outputs can be shifted to where you need them. This gives you 4 PWM outputs that can be shifted to any of the 48 I/O pins on the Papilio.
The Infrared Wing Quick Start Video shows an example of moving a PWM pin on the fly. Skip to 3:08 if you just want to see the pins moved.
On the Papilio, every I/O pin is equal, no more figuring out which pins your SPI or PWM devices need to connect to. Connect to any open pin and let the Papilio do the work. This also provides freedom in developing Wings, you don't need to worry about routing a PWM to pin 3 like you do with shields. Best of all, once you design a Wing it can be connected to any open Wing Slot and you can configure the FPGA to adapt to its location.
|Peripheral Name||Peripheral Pin||Register||Location|
|Papilio Stepper Core||Wing Slot Group||SM1_LOC||0x2000|
|Papilio Button/LED Core||Wing Slot Group||BL1_LOC||0x3000|
(Visit the Papilio Pinout Page to learn valid values to use for pin locations.)
Example sketch to move SPI pins
For more in depth examples look at the SDFat examples under File/Examples/SDFat in the Papilio-Arduino IDE.
Example sketch to move PWM pins
For more in depth examples look at the IRRemote examples under File/Examples/IRRemote in the Papilio-Arduino IDE.
The version of the AVR8 that is included with the Papilio-Arduino IDE is known as the "Shifty" branch which is based on the AVR8 "Vanilla" source code. The AVR8 "Shifty" branch implements functionality like shifting pins, an SPI master, custom cores and it uses 99% of the Papilio One 250K resources. In comparison, the AVR8 "Vanilla" branch only uses 60% of the Papilio One 250K resources when all peripherals are disabled. It leaves as many resources available for your unique customizations as possible while the AVR8 "Shifty" branch provides as much functionality as possible.
With the AVR8 "Shifty" branch registers that control pin location are added to the 0x1000 address space. The 0x1000 address space is normally reserved for external SRAM in the AtMega103.
In the Papilio-Arduino IDE there is a file (hardware/arduino/cores/pins_papilio.c) that provides a name for those registers that can be used by sketches.
Using that user friendly name to set the register with a pin location instructs the custom VHDL in the "Shifty" core to connect the peripheral to the specified pin.