Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 30th November 2007, 06:39 AM   (permalink)
Default Intermittent PIC problem

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 is offline  
Reply With Quote
Old 30th November 2007, 06:44 AM   (permalink)
Default

Quote:
Originally Posted by mikesmixes777
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 by futz; 30th November 2007 at 06:47 AM.
futz is online now  
Reply With Quote
Old 30th November 2007, 06:46 AM   (permalink)
Default

What PIC are you using did you use MCLR off? If it is off the pullup for MCLR pin will set internally.

If you make MCLR on you need to put a pull up resister to the MCLR pin.
__________________
Gayan

My Website
http://gsmicro.blogspot.com/
Gayan Soyza is offline  
Reply With Quote
Old 30th November 2007, 07:03 AM   (permalink)
Default

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;
}
mikesmixes777 is offline  
Reply With Quote
Old 30th November 2007, 07:07 AM   (permalink)
Default

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.

Quote:
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 by futz; 30th November 2007 at 07:10 AM.
futz is online now  
Reply With Quote
Old 30th November 2007, 07:29 AM   (permalink)
Default

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;
}
mikesmixes777 is offline  
Reply With Quote
Old 30th November 2007, 07:37 AM   (permalink)
Default

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.
futz is online now  
Reply With Quote
Old 30th November 2007, 07:43 AM   (permalink)
Default

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
mikesmixes777 is offline  
Reply With Quote
Old 30th November 2007, 08:00 AM   (permalink)
Default

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.

Mike.

Last edited by Pommie; 30th November 2007 at 09:22 AM.
Pommie is offline  
Reply With Quote
Old 30th November 2007, 01:18 PM   (permalink)
Default

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 by mikesmixes777; 30th November 2007 at 01:29 PM.
mikesmixes777 is offline  
Reply With Quote
Old 30th November 2007, 02:35 PM   (permalink)
Default

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)
matc is offline  
Reply With Quote
Old 30th November 2007, 03:52 PM   (permalink)
Default

Quote:
Originally Posted by mikesmixes777
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).
eng1 is offline  
Reply With Quote
Old 1st December 2007, 02:26 AM   (permalink)
Post

Quote:
Originally Posted by mikesmixes777
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.
Pommie is offline  
Reply With Quote
Old 3rd December 2007, 07:16 AM   (permalink)
Default

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.
mikesmixes777 is offline  
Reply With Quote
Old 3rd December 2007, 08:45 AM   (permalink)
Default

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.
__________________
L.Chung
eblc1388 is offline  
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Latest
PIC16F877A charging problem eleceyes Micro Controllers 6 22nd November 2007 07:06 AM
Problems switchin relay with PIC Andy1845c General Electronics Chat 5 17th November 2007 06:13 PM
PIC pin to MOSFET gate problem Futterama Electronic Projects Design/Ideas/Reviews 7 8th November 2007 05:30 PM
I think I gave PIC 12V instead of 5V kavelot General Electronics Chat 3 5th November 2007 05:04 PM
strange color camera problem schrodingerscat Electronic Projects Design/Ideas/Reviews 5 4th October 2003 07:25 PM



All times are GMT. The time now is 11:03 PM.


Electronic Circuits  |  Electronics Wiki
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.