Tri-state pin not working


#1

I’m attempting to run two of my pins in tri-state inout mode. It didn’t work so I began narrowing down the problem. The test case below does not run correctly.

pin12 has an internal pullup and is connected to ground via a button
PIN_4, the tristate pin is connected to an active low LED for the test case

assign PIN_4 = pin12 ? 1 : 0;

The above code successfully turns the LED on when the button is pressed, and off when it’s not. However…

assign PIN_4 = pin12 ? 0 : 0'bz;

causes the LED to always be on, and

assign PIN_4 = pin12 ? 1 : 1'bz

also causes the LED to always be on (in active-high configuration)

I thought tri-state operation was possible due to this post, but it is strangely not working for me. I’m using the standard toolchain setup.

Any help would be appreciated


#2

First of all, 0'bz should be 1b'z - otherwise you are creating a 0-bit-wide signal.

It would also be worth looking at nextpnr if you are currently using arachne-pnr, and also ensuring that you are on latest git Yosys.


#3

Ok I’m working on setting up the toolchain in the non-apio configuration. Hopefully nextpnr will fix the tristate problem when I run it tomorrow. I was going to setup nextpnr sometime anyway to use that cool routing viewer.

Oh, another interesting thing, the following code correctly creates a floating pin

assign PIN_4 = pin12 ? 1'bz : 1'bz;

I also changed PIN_4 from inout to output to see if it fixed it, it didn’t.

If anyone else can recreate this then a bug report should be necessary, for which package I have no idea.

Also, when will we see apio support for nextpnr? Apio makes things so much easier!


#4

Looking at this some more, I think it is a width/sign extension issue, as “1” is a 32-bit rather than 1-bit number.

Switching to

assign PIN_4 = pin12 ? 1'b0 : 1'bz;

or

assign PIN_4 = pin12 ? 1'b1 : 1'bz;

should hopefully fix things.