3
\$\begingroup\$

I have a PIC18F2550 that I'm trying to get a simple hello world type program to run on. The code is configured to flash an LED on and off with 250ms delays in between the cycles. I have a 4Mhz crystal attached to pins 9 and 10 with 2 18pF capacitors. When I attach my oscilloscope to the output pin and power on the chip, I can see the high low signals go from 0V-5V for about 3-5 seconds then it just flat lines.

enter image description here

If I power the chip off for a while and plug it back in, it starts to work again, but after 3-5 seconds it will go to 0 again.

What can I do to troubleshoot this problem?

Update

I should also add that after repeating the whole process several times (i.e. powering on and off the device), it eventually won't turn on the output at all.

I've tried multiple PIC18F2550 chips with the same software and get the same effect, so it's not the PIC processor.

I'm thinking this must be a hardware issue since the software was copied from a working sample. In case someone thinks it is a software issues, here's the MikroC code (although I don't think this is the right Stack Exchange site for source code):

void main() {
    TRISB = 0; //Make all PortB pins output

    while(1)
    {
        PORTB = 0; //Turn off the port
        Delay_ms(250);
        PORTB = 255; //Turn on the port
        Delay_ms(250);
    }
}

Here a (very) rough schematic of the circuit. I have the scope hooked to pin 24.

enter image description here

Here are the parts that I'm using

Crystal
Crystal Capacitors

\$\endgroup\$
  • 1
    \$\begingroup\$ You need bypass capacitors across the power supply connections. As a 0.1 uF capacitor between pins 19 and 20, as close as you can get it to the IC. \$\endgroup\$ – Connor Wolf Jul 20 '13 at 3:05
1
\$\begingroup\$

In my experience accidentally leaving the _MCLR pin floating causes erratic behaviour such as yours. Make sure it is tied to +5V through a resistor (47kΩ or so), in order to prevent the PIC from randomly resetting.

\$\endgroup\$
  • \$\begingroup\$ @Matt The data sheet specifies that the _MCLR pin is connected to some voltage (+5V here) (they are programmable after all) and not to let it get above the system voltage . If it does it enters programming mode. So for all micro's (and a lot of IC's in general) attach all the supply and ground pins plus anything left floating should have a good reason to be floating other wise pull them down or up with a resistor (I prefer resistors because you can override them during debugging without breaking tracks). \$\endgroup\$ – Spoon Jul 21 '13 at 0:05
  • \$\begingroup\$ Yeah, I've read that before, but up until now I've gotten away without doing it (I guess my luck ran out). I'll be sure not to leave pins floating in the future. Thanks for the tip. \$\endgroup\$ – Matt Ruwe Jul 22 '13 at 12:05
1
\$\begingroup\$

Usually setting breakpoints is the best way to go at it, but this seems like an initialization/setup problem.

Try disabling the watchdog

   WDTCON  = 0;

Did you setup your oscillator? How about clear most registers? (TRISx, INTCON, TxCON, UCON, etc..)

\$\endgroup\$
  • \$\begingroup\$ I have configured the oscillators and setup the proper TRIS register - the examples that I've seen look like all I need to do is configure the TRISB register. \$\endgroup\$ – Matt Ruwe Jul 19 '13 at 21:57
  • \$\begingroup\$ Are you using a forever while loop? while(1){ [code] }; \$\endgroup\$ – Iancovici Jul 19 '13 at 22:00
  • \$\begingroup\$ Yes, I'll add the code to my post, although, I don't think this is a software problem. \$\endgroup\$ – Matt Ruwe Jul 19 '13 at 22:02
  • \$\begingroup\$ FYI, I tried disabling the watchdog, but it didn't help. Any other ideas? \$\endgroup\$ – Matt Ruwe Jul 19 '13 at 22:15
  • 1
    \$\begingroup\$ Can you give us ALL the config info, a circuit diagram, and some datails on how you're powered and bypassed? You'll get a better answer, and faster. A part number for your crystal might also help to see if 18 puffs is the right number \$\endgroup\$ – Scott Seidman Jul 19 '13 at 23:38

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.