PIC18F2550 Newbie


Closed Thread
Results 1 to 10 of 10
  1. #1
    Join Date
    Apr 2007
    Posts
    7

    Default PIC18F2550 Newbie

    I'm quite new to microcontrollers, but have completed a successful project on a PIC16F628A. I need to eventually have USB capability and want to learn the PIC18F2550. To start simply, I wired a circuit with an LED and used a 20Mhz crystal with the following code:

    DEFINE OSC 20

    loop:
    High PORTA.0 ' Turn on LED connected to PORTA.0
    Pause 500 ' Delay for .5 seconds

    Low PORTA.0 ' Turn off LED connected to PORTA.0
    Pause 500 ' Delay for .5 seconds

    Goto loop ' Go back to loop and blink LED forever
    End

    This works but the LED blinks twice as fast as it should. I haven't yet run across anything in the Datasheet that would account for this. I'm sure I'm missing something simple. Any input is appreciated.

    Thanks,
    Jeff
    Last edited by JeffnDana; - 24th April 2007 at 17:15.

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by JeffnDana View Post
    I'm quite new to microcontrollers, but have completed a successful project on a PIC16F628A. I need to eventually have USB capability and want to learn the PIC18F2550. To start simply, I wired a circuit with an LED and used a 20Mhz crystal with the following code:
    define OSC 20
    loop:
    High PORTA.0 ' Turn on LED connected to PORTA.0
    Pause 500 ' Delay for .5 seconds
    Low PORTA.0 ' Turn off LED connected to PORTA.0
    Pause 500 ' Delay for .5 seconds
    Goto loop ' Go back to loop and blink LED forever
    End
    This works but the LED blinks twice as fast as it should. I haven't yet run across anything in the Datasheet that would account for this. I'm sure I'm missing something simple. Any input is appreciated.
    Thanks,
    Jeff
    Is it running 2x as fast as it should be or 2.4x as fast as it should be?

  3. #3
    Join Date
    Mar 2005
    Location
    Iowa, USA
    Posts
    216


    Did you find this post helpful? Yes | No

    Default

    Try DEFINE capitalized.
    Wisdom is knowing what path to take next... Integrity is taking it.
    Ryan Miller

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by rhino View Post
    Try DEFINE capitalized.
    GOOD call!
    I was going for the misconfigured PLL myself...but yours is much better...

  5. #5
    Join Date
    Apr 2007
    Posts
    7


    Did you find this post helpful? Yes | No

    Default

    Actually, in my code DEFINE is capitalized. Sorry for that, not sure why it isn't capitalized in my post.

  6. #6
    Join Date
    Mar 2005
    Location
    Iowa, USA
    Posts
    216


    Did you find this post helpful? Yes | No

    Default

    hmmm.... I'm stumped. Might want to look into what Skimask says about the PLL. Check out this LINK. You may have to tell us your PBP version, IDE, MPASM version, programmer, social security #, mother's maiden name, etc.
    Wisdom is knowing what path to take next... Integrity is taking it.
    Ryan Miller

  7. #7


    Did you find this post helpful? Yes | No

    Default

    Hello. I had similar timing issues with a 18F2510. In my case, the timing was slower than it should be with a 4MHZ resonator. Within MPLAB I changed the watchdog postscaler from 1:128 (DEFAULT) TO 1:8. This seemed to correct the problem. I noticed the 2550 defaults to 1: 32768. Maybe you can try this route
    Last edited by peterdeco1; - 24th April 2007 at 19:36. Reason: spelling

  8. #8
    Join Date
    Apr 2007
    Posts
    7


    Did you find this post helpful? Yes | No

    Thumbs up

    I got it working thanks to all of you. I'm using MicroCode studio and changed the configuration settings from the Compile and Program dialog. While changing the watchdog postscaler setting I noticed that the Oscillator mode was set to HSPLL. When I set this to HS the timing was correct. According to the datasheet there is a postscaler adjustment for the PLL setting (1/2, 1/3, etc) so I assume I would change that if the mode were HSPLL. If I understand it correctly, I would want to use HSPLL when using the USB functionality.

    Thanks again,
    Jeff

  9. #9
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by JeffnDana View Post
    If I understand it correctly, I would want to use HSPLL when using the USB functionality.
    Thanks again,
    Jeff
    The HSPLL can be used anytime, whether using USB or not. Use the HSPLL, and you can get 48Mhz internal at the PIC, while only having to design for a 12Mhz crystal/oscillator. Makes circuit design just that much easier than trying to get a 48Mhz crystal to work on a sloppy design.

  10. #10
    Join Date
    Apr 2007
    Posts
    7


    Did you find this post helpful? Yes | No

    Default

    Thanks for the info skimask, that's good to know.

Similar Threads

  1. Newbie: Temperature measurements
    By Budda in forum General
    Replies: 10
    Last Post: - 30th March 2007, 09:56
  2. PIC Newbie
    By azmax100 in forum Schematics
    Replies: 7
    Last Post: - 23rd February 2007, 04:52
  3. PIC18F2550 and GSM modem
    By zach in forum GSM
    Replies: 7
    Last Post: - 28th November 2006, 09:01
  4. request for a newbie forum
    By nimonia in forum Forum Requests
    Replies: 1
    Last Post: - 20th May 2006, 09:01
  5. PIC18F2550 ICSP - newbie
    By icicle in forum Off Topic
    Replies: 8
    Last Post: - 9th August 2005, 22:41

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts