Well I finally decided to get familiar with PICs and got myself a PIC18F4680 and a clone of PICkit 2. I made a simple hello world circuit as shown here:

crappy circuit schematic

So basically I have an LED from port A pin 0, a crystal oscillator, one of those all in one units in a can (am I using it correctly?), two 100 nF capacitors and the MCLR pin pulled high (and connected to the programmer when I'm using it).

On the programmer, I have Vpp/MCLR, Vdd, Vss, ICSPDAT/PD, ICSPCLK/PGC and AUX pins. After some reading, I found out that the AUX should be connected to the PGM pin on the PIC. I connected all pins of the programmer connected to the respective pins on the PIC.

I've tried using the PIC with the external oscillator at 40 MHz and with internal oscillator at 1 MHz and it made no difference to the main problem. I think that the oscillators are fine because I can see a 250 kHz output on pin 14 when I'm using the 1 MHz internal oscillator and some strange reading when I'm using the 40 MHz external oscillator (which is to be expected since my multimeter can measure frequencies up to 5 MHz and I'm expecting 10 MHz output, according to the datasheet of the microcontroller).

The problem is that when I connect the programmed PIC to power, it won't do anything as far as I can see. Instead I need to connect the PICkit to it, open the Microchip's PICkit 2 application and after it verifies the chip, LED starts blinking as it's supposed to with correct frequency. When I disconnect the PICkit from the circuit or the computer, the flashing LED stops.

  • \$\begingroup\$ This sounds similar to this post recently electronics.stackexchange.com/questions/27093/… (In particular the pgm pin part?) \$\endgroup\$ – John Burton Mar 1 '12 at 13:11
  • \$\begingroup\$ @John Burton Well the main difference is that I'm not getting the intermittent operation as seen in that post. It simply doesn't work. Also, I'm pulling the MCLR pin high, so the solution seen there doesn't apply. \$\endgroup\$ – AndrejaKo Mar 1 '12 at 15:30
  • \$\begingroup\$ The point is you need to pull PGM high when not programming the chip or you can get this. I have no way to know if this is your problem of course. \$\endgroup\$ – John Burton Mar 1 '12 at 15:46
  • \$\begingroup\$ @John Burton OK. I tied PGM to Vdd and it didn't help. Also I'm (I think) using high voltage programming, so PGM pin should be available as a normal pin. Also from where are you getting the information about which pin should be connected where? I'm not sure from where you could be getting the information. For example the datasheet says that While in Low-Voltage ICSP Programming mode, the RB5 pin can no longer be used as a general purpose I/O pin and should be held low during normal operation. and RB5 is PGM here. \$\endgroup\$ – AndrejaKo Mar 1 '12 at 16:27
  • \$\begingroup\$ I've just seen several times using pics that leaving pgm floating caused this issue and setting it high ensured that the chip doesn't think it's in progamming mode. It was just a thought, something I've seen. Your problem is likely something else then if that didn't fix it. \$\endgroup\$ – John Burton Mar 1 '12 at 17:25

It sounds like you have it set up in MPLAB to use the PICkit as a debugger, not a programmer. That will allow it to work with the PICkit connected and running MPLAB, but not stand alone. Make sure the debug config bit is off and that you program the part with the PICkit as a programmer, not as a debugger.

  • \$\begingroup\$ Looks like that was the main source of the problem. \$\endgroup\$ – AndrejaKo Mar 2 '12 at 19:16

What frequency is your external oscillator? I don't know if the PIC can take 40MHz in. Normally we use a 10MHz oscillator and use the PIC's internal PLL to increase it to 40MHz. But check that your configuration settings are HS for the oscillator.

Also, check that the external oscillator is actually producing an output. Often these devices have 4 pins, where one is an enable input. You have have to connect the enable input to +5v to make it work.

  • \$\begingroup\$ The oscillator is 40 MHz and I'm using the EC option. According to the datasheet, this PIC can take up to 10 MHz of RC oscillator input and use PLL on that or 40 MHz external clock source. Also it has option to revert to internal clock if there's no external (and I've enabled that option). Also the problem wouldn't occur when I'm using internal oscillator. \$\endgroup\$ – AndrejaKo Mar 1 '12 at 15:29

You need to add a 10kOhm pull-up resistor on MCLR (Pin 1)

  • \$\begingroup\$ I've tried with 10k pull-up and it didn't help. \$\endgroup\$ – AndrejaKo Mar 1 '12 at 16:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.