|
|
View previous topic :: View next topic |
Author |
Message |
SW
Joined: 09 Jun 2011 Posts: 10
|
MPLAB, CCS Compiler, & PICKit 2 |
Posted: Thu Jun 09, 2011 6:14 pm |
|
|
I've worked quite a bit with the CCS compilers and Microchip's PICKit 2 over the last couple years. I recently moved and am recreating the lab I used while I was in college.
I've run into a problem that I haven't been able to solve, and it's probably one of those simple ones that makes you smack your forehead when someone shows you your oversight.
I'm working with a 16F877A (40 pin) and a 16F876 (28 pin). I have my little "hello world" with flashing LEDs but when I compile through MPLAB (version 8.63) using the CCS addon, and use my PICKit 2 (version 2.61) to load the .hex on the chips nothing happens. Using only a logic analyzer I can see distinct pulses that appear to be something other than noise on PGD and PGC. My code for the 16f876 is as follows:
Code: |
#include <16f876.h>
//#fuses NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
void main()
{
output_low(PIN_B2);
output_low(PIN_B5);
while(1)
{
output_high(PIN_B2);
output_high(PIN_B5);
delay_ms(1000);
output_low(PIN_B2);
output_low(PIN_B5);
delay_ms(1000);
}
}
|
I have rechecked my connections three times to ensure they are correct. I can't believe that I'd have two DOA chips, but maybe that's the case. I have images and screenshots and can email them if needed. My NAS is down or I'd upload them.
My basic connections for the 877A are the standard MCLR, 20MHz crystal with 33pf capacitors, and two LEDs (you'll see four, but two are reversed for a dummy check). My setup for the 876 is the same minus the MCLR setup. LED resistors are 220 Ohm, and an LM7805C with capacitors is being used when powered from a 9V battery. However, the setup doesn't even work with the PICKit 2 powering it so I doubt any of that is the cause of the problem.
Again, everything seems to load to the chip correctly, but my logic analyzer shows no activity on any leg other than when the PICKit 2 is programming the chip.
Am I overlooking something? Could the PICKit 2 be bad without showing any signs of failure?
Thank you, _________________ -SW |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jun 09, 2011 7:05 pm |
|
|
Put in the #fuses line as shown below.
Code: |
#include <16F876.h>
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=20000000)
|
Quote: | My basic connections for the 877A are the standard MCLR |
Describe the MCLR circuit. |
|
|
SW
Joined: 09 Jun 2011 Posts: 10
|
|
Posted: Mon Jun 13, 2011 5:15 pm |
|
|
I updated as you suggested and still have nothing. My rails are showing 4.9 volts and after checking all legs I show no voltage pulsing from any pin. Vdd shows hot as it should, and the two Vss show 0 as they should.
To dumb it down for myself, I have a 20MHz crystal (DigKey model 20.0UY6K) and two ceramic capacitors with 33 stamped on them which go to ground. Each LED has a 470 Ohm resistor connected to it. On the 16f876 I do not have an MCLR setup since the PICKit 2 is supposed to take care of that. I do have one set up on the 16f877a though. Neither setup works.
Any other suggestions?
Thank you. _________________ -SW |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jun 13, 2011 5:29 pm |
|
|
1. Put a 10K resistor to +5v on the PIC's MCLR pin. (That's on pin 1).
That's part of the ICSP specification for Pickit 2.
2. What's your CCS compiler version ? It's given at the top of the .LST
file, which will be in your project directory. Example of version numbers:
http://www.ccsinfo.com/devices.php?page=versioninfo
3. Post your current complete test program, including all the modifications
that I suggested.
4. Your crystal number is probably what you see stamped on top ot it.
It's not found with Digikey's search engine. What's the Digikey part number ?
5. Is your crystal placed across pins 9 and 10 ? Are the 33pf caps
placed from pin 9 to ground, and pin 10 to ground ?
6. Are the two ground connections on the PIC to pins 8 and 19 ?
And the Vdd (+5v) to pin 20 ?
7. Are you testing the program in Debug mode or in Release mode ?
Try it in Release mode. This is selected with the drop-down box at the
top of the screen in MPLAB.
8. You can upload images to imageshack.com and post the links to them. |
|
|
SW
Joined: 09 Jun 2011 Posts: 10
|
|
Posted: Mon Jun 13, 2011 5:33 pm |
|
|
What are the odds that my PICKit 2 is bad? Nothing looks out of the ordinary, and it seems to verify the code after it is written without error. When it is programming the chip, the Busy light flashes like normal too. I'm out of ideas here. I don't know how I could have two bad chips at the same time when both are new. _________________ -SW |
|
|
SW
Joined: 09 Jun 2011 Posts: 10
|
|
Posted: Mon Jun 13, 2011 5:36 pm |
|
|
Okay, going through my parts list again. The Digikey crystals I bought are P/N 887-1023-ND, or "Crystal 20.000 MHZ 18PF HC49US". Could it be the built-in capacitance that is messing me up?
Thanks, _________________ -SW |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Tue Jun 14, 2011 2:13 am |
|
|
Not really.
The 18pF, is the _load capacitance_ expected by the crystal to work at the specified frequency. It'll still resonate with the wrong capacitance, _but your capacitance looks about right_. The 'load' seen by a crystal, is (assuming the two capacitors are the same value):
Cl = ((C^2)/2C)+Cs
Which simplifies to:
Cl= C/2 + Cs
Where Cl is the load capacitance, 'C' is the capacitor value you use, and 'Cs' is the stray capacitance on the board and PIC pins. Typical value for this is 5pF.
So, with your 33pF:
Cl = 33/2 +5 = 18.5pF
Just about spot on, assuming there is no silliness with the board tracks, giving extra stray capacitance.....
As PCM Programmer says, post the modified code with the mods made as he describe, and verify the connections he lists. Until the 'HS' fuse is used, the oscillator is _not_ enabled to run in the right mode.
Check the invoice for the capacitors, or what you ordered, or if they have any extra markings. Assuming they are 33pF, they should work fine, but if (for example), they were 33nF, there would be a problem. Also look over the board with a magnifying glass, looking for solder whiskers or blobs bridging pins.
Best Wishes |
|
|
SW
Joined: 09 Jun 2011 Posts: 10
|
|
Posted: Tue Jun 21, 2011 4:49 pm |
|
|
I've made the suggested corrections with the exception of the build configuration as it was not an option for me for some reason. I have also verified my Vdd, Vss, and LED connections. The pictures of my setup can be found here:
http://imageshack.us/g/215/bb002small.jpg/
The first five pictures are of a larger breadboard I was using when I posted my first message. The two after that are of a smaller one I used to rule out any possible problems with the larger breadboard. The active green LED just shows I have power from the PICKit 2 applied to the board. The last picture is a screenshot of the CCS setup in MPLAB, along with my PICKit 2 software showing a valid load.
The capacitors in question read "33" on them. I understand this value is in the form of pF. If that is not the case, that could be a problem.
My current code for the 16F876A is:
Code: |
#include <16F876A.h>
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=20000000)
void main()
{
output_low(PIN_B2);
output_low(PIN_B5);
while(1)
{
output_high(PIN_B1);
output_high(PIN_B2);
output_high(PIN_B3);
output_high(PIN_B4);
output_high(PIN_B5);
delay_ms(1000);
output_low(PIN_B1);
output_low(PIN_B2);
output_low(PIN_B3);
output_low(PIN_B4);
output_low(PIN_B5);
output_low(PIN_B5);
delay_ms(1000);
}
}
|
I'm still having the same old problem where I cannot detect any voltage coming from any leg with a voltmeter.
Thanks for the imageshack suggestion. I thought I was going to have to use a Hotmail space.
Thanks for the help! _________________ -SW |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Jun 21, 2011 4:59 pm |
|
|
Quote: | with the exception of the build configuration as it was not an option for me for some reason. |
Shut down MPLAB. Install the latest CCS "plug-in" for MPLAB, and re-start
MPLAB. See if the Debug/Release box now works.
http://www.ccsinfo.com/downloads/setup_mplab_plugin.exe
Quote: |
I'm still having the same old problem where I cannot detect any voltage
coming from any leg with a voltmeter. |
You appear to be using the Red stripe as ground on your breadboard,
and the blue stripe as +5v. That's the opposite of what most people
would do. You know, Red = hot = the hot wire = power. Can you
confirm that pin 20 of the PIC really has +5v on it ? That's the Vdd pin.
Check it with a meter. |
|
|
SW
Joined: 09 Jun 2011 Posts: 10
|
|
Posted: Wed Jun 22, 2011 8:18 pm |
|
|
Yeah, I forgot to mention that. I switched red and blue. I know that's backwards, but I didn't want to go digging around to find my jumper box. The blue and red are switched depending on whether I use the larger breadboard or smaller one. I can confirm that pin 20 has 4.83 volts, which is odd since I have the PICKit 2 set to 5.0. I also have the PICKit 2 connected to a powered USB hub. As an added check, the greeen LED won't function if the voltage was reversed.
I installed the CCS MPLAB plugin as described. I now have a debug/release feature, however the problem still persists. _________________ -SW |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Thu Jun 23, 2011 2:09 am |
|
|
Er.
Don't see how this can work. Might explain why it doesn't!....
On the 876, you seem to have a wire connection to pin 8, and the same signal going to pin 9, and pin 10 (three parallel red wires below the crystal, in the last layout). Assuming this is '0v', the one to pin 8 is rcorrect, but then the one to pin 10, is shorting out the crystal output, and the one to pin 9, is shorting the crystal input to ground. Internal gate will then be fighting itself, and won't work. The crystal capacitors seem to be running vertically down the contact strip, which will short them out completely....
As a comment, can I suggest you get some black wire, and use black for your 0v connections, red or white for for 5v connections (standardise on whichever you want), and then use other colours for your other connections.
Both layouts show exactly the same fault.
Best Wishes |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jun 23, 2011 12:57 pm |
|
|
Per Ttelmah's comment,
Here's a photo of a 28pin PIC in a breadboard, showing the correct
colors for power and ground, and the correct crystal and cap layout
for the oscillator circuit:
http://www.voti.nl/blink/pics/bb-870-big.jpg |
|
|
SW
Joined: 09 Jun 2011 Posts: 10
|
|
Posted: Thu Jun 23, 2011 7:49 pm |
|
|
Hey guys thanks a bunch. Ttelmah was right. It was the capacitors! I can't believe I overlooked those all three times I rewired the board. Everything is working now!
The wires you see on the boards are color-coded by their lengths. They come from the jumper kit JW-350 by Elenco.
Thanks again for all the help! _________________ -SW |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|