PDA

View Full Version : ICD, ICSP and Picbasic Pro



mwhatley
- 24th September 2005, 16:27
I'm a bit confused about using the ICD feature of the PICs that support ICD. I have managed for years using the serial DEBUG command to work out my bugs but have recently become interested in the ICD feature. A project I just completed used a 16F628 and while I still had it on the protoboard I thought I would see if I could get the ICD to work. I already had a MAX232 converter set up so it was a simple matter to give it a try. I am using MicroCode Studio and PicBasic Pro with a Warp13 programmer (I was not using ICSP). Using Bruce Reynolds' posting on his site I was able to get a simple program to work but when I tried it on a "real" program it would hang and stop running. In Bruce's circuit he uses the RX/TX pins on the '628 but I see that Microchip's AN DS51242A says that the ICD uses RB6 and RB7. I have also found reference to adding a NOP as the first executable instruction and also adding an INCLUDE ICDDEFS.BAS. My copy of PBP has several variations of this include file, none of which say they are for the '628.

From what I can gather the Microchip ICD2 can connect to the ICSP pins and act as a programmer and then as a debugger, I assume using MPLAB. So my question is this:

Will the ICD2 work with Microcode Studio and PicBasic Pro and provide programming and debugging functions?

Is there something better than the ICD2 ?

Many thanks,

Mark

crematory
- 24th September 2005, 22:07
Hi

You can't use ICD with MCSP any way, and you need a firmware to download in the PIC before you can use the ICD feature. Don't mix between the loader of MCSP, and that for ICD. Anyway, if wanna use ICD, then you have to use MPLAB instead...

Good luck

Demon
- 24th July 2006, 18:10
I disagree. MicroCode Studio Plus has in-circuit debugging.

I can't figure out how to make it work, but it's there. I tried using that MAX232CPE circuit too, connected to TX/RX with the same results.

Gonna try PGC/PGD and see what happens.

Robert
:(

EDIT: D'OH! I had 1 cap and 1 wire from RS232 in the wrong place. Works like a charm now, using TX/RX too. The only downside to in-circuit serial debugging is that it interferes with any HSERIN/OUT, but it's awesome to find errors.

Bruce
- 24th July 2006, 19:31
The ICD feature in MicroCode Studio is totally different than Microchips ICD2.
Hardware & software wise.

ICD2 also doubles as a device programmer. That's why it uses the PICs'
programming clock & data pins. To use ICD2 you need MPLAB, the ICD2
hardware, and the PIC wired like shown in the ICD2 hardware diagram.

The MCS ICD feature uses the PIC onboard hardware USART to send debug
information back to the PC via the serial connection. When you compile your
code in the MCS editor using the ICD compile button, it automatically includes
additional debug code mixed in with yours to handle the ICD apsect.

The two are completely different.

Charles Linquis
- 25th July 2006, 04:39
I, too have tried to use the debuggers, but have had no success whatsoever. I'm either 1. Too dumb to understand the tutorials, or 2. Expecting it to work like it would if I wrote it.
In either case, I have found both of the debuggers useless. So far, my opinion is that Microchip's is hard to use because it is purely software, and therefore has a hard time dealing with hardware events (how DO you write stimulus files, anyway?), while the Microcode Studio version always gives me errors, such as "path too long" - even when I have moved all files to the root of my C: drive.

If someone has a "dumbed-down" explanation of the step-by-step use of a debugger, I would really appreciate it if they would post it.

I have several ICD2's and all my PIC circuits use 8720's or 8722's with MAX chips. I use MCStudio. If there is a better/easier debugger that I should be using, tell me and I'll buy it.

Rob
- 25th July 2006, 09:36
Hi,

I have successfully used ICD with MCSP on a particular program I have used in the past (on a 16F877A) and found it to be invaluable - it really cut down the time to market on one of our more extensive projects!

Using Bruce's circuit, you don't need an ICD2 for this, you can program and debug the software in circuit. You need to use the correct boot loader for the PIC you are using which is found in the MCLoader of MCSP program files. This needs to be programmed into the PIC with a programmer before placing the PIC into the ciruit.

The RX and TX pins are the right pins to use for communiaction in this circuit.

In the PIC program, you must type:
DEFINE LOADER_USED 1 at the top of the program

Choose specific points of the program that you wish to debug and type:
ENABLE DEBUG before it
then after that part of the program type:
DISABLE DEBUG

You then have to use the ICD Compile and Program Button to compile the program rather than just the Compile and Program button.

The "Loader Help Topics" in the Help section of MCSP contain all the necessary information for ICD including the circuitry between the PIC and the PC - check 'em out as they're very useful.

Hope these pointers help.

Demon
- 25th July 2006, 12:15
Again, apples and oranges. The loader is one thing and ICSD is another. I use in-circuit serial debugging from MCSP without using the loader at all.

Robert
:)

Rob
- 25th July 2006, 12:48
The loader is one thing and ICSD is another. I use in-circuit serial debugging from MCSP without using the loader at all.


True - but if you program a bootloader into the chip, then program the chip in circuit you are testing that your hardware/wiring is correct.

Regards

Rob

