Example: barber

AN234 Hardware Techniques for PICmicro …

2003 Microchip Technology 1AN234 INTRODUCTIONIt is the responsibility of engineers to get the mostperformance and capability out of the resourcesavailable. In this application note, we present ideas thathave helped previous designs reduce size and application note looks at different ways of: saving input pins driving multiple LEDs saving output pins maximizing pin usage power saving tricksSAVING INPUT PINSM ultiple Switches on a Single InputSome designs connect one switch to a single inputwhile others use keypad style multiplexing to getmultiple switches on fewer inputs. However, somedesigns are able to get many switches on one technique requires you to change the switchproblem from digital-to-analog. Once this change hasbeen made, we can measure the analog signals withthe digital CONVERTER (ADC)If your microcontroller has an extra ADC inputavailable, the ADC can be used to detect one or moreswitch closings by using a few resistors.

2003 Microchip Technology Inc. DS00234A-page 3 Driving two LEDs with one pin is simple. A bit more complex, driving 6 LEDs with 3 I/O pins is shown in

Tags:

  Hardware, Technique, Picmicro, Hardware techniques for picmicro

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Advertisement

Transcription of AN234 Hardware Techniques for PICmicro …

1 2003 Microchip Technology 1AN234 INTRODUCTIONIt is the responsibility of engineers to get the mostperformance and capability out of the resourcesavailable. In this application note, we present ideas thathave helped previous designs reduce size and application note looks at different ways of: saving input pins driving multiple LEDs saving output pins maximizing pin usage power saving tricksSAVING INPUT PINSM ultiple Switches on a Single InputSome designs connect one switch to a single inputwhile others use keypad style multiplexing to getmultiple switches on fewer inputs. However, somedesigns are able to get many switches on one technique requires you to change the switchproblem from digital-to-analog. Once this change hasbeen made, we can measure the analog signals withthe digital CONVERTER (ADC)If your microcontroller has an extra ADC inputavailable, the ADC can be used to detect one or moreswitch closings by using a few resistors.

2 See Figure using a switched resistor network, the value of avoltage divider can be changed. The voltage is thenmeasured with the ADC. Using simple code, the switchvalue is determined. One downside of this design isdetecting combinations of switches. To detectcombinations, the resistors have to be chosen so thatthe voltage resulting from a switch combination 1:MULTIPLE SWITCHES WITH ADCCOMPARATOR AND TIMINGA comparator can be used to detect multiple switcheson a single line. If the resistor values are selectedappropriately then the internal voltage reference couldbe adjusted to find the pressed switches. By making asmall change to the circuit, two additional methodsbecome possible. We can add enough circuitry to usethe comparator as an ADC and then use the methodpresented above, or we can change the circuit slightlyand charge a capacitor. See Figure 2:MULTIPLE SWITCHES WITH CHARGE TIMINGA uthor: Joseph JulicherMicrochip Technology inputVDDR3R2R1S3S2S1R4 PICmicroDigital In/VDDC omparator InR3R2R1S3S2S1C1R5 Note:R5 is approximately 100.

3 Hardware Techniques for PICmicro MicrocontrollersDS00234A-page 2 2003 Microchip Technology Figure 2 shows, R4 has been changed to a capaci-tor (C1). Instead of measuring voltage, we are nowmeasuring the time it takes the capacitor to , care must be taken to ensure that the capacitorcharge time is reasonable. If the timing is too fast, themicrocontroller could miss the event. If it is too slow, itwill take all day to process the switch inputs. Theresistor values should be chosen to provide enoughgap in charge times so that each switch or switchcombination is unique. If the design does not allowsimultaneous switch presses, the resistor selection isgreatly a single comparator input to detect the switchpresses requires that the input pin be changed to anoutput. This allows the capacitor to be pulled to , the pin is changed back into the singlecomparator input to let the capacitor charge up.

4 Whenthe capacitor voltage reaches the comparator thresholdvoltage, the state of the comparator will change. Thesoftware will measure the time it takes the capacitor tocharge to the threshold from the time the pin directionis THRESHOLDS AND TIMINGThe digital method is similar to the comparator fact, the circuitry is the same. Instead of using acomparator threshold to detect the charge of thecapacitor, the VIH threshold is used. Since the VIHthreshold of a Schmitt trigger input is larger than theTTL input, it provides a larger input detection , it is best to use a Schmitt trigger input todetect the capacitor charge. The downside to using adigital input is the current consumption is higher. Thehigher current consumption is caused by placingintermediate analog voltages on a CMOS gate. VIHcharges between parts so calibration may be to a Single InputKeypads are commonly used to input numeric data intomany applications.

5 Therefore, PORTB on thePICmicro microcontroller includes special features tosimplify reading the keypad. While keypads havebenefits, they require many pins in order to befunctional. A typical 4x4 keypad requires eight I/O 3 illustrates a resistor network, which changes a4x4 keypad into a switchable resistor matrix. Theresulting resistance is read by an ADC or a capacitorcharge timer, which determines the key that is is practical only when one key is pressed at a 3:4X4 KEYPAD RESISTOR NETWORK DIAGRAMDRIVING MULTIPLE LEDSL ight emitting diode (LEDs) are one of the most populardevices connected to PICmicro microcontroller out-puts. PICmicro microcontrollers are ideal drivers forLEDs because the output pins provide enough currentto turn them on. Unfortunately, the number of outputpins available is limited due to cost constraints. Tosolve this problem, we have a few suggestions.

