Input issue on a Pic16F88

Discussion in 'The Projects Forum' started by Geoffr67, Feb 4, 2012.

  1. Geoffr67

    Thread Starter Member

    Dec 5, 2011
    69
    0
    Hello all i am having some problems i cannot figure out on a project i am building. ill try to describe the best i can.

    Pic 16F88 In 300 mil SOIC pkg.
    20mhz (citizen crystal) 18pf caps

    Port A4 is a input (momentary push button)
    Port A0 is a input (Momentary push button)
    Port A1 is a input (Momentary push button)
    ALL ACTIVE HIGH have 4.7k pulldown resistors attached as well.

    Software wise all my routenes are the same for reading the status of these buttons, BUT input A4 is erratic it will not work like it should, In my software i have a configuration area when A4 is help down it enters config, oddly it does this fine but once it reaches the main loop it ceases to function when the button is pressed. If i cycle the power to the ckt off and on really fast a few times the port a4 will work. if i shut it down wait a min and apply power it will not work. I have done a continuity check on all traces and wires and those are all good.Is it possible the Chip is bad or possibly overheated when i soldered it to the pcb damaging pin a4. anyone have any ideas?
     
  2. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    RA4 has a Schmitt trigger input buffer but the others are TTL which means RA4 needs a higher voltage to read logic 1 (0.8Vdd) so 4V with a 5V supply.
    As described the circuit should work, but maybe increasing the value of the pulldown resistors might help. Also check the voltage at the pin with the button pressed.
     
  3. Geoffr67

    Thread Starter Member

    Dec 5, 2011
    69
    0
    Thanks for the input Mark, i am going to go measure the voltage on the pin right now will report back shortly. What value do you propose i should try on the pulldown in lieu of the 4.7k
     
  4. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    4.7K is in the area which should work, but maybe 20K might be worth trying. It's probably not the problem, the button would have to be nearly 1K in it's on position to cause the problem, and even membrane switches are normally only about 100 ohms.
     
  5. Geoffr67

    Thread Starter Member

    Dec 5, 2011
    69
    0

    I measured 4.844V at the pin with the wire shorted to the 5v reg. I removed the switch and just shorted the pin. I got 4.844v and it still does not work as expected.
     
  6. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    It's good to rule things out, the problem must be the PIC or the code. If you post the code someone will probably have a look.
     
  7. crutschow

    Expert

    Mar 14, 2008
    13,042
    3,243
    Could switch bounce be a problem? Do you have delay in the loop of about a 100ms or so before it can respond to another switch change?
     
  8. Geoffr67

    Thread Starter Member

    Dec 5, 2011
    69
    0
    i wrote the code in flowcode. i am useing the same routenes to read all 3 switches the pins A0-A1 work, A4 does not work for some reason. it is not the switches though cause i removed them and shorted the pin directly to 5v, a0-a1 respond, a4 still does not.
     
  9. Geoffr67

    Thread Starter Member

    Dec 5, 2011
    69
    0
    Whats really odd is if i cycle the power to the ckt (12v applied) to a 5v reg. on off on off really fast and keep it on, Pin a4 will respond. if i let it sit there and just apply power without cycleing it, it does not respond.
     
  10. PaulEE

    Member

    Dec 23, 2011
    423
    32
    This sounds like a stupid suggestion, but I have wasted countless hours on a circuit like this before. The reason? I forgot to configure the port I/O as DIGITAL I/O as opposed to ANALOG. Check the ANSEL register to be sure that the power on reset value of the pin you're having issues with #1 doesn't conflict with other default-on modules and #2 is configured as digital and not analog.

    Again, I'm sure you've already checked this, but I had to say it because of the countless hours I've spent troubleshooting similar issues.

    Also, with reference to the Schmitt Trigger comments...Schmitt Triggers are just buffers with hysteresis to quiet noisy signals.

    The 16f88 datasheet specifies a logic low on a Schmitt Trigger as 0.2*Vdd (1 V for Vdd = 5v) and 0.8 * Vdd = 4v for logic high. BUT, these are MAXIMUM values..in other words, the upper limit of the logic low/high are 1.0v and 4.0v, that doesn't imply that they have to be those values. Technically, logic high could be anywhere above 1.0v to 4.0v to be valid.

    I have a few 16f88s I plan on doing a few tutorials on sitting right here with me...nice little chips. The 12f683 is also excellent.

    Hope this helps!
     
  11. Geoffr67

    Thread Starter Member

    Dec 5, 2011
    69
    0
    i did a quick search in the C outputted from flowcode and here is what it says.

    //Initialisation
    ansel = 0;
    cmcon = 0x07;

    //Interrupt initialisation code
    option_reg = 0xC0;
     
  12. PaulEE

    Member

    Dec 23, 2011
    423
    32
    You're good. ANSEL = 0'b 00000000 means all I/O on pins that have ANx labels are set as digital I/O. Had to check!
     
  13. Geoffr67

    Thread Starter Member

    Dec 5, 2011
    69
    0

    What else can i check that could be a problem. This problem is driving me nuts! I am useing the same routene to check the status of the switches. the other ones work just a4 dont. im at a loss as to what it could be!
     
  14. PaulEE

    Member

    Dec 23, 2011
    423
    32
    I, personally, am not familiar with "flow code".

    When I set out to do a PIC project, I come up with a plan and then go through each pin and decide whether or not any internal modules are on by default and am sure to shut each one off in code. (The ones that will interfere with my I/O on that port/pin(s). )

    The datasheet, with reference to "I/O Ports" - "PORTA and TRISA", lists all the different functions of PORTA.B4. The datasheet claims "Input/output, analog input or TMR0 external input or comparator input".

    Translated by my brain: Set as digital I/O in ANSEL, shut off ADC module, CCP module, and check that TMR0 interrupt isn't messing with your code either. Look at the interrupt structure and make sure that one is disabled. This may or may not explain the sporadic behavior with power cycling and time going by. Also, CMCON, ADCON0, ADCON1, CCP1CON, ANSEL, CMCON0 and a few other registers are work checking out. Most of those were O.K. on power-on reset, though.

    You're positive that it's RA4 that's giving you issues, not RA5, right? Had to ask.
     
  15. Geoffr67

    Thread Starter Member

    Dec 5, 2011
    69
    0
    Yes im positive its A.4 giving me the problem. ;/ lol damn bugs!
     
  16. PaulEE

    Member

    Dec 23, 2011
    423
    32
    Can you send me the entire output of the flow code? Perhaps I can spot an issue better looking directly at the C that it spits out...
     
  17. Geoffr67

    Thread Starter Member

    Dec 5, 2011
    69
    0
    yes i can, Can you PM me your email addy?
     
  18. PaulEE

    Member

    Dec 23, 2011
    423
    32
    By me, I meant copy and paste it on the forum :)
     
  19. Geoffr67

    Thread Starter Member

    Dec 5, 2011
    69
    0

    Being sent your way now. the application of the code would violate forum rules. or else i would. Automotive related
     
  20. Geoffr67

    Thread Starter Member

    Dec 5, 2011
    69
    0
    i have sent it to your inbox. I will be leaving for a little bit. i will be back in about 2 hours. let me know if you find anything wrong. at quick glance.
     
Loading...