PIC 18F2431 PORTB.6 and 7 - strange behavior on restart after a few hours "rest"
+ Reply to Thread
Results 1 to 21 of 21
  1. #1
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french region)
    Posts
    755

    Default PIC 18F2431 PORTB.6 and 7 - strange behavior on restart after a few hours "rest"

    Hello everyone,

    I have made a little circuit based on a 18F2431; it's un circling dot on a 8x8 LED matrix.

    My code below works well BUT when I restart my circuit after a few hours "rest" (= no power on the circuit), both PORTB.6 and PORTB.7 seem not to work as outputs anymore. I can see it because the dot doesn't light up when those two PORTs are used.

    If I reprogram the chip, it will work fine again. Even after two hours with no power on the circuit, it will still work. But after maybe 5 or 6 hours, the problems occurs.

    I'm not sure what is wrong but I might have to set something in the CONFIG fuses I couldn't find up to now. I'm beginning with 18F PIcs....

    Anyone an idea what I'm missing?

    Code:
    ' ====== FUSES =====================================================================================
    ' PIC 18F2431
    
    ' INTernal oscillator
    @ __CONFIG _CONFIG1H, _OSC_HS_1H '& _FCMEN_ON_1H & _IESO_OFF_1H
    
    @ __CONFIG _CONFIG2L, _PWRTEN_OFF_2L & _BOREN_OFF_2L & _BORV_45_2L
    @ __CONFIG _CONFIG2H, _WDTEN_OFF_2H & _WINEN_OFF_2H & _WDPS_1_2H
    @ __CONFIG _CONFIG3L, _T1OSCMX_OFF_3L & _HPOL_LOW_3L & _LPOL_LOW_3L & _PWMPIN_OFF_3L
    @ __CONFIG _CONFIG3H, _MCLRE_OFF_3H
    @ __CONFIG _CONFIG4L, _STVREN_OFF_4L & _LVP_OFF_4L & _DEBUG_OFF_4L
    @ __CONFIG _CONFIG5L, _CP0_OFF_5L & _CP1_OFF_5L
    @ __CONFIG _CONFIG5H, _CPB_OFF_5H & _CPD_OFF_5H
    @ __CONFIG _CONFIG6L, _WRT0_OFF_6L & _WRT1_OFF_6L
    @ __CONFIG _CONFIG6H, _WRTB_OFF_6H & _WRTC_OFF_6H & _WRTD_OFF_6H
    @ __CONFIG _CONFIG7L, _EBTR0_OFF_7L & _EBTR1_OFF_7L
    @ __CONFIG _CONFIG7H, _EBTRB_OFF_7H
    
    ' ====== REGISTERS =================================================================================
    '          76543210
    OSCCON  = %01110000 'set INTRC to 8 MHZ
    OSCTUNE = %00000000 'OSCILLATOR TUNING REGISTER
    ADCON0  = %00000000 'A/D CONTROL REGISTER 0
    ADCON1  = %00000000 'A/D CONTROL REGISTER 1
    ADCON2  = %00000000 'A/D CONTROL REGISTER 2
    ANSEL0  = %00000000 'Analog Select Register 0
    INTCON  = %00000000 'INTERRUPT CONTROL REGISTER, Enable global interrupts, enable overflow flag
    INTCON2 = %00000000 'INTERRUPT CONTROL REGISTER 2
    INTCON3 = %00000000 'INTERRUPT CONTROL REGISTER 3
    'PORTA   = %00000000 'State High (1) or Low (0)
    LATA    = %00000000 'State High (1) or Low (0)
    TRISA   = %00001111 'Data Direction Control Register (Input/Output)
    'PORTB   = %00000000 'State High (1) or Low (0) 
    LATB    = %00000000 'State High (1) or Low (0) 
    TRISB   = %00000000 'Data Direction Control Register (Input/Output)
    'PORTC   = %00000000 'State High (1) or Low (0) 
    LATC    = %00000000 'State High (1) or Low (0) 
    TRISC   = %00000000 'Data Direction Control Register (Input/Output)
    
    ' ====== DEFINES ===================================================================================
    DEFINE OSC 8
    
    ' ====== VARIABLES =================================================================================
    Counter_A   VAR BYTE
    Cycles      VAR BYTE
    Row_Port    VAR LATC ' this is ROW
    Col_Port    VAR LATB ' this is COLUMN
    Row_State   VAR BYTE(30)
    Col_State   VAR BYTE(30)
    Cycle_Speed VAR BYTE
    
    ' ====== ALIASES =================================================================================
    
    ' ====== INITIALIZE ================================================================================
    Counter_A   = 0
    Cycles      = 3
    Row_Port    = %11111111
    Col_Port    = %00000000
    Cycle_Speed = 50
    
    ' For ROW, 0 is ACTIVE
    Row_State(1)  = %11111110
    Row_State(2)  = %11111110
    Row_State(3)  = %11111110
    Row_State(4)  = %11111110
    Row_State(5)  = %11111110
    Row_State(6)  = %11111110
    Row_State(7)  = %11111110
    Row_State(8)  = %11111110
    Row_State(9)  = %11111101
    Row_State(10) = %11111011
    Row_State(11) = %11110111
    Row_State(12) = %11101111
    Row_State(13) = %11011111
    Row_State(14) = %10111111
    Row_State(15) = %01111111
    Row_State(16) = %01111111
    Row_State(17) = %01111111
    Row_State(18) = %01111111
    Row_State(19) = %01111111
    Row_State(20) = %01111111
    Row_State(21) = %01111111
    Row_State(22) = %01111111
    Row_State(23) = %10111111
    Row_State(24) = %11011111
    Row_State(25) = %11101111
    Row_State(26) = %11110111
    Row_State(27) = %11111011
    Row_State(28) = %11111101
    Row_State(29) = %00000000 ' all ON
    Row_State(30) = %11111111 ' all OFF
    
    ' For COL, 1 is ACTIVE
    Col_State(1)  = %00000001
    Col_State(2)  = %00000010
    Col_State(3)  = %00000100
    Col_State(4)  = %00001000
    Col_State(5)  = %00010000
    Col_State(6)  = %00100000
    Col_State(7)  = %01000000
    Col_State(8)  = %10000000
    Col_State(9)  = %10000000
    Col_State(10) = %10000000
    Col_State(11) = %10000000
    Col_State(12) = %10000000
    Col_State(13) = %10000000
    Col_State(14) = %10000000
    Col_State(15) = %10000000
    Col_State(16) = %01000000
    Col_State(17) = %00100000
    Col_State(18) = %00010000
    Col_State(19) = %00001000
    Col_State(20) = %00000100
    Col_State(21) = %00000010
    Col_State(22) = %00000001
    Col_State(23) = %00000001
    Col_State(24) = %00000001
    Col_State(25) = %00000001
    Col_State(26) = %00000001
    Col_State(27) = %00000001
    Col_State(28) = %00000001
    Col_State(29) = %00000000 ' all OFF
    Col_State(30) = %11111111 ' all ON
    
    ' ====== PROGRAM TOP ===============================================================================
    MAIN:
        FOR Counter_A = 1 TO 28
            Col_Port = Col_State(Counter_A)
            Row_Port = Row_State(Counter_A)
            PAUSE Cycle_Speed
        NEXT Counter_A
        GOTO MAIN                                
    END
    Roger

  2. #2
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,231

    Default Re: PIC 18F2431 PORTB.6 and 7 - strange behavior on restart after a few hours "rest"

    Similar issue happened to me.

    Eventhough MCLR is OFF, it needs to be sometimes tied to Vdd with a 4K7 - 10K, and to GND with a 100nf cap.

    This had solved my issue after weeks of work.
    When I removed 100nf, it started again. SO don't remove the cap.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  3. #3
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french region)
    Posts
    755

    Default Re: PIC 18F2431 PORTB.6 and 7 - strange behavior on restart after a few hours "rest"

    Thanks Sayzer,

    I already found some tricky PIC's behavior around the MCLRE pin but couldn't get rid of the problem

    I'll give it a try - thanks a lot again

    If some PIC "makers" could explain what really happens, it would be nice to know.
    Roger

  4. #4
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french region)
    Posts
    755

    Default Re: PIC 18F2431 PORTB.6 and 7 - strange behavior on restart after a few hours "rest"

    Thanks a lot Sayzer.

    The 0.1µF cap alone did the trick

    Attachment 8898

    I did a quick search in the datasheet but there is nothing about this in there.

    Anyway, you helped to sort this out - thanks again
    Roger

  5. #5
    Join Date
    Sep 2009
    Posts
    753

    Default Re: PIC 18F2431 PORTB.6 and 7 - strange behavior on restart after a few hours "rest"

    I'm not sure, but look like that you probably have some issue with static. Much better solution would be to add pull up or pull down resistor.
    Only way to disable RB6, RB7, and to have rest of PIC running is that PIC try to enter to program mode. So it will redirect RB7 and RB6 to programmer, but it newer see sequence for starting, so it start processor. For this to happen PIC must see more than 9V on MCLR. So from that I must conclude it's static charge build up(Floating input is basically capacitor). Adding bigger cap just slows down process.
    Simple way to test this is to have device fail to start properly, then remove power, discharge all caps, short MCLR to GND, or place (wet) finger across programming header and turn on power(without removing finger). Device then should start normally, without reprogramming.
    How ever you MUST NOT LEAVE ANY INPUT FLOATING. In any design. As this can cause unsuspected reset, and lock up, oscillation, generally bad stuff...
    For board from image, as I can see there is no ground plane. So there is another issue. Power must be LOW impedance, and properly decoupled. This would not add any cost, just little bit of careful design is needed.
    Also it can cause you to fail EMC test...

  6. #6

    Default Re: PIC 18F2431 PORTB.6 and 7 - strange behavior on restart after a few hours "rest"

    Pretty sure Pedja nailed it, also note that 18F2431 is an older design that still included PGM, so maybe some odd LVP (I know the poster turn it off in the fuses) issue.
    George

  7. #7
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french region)
    Posts
    755

    Default Re: PIC 18F2431 PORTB.6 and 7 - strange behavior on restart after a few hours "rest"

    Thanks Pedja089 for your advice.

    Except for 4 pins, all ports are OUTPUTs. The only 4 INPUT pins have each a pull-up resistors (10k).

    You're right, the ground-planes are missing (both sides); this has already been added in the final design (the picture shows the lab prototype).

    "Power must be LOW impedance, and properly decoupled" Can you explain please?
    Roger

  8. #8
    Join Date
    Sep 2009
    Posts
    753

    Default Re: PIC 18F2431 PORTB.6 and 7 - strange behavior on restart after a few hours "rest"

    MCLR is input pin, even when not used.
    I could try to explain about decoupling and impedance, but here is video that can explain much better.

    Just to mention, that if you prevent noise to go out, you also prevent it to get from outside to pic.

  9. #9
    Join Date
    Sep 2009
    Posts
    753

    Default Re: PIC 18F2431 PORTB.6 and 7 - strange behavior on restart after a few hours "rest"

    Just looked you fuse, and see _PWRTEN_OFF_2L
    Turn it on, it cant hurt. Probably will bring back RB6 and RB7. But it isn't solution.
    The Power-up Timer provides a nominal 72 millisecond delay after a Power On Reset (POR), Brown Out Reset (BOR) or after MCLR pin reset is initiated. The PWRT operates on a dedicated internal RC Oscillator. The device is kept in reset as long as the PWRT has not timed out. The PWRT is used to allow the Vdd voltage of the PIC® MCU to rise to an acceptable level before operating. The PWRT delay may vary from device to device due to Vdd, temperature, and process variations. The DC parameters section of the device data sheet will specify the details.
    Last edited by pedja089; - 3rd April 2019 at 15:26.

  10. #10
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,180

    Default Re: PIC 18F2431 PORTB.6 and 7 - strange behavior on restart after a few hours "rest"

    If you have access to an oscilloscope, place the probe on the power line to your board and capture the rise time for the supply. I notice that from the board picture there is only 1 capacitor present? you may be experiencing a slow startup of the main supply you are using after a long period of being shut off. With the PWRT in the off state the oscillator may not be starting. I have to ask, are you strapped for pins and that is why you have the EXT reset pin enabled internally?
    Dave Purola,
    N8NTA
    EN82fn

  11. #11
    Join Date
    Sep 2009
    Posts
    753

    Default Re: PIC 18F2431 PORTB.6 and 7 - strange behavior on restart after a few hours "rest"

    Slow start up isn't issue here. I'm 99,999% sure.
    That board need more than one cap. With more capacitor it would be slower.

    And oscillator start up isn't problem, as board works as it should, except something hick jack RB7 RB6. And only thing I can think of is programmer circuit inside PIC.

  12. #12
    Join Date
    Apr 2014
    Location
    Northeast
    Posts
    299

    Default Re: PIC 18F2431 PORTB.6 and 7 - strange behavior on restart after a few hours "rest"

    Odd. I was having similar issues and just happened to check this forum; what do you know? The answers provided helped me find my solution! Thanks all!
    I don't need the world to know my name, but I want to live a life so all my great-grandchildren proudly remember me.

  13. #13
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french region)
    Posts
    755

    Default Re: PIC 18F2431 PORTB.6 and 7 - strange behavior on restart after a few hours "rest"

    Quote Originally Posted by Dave View Post
    ...I notice that from the board picture there is only 1 capacitor present?...
    I have a 100nF across VDD and VSS pins of the PIC and two capacitors "enclosing" the voltage regulator (currently not on the board - it doesn't like the power coming from the PICkit programmer). I now also added an additional 100nF capacitor on the MCLR pin.


    Quote Originally Posted by Dave View Post
    ...I have to ask, are you strapped for pins and that is why you have the EXT reset pin enabled internally?...
    Yes, I'm short in I/Os so this is why I chose this particular PIC. But I don't get it about the MCRL (EXT) pin. Do I have a fuse set (wrongly) that could generate problems? Anyway, this pin is not currently used in my circuit.
    Roger

  14. #14
    Join Date
    Sep 2009
    Posts
    753

    Default Re: PIC 18F2431 PORTB.6 and 7 - strange behavior on restart after a few hours "rest"

    Your fuses are ok. But I'll suggest tu torn power up timer.
    MCLR is unused, but it is still input. So you need to have proper circuit on it. You can tie it to GND, but then you won't be able to use ISCP.

  15. #15
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french region)
    Posts
    755

    Default Re: PIC 18F2431 PORTB.6 and 7 - strange behavior on restart after a few hours "rest"

    Quote Originally Posted by pedja089 View Post
    Your fuses are ok. But I'll suggest tu torn power up timer.
    You mean turn it ON, right? What is it going to do please? I don't get it reading the datasheet


    Quote Originally Posted by pedja089 View Post
    MCLR is unused, but it is still input. So you need to have proper circuit on it. You can tie it to GND, but then you won't be able to use ISCP.
    Yes, I need it for ICSP. It is now tied to VDD with a 4k7 resistor and to VSS via a 100nF. Should it be done another way?
    Roger

  16. #16
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,180

    Default Re: PIC 18F2431 PORTB.6 and 7 - strange behavior on restart after a few hours "rest"

    Roger, I have never placed any capacitor on the reset pin as long as I have been designing circuits with PIC processors. (about 20 years or so) Also I usually use a 10K resistor for the RESET pin pullup.

    This is an excerpt from a normal data sheet:


    Note 1: External Power-on Reset circuit is required
    only if the VDD power-up slope is too slow.
    The diode D helps discharge the capacitor
    quickly when VDD powers down.
    2: 15 k < R < 40 k is recommended to make
    sure that the voltage drop across R does not
    violate the device’s electrical specification.
    3: R1  1 k will limit any current flowing into
    MCLR from external capacitor C, in the event
    of MCLR/VPP pin breakdown, due to
    Electrostatic Discharge (ESD) or Electrical
    Dave Purola,
    N8NTA
    EN82fn

  17. #17
    Join Date
    Sep 2009
    Posts
    753

    Default Re: PIC 18F2431 PORTB.6 and 7 - strange behavior on restart after a few hours "rest"

    Quote Originally Posted by flotulopex View Post
    You mean turn it ON, right?
    Yes.
    Quote Originally Posted by Microchip
    The Power-up Timer provides a nominal 72 millisecond delay after a Power On Reset (POR), Brown Out Reset (BOR) or after MCLR pin reset is initiated. The PWRT operates on a dedicated internal RC Oscillator. The device is kept in reset as long as the PWRT has not timed out. The PWRT is used to allow the Vdd voltage of the PIC® MCU to rise to an acceptable level before operating. The PWRT delay may vary from device to device due to Vdd, temperature, and process variations. The DC parameters section of the device data sheet will specify the details.
    Quote Originally Posted by flotulopex View Post
    Yes, I need it for ICSP. It is now tied to VDD with a 4k7 resistor and to VSS via a 100nF. Should it be done another way?
    Resistor should be enough.

  18. #18
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,231

    Default Re: PIC 18F2431 PORTB.6 and 7 - strange behavior on restart after a few hours "rest"

    Microchip has a guide.

    http://microchipdeveloper.com/8bit:guide


    Attachment 8900

    R1 ≤ 10 kΩ is recommended. A suggested starting value is 10 kΩ. Ensure that the MCLR pin VIH and VIL specifications are met.
    R2 ≤ 470 Ω will limit any current flowing into MCLR from the external capacitor, C1, in the event of MCLR pin breakdown, due to Electrostatic Discharge (ESD) or Electrical Overstress (EOS). Ensure that the MCLR pin VIH and VIL specifications are met.






    Attachment 8901
    Ri ≤ 100 Ω is recommended. Resistance value should be low enough to not affect the external circuit but still isolate the ICSP connections from the application circuitry.
    Last edited by sayzer; - 5th April 2019 at 04:45.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  19. #19
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french region)
    Posts
    755

    Default Re: PIC 18F2431 PORTB.6 and 7 - strange behavior on restart after a few hours "rest"

    Thank you very much
    Roger

  20. #20
    Join Date
    Apr 2014
    Location
    Northeast
    Posts
    299

    Default Re: PIC 18F2431 PORTB.6 and 7 - strange behavior on restart after a few hours "rest"

    Reading instructions for the PICkit3 it explicitly states not to use any capacitors in the Vpp/MCLR line. Again, conflicting information?
    I don't need the world to know my name, but I want to live a life so all my great-grandchildren proudly remember me.

  21. #21
    Join Date
    Sep 2009
    Posts
    753

    Default Re: PIC 18F2431 PORTB.6 and 7 - strange behavior on restart after a few hours "rest"

    Not really. For debugging it isn't desirable. For stand alone usage, it is recommended. Sometimes it wotn't works without it.
    Pic should be released from reset, only when supply voltage is stable, and in working limits. If ramp up of Vdd is to slow, it may(usually not) cause undesired thing to happen inside PIC.
    So POR and capacitor on MCLR should delay start up of PIC.

Similar Threads

  1. Strange behavior on PORTB on a PIC18F26K20
    By Dosbomber in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 28th September 2016, 23:31
  2. How to do the "SerIN" and "SerOut " for the usb ?
    By vicce67 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 13th March 2015, 02:01
  3. Replies: 0
    Last Post: - 14th November 2013, 03:32
  4. Replies: 1
    Last Post: - 22nd March 2013, 00:44
  5. Replies: 3
    Last Post: - 15th October 2012, 08:06

Members who have read this thread : 16

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts