• AVR Freaks

Hot!System hanging when PICKIT3 removed from target

Page: 12 > Showing page 1 of 2
Author
gbgb
New Member
  • Total Posts : 27
  • Reward points : 0
  • Joined: 2007/02/14 07:45:57
  • Location: 0
  • Status: offline
2018/06/24 03:12:40 (permalink)
0

System hanging when PICKIT3 removed from target

I have a system with a PIC18F6527
I debug and program it using MplabX and a PicKit3.
As long as the PicKit remains plugged in the system it works fine, but if I remove it the system hangs (obviously I am referring to the stage after programming the chip for standalone operation). Just plugging back the PicKit and resetting the system - it works fine.
I have the same chip on three different designs and it behaves so only on one of the designs.
I do not know if it has anything to do with this, but the only major difference between the designs (in terms of the PIC circuitry) is that the problematic board has many unused PIC pins which are not terminated (I set the unused pins as outputs and force them to low).
 
One thing which seems to have some kind of effect - I use both UART ports with interrupt based code. If I leave the code using the serial ports then it seems to hang immediately  (hard to tell exactly where since I cannot use the PicKit to debug). If I eliminate the code then it works for several seconds and then hangs. T0 also uses interrupts. However the same code with the interrupts is used in the other boards that do not have any problem
 
Pickit pins are left unused when it is removed (same on all boards)
 
Any suggestions?
 
#1

