(Solved) Works when powered by PicKit, doesn't work when powered by external 5V - Page 1
Forum section: electronics / beginners

author: plastygrove
author_rank: Contributor
timestamp: October 18, 2014, 05:31:53 am
content: Hi All,This is my first forum post! I've run into an embarrassingly strange problem.I have a pic18F4550 which has an LED connected to Pin21 (RD2) in series with a 1K resistor going to ground.I'm using a cheap PicKit 2 programmer which I purchased locally to program the device. The PicKit also allows for an output of 5V to power the microcontroller so I can test it. Been running a few blinky programs and also trying out some switch inputs interrupts and timer interrupts the last week.The problem is that it works when I power it with the PicKit but not when I try to power it with an external 5V source. For the external 5V source, I'm using the +5V pin and the GND pin of an Arduino that I have lying around. I've tried connecting the Arduino to an external 5V phone charger and also a USB port on my laptop. When I do this, the LED just stays on and doesn't do anything.Here's the code I'm using and I've also attached the pic of the circuit I'm using. This is totally bizarre and didn't happen when I tried the same thing with an Atmega 1284pCode:#include <xc.h>#define _XTAL_FREQ 1000000L#pragma config PLLDIV = 5#pragma config CPUDIV = OSC2_PLL3#pragma config FOSC = INTOSC_HS#pragma config WDT = OFF#pragma config LVP = OFF#pragma config BOR = OFF#pragma config MCLRE = ON#pragma config PWRT = ON#pragma config PBADEN = OFF#define LEDPORT TRISDbits.RD2#define LED LATDbits.LATD2#define HIGH 1#define LOW 0#define OUTPUT 0#define INPUT 1//Blinks on Pin 21void main(void){LEDPORT = OUTPUT;while(1) {LED = HIGH;__delay_ms(500);LED = LOW;__delay_ms(500);}}

author: Skimask
author_rank: Super Contributor
timestamp: October 18, 2014, 06:01:48 am
content: Where's the pull up on MCLR?RTFDS

author: Asim
author_rank: Regular Contributor
timestamp: October 18, 2014, 06:03:07 am
content: you need to connect a crystal oscillator and also keep MCLR ( the reset pin) highcheck this outhttp://www.mikroe.com/img/publication/pic-books/pic-microcontrollers/chapter/appb/appb_fig26.gif

author: DavidDLC
author_rank: Frequent Contributor
timestamp: October 18, 2014, 06:04:28 am
content: Yes, I was just writting about MCLR with pull ups, you guys beat me.David.

author: Skimask
author_rank: Super Contributor
timestamp: October 18, 2014, 06:06:21 am
content: Quote from: Asim on October 18, 2014, 06:03:07 amRTFPInternal OSCillator.

author: plastygrove
author_rank: Contributor
timestamp: October 18, 2014, 06:15:27 am
content: Wow, thanks everyone, I couldn't for the life of me understand why this wasn't working. I guess when I was using the PicKit it was pulling MCLR high.I just added a 10K resistor to pull it up and it works perfectly!And yes, I am using the internal oscillator. I was using an external one, but was trying to debug this issue and pulled everything apart and changed it to the internal oscillator.Thanks again Skimask, Asim and David!

author: Asim
author_rank: Regular Contributor
timestamp: October 18, 2014, 07:57:06 am
content: Quote from: Skimask on October 18, 2014, 06:06:21 amI assumed he was using an external one xD