PDA

View Full Version : Unpacking a PICkit 2 Programmer/Debugger



duncan303
- 22nd March 2008, 21:16
Well I have just come to the end of day having finally unpacked a pickit2 debug express DV164121 which has a 16F887 on a small dev board.

Although I researched MPLAB IDE a few years ago I have had little further to do with it preferring the easier option of MCSP 3.0.0.5 together with Melabs serial programmers and of course PBP2.50a. I am very comfortable with PBP/MCSP configuration I also have a LabX1 devboard which I still regularly use. However having been spoiled by David Barker’s ICD within MCSP, I have been developing much larger programs “in the dark” on devices not catered for in the ICD module MCSP.
I am disappointed, but not surprised, by Microchip’s policy of secrecy regarding the Debug routines for the majority of it’s own devices. Anyway some time ago I ordered a PICkit 2 to be able to transfer code over and get a “look inside” on some trickier problems (for me) to solve.

First I loaded the PICkit 2v2 software which was straightforward except for the fact that it took at least an hour and half for the “necessary” Net framework to be installed, I hoped this was not going to be an omen for badly written code, after all I have PBP and MCSP running off a ZX81! (Not really but close). Anyway a few hundred megs later I got PICkit 2 up and running, a simple interface with what looks like a handy box to control VDD. Getting it to work, sort of, seamlessly with MCSP requires downloading a PK2CMD application and setting it up. There is a comprehensive step by step article in Jan 2008 issue of Nut and volts, thanks Chuck Hellebuyck . For the moment I had been powering from the PICkit 2 but it appeared reluctant to let go of the programmed device, holding it in reset. Maybe this would not be the case with an external supply. The most noticeable difference is that there is no direct access to configuration fuses using the pickit2, fuses have to be set within code file, and there appears to be little in the way of control over the device itself whilst using MCSP. The MELabs programmer gives all the fuses with their options listed in combo boxes for all supported devices, this is very handy to quickly see and change a fuse value especially when you are using an unfamiliar device. Personally I later embed the fuse configuration into the file once I have them fixed and then set “read fuses from file” option. So it looks as if Pickit2 with MCSP works almost exclusively in the background, and it doesn’t much like having two instances open either, this appears to cause a major lockup.
Maybe it looks as if pickit2 is designed to work more flexibly within the Mplab environment.

As the purpose of this exercise is to debug it was time investigate MPLAB IDE V8. My few skirmishes with this IDE in the past have left me a little cold, so I have been putting it off a little.

Anyway I followed the step by step tutorial that came with the PICkit 2 and had the unit working in debug mode on the 16F887 very quickly. The PICkit2 is clearly designed to function more usefully within this environment, for a start it auto updates the PICkit OS, which I had previously done manually earlier on.(was it worth the time waiting for Net framework?)1 There is a monitor child window that relays info from the programmer as it operating, I suspect that there may well be more ways to interface the programmer later on, the only mechanism I tried was to be able to easily read the code space and eeprom from the current device, although there is a task bar button to read device I couldn’t easily find a way to display the contents without resorting back to the programmer interface, but I guess a few more hours will help here.

So now all that is left is to get the MPLAB to debug a program created in PBP. Time to install the MPLAB plugin created and downloaded from Melabs, this is installed as a language suite within MPLAB, so far so good.

Next to write a small few lines in PBP and compile and write to the device. First I used the project wizard to create a new file, but I have to say I got in a right pickle and gave up the wizard altogether and set about creating and naming a new project and creating and naming a new file directly from the menus, only thing to remember is to save the file as a .BAS or .ASM which allows it to become a “source file” that can then has to be added to the project. So now I have PBP operating within the MPLAB and can compile (build) and program a device, things are moving on quite fast. Next I build (compile) not as a “release” but as a “debug”, everything is fine and I note how well the PICkit performs.

I can set breakpoints within the PBP code, and it appears as if I have access to registers etc. Next I set the debug to animate, this time instead of animating my PBP code it animates the PBP 14bit core library file. I am hoping to get that sorted as I would prefer the PBP code to be animated but I think this has been enough progress for today.
So all in all not too bad, I thought it would be worse. Mind you MPLAB takes up so much space on the drive I think I have every right to expect it to work, but……… there is a lot more opportunity for it to go wrong and I fully expect it to sometime soon.

Is MPLAB more professional (serious) or is it just bigger and overly complicated, some (most) of the sweetest work I do is executed with the simplest tools.

Off to have a glass of wine…. Oh yeah Happy Easter to you All :D

mackrackit
- 22nd March 2008, 23:16
Is MPLAB more professional (serious) or is it just bigger and overly complicated
I think it is no more professional or less professional than MCS. It can do things that MCS cannot. So it is just a matter of different tools for different jobs.

One of the things I like about MPLAB is it can tell me how the fuses are set after a program is compiled. I find this very useful when working with an unfamiliar chip when I am not sure it I have things correct. It also can take a saved hex and tell you how the fuses are set, nice when you need it.

Again it is a matter of the right tool for the right job, and what you become comfortable with. Some times I us XP or Linux, MPLAB or MCS, PICKIT1 or PICKIT2 or PICSTART PLUS. Seems the only thing constant is PBP.

mvs_sarma
- 23rd March 2008, 05:42
Well I have just come to the end of day having finally unpacked a pickit2 debug express DV164121 which has a 16F887 on a small dev board.

Although I researched MPLAB IDE a few years ago I have had little further to do with it preferring the easier option of MCSP 3.0.0.5 together with Melabs serial programmers and of course PBP2.50a...............
First I loaded the PICkit 2v2 software which was straightforward except for the fact that it took at least an hour and half for the “necessary” Net framework to be installed, I hoped this was not going to be an omen for badly written code, ..................

Off to have a glass of wine…. Oh yeah Happy Easter to you All :D

I had downloaded the PICKIT2 with .net elements from microchip site. It did not take that sort of time for me. If I remember, it took hardly less than 10 mnts

duncan303
- 23rd March 2008, 08:28
Hi Dave


……One of the things I like about MPLAB is it can tell me how the fuses are set after a program is compiled.……

I noticed the child window available in Mplab, but I have to say that initially I much prefer the Melabs Serial programmer Interface. I assume that multiple options are probably equally available using PICkit2, I just haven’t found them yet. Like reading the eeprom of a device and having it displayed full screen height rather than a piddly little 5 line scroll combo box. I like to use eeprom as an alarm event log recorder so the more I can see in one hit the better.

Redeading my post, I appear to have presented it as a better/ worse thread, this wasn’t my intention, I just thought I would share an experience. Having to succumb to Microchips policy of protectionism.


Hi Sarma,

Yeah I guessed something was wrong, to be honest most of the time taken was with installing windows updates to Net framework, my point was really that MPLabs is a monster and in my humble experience, vulnerable to failure. For example Windows update continues to attempt a forced install of a critical update service pack to Net framework V.1, but it also has installed through to version 3. PICkit initially installed version 2. Do I want to go searching the windows Knowledge base on an Easter weekend, yeah I think Not.

I hate to sound jaded but it is many years now since I was “in love” with PC’s. I am reminded of a quote by Damon Hill an F1 racing driver who found himself looking across at a competitor as he was entering the first bend and thinking “what’s the rush?”. I am sure Damon continues to thoroughly enjoy driving but there is only so much of your life you can spend fiddling about with the OS on any computer. How many guys do we all know who come into work on a monday having spent the weekend Fdisking their Hdrives and getting the optimum setup “for the very last time”….. until the next month!

Minimum code = Maximum enjoyment! Just look at the response on here when you get a code condensing thread.

“If it ain’t bust don’t try to fix it” ………… just hang on as I put my bright yellow cardigan on and settle down into my rocking chair :D

Duncan

Acetronics2
- 23rd March 2008, 09:12
Hi, Duncan

I've always used PbP with MPLAB, Picstart plus and ICD2 ...

I do agree MPLAB is somewhat Huge ... but, I also do think we are really far from using it's real and full power ...
Not really useful for Hobbyist, but really nice for pro's ...


I also use some others IDEs ... and find MPLAB is one of the ... lightest !!!

you should have a try with PSoC Express ( Cypress ) or Processor Expert ( Moto ... euhhhh, Freescale ) ...

Just to have something to "trim your scale" ... ( LOL )

And a yeah Happy Easter to you and everybody here

Alain

mvs_sarma
- 23rd March 2008, 12:57
Hi Dave

I noticed the child window available in Mplab, ...............
Hi Sarma,

Yeah I guessed something was wrong, to be honest most of the time taken was with installing windows updates to Net framework, my point was really that MPLabs is a monster and in my humble experience, vulnerable to failure. For example Windows update continues to attempt a forced install of a critical update service pack to Net framework V.1, but it also has installed through to version 3. PICkit initially installed version 2. Do I want to go searching the windows Knowledge base on an Easter weekend, yeah I think Not.

I hate to sound jaded but it is many years now since I was “in love” with PC’s. I am reminded of a quote by Damon Hill an F1 racing driver who found himself looking across at a competitor as he was entering the first bend and thinking “what’s the rush?”. I am sure Damon continues to thoroughly enjoy driving but there is only so much of your life you can spend fiddling about with the OS on any computer. How many guys do we all know who come into work on a monday having spent the weekend Fdisking their Hdrives and getting the optimum setup “for the very last time”….. until the next month!

Minimum code = Maximum enjoyment! Just look at the response on here when you get a code condensing thread.

“If it ain’t bust don’t try to fix it” ………… just hang on as I put my bright yellow cardigan on and settle down into my rocking chair :D

Duncan


I do understand that you and many of us might be tuned for PBP and associated stuff.
But I expect more than 30% of our members become professional experts as days pass by and will not remains in hobby alone. So we may not look at the magnitude of the MPLAB. In fact I am a beginner in software learning and at an advanced age of 62. Once i have a HDD of 80 or 160GB , this MPLAB is nothing perhaps, and I bite only as much a can chew. Perhaps you may be right from your perspective.

ardhuru
- 13th May 2009, 07:47
I can set breakpoints within the PBP code, and it appears as if I have access to registers etc. Next I set the debug to animate, this time instead of animating my PBP code it animates the PBP 14bit core library file. I am hoping to get that sorted

Duncan, I'm in precisely the same situation, with a progress curve very similar to yours. I too am using a 16F887, and when I animate, the 14bit core lib. file opens up and animates.

Very curious to know if you sorted it out.

And a question to Bruce as well; with the help of your recent post at http://www.picbasic.co.uk/forum/showthread.php?t=5785&highlight=mplab+animate

I have been able to see my variables in the watch window. However, I still cant see the variables assigned to the port pins. Is there any way to achieve this?

BTW, I'm suing MPLAB 8.00

Thanks and Regards,

Anand

Bruce
- 13th May 2009, 15:56
Hi Anand,

When you create a variable for a port like PORT VAR PORTB or PORT VAR GPIO, all you're
doing is creating an alias to the port. It doesn't create a variable in RAM like it would for
something like X VAR BYTE.

Look at the screen capture attached. Check out the address for _PORT, GPIO, _X and _Y.

X and Y are variables in RAM. _PORT is just another name for the physicall address of GPIO.
It's not a variable created in RAM. Just an alias to the port address.

Running animations in MPLAB for PBP programs is a bit different than using it with assembly.

If you run something like what's shown in my screen capture, and hit animate, it will show
the green cursor on each line as it executes. Now insert a PAUSE 1 just after PORT = X.

When it lands on the PAUSE 1 it calls the PBP library routine, so the library window opens
and you don't see it execute the PAUSE 1 in the BASIC source window. It's only going to
show inline type commands. Calls to PBP library functions aren't shown in the source code
window. That's why the library window pops up.

