![]() |
![]() |
![]() |
|
|
|||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
|
|
Thread Tools | Display Modes |
|
|
(permalink) |
|
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 |
|
|
|
|
|
|
(permalink) | |
|
Quote:
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. |
||
|
|
|
|
|
(permalink) |
|
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. |
|
|
|
|
|
|
(permalink) |
|
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; } |
|
|
|
|
|
|
(permalink) | |
|
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:
Last edited by futz; 30th November 2007 at 07:10 AM. |
||
|
|
|
|
|
(permalink) |
|
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;
}
|
|
|
|
|
|
|
(permalink) |
|
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. |
|
|
|
|
|
|
(permalink) |
|
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 |
|
|
|
|
|
|
(permalink) |
|
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. |
|
|
|
|
|
|
(permalink) |
|
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
Last edited by mikesmixes777; 30th November 2007 at 01:29 PM. |
|
|
|
|
|
|
(permalink) |
|
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) |
|
|
|
|
|
|
(permalink) | |
|
Quote:
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). |
||
|
|
|
|
|
(permalink) | |
|
Quote:
Code:
void delay(void)
{
for(i=0; i<130000; i++)
{
return;
}
}
Code:
void delay(void)
{
for(i=0; i<130000; i++){}
return;
}
or,
for(i=0; i<130000; i++);
return;
I have done some C programming on Pics. See this thread for my last attempt. Mike. |
||
|
|
|
|
|
(permalink) |
|
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;
}
|
|
|
|
|
|
|
(permalink) |
|
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 |
|
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
|
|
||||
| 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 |