In Circuit Debugging stops working?


Closed Thread
Results 1 to 10 of 10
  1. #1
    Join Date
    Mar 2011
    Location
    Los Angeles, California
    Posts
    322

    Default In Circuit Debugging stops working?

    Hi All,
    Probably another silly question and I wrote a program that works fine with a ceramic resonator running at 10 MHZ. Change the program to a 20 MHZ resonator (OSC) and it quits working! PIC is a 16F628A. I am so confused! Thanks, Ed

    DEFINE LOADER_USED 1
    DEFINE OSC 20
    Include "Modedefs.bas"

    CK VAR PortA.0 ' Clock from Pin 17 to Pin 7 of the 1298 yellow
    DOUT VAR PortA.1 ' Data Out from Pin 18 to Pin 6 of the 1298 orange
    DIN VAR PortB.6 ' Data In from Pin 12 to Pin 5 of the 1298 violet
    CS VAR PortB.7 ' Chip Select From Pin 13 to Pin 1 of the 1298 blue
    addr VAR BYTE ' Channel address / mode
    result VAR WORD ' Reading from the A/D
    Vbits VAR WORD ' Variable to store A/D volts reading
    Abits VAR WORD ' Variable to store A/D Amps reading
    REF VAR WORD ' 0.0 Amps reference point
    AMPS VAR WORD ' Amps reading
    VOLTS VAR WORD ' Volts reading
    cmcon = 7 ' Set all the PIC inputs to be digital

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,516


    Did you find this post helpful? Yes | No

    Default Re: In Circuit Debugging stops working?

    Hi,
    (Why posted in the FAQ-section?)

    Are you saying that your program runs but that you can't debug? What in circuit debugger are you using?

    I see that you're using a bootloader so I suspect what you actually mean is that you can no longer program the chip thru the bootloader - is that it?
    If so, the reason most likely is that the bootloader code is written for a certain oscillator speed (10MHz if that what used to work for you) and when you just change to a 20MHz resonator the bootloader code runs twice as fast as it's supposed to so the baudrate and other timings will off by 100% = no go. Try reprogramming the PIC with a bootloader stub for the correct frequency.

    /Henrik.

  3. #3
    Join Date
    Oct 2004
    Posts
    448


    Did you find this post helpful? Yes | No

    Default Re: In Circuit Debugging stops working?

    Hi Ramius (Marko?!)

    Two things that come to mind.

    The 16F628A cannot use a bootloader; I assume you are not trying to use one. So, delete the first line.

    For 20 MHz oscillator, have you set the HS fuse?

    Regards,

    Anand Dhuru

  4. #4
    Join Date
    Mar 2011
    Location
    Los Angeles, California
    Posts
    322


    Did you find this post helpful? Yes | No

    Default Re: In Circuit Debugging stops working?

    Hi All,
    I thought maybe this was a "common" problem that others may have experienced so "frequently asked questions" seemed like a good place? As far as I know (which isn't much) all the code examples say to use "DEFINE LOADER_USED 1" and "DEFINE OSC 20", and "Include "Modedefs.bas"". Okay so I tried to compile without the "DEFINE LOADER_USED 1" no change, and changed the baud rate to 19200, no change. For me with the programmer I have which is a "Picstart Plus" you must compile in Microcode Studio Plus ver 5.0.0.3 complier ver PBPX 3.0.4.4, then program the PIC in MPlab IDE v8.84, then run the program in Microcode Studio. There are so many options and choices in both programs it boggles the mind! To the best of my small knowlege when you define your OSC as 20 this takes care if the HS (High Speed) fuse setting or is this not correct? Is there another "Loader_Used" and how do you know which is correct? I can program the PIC without any errors. It is when you try to "Run" the program that nothing seems to work and you get a "IDC Connection Timeout" error. Thanks, Ed

  5. #5
    Join Date
    Mar 2011
    Location
    Los Angeles, California
    Posts
    322


    Did you find this post helpful? Yes | No

    Default Re: In Circuit Debugging stops working?

    Just wanted to add that everything works fine with a 4MHZ resonator and a baud rate of 115200. So my guess is that somewhere there must be some setting that needs to be changed and I have no idea where! Best, Ed

  6. #6
    Join Date
    Oct 2004
    Posts
    448


    Did you find this post helpful? Yes | No

    Default Re: In Circuit Debugging stops working?

    Quote Originally Posted by Ramius View Post
    To the best of my small knowlege when you define your OSC as 20 this takes care if the HS (High Speed) fuse setting or is this not correct?
    No it doesnt; you will have to explicitly set it either in your code OR the programmer software. From what you describe, the HS setting just might be the issue.

  7. #7
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,516


    Did you find this post helpful? Yes | No

    Default Re: In Circuit Debugging stops working?

    Hi Ed,
    OK, several things here,

    First the oscillator.
    When you DEFINE OSC xx you are simply informing the compiler at which speed YOU intend to run the PIC so that it (the compiler) can figure out how many cycles it takes to PAUSE 100 or generare PWM with a certain frequency etc etc. It does not SET the frequency of the PIC in any way shape or form and it does not set any CONFIG fuses/bits either. That's up to you to do - either thru the compiler or manually in the programmers software. For a 20MHz crystal or resonator you want it set to HS.

    Second, DEFINE LOADER_USED 1
    This tells the compiler that you've already programmed the PIC with a small program (called a bootloader) and that it (the compiler) needs to stay away from certain areas of the program memory (or it will overwrite the bootloader). The bootloader allows the PIC to reprogram itself via a serial connection (no need for a programmer except for getting the bootloader into the PIC to begin with). It's generally used with the MicroCode Loader (but there others). So, if you're not using a bootloader don't tell the compiler that you are. (I don't think it matters in this particular case though).

    Third, the MicroCode Studio ICD
    To use this the PIC must have its USART pins wired thru a RS232 level converter like the MAX232 and you must specifically compile the program for use with the debugger. This is done with the ICD compile button in MicroCode Studio, THEN you program the PIC with the generated .hex file and THEN you can use the "play button" etc to run the program, set breakpoint etc. There's guide available at Rentron - read it!

    /Henrik.

  8. #8
    Join Date
    Mar 2011
    Location
    Los Angeles, California
    Posts
    322


    Did you find this post helpful? Yes | No

    Default Re: In Circuit Debugging stops working?

    Hi All!
    You guys are very correct and I do have the MAX232 and with the 16F628A ICD works fine now with a 20 Mhz resonator. What I did not know is that it is necessary to look at the .info file for a given PIC to know what the default(s) are. Turns out that with a 16F628A the default OSC setting is XT. In the beginning of the .info file are 3 config statements that you need to copy and paste into your code to change the XT to HS. Then everything will work fine! There is one PIC I can never seem to run in ICD mode and that is a 18F1320. I know this device uses different pins for TX and RX and checking the .info the default OSC setting is 20 Mhz. Any change someone has known good working code I could use just to do some further checking? Thanks, Ed

  9. #9
    Join Date
    Mar 2011
    Location
    Los Angeles, California
    Posts
    322


    Did you find this post helpful? Yes | No

    Default Re: In Circuit Debugging stops working?

    Hi All! Turns out that the 18F1320 is a "unique" PIC requiring special handling. First the following lines are required for it to operate at 20 Mhz:
    #CONFIG
    __CONFIG _CONFIG1H, _HS_OSC_1H
    __CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
    __CONFIG _CONFIG4L, _LVP_OFF_4L
    #ENDCONFIG

    Next a very wonderful person Dannel Taylor sent me the attached file for the ICD to work. As part of the "trouble shooting" process I discovered that if you jumper the TX and RX out of the MAX232 that goes to the PIC in MicroCode Studioss you can open VIEW, Serial Communicator, then "connect" and type something and if your computer is talking to the MAX232 then it will echo back what you typed! If it does not then you can check that your computer comm port settings are correct and that the MAX232 is working. It's nice to have the warm and fuzzy feelings knowing at least how far things are working! Hope this helps others.

    Best, Ed
    Attached Files Attached Files

  10. #10
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: In Circuit Debugging stops working?

    Sorry to tell you but there is nothing special or unique about it.
    The configs posted are typical.

    But , Good job figuring it all out.
    Dave
    Always wear safety glasses while programming.

Members who have read this thread : 1

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