INDUSTRIAL LCD DISPLAYS / IGBT MODULES DISTRIBUTOR

Infineon / Mitsubishi / Fuji / Semikron / Eupec / IXYS

Using Pin Multiplexing to Reduce Pin Usage on 8-Bit Microcontrollers

Using Pin Multiplexing to Reduce Pin Usage on 8-Bit Microcontrollers

Posted Date: 2023-06-25

Pin Multiplexing on PIC® and AVR® Microcontrollers

Common Function Enter/Output (GPIO) pins are one of the vital necessary specs when contemplating a microcontroller for a design. You want sufficient pins to attach your microcontroller to all the opposite parts in your design; nevertheless, extra pins than wanted may cause an pointless improve in design price and occupy extra space in your board. Moreover, decreasing the required variety of pins in a design might be the distinction between two bundle sizes in a design. If solely there was a solution to squeeze just some extra I/O pins out of the smaller one! Luckily, there are strategies to unencumber pins in such circumstances.

Listed here are two examples created by our Microchip functions crew utilizing the AVR DD household of microcontrollers. First, we’ll focus on multiplexing GPIO pins to regulate LEDs by means of a way known as “Charlieplexing.” Following that, we are going to take a look at the way to concurrently run a separate pushbutton and LED utilizing a single pin.

The core thought behind Charlieplexing is to leverage the three states the microcontroller pin might be in: digital HIGH, LOW and high-impedance digital enter state (also called HIGH-Z or Tri-State). By utilizing these three states as an alternative of simply the everyday HIGH and LOW, the consumer can use n variety of pins to drive as much as (n2-n) separate LEDs. On this instance, three designated pins would permit for six separate LEDs.

So how precisely does charlieplexing work? To know that we’ll want to take a look at an instance.

Using Pin Multiplexing to Reduce Pin Usage on 8-Bit Microcontrollers

Right here we have now three I/O pins driving six LEDs.

If we need to activate simply LED 1, we might want to set PA2 HIGH, PA3 LOW and PA4 to HI-Z. Present will movement by means of LED1 and switch it on while leaving all the opposite LEDs within the off state.

Using Pin Multiplexing to Reduce Pin Usage on 8-Bit Microcontrollers

The tri-state is necessary right here as a result of if PA4 was “LOW” as an alternative, it could additionally activate LED 5 inadvertently. As proven under:

Using Pin Multiplexing to Reduce Pin Usage on 8-Bit Microcontrollers

The excessive impedance logic state ensures electrical present solely travels by means of LED1. This course of could also be repeated for any LED within the circuit with the corresponding mixture of I/O pin states (the consumer should have one HIGH, one LOW and the rest HIGH IMPEDANCE for anticipated conduct).

Whereas at any given second this technique solely lights one LED, rapidly altering I/O states will create the phantasm of a number of lit LEDs. (LED dimming works by a really comparable precept utilizing Pulse Width Modulation on a single LED). This may be seen under:

Using Pin Multiplexing to Reduce Pin Usage on 8-Bit Microcontrollers

The second instance includes juggling an LED and a pushbutton on a single pin.

That is completed by utilizing interrupts and timers to our benefit. More often than not the microcontroller pin is driving the LED. Nonetheless, a timing peripheral will periodically set off an interrupt contained in the microcontroller to rapidly change the pin from an output to an enter after which test the standing of the pushbutton. Whereas this can briefly cease driving the LED, if the method might be finished fast sufficient, there's little to no seen impact on the LED whereas the button’s standing is checked.

We use this technique within the instance under. The microcontroller is driving a blinking LED nonstop whereas periodically checking the pushbutton and lighting a separate LED if the button is pushed.

Using Pin Multiplexing to Reduce Pin Usage on 8-Bit Microcontrollers

Whereas this submit solely covers the fundamentals of those two methods, the corresponding GitHub web page revealed by our Microchip functions crew comprises diagrams, pattern code and a way more detailed rationalization. Please go to that submit and our AVR DD Product Household web page to be taught extra.