12F683 too few outputs

Discussion in 'Embedded Systems and Microcontrollers' started by tracecom, Oct 2, 2013.

  1. tracecom

    Thread Starter AAC Fanatic!

    Apr 16, 2010
    3,869
    1,393
    I have a circuit that uses two ADC inputs, and I need four digital outputs from the 12F683. Three of the outputs are for LED indicators (on/off) and one is for an LCD. The only spare GPIO is GPIO.3, which is input only.

    Any suggestions (other than a larger PIC)?

    Thanks.
     
    Last edited: Oct 2, 2013
  2. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
  3. tracecom

    Thread Starter AAC Fanatic!

    Apr 16, 2010
    3,869
    1,393
    Please explain that further. Thanks.
     
  4. JohnInTX

    Moderator

    Jun 26, 2012
    2,341
    1,022
    Stack 2 LEDs and 2 resistors from V+ as anodeLED1cathode->R1->R2->anodeLED2cathode->GND. Make V+ about 1.5*Vforward of the LEDs (use a zener between V+ and LED1 if you need to). Connect a GPIOutput to the junction between R1 and R2.

    Output=1 turns on LED2
    Output=0 turns on LED1.
    HIz turns both off.

    It may be easier to make the voltages work by using 2 zeners, replacing R1 and R2, and have a single resistor between the zeners and the PORT. The idea is that V+ for the series LEDs/zeners is not enough to light them when the PORT is HIz but the port sinking or sourcing will be enough to turn one on.

    You also could run 2 LEDs in inverse parallel, one node to the port and the other to a voltage divider, zener supply etc. at 1/2 Vdd.

    To be able to turn both on at once you run a 50% duty cycle output to PORTx all the time and use the TRISx bit, sync'ed with the output level to determine whether the LED is off or on on its 1/2 cycle.

    I don't know if it buys you anything over Charlieplexing but it may be simpler to code.

    BTW any of these schemes will likely require the GPIO port to be shadowed i.e. flip the bits on a byte in RAM then movwf GPIO rather than using bcf, bsf.

    Me too.
     
    Last edited: Oct 3, 2013
  5. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    I've used a shift register to expand digital outputs on a 12F683 before...
     
  6. MMcLaren

    Well-Known Member

    Feb 14, 2010
    759
    116
    Can you tell us about the one pin LCD, please? Is this a serial LCD? If so, does it have some digital outputs that could be used for the LEDs? If not, you might be able to patch into the four LCD data lines and use them to mux' four switches onto a single I/O pin and four LEDs onto a single I/O pin (three pins total for LCD, switches, and LEDs).

    Cheerful regards, Mike
     
    Last edited: Oct 3, 2013
  7. tracecom

    Thread Starter AAC Fanatic!

    Apr 16, 2010
    3,869
    1,393
    Okay, I should have provided more information.

    This is a thermostat. The two analog inputs are the sensor and the setpoint voltages. The four outputs are: one to a MOSFET to switch a heater (or fan, or cooler) on/off as required, one to an LED that indicates a "too cold" condition, one to an LED that indicates a "too hot" condition, and one to a serial LCD that will be used only during programming of the micro-controller. The "too cold" and "too cold" LEDs will never be on simultaneously, but can be off simultaneously, which makes me think that one digital output from the μC could be used to control both LEDs, but I can't quite think how to do it. Note that the "too cold" and "too hot" LEDs do not coincide with the on/off operation of the MOSFET drive pin.

    Thanks for the feedback.
     
  8. Art

    Distinguished Member

    Sep 10, 2007
    785
    61
    You can use an IO pin's tris register to either source or sink current for an LED,
    so you should be able to use two LEDs connected with opposite polarities
    to the same IO pin and alternate the pin's tris and state to do all but switch both LEDs on at the same time.
     
  9. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    You can put two LEDs on the two ADC input pins. Use a series resistor from the PIC pin to the LED anode, then the LED cathode goes to ground. The ADC connects through another resistor to the same PIC pin.

    To light the LED you turn the pin to an output for about half the time. This is done at >100 Hz so the user won't see the LED flicker. The other half of the time, the pin will work fine as an ADC input (provided the analogue voltage is less than the 1.2v which is the Vf of the LED).

    Total cost; 2 extra resistors.
     
  10. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    You could also implement it such as continuous on. Is one kind of status. Slow blinking is a second, and fast blinking is third status. Blinking is good for error condition. As it is easy to spot.
     
  11. tracecom

    Thread Starter AAC Fanatic!

    Apr 16, 2010
    3,869
    1,393
    Thanks for the suggestions and explanations. I will put something together next week and try it out.
     
  12. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    This is what Art said:

    [​IMG]

    I drew it before I read his post I swear! :D

    Since the LCD is only used during programming I would have to ask why this same pin could not do that function also? Share 2 LEDs and one LCD all on the same pin.

    It's way more practicable then sharing an analog input with a digital output.
     
  13. Art

    Distinguished Member

    Sep 10, 2007
    785
    61
    We were both confused then! :D
    The top LED needs to be reversed.
     
  14. tracecom

    Thread Starter AAC Fanatic!

    Apr 16, 2010
    3,869
    1,393
    I think I am going to first try the dual LED approach, but with a two color LED. The LED will show one color for "too cold" (blue would be nice) and a different color for "too hot" (red would be nice). I don't suppose there is such an LED, but it won't hurt to look.

    Thanks, guys.

    In the following diagram, if the pin is set to be an input, won't both LEDs light dimly?

    [​IMG]
     
    Last edited: Oct 3, 2013
  15. Art

    Distinguished Member

    Sep 10, 2007
    785
    61
    I think bicolour LEDs will have the wrong terminals connected together internally, you would need access to all four pins of the package :(
     
  16. tracecom

    Thread Starter AAC Fanatic!

    Apr 16, 2010
    3,869
    1,393
    Because I want to see the LEDs operate while I am looking at data from PIC on the LCD.
     
  17. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    You could get rid of the glow with some more series diodes. How many depends on the supply voltage and the type of LEDs used.

    Yes, it's a kludge, but so is not going with a PIC with enough pins. :rolleyes:
     
  18. tracecom

    Thread Starter AAC Fanatic!

    Apr 16, 2010
    3,869
    1,393
    I suppose it's my frugal nature to try to squeeze the most of every nickel. What really bugs me is having GPIO.3 doing nothing.
     
  19. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    It could be used as a current sink for a LED ;)
     
  20. tracecom

    Thread Starter AAC Fanatic!

    Apr 16, 2010
    3,869
    1,393
    Does that mean that I could tie the anode of the LED to Vcc (with a resistor) and turn the LED on and off with software? If so, that solves my problem.
     
Loading...