Internal pullup in BX


#1

A newbie here, to TinyFPGA and to Verilog (I’m an Ada programmer by trade)

My first attempt is to control an LED via a pushbutton, as in this discussion but inverted (push button to light LED).

All is OK so long as I use a 100k external pullup, but as I read the documentation

  • the FPGA provides an internal (weak?) pullup,
  • the default is for all pins to be set to input with internal pull-up.

This isn’t happening; without the external pullup, the input pin is just seeing noise (the LED is fully on when the button is pushed, half intensity when not).

How do I configure the internal pullup, if indeed that’s possible? advisable? I’ve looked on the web but most of the resources are for much more complex configurations, & I’d rather start small!


#2

The pullup is not the default - I don’t know what documentation you read.

To configure the pin with the pullup, you use the SB_IO directive:

wire button;

SB_IO #(
  .PIN_TYPE(6'b 0000_01),
  .PULLUP(1'b 1)
) button_input(
  .PACKAGE_PIN(PIN_1),
  .D_IN_0(button)
);

Then you use button instead of PIN_1 to access the pin.


#3

Thanks so much, worked a treat.

As to the doc I read - clearly brain fade, sorry.

Is there some documentation which says “you need to read these if you’re using Lattice FPGAs”?


#4

I don’t really know of definitive documentation. The Lattice Ice40 documentation describes the directives like SB_IO and is useful for some other things but is not an easy read and tends to describe things from a Lattice tools perspective. For some things you need to read icestorm documentation as not everything that Lattice’s or other variants of Verilog support, is supported by icestorm. There are then a lot of useful Verilog tutorials.

(BTW, I didn’t know there were so many Ada programmers stil around, with you and @Fabien on this forum).


#5

@Fabien’s postings on Twitter & the Adacore blog were what got me here!

Will check out the icestorm doc (already found the Ice40 docs & several tutorials), thanks


#6

How can we enable many pullups with this notation? For example I want to enable pullups on the inputs PIN_1 through PIN_8 for eight total button inputs.


#7

Yes, just change button_input to button_input[7:0] or whatever and declare the PACKAGE_PIN and D_IN_0 wires or registers with the same dimensions.

PACKAGE_PIN({PIN_8, PIN_7, PIN_6, PIN_5, PIN_4, PIN_3, PIN_2, PIN_1} ) probably works as well.

Or you can do each one separately.