Insufficient I/O ports in MCU

Discussion in 'Embedded Systems and Microcontrollers' started by raychar, Feb 6, 2013.

  1. raychar

    Thread Starter Member

    Nov 8, 2011
    82
    0
    Hello, everybody,

    I have many I/Os lines in my circuit and the current PIC16F877A can't fullfill the requirement. Currently, except the MCLR, OSC1, OSC2, PGD, PGC, PGM pins, all others are used. I also use multplexing method and input and output lines on the same port method. As I don't want to make the circuit and program so complicated and also now, still is of shortage five I/Os. Are there other MCU models which have more I/O pins that I can used instead of this one or some other methods?

    Thanks,
     
  2. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    Read the first link in the first post of the sticky "A goldmine for the PIC programmer" at the top of the embedded forum. It has lots of tips and tricks.
     
  3. raychar

    Thread Starter Member

    Nov 8, 2011
    82
    0
    There a lot of tips and tricks that are very useful. I confess I would have definitely progressed a lot if I read it some time ago. There are many
    circuits and designs that I tried before and problems encountered before..

    For the several keys on a port using RC charging time method, it is a bit difficult for me to write the program indeed...

    Are there other simpler methods ?

    Thanks,
     
  4. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    It's hard to say without more detail.
    Recently I made a project using a resistor ladder and one ADC pin to read ten buttons. Of course it only works if only one button is pressed, but sometimes that is all you need.
     
  5. MrChips

    Moderator

    Oct 2, 2009
    12,440
    3,361
    Every situation is different. There are no hard and fast rules on how to accommodate all your I/O needs.

    The first step would be to make a list of all the I/O pins you need and their functions.
    Some functions may be able to share I/O pins.

    The first solution, of course, is to go with a chip with a higher pin count.
    Sometimes this is not acceptable. In that case, you start looking at multiplexing and I/O expansion taking advantage of SPI, I2C, UART interfaces etc.

    In a complex system integration design, it is possible to go to a RS-485 network. I have do this very successfully in industrial applications.
     
  6. John P

    AAC Fanatic!

    Oct 14, 2008
    1,634
    224
    I'd say first of all see which functions you can multiplex (pushbuttons and LED indicators would be easiest) and if that doesn't help enough, the first thing to try would be SPI. That's very easy to use and interface with other hardware.
     
  7. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    You need a second PIC for the I/O, which you can transfer via a 3-wire or 4-wire bus.

    DAT - serial data
    CLK - serial clock
    RDY - strobe from the slave that it is ready to accept data (must cycle through 1-0-1 to avoid out of sync).
    SEL - select chip line if you use more than one slave PIC, so you can share the 3-wire serial bus for more than one chip.

    All this can be done in software.

    If you use the hardware serial port, you can get away with less I/O even. But then you need to design interrupt handlers, and buffering.

    Depends mainly how fast you need a response.

    Using a 18F etc. with more pins is another option.
     
  8. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,388
    1,605
    The PIC16F877A seems to have 36 I/O pins. The 16F series has up to 53,54 or 55 I/O pins using either the 64/QFN or 64/TQFP packages.

    You can get upto 87 I/O pins in the PIC18's in the 100/TQFP package.

    On the MC Products page you can pick a series (left side) and get a table with selections to drill down to a useful part. Start here:

    http://www.microchip.com/pagehandler/en-us/products/picmicrocontrollers
     
  9. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    Yes but you need SMD capabilities for handling.
     
  10. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,388
    1,605
    Have you noticed the time?

    It's 2013.
     
  11. raychar

    Thread Starter Member

    Nov 8, 2011
    82
    0
    Hello,

    Thanks for the information.

    Some time ago, i have sucessfully used resistor laddler method in a port to detect several input lines. However, I can apply it only in several positions type sliding switch. It stays on a position and have fixed voltage and then another position of another fixed voltage. I can't apply it in momentary buttons in which voltage rises back to high voltage (5V) when it is released, in the course, different voltages are sensed and make wrong judgement.

    Can anyone suggest how to improve it?

    Thanks,
     
  12. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    I did it a similar way to button debouncing:
    Every 20ms read ADC
    Convert ADC to button number
    Compare to button number from 20ms ago
    If it's the same the button is pressed, if not ignore it and save the button number for next time.
    Here's the schematic:
    http://www.marksphotos.info/3w1.gif
    Here' some scrappy, badly commented code (works fine though):

    Code ( (Unknown Language)):
    1.     bsf ADCON0, 1            ;start conversion
    2. adc_wait2
    3.     btfsc ADCON0, 1
    4.     goto adc_wait2
    5.      
    6.     call get_button
    7.     movwf count2
    8.  
    9.     subwf AN2_old_val, W        ;is it the same as last time?
    10.     btfss STATUS, Z
    11.     goto not_new_number_press
    12. ;should do something if button changed    
    13.     movf count2, W                ;is it button release?
    14.     btfsc STATUS, Z
    15.     goto number_release
    16.  
    17.     btfsc flags, number_button_pressed
    18.     goto not_new_number_press
    19.     goto new_number_press
    20.  
    21. number_release
    22. bsf flags, number_button_released
    23. goto not_new_number_press
    24.  
    25. new_number_press
    26. bcf flags, number_button_released
    27.     bsf flags, number_button_pressed
    28.     movf count2, W
    29.     movwf number_button_val
    30.  
    31. not_new_number_press
    32. movf count2, W
    33. movwf AN2_old_val
    Code ( (Unknown Language)):
    1. get_button
    2. movlw d'243'
    3. subwf ADRESH, W
    4. btfsc STATUS, C
    5. retlw d'10'
    6.  
    7. movlw d'217'
    8. subwf ADRESH, W
    9. btfsc STATUS, C
    10. retlw d'9'
    11.  
    12. movlw d'191'
    13. subwf ADRESH, W
    14. btfsc STATUS, C
    15. retlw d'8'
    16.  
    17. movlw d'165'
    18. subwf ADRESH, W
    19. btfsc STATUS, C
    20. retlw d'7'
    21.  
    22. movlw d'139'
    23. subwf ADRESH, W
    24. btfsc STATUS, C
    25. retlw d'6'
    26.  
    27. movlw d'113'
    28. subwf ADRESH, W
    29. btfsc STATUS, C
    30. retlw d'5'
    31.  
    32. movlw d'87'
    33. subwf ADRESH, W
    34. btfsc STATUS, C
    35. retlw d'4'
    36.  
    37. movlw d'61'
    38. subwf ADRESH, W
    39. btfsc STATUS, C
    40. retlw d'3'
    41.  
    42. movlw d'35'
    43. subwf ADRESH, W
    44. btfsc STATUS, C
    45. retlw d'2'
    46.  
    47. movlw d'9'
    48. subwf ADRESH, W
    49. btfsc STATUS, C
    50. retlw d'1'
    51.  
    52. retlw 0
     
    Last edited: Feb 7, 2013
  13. MMcLaren

    Well-Known Member

    Feb 14, 2010
    759
    116
    Can you show us what your circuit looks like now? That is, what do you have connected to the microcontroller?

    Regards, Mike
     
  14. raychar

    Thread Starter Member

    Nov 8, 2011
    82
    0
    Hello,

    My circuit mainly consists a number of button switchs and LED indicators to do the logic functions to control two small DC voltage motors, in which one draws fairly large current that will be driven by relays or mosfets, 20A. Sorry that i can't post it because it was just sketched on paper. Actually, it is applied in industrial device. I may switch to 18F controller for the full-bridge PWM that it has, however, as the response is not so critical in my design, so I am still pending to do it.

    BTW, I find PIC16F1526 from the Pagehandler of PIC website:

    >it is SMD type, i need to upgrade my knowlegde and skill?? Yes, it is 2013, as an amateur like me, oh!?..
    >will my debugger ICD2 be suitable for it? Any suggestion?
    >I haven't any demonstration board for 18F and 16F in the past and usually assembling the trial boards on my own to do debugging.
    >what type of demo board shall i need to purchase for this IC?
    >I use MPLAB IDE v8.10 and PICCLITE and old version PIC18 complier, what types and version of softwares shall i need for it?
    >will this 16F1526 be a suitable choice or any suggestions?

    Sorry that i have limit knowlegde outside 16F877A, 677, 628 and 18F482 microcontrollers.

    Thanks,
     
  15. MMcLaren

    Well-Known Member

    Feb 14, 2010
    759
    116
    Unfortunately, that doesn't help much. How many switches? How many LEDs? How many I/O pins for motors? Please put some effort into your answers to match the effort we're willing to invest to help...
     
  16. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,388
    1,605
    >it is SMD type, i need to upgrade my knowlegde and skill?? Yes, it is 2013, as an amateur like me, oh!?..
    With a small iron tip and a magnifier, thin solder and some solder wick anyone can solder tiny SMD parts.

    Adapter boards are essential to wire these. An adapter gets the close leads onto a 0.1" center which normal humans can handle. QUAD flatpacks have leads on all 4 sides and hence don't work in solderless breadboards. That's not an issue for anyone with a soldering iron and some wire.

    >will my debugger ICD2 be suitable for it? Any suggestion?
    Pick a PIC device, open MPLAB, and when you hit the menu for Configure | Select device you will see all the supported programmers & debuggers for that PIC. So pick a PIC your ICD works with.

    >I haven't any demonstration board for 18F and 16F in the past and usually assembling the trial boards on my own to do debugging.
    >what type of demo board shall i need to purchase for this IC?
    I am not aware of any demo boards, I'm sure they exist but I toss mine together myself.

    >I use MPLAB IDE v8.10 and PICCLITE and old version PIC18 complier, what types and version of softwares shall i need for it?
    I use MPLAB (non-X) and like it, I keep hearing about quirks in MPLAB-X.
    The C18 compiler is still a free download. You get 60 days free for the full version, after that it works but you get bigger code.


    >will this 16F1526 be a suitable choice or any suggestions?
    Selector guide says 55 I/O pins, best check that in the data sheet! If you're comfortable with PIC16 then stay with it, though I don't see much of a difference between PIC16 and 18 when working in C., except the PICs with more memory are PIC18's.

    BTW I keep a stock of adapters such as this on hand:

    [​IMG]

    Good thing I keep some around, as my favorite Chinese vendor (free shipping but takes 2 weeks) is closed till 2/15 for the Chinese New years. Some vendors from Thailand have PIC specific adapter boards with placed for decoupling caps and even the pins for a PICkit.
     
  17. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    I use all regular soldering wire, a broad tip, sometimes also a desoldering pump and a magnifying glass.

    Putting a TQFP64 adapter board on flywires is a tedious work, but, it is even self supporting with so many wires :)
     
  18. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,388
    1,605
    That's why I don't use fly wires.
     
  19. raychar

    Thread Starter Member

    Nov 8, 2011
    82
    0
    Many thanks for the suggestions, especially, the schematic and codes. It is amazed that the sucess of number of buttons on the same pin, i usually do only 4~5 buttons.

    Regards,
     
  20. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    If you want a 32 keys pad, make a matrix like for LEDs, use a shifter for the columns if you like, and test each with a "1" on the columns and see if there is a "1" on the rows.

    Flywires yes, it is a lot of work for 64 lines. Not even to think about 80 or 100 wires. Actually I also have the SMD chips here and tried with the layout. Interleaving the RAM chips requires a lot of PCB space, and latches are required as well.

    Looks futuristic at least, kind of Yesterday's tomorrow.
     
Loading...