PDA

View Full Version : PIC18F2550 Newbie



JeffnDana
- 24th April 2007, 15:19
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

skimask
- 24th April 2007, 15:42
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?

rhino
- 24th April 2007, 15:59
Try DEFINE capitalized.

skimask
- 24th April 2007, 16:36
Try DEFINE capitalized.

GOOD call!
I was going for the misconfigured PLL myself...but yours is much better...

JeffnDana
- 24th April 2007, 17:15
Actually, in my code DEFINE is capitalized. Sorry for that, not sure why it isn't capitalized in my post.

rhino
- 24th April 2007, 19:33
hmmm.... I'm stumped. Might want to look into what Skimask says about the PLL. Check out this LINK (http://www.picbasic.co.uk/forum/archive/index.php/t-543.html). You may have to tell us your PBP version, IDE, MPASM version, programmer, social security #, mother's maiden name, etc.

peterdeco1
- 24th April 2007, 19:35
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

JeffnDana
- 24th April 2007, 23:48
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

skimask
- 25th April 2007, 14:52
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.

JeffnDana
- 26th April 2007, 15:13
Thanks for the info skimask, that's good to know.