Using MPLAB with PBP takes a bit of getting used to, but it's worth the effort.

ardhuru
- 13th May 2009, 18:22
Hi Bruce,

Thanks for the reply; very lucid, as always.

I now understand the issue I'd raised (kind of). What I dont understand yet, although you've touched upon it, is why the animation jumps to the library window whenever it encounters a pause statement. And then doesnt seem to return back to the source window. But, single-stepping seems to work fine.

About the port pins. What you are saying is, I'd have to watch the whole port, and then see the behaviour of the individual pins within; am i right in my understanding?

I must say MCS Plus has really spoilt me; this is one thing about it I miss. But like you said, there seem to be loads of other things in favour of MPLAB that makes the transition worthwhile.

Thanks again.

Anand

Bruce
- 13th May 2009, 18:50
Hi Anand,


But, single-stepping seems to work fine.
Because when you're single-stepping with the Step Over button it steps over the huge
library functions. If you single-step using Step Into, it executes the library function line
by line. Step Over runs the whole library function immediately returning to the next PBP
BASIC statement.

Animation works similar to Step Into - so you lose the green animation cursor when a call
to a library function is made.


About the port pins. What you are saying is, I'd have to watch the whole port, and then see the behaviour of the individual pins within; am i right in my understanding?

Yep. You can watch the port or the alias you've created, but you're still essentially
watching the same thing since the alias is just another name for the same register address.


I must say MCS Plus has really spoilt me; this is one thing about it I miss. But like you said, there seem to be loads of other things in favour of MPLAB that makes the transition worthwhile.
MCS+ is a great little program, but once you get the hang of using MPLAB/MPSIM with PBP
you'll never look back.

MPLAB has a lot of things MCS+ doesn't like the stop watch, logic analyzer, and advanced
features like register injection. You can setup stimulus files to send analog values to A/D
inputs, simulate external switches on pins, and a lot more.

It goes way beyond just watching the animation cursor & viewing register values...;o}

Ioannis
- 13th May 2009, 19:44
MPLAB has a lot of things MCS+ doesn't like the stop watch, logic analyzer, and advanced
features like register injection. You can setup stimulus files to send analog values to A/D
inputs, simulate external switches on pins, and a lot more.

By the way are there any tutorials on these?

Ioannis

Bruce
- 13th May 2009, 20:01
Hi Ioannis,

None that I'm aware of. I'll put one together.

Bruce
- 14th May 2009, 02:18
Here's a complete PBP application showing how to use several of the cool features built
into MPLAB/MPSIM with PBP.

You can run this without even owning PBP, but you can't make changes or re-compile
without PBP - obviously, and you will want to create a directory on drive C as follows -
C:\PBP\SIMTST to install these files in.

If you do own PBP, and it's in C:\PBP, then create the directory as shown above, and unzip
all files into that directory.

What you'll need:

Download & install MPLAB 8.15a. This is the latest/greatest version that supports PBP until
MeLabs makes a few changes. And don't bother asking for help if you're using an earlier
version of MPLAB since this was done with version 8.15a...;o}

You can download 8.15a from the link below;
http://ww1.microchip.com/downloads/en/DeviceDoc/mplab_v815a.zip

Now follow the instructions from MeLabs website on installing MPLAB at the link here;
http://melabs.com/support/mplab.htm for your operating system.

TIP: Anyone that owns the Microchip C18 compiler, that has installed the latest/greatest
version, or anyone that might have installed another program that installs a new version of
MPASM assembler, here's something to look for;

When installing some other program that includes itself in your path statement, it may
C18 does install its own entry before entries that were previously dropped in
your path statement when installing MPLAB.

If that's the case, you may end up with error messages when you try compiling your PBP
program code stating it can't locate .COD files. If you see this, then edit your path
statement placing the PBP & MPLAB entries first - like this;

