<< | Papilio Introduction | >>

AVR8 Shifty Variant

Overview

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!

Shift SPI

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.

Shift PWM

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.

All I/O is Equal

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.

Available Peripherals

Peripheral Name Peripheral Pin Register Location
Timer 0 PWM0 PWM0_LOC 0x1000
Timer 1 PWM1A PWM1A_LOC 0x1001
Timer 1 PWM1B PWM1B_LOC 0x1002
Timer 2 PWM2 PWM2_LOC 0x1003
SPI 1 MOSI SPI1_mosi_LOC 0x1004
SPI 1 MISO SPI1_miso_LOC 0x1005
SPI 1 SCK SPI1_sck_LOC 0x1006
SPI 1 CS SPI1_cs_LOC 0x1007
Papilio Stepper Core Wing Slot Group SM1_LOC 0x2000
Papilio Button/LED Core Wing Slot Group BL1_LOC 0x3000
  • The Stepper Core and B/LED Core are included in the AVR8 "Shifty" branch but they are not documented here. A future article will cover the use of these cores.

Examples

(Visit the Papilio Pinout Page to learn valid values to use for pin locations.)

Example sketch to move SPI pins

void setup() {
  //Specify where to connect the SPI pins at startup
  SPI1_mosi_LOC=AL3;    //AL3 for Wing Slot AL
  SPI1_miso_LOC=AL1;    //AL1 for Wing Slot AL
  SPI1_sck_LOC=AL2;     //AL2 for Wing Slot AL
  SPI1_cs_LOC=AL4;      //AL4 for Wing Slot AL

}
void loop() {

  delay(2000);          // wait for two seconds

  //Move SPI pins on the fly
  SPI1_mosi_LOC=CL3;    //CL3 for Wing Slot CL
  SPI1_miso_LOC=CL1;    //CL1 for Wing Slot CL
  SPI1_sck_LOC=CL2;     //CL2 for Wing Slot CL
  SPI1_cs_LOC=CL4;      //CL4 for Wing Slot CL

  // This loop loops forever and does nothing
  while(true) {
    continue;
  }
}

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

void setup() {
  //Specify where to connect the SPI pins at startup
  PWM0_LOC=AL1;         //AL1 for Wing Slot AL
  PWM1A_LOC=AL2;        //AL2 for Wing Slot AL
  PWM1B_LOC=AL3;        //AL3 for Wing Slot AL
  PWM2_LOC=AL4;         //AL4 for Wing Slot AL

}
void loop() {

  delay(2000);          // wait for two seconds

  //Move SPI pins on the fly
  PWM0_LOC=CL1;         //CL1 for Wing Slot CL
  PWM1A_LOC=CL2;        //CL2 for Wing Slot CL
  PWM1B_LOC=CL3;        //CL3 for Wing Slot CL
  PWM2_LOC=CL4;         //CL4 for Wing Slot CL

  // This loop loops forever and does nothing
  while(true) {
    continue;
  }
}

For more in depth examples look at the IRRemote examples under File/Examples/IRRemote in the Papilio-Arduino IDE.

Technical Information

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.

  

Share |