A Closer Look at Digital Input in the RP2040

Last post we look at digital output in the RP2040 microprocessor (used in the Raspberry Pi Pico). Now let's take a closer look at digital input. The object of digital input is, of course, to check if a pin has a high or low voltage level applied.

Looking again at the logical structure of an RP2040 pin, we will notice that the input signal, coming from the I/O pad can be directed to a peripheral (one of them is the GPIO that does digital input) and to the interrupt logic (IRQ). It can also be inverted before going to GPIO or IRQ.

source: RP2040 datasheet


Now let's look at the I/O Pad. For the input function we will be interested in the lower two parts: the input buffer and the pull resistors.

source: RP2040 datasheet

The input buffer has two functions: provide a high input impedance (to reduce the current into the pin and avoid to affect the voltage at the input) and to decide whether this voltage is low or high (generating the Input Data signal). The Input Enable signal can disable the buffer when we are using the pin for analog input or we are not using it and want to reduce power consumption. The Schmitt Trigger, if active, introduces a hysteresis into the decision by using different decision values for low to high and high to low transitions. This reduces changes in the input data when the voltage at the pin makes small changes around the limit between low and high level.

The RP2040 provides for pull-up and pull-down resistors (with values somewhere between 50k and 80k), These resistor are useful to guarantee a known level if a pin is open. One common example is connecting switches that connect a pin to ground or leave it open. Another example are components that can pull the down or leave it open (what is called, often not precisely, as open collector).

As for interrupts, they can generated by level (low or high), edge (change for low to high or high to low) or a combination of these. Each ARM cores has a bitmask to select from which pins it will accept interrupts, so we can, for example, say that interrupts generated by GPIO0 will be treated by the core 1 and interrupts generated by GPIO5 will be treated by the core 0. Bad things can happen with it enable interrupts from the same pin in the two cores, so don't do it!

Interrupt requests from all the enabled pins are connected to a single interrupt source in the cores, a status register needs to be read to find out which pin generated the interrupt. GPIO interrupts can also be used to wake up the RP2040.

Let's finish with a quick look at the digital input related functions available in the C/C++ SDK:
  • gpio_set_pulls, gpio_pull_up, gpio_pull_down e gpio_disable_pulls control a pin's pull-up and pull-down resistors
  • gpio_set_input_enable enable or disable a pin's input buffer
  • gpio_set_input_hysteresis_enabled controls the schmitt trigger function of a pin's buffer
  • gpio_set_irq_enabled selects the conditions for generating an interrupt
As usual, details about the RP2040 can be found at its datasheet, details on the SDK functions can be found in its manual. Both documents are available for download at


Comments

Popular posts from this blog