mwhatley
- 30th July 2006, 02:54
After I made the initial post to this thread I continued my "research". I now understand that the MCSP ICD and the Microchip ICD are two completely different animals. But recent posts still have me puzzled. I have kept the MC ICD page bookmarked and I recently reviewed the information presented thereon. The only mention of a bootloader is that MCSP now includes a free bootloader that enables the user to program certain PICs without a hardware programmer. There is no mention of any bootloader being required to get the ICD to work reliably. I use the MELabs USB programmer and do almost all my programming using ICSP and it works very nicely.

All that said, I must admit that I have not actually had a chance to try the experiment again. I've been living with DEBUG statments but I can surely see the advantages of MCSP ICSD if only I could get it to work on something other than simple programs.

Does anyone really know if a bootloader is the answer?

Thanks everyone. Mark

Bruce
- 30th July 2006, 03:33
Using a boot-loader is totally optional. You can program the PIC in-circuit with
your device programmer, use a boot-loader, or move the PIC back & forth
from programmer to ICD circuit.

It makes no difference how you get your code into the PIC. Only that you use
the ICD/Compile button when creating your code.

Demon
- 30th July 2006, 04:12
Yup, I wired the 10-pin connector on my MeLabs serial programmer directly to the breadboard and do all my programming in-circuit. I use MicroCode Studio Plus using normal compilation and try to get everything working right. The other night was the first time I hit a wall in the debugging and slapped together a MAX232CPE circuit and followed these steps:

- ICD compile using MeLabs serial programmer.
- unplug programmer and connect MAX232CPE circuit.
- run ICD and follow the breadcrumbs.

You don't have to do step #2 'cause you have a USB programmer.

Now I have to make myself a "Y" switchboard to toggle between 2 DB9 connectors: serial programmer and ICD debugger. That way I won't have to play musical chairs with the single serial cable on my computer.

Robert
:)

mwhatley
- 30th July 2006, 05:18
Thanks Bruce and Robert. Since I posted the original post I have purchased the full MCSP package but I have not tried the ICD method again. I had assumed that what Bruce said was the correct method and no bootloader was required.

My original problem was that it worked fine on a sample program that I believe I got off the Rentron site. So I know the basic hardware was good. When I tried it on an actual project it would hang up after the first few executable lines - and not always in the same place. I don't remember what the project was now but I think the problems came during the initialization portion.

All my 'stuff' is at my office and when I get a chance I'll try the ICD again with the new MCSP.

Thanks again, Mark

keithdoxey
- 30th July 2006, 13:36
Hi All,

Havent used the ICD feature before but this thread has made me take a closer look at it.

I decided that my current project will benefit from this as I currently have loads of code stuffed in there to try and debug what is happening but have realised that if I use ICD then I dont need it.

The problem I have is with this section of code

For CharCount = 0 to NameCount
Hserout [Name[CharCount]]
Next CharCount
Hserout [10]
Hserout ["IP: ",DEC IP[0],".", DEC IP[1],".", DEC IP[2],".", DEC IP[3],10] 'Display IP Address

The two lines in bold fail with the message "Bad Expression" but ONLY when I compile with ICD (CTRL+F9).
If I compile normally (F9) then it compiles without errors!!

Any ideas ?

Thanks

Demon
- 30th July 2006, 14:05
HSERIN/OUT commands opened up a Serial Window when I executed them in ICD. At first glance I can't see what is wrong with your code.

What about the HSER definitions in your program, what does that code look like? Baud rate, etc.

Robert
:)

mwhatley
- 30th July 2006, 17:15
I believe that the ICD uses the hardware UART of the target PIC to communicate with MCSP. My guess is that you can't do both - run the ICD AND use the hardware UART under your program control. The complier is raising an error when it sees the HSERIN/OUT command when compiling for ICD use.

Bruce
- 30th July 2006, 17:24
I suspect it's this line Hserout [Name[CharCount]]

How is this supposed to work? I.E. how are your variables/constants defined?

EDIT: Found the solution. Enclose all your array elements in parenthesis VS
square brackets.

For CharCount = 0 to NameCount
Hserout [Name(CharCount)]
Next CharCount
Hserout [10]
Hserout ["IP: ",DEC IP(0),".", DEC IP(1),".", DEC IP(2),".", DEC IP(3),10] 'Display IP Address

Works as expected.

keithdoxey
- 30th July 2006, 19:38
I suspect it's this line Hserout [Name[CharCount]]

Found the solution. Enclose all your array elements in parenthesis VS
square brackets.

Hserout [Name(CharCount)]

Works as expected.

Excellent. Thanks Bruce.

I also found out that instead of

For CharCount = 0 to NameCount
Hserout [Name(CharCount)]
Next CharCount

it would compile with a single line of

Hserout [STR Name\Namecount]

which would achieve the same result although "Namecount" would have to be one higher than in the For/Next example.

What I dont understand is why the ICD compile gets upset with the square brackets when the ordinary complier accepts it.

I use the following two bits of code in the same program which follow the same style and both of those are fine.

For CharCount = 0 to NameCount
Read NameBase + CharCount,Char
Name[CharCount]=Char
Next CharCount

For CharCount = 0 to NameCount
LCDout Name[CharCount] ' Boot message.
Next CharCount

It would appear that it is only a problem with Hserout because that command requires square brackets as part of its syntax.
Just tried Hserin with the line Hserin [Name[Namecount]] and that compiles fine with [] or () around the array element.

Mighty strange, will drop David Barker an email to let him know of the inconsistency between the two compiles.