C:\PBP;C:\Program Files\Microchip\MPASM Suite;c:\mcc18\mpasm;c:\mcc18\bin, blah,
blah.

I ran into this problem after updating C18 to the latest version, and it was a HUGE pain in
the butt to find/fix. MPLAB showed MPASM 5.22 on-screen, but the .LST file showed it was
actually assembled by a much newer version 5.30.01 assembler, which was installed in my
MCC18 directory. A BIG bug to watch out for. MPLAB pops up an MPASM assembler screen
indicating it's using 5.22, but it's really assembling with the 5.30.01 MPASMWIN.EXE in
another directory, so you've been warned...;o}

Moving on:

Once you have MPLAB version 8.15a installed, and these files unzipped into your
C:\PBP\SIMTST directory, you're ready to go.

Start MPLAB. Click Project >> Open, and find C:\PBP\SIMTST\SIMTST.MCP to open this
project.

Click the Step Into button once. If the Watch window doesn't show a value of 00000001
on PORTB, then click on the Stimulus window > Fire button next to RB0. Then click the
Step Into button once more. Now you should see in the Watch window PORTB = 00000001.

Next click the Run button. It will sit & spin now until you click the > Fire button again in
the Stimulus window.

Once you click the Stimulus window > Fire button, it will stop on the breakpoint at the
ADCIN command, and display the pulse stream output on RB1, and the RB0 switch input
pulse in the logic analyzer window.

Next click the Stimulus > Fire button again, then Step Into, and make sure it shows PORTB
00000001 in the watch window again, then click the Run button. You should see the simulated
A/D value passed from the Stimulus Register Injection file ADSTIM.TXT shown in the
Output window under SIM Uart1.

Now comment out the WHILE Switch WEND code, recompile, and just keep pressing the Run
button to see the difference.

Yeah, I know, it's not a complete tutorial, but it does help to show some of the cool MPLAB
& MPSIM features you can work with in PBP.

When I can find the time, I'll work-up a complete tutorial for this, including setup & extra
info on our website and post a link to it here.

ardhuru
- 14th May 2009, 06:39
Hi Bruce,

Okay, that pretty much puts things in perspective. Wouldnt have been able to do the switch without all the inputs I got.

Thanks,

Anand

Ioannis
- 14th May 2009, 07:43
Hi Bruce. Thanks a lot for the quick tutorial!

What if there is already installed the 8.30 version of the MPLAB? Will be any problem with the latest (greatest?) version?

Ioannis

Bruce
- 14th May 2009, 14:59
See the first section here http://melabs.com/support/mplab.htm for info on using PBP with
MPLAB version 8.20 or later.

MeLabs is working on it, but it's not ready yet. If you want to use MPLAB with the latest
version of PBP, you'll need to install MPLAB version 8.15a or earlier.

ardhuru
- 14th May 2009, 15:42
Been making a lot of progress, Bruce.

Now I have a question again.

When using the simulator, my switches (which in hardware have a pull-up) show to be low; how can i change that so that I could use the stimulus to trigger these?

Regards,

Anand

Bruce
- 14th May 2009, 17:38
Click in the stimulus Action window for options. See attached screen capture.

ardhuru
- 14th May 2009, 19:23
Yes, I discovered that, Bruce. But does 'pulse low' mean that input would otherwise be high by default, as it would with a pull-up? Or does one have to set it high every time, before a pulse low can be used?

Anand

Bruce
- 14th May 2009, 19:52
Weak pull-ups on ports not implemented in MPLAB SIM. Use Toggle.

Ioannis
- 14th May 2009, 21:24
See the first section here http://melabs.com/support/mplab.htm for info on using PBP with
MPLAB version 8.20 or later.

MeLabs is working on it, but it's not ready yet. If you want to use MPLAB with the latest
version of PBP, you'll need to install MPLAB version 8.15a or earlier.

Well, I asked because 1. did not read the mentioned article by Melabs and 2. I run your tutorial with no problems. I did not though compiled yet any program in 8.30...

Ioannis