0
\$\begingroup\$

I am a newbie with PIC doing my first project to understand how PICs work. I have some experience with Arduino and trying to learn PIC now.

I have chosen PIC16F887 (40 pin DIP package) as my first PIC chip. I am using MPLAB v5.30. I am only trying to blink an LED attached to pin 20 (RD1) in my first project. But what I am experiencing is that the PIC BOTH Runs and Debugs well when its connected to PICKIT3, but when I am supplying the power through an external source, nothing happens at all.

While connected to PICKIT3, in order to run the project in "release mode", I am using the option "Program device for Production Main Project" from MPLAB. To debug, I am only running - "Debug Main Project" from the debug menu. Both these options end up with PIC running on the breadboard. I understand that with the external power source, the MCU is not supposed to work with a debug build. Hence before powering from external source, I am using the "Program device for Production Main Project" MPLAB option to program the chip. I also tried option - "Run Main Project", but this option does not work, neither with PICKIT3 connected nor with the external power. That seems strange.

For external supply I am using the L7805CV 5v voltage regulator. I am also pulling up the pin1-MCLR using the resistor "R1" when using external source. Have tried various values of R1 from 4800 ohms to 68000 ohms with no luck. I am attaching the hand drawn circuits here which I am using both with PICKIT3 and external power. My code which I am trying to run is also mentioned below. I have tried setting MCLRE as OFF, ON and default (not mentioning in code at all) with no luck. The crystal frequencies tried as 8, 20 and 32 mhz.

Can someone please see whats missing in the circuit or the code? Also notice that, this MCU has two VDD and VSS pins. Seems unlikely to me, but do I need to supply voltage to both of them in order for the chip to work? I have only one chip currently, do not want to fry it, hence have not tried this option.

// PIC16F887 Configuration Bit Settings

// 'C' source line config statements

// CONFIG1
#pragma config FOSC = INTRC_NOCLKOUT// Oscillator Selection bits (INTOSCIO oscillator: I/O function on RA6/OSC2/CLKOUT pin, I/O function on RA7/OSC1/CLKIN)
#pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled and can be enabled by SWDTEN bit of the WDTCON register)
#pragma config PWRTE = OFF      // Power-up Timer Enable bit (PWRT disabled)
#pragma config MCLRE = ON      // RE3/MCLR pin function select bit (RE3/MCLR pin function is digital input, MCLR internally tied to VDD)
#pragma config CP = OFF         // Code Protection bit (Program memory code protection is disabled)
#pragma config CPD = OFF        // Data Code Protection bit (Data memory code protection is disabled)
#pragma config BOREN = OFF      // Brown Out Reset Selection bits (BOR disabled)
#pragma config IESO = OFF       // Internal External Switchover bit (Internal/External Switchover mode is disabled)
#pragma config FCMEN = ON       // Fail-Safe Clock Monitor Enabled bit (Fail-Safe Clock Monitor is enabled)
#pragma config LVP = ON         // Low Voltage Programming Enable bit (RB3/PGM pin has PGM function, low voltage programming enabled)

// CONFIG2
#pragma config BOR4V = BOR40V   // Brown-out Reset Selection bit (Brown-out Reset set to 4.0V)
#pragma config WRT = OFF        // Flash Program Memory Self Write Enable bits (Write protection off)

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.

#include <xc.h>
#include <stdio.h>
#include <stdlib.h>

# define _XTAL_FREQ 20000000

void main()
{
    TRISD1=0;

    while(1)
    {
        RD1 = 1;
       __delay_ms(1000);
       RD1 = 0;
        __delay_ms(1000);
    }
}

PIC BOTH WORKING AND DEBUGGING WELL WITH PICKIT3

PIC NOT WORKING WITH EXTERNAL POWER

\$\endgroup\$
  • 2
    \$\begingroup\$ Is your regulator all properly configured? draw a full schematic, not half of one. You need capacitors on the input and output of a 7805 for stability. \$\endgroup\$ – Hearth Nov 10 at 1:15
  • \$\begingroup\$ hi @Hearth, Thanks for looking at it. Sorry for missing the capacitors. Yes, I have one of 10 micro farad capacitor on both input and output. \$\endgroup\$ – Anurag Nov 10 at 1:43
  • \$\begingroup\$ @Hearth, when using multimeter, i also see constant 4.95v coming out of the regulator. \$\endgroup\$ – Anurag Nov 10 at 1:44
0
\$\begingroup\$

The power source has nothing to do with debug vs. release. You can set the debug tool to supply power or not. The debug release requires the debugger attached to the data and clock lines in order to run. Release should not.

You should connect all the Vdd and Vss pins for reliable operation. You should have a resistor in series with the LED. In addition to input and output caps on the LM7805 regulator (not generally required for stability but recommended), make sure you have an appropriate ceramic bypass capacitor (eg. 100nF) near the power pins of the MCU.

Finally, and most likely your proximate problem, if memory serves, turn off LVP (or add a 1K from PGM to ground).

\$\endgroup\$
  • \$\begingroup\$ Hi @SpehroPefhany Thanks for taking a look at my issue. Sure, as you suggested, let me try 1). Connect all VDD and VSS to power source 2). Adding ceramic capacitors near the power pins on the power pins of the MCU 3). Adding a resistor to the LED. I will report back how this goes. \$\endgroup\$ – Anurag Nov 10 at 3:42
  • \$\begingroup\$ Also, @SpehroPefhany, can you please answer the following questions? 1). How to turn OFF LVP? I think thats the 6th pin of the PICKIT3 and is unused. Can that be toggled in the code as well? 2). With the PGM pin, do you mean, pin 36 of this MCU - ww1.microchip.com/downloads/en/DeviceDoc/40001291H.pdf ? How is this pin related to LVP? \$\endgroup\$ – Anurag Nov 10 at 3:47
  • \$\begingroup\$ The most important item in my post is the last one. Turn off LVP by changing the #pragma \$\endgroup\$ – Spehro Pefhany Nov 10 at 3:49
  • 1
    \$\begingroup\$ Thanks, I am going to try all these recommendations tonight and let you know how it goes ! \$\endgroup\$ – Anurag Nov 10 at 4:01
  • \$\begingroup\$ hi @SpehroPefhany - Thanks a lot for your genius advice! Turning OFF LVP did the trick. Now the chip runs using external voltage supply both when I use "Program device for Production Main Project" and "Run Main Project" options to program the device. I am choosing your answer as the accepted one. Thanks again! \$\endgroup\$ – Anurag Nov 10 at 10:24

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.