Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Intermittent PIC problem

Status
Not open for further replies.

mikesmixes777

New Member
Hi,
I seem to have a grounding or noise problem with my PIC pcb. When I program the PIC to flash an LED, it seems to only flash when I touch the pcb or a pin on the pic like the crystal or a cap on the 3V3 circuit.

Overview of my board:
12-24Vdc in.... 3V3 LDO.....

I currently use a wall socket adapter, and I have tried on a different location, thought maybe my mains was interfering.

ANy ideas? Does the pic need a pull-up resistor somewhere to stop noise.
I can draw up a quick circuit diagram if need be.

Thanks
 
mikesmixes777 said:
Any ideas? Does the pic need a pull-up resistor somewhere to stop noise.
I can draw up a quick circuit diagram if need be.
First, if your MCLR pin is enabled, does it have a pull up? It needs one. I've got 33K resistors on several boards here. I'm sure a range of values would work fine though.

Second, the rest of the pins are likely floating (not connected). All kinds of strange, random things can happen when they're in this state and configured as inputs. Either pull up or down all of em (pain in the butt), or just set your TRIS registers so all unused pins are outputs.
 
Last edited:
Hi,

I am using the PIC18LF252. Do I need to to make all the ports output - I think this mite be the problem.

I am using the ISP so I have a 10K pull-up. I have attached the small code I started with.


#include <p18cxxx.h>
#include <delays.h>

#define INPUT 1
#define OUTPUT 0


void delay(void);
long int i;

void main(void)
{
/* Setup 18LF252 */
TRISC = 0xFD; /* set as output */

while(1)
{

PORTC = 0;
delay();

PORTC = 0x2;
delay();
}

}

void delay(void)
{

for(i=0; i<130000; i++)

return;
}
 
Please put code inside CODE tags. If you don't the formatting disappears and it's VERY difficult to read (not too bad on a short program like that, but when they get longer it's a mess)

When you're about to paste your code, just click on the # in the menu above the text entry window first. Then paste.

I am using the PIC18LF252. Do I need to to make all the ports output - I think this might be the problem.
Try it. Takes only a few seconds to modify the code and recompile.
 
Last edited:
Sorry just a noob at this posting code thing......

Hope this does it...

Code:
#include <p18cxxx.h>
#include <delays.h>

#define INPUT 1
#define OUTPUT 0


void delay(void);
long int i;

void main(void)
{
   /* Setup 18LF252 */
      TRISC = 0xFD;      /* set as output */

while(1)
{
	
      PORTC = 0;
	  delay();

	  PORTC = 0x2;
	  delay();
}
	  
}

void delay(void)
{
        
        for(i=0; i<130000; i++)
        
       return;
}
 
Though I've done plenty of C programming in the past on PC's, I've never programmed a PIC with it. I only use assembly on PICs. That said, it looks fine to me. Someone who does C on PICs may spot something that I don't see.

Try setting all ports to all outs - all zeros. Any pin you're not using, anyway.

If you're someplace with cold weather and your house is dry and staticy, don't wear those staticy clothes (fleece, sweaters, etc.) when doing electronics. That can cause weirdness for sure. Cotton (jeans/tee shirt) works well to limit static a bit. A grounded wrist strap is a good idea, but they're a royal pain in the butt with the snagging on everything.
 
Thanks Futz,

I shall try and get back to you. I also used to use assembly but trying C programming now. Just getting started.....my end goal is to develope an embedded webserver..... well we all got to start somewhere. Will keep it updated.
Thanks
 
Don't you need a semi colon or braces on the for line? Or did you intend it to execute the return 130,000 times.:D :D

Mike.
 
Last edited:
ya sorry, just had a look at my mplab code and the return is in the right place....not sure why its hanging around there lol..... my bad :).... Mike do you do alot of C programming with PIC's?
 
Last edited:
Well, you've got a hardware problem if it's responding to a finger touch.
- Check you don't have any floating inputs (or set them to outputs)
- Disable BOR (brown out reset), this will make you more noise tolerant
- Add your own pullup to mclr/reset (one less thing to go wrong)
- Check your voltage levels and noise on your power line.
- Implicity disable interupts as your first line of code (GIE=0)
 
mikesmixes777 said:
Overview of my board:
12-24Vdc in.... 3V3 LDO.....
LDO regulators require careful selection of the output capacitor. Is this requirement met in your circuit? Have you tried powering it from batteries?

Have you connected all power pins of the uC to Vdd/GND?

Show your configuration settings (oscillator type, etc... as suggested, BOR should be disabled; MCLR must be pulled up to Vdd with an external resistor if MCLR is enabled).
 
mikesmixes777 said:
ya sorry, just had a look at my mplab code and the return is in the right place....not sure why its hanging around there lol..... my bad :).... Mike do you do alot of C programming with PIC's?

Your code is the equivalent of,
Code:
void delay(void)
{
	for(i=0; i<130000; i++)
	{
		return;
	}
}

I'm sure your intention was,
Code:
void delay(void)
{
	for(i=0; i<130000; i++){}
	return;
}

or,

	for(i=0; i<130000; i++);
	return;

I don't think this is your problem as it sounds like hardware, but it may mask the solution.

I have done some C programming on Pics. See this thread for my last attempt.

Mike.
 
I set all the pins as outputs, however still no luck. The LED still only seems to flash once you touch the pcb or hold it.

The LDO i'm using is the LD1086-33. I have a 10uF and a 100nF on the input and output as per datasheet.

Config Bits are: (These are set using the COnfig Bits in MPLAB IDE)

Osc = HS
Osc switch Enabled = Disabled
PowerUp Timer = Disabled
Brown Out Detect = Disabled
Watchdog Timer = Disabled
Stack Overflow Reset = Enabled
Low VOltage Program = Enabled

The modified code is:

Code:
#include <p18cxxx.h>
#include <delays.h>

void delay(void);
long int i;

void main(void)
{
   /* Setup 18LF252 */
          TRISA = 0x0;      /* set as output  */
	  TRISB = 0x0;
	  TRISC = 0x0;
	  

while(1)
       {
	
          PORTC = 0;
	  delay();

	  PORTC = 0x2;
	  delay();

        }
}

void delay(void)
{
        
        for(i=0; i<130000; i++);
        return;
		
}

Oh yes... I am new to C programming so I understand that there might be shorter code for what i'm trying to achieve. I shall get there one day.
 
Your timing variable "i" has nothing to do outside the delay() routine and does not need to be declared as a global variable.

I would place the "long int i;" declaration inside the delay() routine.

If you enable Low Voltage Programming on the PIC, be sure to use a resistor to pull the PGM pin low.
 
eblc1388 said:
If you enable Low Voltage Programming on the PIC, be sure to use a resistor to pull the PGM pin low.

Well spotted, that would explain his problem.
I am sure he doesn't need LVP on and would advise turning it off in the config.

Mike.
 
Perfect!!!!
I disabled the LVP and all is good. Thanks for all the advice and help.

Now with this fixed I can move forward and advance my program to do ADC and RS232 comms.

I'll try not be, but I'm sure i'll be back....

Thanks Again.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top