6 SeeComplementary LED Drive Technical Brief (TB029) formore information. 2 LEDs on a single I/O pin and 6 LEDs on 3 I/O pins 12 LEDs on 4 I/O pinsLED's are diodes that allow current to flow in onedirection, which distinguishes them from filament lightbulbs. With this in mind, Figure 4 shows how to drive 2 LEDs with 1 I/O 4:2 LEDS ON 1 I/O PINVDDADC InputKeypadR3R2R1R4R5R6R7R8R9 PICmicroto A/DChannelVDDPIC microR1R2D1D2 Digital Output 2003 Microchip Technology 3 Driving two LEDs with one pin is simple. A bit morecomplex, driving 6 LEDs with 3 I/O pins is shown inFigure 5:6 LEDS ON 3 I/O PINSIf this concept is extended further, four I/O pins can beused to drive 12 LEDs as in Figure 6:12 LEDS ON 4 I/O PINSA lthough this is a very interesting concept, there arepotential problems with this approach. Additionalsoftware is required to drive this display. If the displayis illuminating more than one LED at a time, thensignificant amounts of software time can be consumedmultiplexing the LEDs to appear to be lit simulta-neously.

7 If the application is driving a dot matrixgraphics display where each LED is one pixel, then thedisplay will get dimmer as the LED count goes up. Thisis due to the amount of time spent switching one LEDon at a time. The duty cycle and intensity is , if the application s purpose is to light only 1 LED at a time, there is no reduction in intensity and thisconcept works mentioned earlier, driving this display requires somework. Each LED requires two outputs to be active, onehigh and one low. The rest of the pins are inputs so thatno current flows through them. To light more than oneLED at a time, the inputs and outputs must be re-con-figured often enough to appear that both LEDs areactive at the same time. It is best to keep each LED onfor the same amount of time and reserve time slots inthe multiplexing for the LEDs that are not lit. If themultiplexing only cycles between active LEDs andignores the inactive LEDs, the light intensity willdecrease as additional LEDs are Multiple Seven-segment Displays with 8 I/O PinsSeven-segment displays are one of the most oftenused numeric (and sometimes alphanumeric) the keypads, seven-segment displays requiremany output pins.

8 They require output pins for eachsegment and may require output pins to control thecommon cathode (or anode) of each digit. In the caseof a single digit display, pins are only required for thesegments as the common cathode (or anode) can betied to ground (or power). Which begs the question,how to drive multiple digits with only a small handful you only need to drive 2 digits, it is possible to useeight pins by mixing common cathode and commonanode type displays. See Figure 7:2 DIGITS ON 8 I/O PINSOne method of driving two displays is to use two seven-segment display driver chips. These chips translatefour bits of data into the correct segments pattern. Ofcourse, if you need more than two digits, you will needadditional D6D3D4 Digital I/O Digital I/O Digital I/O PICmicroR1R2R3R4D1D2D3D4D5D6D7D8D9 D10D11 D12 Digital I/O Digital I/O Digital I/O Digital I/O for CCLow for CACACCR1R2R3R4R5R6R7 Note:Pins A - G are Digital 4 2003 Microchip Technology 8:DIGIT EXPANSION USING AN OCTAL LATCHA nother technique is to use an octal latch, such as74F573, to be the digit selection.

9 See Figure 8. To use the octal latch described in Figure 8, the latchmust be loaded with the correct digit. The procedure isas follows:1. Raise LE and set <A-G> to the desired digitpattern. <A> = 1 and <B-G> = 0 will enable G1or Digit Lower LE and set <A-G> to display the correctnumeral. <A-F> = 1 and <G> = 0 will display 0 on Digit Delay long enough for the reader to notice. With3 ms per digit and 21 ms for all 7 digits, theresult is a 47 Hz refresh OUTPUT PINSU sing Opto-isolators as Output ExpansionEarlier, a method was described to drive many LEDswith just a few I/O pins. This same technique can beused with opto-isolators to drive a large number ofoutputs with just a few I/O pins. When D1 is activated, Q1 allows current to flow. Thiswill reduce the voltage on C1 and activate the D1 is deactivated, Q1 releases C1 and thevoltage on C1 begin to rise.

10 C1 will rise until M1 turnson and the load is deactivated. R1 and R2 slow theturn-on of M1 and provide the resistive component of aRC time constant. The time to turn off depends on thegate threshold of M1 and the RC time constant of (R1+ R2) x C. R2 should be chosen to limit the turn-on rateof M1. R1 is required to limit the turn off rate. C1 isadded to further reduce the turn off rate and reduce thevariation due to different gate capacitance. Forexample:When M1 is on, VGATE is turn M1 off, VGATE must reach 5V so:AFBGECDPIC microABCDEFGAFBGECDAFBGECDAFBGECDAFBGECD AFBGECDAFBGECDOE74F573 LER7R1R4R2R6R3R5R8Q1R9Q2R11Q4R10Q3R12Q5R 13Q6R14Q7 Note:Pins A - G are Digital F=VSUPPLY12V=VGTH5V =VC10V=VC12V 2003 Microchip Technology 5 Turn off time is the time it takes the capacitor to chargeto 2V, solving: Refresh the output every 300 s and the load willremain active. Ignore the output and the load will 9:OPTO-ISOLATOR CONTROLLED LOAD W/ AUTOMATIC TURN OFFThis method may not work for all applications.


Related search queries