Close

How to use the LED driver pins as user I/O

A project log for DIPSY

DIY System on Chip based on FPGA, priced below 5 USD

christophChristoph 09/17/2015 at 08:394 Comments

The dipsy FPGA is intended to be used as an LED driver chip, but we can also use the LED pins (RGB0..2, IRLED and BARCODE) as user I/O. To do so, special driver IP needs to be used. Here's a simple verilog source to demonstrate this:

module top (
  input pin_in,
  output pin_out
);

wire mywire;

SB_IO_OD #(
  .PIN_TYPE(6'b000001),
  .NEG_TRIGGER(1'b0)
) pin_in_driver (
  .PACKAGEPIN(pin_in),
  .DIN0(mywire)
);

SB_IO_OD #(
  .PIN_TYPE(6'b011001),
  .NEG_TRIGGER(1'b0)
) pin_out_driver (
  .PACKAGEPIN(pin_out),
  .DOUT0(mywire)
);

endmodule
There an input (pin_in), an output (pin_out) and a wire that's just used as an internal signal. This is as simple as it gets, and when I first tried this I just wrote
assign pin_out = pin_in;
But iCECube barfed at that, telling me that this couldn't be realized with LED driver pins. So I asked antti for advice and he pointed me at those SB_IO_OD things. They are described in the "iCE40 LED Driver Usage Guide". Let's have a closer look at the first one:
SB_IO_OD #(             // IP name
  .PIN_TYPE(6'b000001), // configure as simple input, no output capabilities
  .NEG_TRIGGER(1'b0)    // don't know what that means exactly
) pin_in_driver (       // the instance name
  .PACKAGEPIN(pin_in),  // the pin to use as input
  .DIN0(mywire)         // where to put data from that pin
);
There are more ports to this IP which can be used to synchronize it to a clock, but we don't need that.

The output is very similar:

SB_IO_OD #(
  .PIN_TYPE(6'b011001), // configure as simple input pin
  .NEG_TRIGGER(1'b0)    
) pin_out_driver (
  .PACKAGEPIN(pin_out), // connect to output pin
  .DOUT0(mywire)        // with data from this wire
);
I hope this helps those who try to use LED driver pins as simple I/O. I was able to apply a 1 Hz square wave on pin_in (RGB0), and drive an LED (with a current limiting resistor) on pin_out (RGB1).

This example is currently in my own dipsy fork (THP2015/examples/verilog/basics/01_inout/), but I've already created a pull request for antti.

Discussions

AlexKraft wrote 01/29/2021 at 10:32 point

you are my savior! Thank you

  Are you sure? yes | no

rguighamza0 wrote 01/12/2018 at 21:47 point

i didnt understand your code, can you write an IRLED driver for example ? 

please !!

  Are you sure? yes | no

Yann Guidon / YGDES wrote 09/17/2015 at 17:02 point

What about a VHDL version of this tutorial ? :-)

  Are you sure? yes | no

Christoph wrote 09/17/2015 at 17:04 point

Well I'm only just learning to use FPGAs, and found verilog to be a bit easier to get used to. OTOH a VHDL version of *this* tutorial should be fairly easy to do, as the LED Driver Guide has VHDL examples.

  Are you sure? yes | no