PIC18F13K22 Autorun when only Supply Voltage is Applied

Thread Starter

razor367

Joined Sep 12, 2016
26
On the last leg of my project, thanks to all the great help I have received here. The final stumbling block is this:

-Circuit works as designed when PICkit3 is in circuit
-Circuit will not start as designed when only supply voltage is applied (replacing PICkit3 pins 2 and 3)
-I have verified that I am building and programming device for main project (using MPLAB X IDE)
-I have tried to configure MCLR pin as an input, no change in behavior under supply only condition

C:
// PIC18F13K22 Configuration Bit Settings

// 'C' source line config statements

// CONFIG1H
#pragma config FOSC = IRCCLKOUT // Oscillator Selection bits (Internal RC oscillator, CLKOUT function on OSC2)
#pragma config PLLEN = OFF      // 4 X PLL Enable bit (PLL is under software control)
#pragma config PCLKEN = ON      // Primary Clock Enable bit (Primary clock enabled)
#pragma config FCMEN = OFF      // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor disabled)
#pragma config IESO = OFF       // Internal/External Oscillator Switchover bit (Oscillator Switchover mode disabled)

// CONFIG2L
#pragma config PWRTEN = OFF     // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = SBORDIS  // Brown-out Reset Enable bits (Brown-out Reset enabled in hardware only (SBOREN is disabled))
#pragma config BORV = 19        // Brown Out Reset Voltage bits (VBOR set to 1.9 V nominal)

// CONFIG2H
#pragma config WDTEN = OFF      // Watchdog Timer Enable bit (WDT is controlled by SWDTEN bit of the WDTCON register)
#pragma config WDTPS = 32768    // Watchdog Timer Postscale Select bits (1:32768)

// CONFIG3H
#pragma config HFOFST = ON      // HFINTOSC Fast Start-up bit (HFINTOSC starts clocking the CPU without waiting for the oscillator to stablize.)
#pragma config MCLRE = OFF       // MCLR Pin Enable bit (MCLR pin enabled, RA3 input pin disabled)

// CONFIG4L
#pragma config STVREN = ON      // Stack Full/Underflow Reset Enable bit (Stack full/underflow will cause Reset)
#pragma config LVP = ON         // Single-Supply ICSP Enable bit (Single-Supply ICSP enabled)
#pragma config BBSIZ = OFF      // Boot Block Size Select bit (512W boot block size)
#pragma config XINST = OFF      // Extended Instruction Set Enable bit (Instruction set extension and Indexed Addressing mode disabled (Legacy mode))
//#pragma config BKBUG = OFF    // Background Debugger Enable Bit

// CONFIG5L
#pragma config CP0 = OFF        // Code Protection bit (Block 0 not code-protected)
#pragma config CP1 = OFF        // Code Protection bit (Block 1 not code-protected)

// CONFIG5H
#pragma config CPB = OFF        // Boot Block Code Protection bit (Boot block not code-protected)
#pragma config CPD = OFF        // Data EEPROM Code Protection bit (Data EEPROM not code-protected)

// CONFIG6L
#pragma config WRT0 = OFF       // Write Protection bit (Block 0 not write-protected)
#pragma config WRT1 = OFF       // Write Protection bit (Block 1 not write-protected)

// CONFIG6H
#pragma config WRTC = OFF       // Configuration Register Write Protection bit (Configuration registers not write-protected)
#pragma config WRTB = OFF       // Boot Block Write Protection bit (Boot block not write-protected)
#pragma config WRTD = OFF       // Data EEPROM Write Protection bit (Data EEPROM not write-protected)

// CONFIG7L
#pragma config EBTR0 = OFF      // Table Read Protection bit (Block 0 not protected from table reads executed in other blocks)
#pragma config EBTR1 = OFF      // Table Read Protection bit (Block 1 not protected from table reads executed in other blocks)

// CONFIG7H
#pragma config EBTRB = OFF      // Boot Block Table Read Protection bit (Boot block not protected from table reads executed in other blocks)

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
upload_2016-10-19_11-21-1.png

Moderators note: please use code tags for pieces of code
 

Thread Starter

razor367

Joined Sep 12, 2016
26
upload_2016-10-19_13-29-15.png
I have Pin 7 (PGM) tied to a pull down resistor as shown above.

According to the Microchip MPLAB X wiki, "The build process in MPLAB® X is a little different from other development environments. If you are working with a target board and wish to build and run your code on it, you do not need to do a Build or Clean and Build first. Instead, you simply need to do a Run Project.

The Run Project button performs the following tasks:

  1. Build (make) the project in release mode.
  2. If there are no build errors, your application is programmed into the target device using the debug/programming tool selected in the project options.
  3. The target device is released from reset and your code begins running unless you have selected Hold In Reset from the toolbar.
You DO NOT normally need to explicitly do a Build
or Clean and Build
first. The Run Project and Program Target Project functions do a build (make) automatically."
 

jayanthd

Joined Jul 4, 2015
945
PIC has to be reset after burning the .hex file.

Change this

C:
#pragma config LVP = ON         // Single-Supply ICSP Enable bit (Single-Supply ICSP enabled)
to

C:
#pragma config LVP = OFF
 
Last edited:

Picbuster

Joined Dec 2, 2013
1,047
Same problem I encountered a long time ago.
make pin mclr active with pull-up 1K and cap to gnd.
check your pwr supply ripple and impedance. ( put 10uf parallel to 0,1 uf pin 1 & 20).
make in your program a test one sec int with led =! led;
Picbuster
 

Thread Starter

razor367

Joined Sep 12, 2016
26
I have turned off LVP, enabled MCLR, changed the resistor between pins 1 & 4 to a 1K resistor, added a 0.1uf capacitor between pin 4 and ground. I tested the circuit after each change. The circuit works with the debugger every time, without the PICkit3, no startup. By default the program is supposed to fire all LEDs when started, but this never happens when connected to the regulated power supply.

Updated code:
#pragma config MCLRE = ON
#pragma config LVP = OFF

Updated schematic:
upload_2016-10-20_12-12-19.png
 

Thread Starter

razor367

Joined Sep 12, 2016
26
I did, yes. I believe the settings are correct, as I was able to match the LED blink cycle time with a stopwatch very accurately.

C:
void ConfigureOscillator(void)
{
    OSCCONbits.HFIOFS   =0b1; //HFINTOSC Frequency Stable Bit unsure pg18
    OSCCONbits.OSTS     =0b0; //Oscillator Start up and time out pg18
    OSCCONbits.IRCF     =0b111; //Internal Oscillator Frequency Select pg18
    OSCCONbits.SCS      =0b00; //clock set to primary clock pg18
    OSCTUNEbits.PLLEN   =0b1;
}
 

RichardO

Joined May 4, 2013
2,270
This may not be your problem but...

Your schematic shows pins 18 and 19 as unconnected when the programmer is unplugged. This could cause unexpected operation.

How have you set the RA0 and RA1 pins? You need to disable the analog inputs by setting the pins to digital. If you leave the pins set as inputs then you must enable pullups on those pins.
 

Thread Starter

razor367

Joined Sep 12, 2016
26
Circuit still works great with PICkit3, no dice with power supply. The power supply is rated to 5A output, the circuit should draw at most 500mA.

Updated code:

C:
TRISAbits.TRISA0 = 0; // set pin as digital output
TRISAbits.TRISA1 = 0; // set pin as digital output
 

NorthGuy

Joined Jun 28, 2014
611
So, you do "Clean and Build" and you see your PIC running. Then you disconnect PICkit3, connect your power supply instead, and PIC is not running even though you measure 5V at VDD and MCLR and 0V at PGM. Is this correct?
 

Thread Starter

razor367

Joined Sep 12, 2016
26
So I tried some hardware debugging. I audited all connections and I had to replace an intermittent fault in one of the jumpers...

So after after fixing that, at +4.75VDC constant voltage mode, the circuit run and fires each LED as is programmed (thankfully), going from 40mA idle to 50mA. When all LEDs are on, I notice a high frequency flicker visually across all LEDs, and the power supply switches to constant current mode, going from 40mA idle to 80mA while dropping the voltage to +4.0VDC.

Not sure why this is dropping the supply voltage, as the supply is rated to 5A. More than likely an EE concept I am not grasping...
 

NorthGuy

Joined Jun 28, 2014
611
I think what you see is this - PIC starts running. You get some short/overload. Voltage drops. PIC resets. While PIC is in reset, voltage recovers, PIC starts again etc.

Since PIC spends most of the time in reset, you don't see high current and voltage drop you measure is minimal.
 

bug13

Joined Feb 13, 2012
2,002
Driving 4 LEDs in series of 150R resistor doesn't look right. That's why I want you to try driving 1 instead of all 4 Leds.

Your PIC can only source 70mA max. 4 LEDs is pretty close to that with 150R resistor. (Or even exceed that)

Or try 470R resistors, and make sure the wire to your power supply is thick enough.
 

Thread Starter

razor367

Joined Sep 12, 2016
26
Driving one LED works with no flicker on power supply. All four together and the flicker returns. However, this behavior is only with the power supply. When running on PICkit power, there is no flicker, which leads me to believe that the PIC can supply the power required, but there is something akin to the reset drop out mentioned by Northguy. The only difference I can think of is some grounding or voltage drop occurring in absence of the PGD PGC pins when using the power supply.
 

bug13

Joined Feb 13, 2012
2,002
Driving one LED works with no flicker on power supply. All four together and the flicker returns. However, this behavior is only with the power supply. When running on PICkit power, there is no flicker, which leads me to believe that the PIC can supply the power required, but there is something akin to the reset drop out mentioned by Northguy. The only difference I can think of is some grounding or voltage drop occurring in absence of the PGD PGC pins when using the power supply.
That indicate there is something wrong in your power supply side, wire too long? too thin? your power supply is not supplying what you need? Maybe your power supply is limiting your current? (you mention your power supply was on constant mode, that mean your circuit was drawing more than your power supply can supply). The power supply is not well regulated? Loose wire connection?

Regardless, you mention something the circuit is drawing 80mA, that is exceeding the 70mA max states in the datasheet. Maybe increase the resistors value, or drive the leds through some transistors. Even you can make it work now, it will fail faster than you would like.

Hope this help.
 
Top