21 Replies Related Threads

    qɥb
    Monolothic Member
    • Total Posts : 3332
    • Reward points : 0
    • Joined: 2017/09/09 05:07:30
    • Location: Jupiter
    • Status: offline
    Re: System hanging when PICKIT3 removed from target 2018/06/24 03:33:04 (permalink)
    0
    You didn't mention what you have done with the MCLR pin.
    Is it enabled?
    Is it floating?
     

    This forum is mis-configured so it only works correctly if you access it via https protocol.
    The Microchip website links to it using http protocol. Will they ever catch on?
    PicForum "it just works"
    #2
    gbgb
    New Member
    • Total Posts : 27
    • Reward points : 0
    • Joined: 2007/02/14 07:45:57
    • Location: 0
    • Status: offline
    Re: System hanging when PICKIT3 removed from target 2018/06/24 03:47:40 (permalink)
    0
    MCLR pin is pulled up (10K). 
    It is enabled and I have a jumper to ground that can be shorted for reset (again - same setup on all 3 designs).
     
    #3
    qɥb
    Monolothic Member
    • Total Posts : 3332
    • Reward points : 0
    • Joined: 2017/09/09 05:07:30
    • Location: Jupiter
    • Status: offline
    Re: System hanging when PICKIT3 removed from target 2018/06/24 03:49:26 (permalink)
    0
    Maybe try 10k pulldowns on PGD and PGC. That's similar to what the PK3 does.
     

    This forum is mis-configured so it only works correctly if you access it via https protocol.
    The Microchip website links to it using http protocol. Will they ever catch on?
    PicForum "it just works"
    #4
    qɥb
    Monolothic Member
    • Total Posts : 3332
    • Reward points : 0
    • Joined: 2017/09/09 05:07:30
    • Location: Jupiter
    • Status: offline
    Re: System hanging when PICKIT3 removed from target 2018/06/24 03:58:48 (permalink)
    0
    gbgb
    Pickit pins are left unused when it is removed (same on all boards)

    But are they also set as outputs driven low?
    When you're not in program/debug mode, they are change on interrupt pins.
    You could be getting spurious interrupts if they're floating.
     

    This forum is mis-configured so it only works correctly if you access it via https protocol.
    The Microchip website links to it using http protocol. Will they ever catch on?
    PicForum "it just works"
    #5
    gbgb
    New Member
    • Total Posts : 27
    • Reward points : 0
    • Joined: 2007/02/14 07:45:57
    • Location: 0
    • Status: offline
    Re: System hanging when PICKIT3 removed from target 2018/06/24 04:06:02 (permalink)
    0
    I will try to set them as outputs and see what happens
    #6
    gbgb
    New Member
    • Total Posts : 27
    • Reward points : 0
    • Joined: 2007/02/14 07:45:57
    • Location: 0
    • Status: offline
    Re: System hanging when PICKIT3 removed from target 2018/06/24 04:51:11 (permalink)
    0
    Nope - neither pulling down with 10K or 3.3K nor setting to output helped. Pickit manual says pulldown is 4,7K but did not find this value, however I do not think it makes much difference from the values I used.
     
    Don't know if it makes difference but the PicKit output is not only pull down resistors - there is also the output of some kind of a buffer. 
     
    Another odd thing - it hangs repeatedly after the same time (I haveon board  a software driven  "heartbeat" blinking led and it stops every time after the same number of blinks) so this is probably a certain piece of code that is causing this problem and not a random noise. But I cannot think of a code that would behave differently with or without the PicKit connected.
    #7
    qɥb
    Monolothic Member
    • Total Posts : 3332
    • Reward points : 0
    • Joined: 2017/09/09 05:07:30
    • Location: Jupiter
    • Status: offline
    Re: System hanging when PICKIT3 removed from target 2018/06/24 04:59:16 (permalink)
    0
    gbgb
    ..
    Don't know if it makes difference but the PicKit output is not only pull down resistors - there is also the output of some kind of a buffer. 

    The buffer is not enabled when you are not in debug mode.
    Really, when it's idling like this, I think the pulldowns on PGC and PGD, and the pullup on MCLR are the only things that should be affecting your circuit.
     
    The only other possibility is that your chip is still in debug mode, but you've stated that you have programmed it for standalone operation...
     

    This forum is mis-configured so it only works correctly if you access it via https protocol.
    The Microchip website links to it using http protocol. Will they ever catch on?
    PicForum "it just works"
    #8
    gbgb
    New Member
    • Total Posts : 27
    • Reward points : 0
    • Joined: 2007/02/14 07:45:57
    • Location: 0
    • Status: offline
    Re: System hanging when PICKIT3 removed from target 2018/06/24 06:03:22 (permalink)
    0
    OK - I found the source but not the reason.
    As I mentioned this board uses both UARTS.
    This board is both a Modbus slave and client.
    The client runs on UART1 and the slave on UART2.
    The system hangs when it receives communication on UART2 (slave).
    If I do not initialize UART2 then even if communication signals come in the system does not hang up - hence the problem is probably not hardware related (I also checked for possible shorts or "semi shorts" between the communication signals and the PGD, PGC, MCLRB lines).
    If I do initialize it for communication then the system hangs.
     
    Here is my initialization code (configuration bits name are self explanatory)
     
    void SerInit_2(void)
    {

     //initialize USART2 control registers
     bSPEN_2=1; //serial port 2 enable
     bRX9_2=0; //8 bits receive
     bCREN_2=1; // enable continuous receive
     bTX9_2=0; //8 bits transmit
     bTXEN_2=1; //enable transmit
     bSYNC_2=0; //async mode
     bBRGH_2=1; //high baud rate
     bBRG16_2=0; //8 bits baud rate generation
     rSPBRG2=129; //9600baud@20Mhz, nominal value ia 129 but may need adjustment.
     
     //default RS485 is receive mode
     b485_Te_2 = 0;

     //set interrupts
     bRC2IP=1; //receive priority (0/1 - low/high)
     bTX2IP=1; //transmit priority (0/1 - low/high)
     bRC2IE = 1; //Enable USART Receive interrupt
         bTX2IE = 0; //Enable USART Transmit interrupt until required

     //reset communications buffer
     SerReset_2();
     
     //globally enable interrupts
          ENABLE_INTERRUPTS()
    }

     
    I still cannot figure out what would behave differently with or without the PicKit (and this initialization code is used in one of the other boards which also uses both UARTS although both as a client). 
     
     
    #9
    Aussie Susan
    Super Member
    • Total Posts : 3635
    • Reward points : 0
    • Joined: 2008/08/18 22:20:40
    • Location: Melbourne, Australia
    • Status: offline
    Re: System hanging when PICKIT3 removed from target 2018/06/24 20:01:35 (permalink)
    0
    UARTs can be very 'picky' beasts on Microchip MCUs and they must be initialised in the correct order, as specified in the data sheet (Seciotns 20.2.1 and 20.2.2).
    Bascially you should set up everything except the SPEN, TXEN and CREN bits. When that is done, you set the SPEN bits, and then the TXEN and CREN bits as required. I think you are setting the TXEN and CREN bits too early which can lead to strange behaviour.
    I'm not sure if this explains what you are seeing but you never know.
    In the original post you state that you cannot use the PicKit3 to debug the code, but you have not said why this is so.
    Susan
    #10
    gbgb
    New Member
    • Total Posts : 27
    • Reward points : 0
    • Joined: 2007/02/14 07:45:57
    • Location: 0
    • Status: offline
    Re: System hanging when PICKIT3 removed from target 2018/06/24 23:26:33 (permalink)
    0
    Thanks, will try to play around with the initialization code.
    What I meant is that I cannot use the Pickit to debug this problem, since there is no problem when it is plugged into the system
    #11
    gbgb
    New Member
    • Total Posts : 27
    • Reward points : 0
    • Joined: 2007/02/14 07:45:57
    • Location: 0
    • Status: offline
    Re: System hanging when PICKIT3 removed from target 2018/06/25 00:13:57 (permalink)
    0
    Playing with the initialization sequence did not help.
     
    However - I switched roles - I put the client on UART2 and the slave on UART1 and it works fine.
     
    Is there a known difference between UART1 and UART2? the code that I am using is identical to both UARTS (initialization, interrupt routine, communications handling etc.).
     
    There is a single difference in terms of the hardware that is connected to these ports, but I can not think why it would affect anything since what the MCU gets is TTL level signals - UART1 is connected to an RS485 transceiver type MAX3082 while UART2 is connected to an isolated RS485 transceiver type ISO3082.
    Although I can change the design to switch between the isolated/non-isolated ports, I think this would be just "sweeping away the problem" and not really understanding and solving it.
     
    #12
    gbgb
    New Member
    • Total Posts : 27
    • Reward points : 0
    • Joined: 2007/02/14 07:45:57
    • Location: 0
    • Status: offline
    Re: System hanging when PICKIT3 removed from target 2018/06/25 22:45:29 (permalink)
    0
    Problem solved, but yet with no explanation to the original phenomenon.
     
    Thanks to Aussie Susan who suggested to look into the initialization code, I went over the whole code line by line. In one of the lines handling UART2 I was clearing RCREG1 instead of RCREG2. Correcting this line fixed the problem.
     
    The mystery is still, why did it work OK when the PicKit was plugged and showed up only when it was unplugged.
    #13
    Aussie Susan
    Super Member
    • Total Posts : 3635
    • Reward points : 0
    • Joined: 2008/08/18 22:20:40
    • Location: Melbourne, Australia
    • Status: offline
    Re: System hanging when PICKIT3 removed from target 2018/06/26 19:41:36 (permalink)
    +2 (2)
    I can't see any code that you have shown us that references RCREG-anything but I guess that it is hidden behind one for the multitude of #defines that you must have at the start of the code somewhere.
    This is why I personally detest this style of coding as it is all too easy to make a mistake that is far away from where you are debugging. 
    I much prefer to make direct reference to the registers and bit fields by the names in the data sheet.
    Susan
    #14
    ErwinH
    New Member
    • Total Posts : 18
    • Reward points : 0
    • Joined: 2013/05/18 14:59:56
    • Location: 0
    • Status: offline
    Re: System hanging when PICKIT3 removed from target 2019/11/22 03:47:29 (permalink)
    0
    I seem to have the same problem. Using a PIC 18F26K22 that shares the UART2 with PGC and PGD. When I want to communicate over UART2 the MCU crashes. Power cycle and it is working again. Problem is that you can't debug because it shares the same pins (UART2 uses PGD and PGC). When I pull the PGD line low it crashes and when I keep it HIGH it continues without problems... I am using an ISR and that works fine when I move the communication stack to UART1. Problem seems to be related to UART2
    Any suggestions are welcome. Will post my findings.
    #15
    ric
    Super Member
    • Total Posts : 24540
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: System hanging when PICKIT3 removed from target 2019/11/22 03:50:54 (permalink)
    0
    It sounds like you're trying to debug the PIC with debug code in it. That uses the PGD line to activate the debugger, so it will only work while the debugger is connected.
    You have to reprogram the chip with a release image to be able to disconnect the debugger.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #16
    ErwinH
    New Member
    • Total Posts : 18
    • Reward points : 0
    • Joined: 2013/05/18 14:59:56
    • Location: 0
    • Status: offline
    Re: System hanging when PICKIT3 removed from target 2019/11/22 04:00:08 (permalink)
    0
    Nope, I am running the project stand-alone by hitting the "Run Main Project" button in MPLAB X.
    #17
    ErwinH
    New Member
    • Total Posts : 18
    • Reward points : 0
    • Joined: 2013/05/18 14:59:56
    • Location: 0
    • Status: offline
    Re: System hanging when PICKIT3 removed from target 2019/11/22 04:09:11 (permalink)
    0
    When I disable the interrupt : >> bcf PIE3, RC2IE, ACCESS the MCU stops crashing but want to use my ISR...
    #18
    ric
    Super Member
    • Total Posts : 24540
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: System hanging when PICKIT3 removed from target 2019/11/22 04:09:43 (permalink)
    0
    In that case it would appear to be a bug in your code related to UART2, possibly not clearing the the interrupt correctly if you get an overrun.
     
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #19
    ErwinH
    New Member
    • Total Posts : 18
    • Reward points : 0
    • Joined: 2013/05/18 14:59:56
    • Location: 0
    • Status: offline
    Re: System hanging when PICKIT3 removed from target 2019/11/22 05:30:56 (permalink)
    0
    Hi ric, Indeed. I jumped into a new section of the ISR that was intended to send data (but not yet finished) and there I got stuck.
    #20
    Page: 12 > Showing page 1 of 2
    Jump to:
    © 2019 APG vNext Commercial Version 4.5