PDA

View Full Version : 18F2550 timing



sstt1976
- 20th August 2008, 18:13
I'm using an 18F2550 with a 20MHz oscillator and a DEFINE OSC 20 statement in my PBP program. I burn the chip with an HS setting and a /3(/2) scaler. Turns out this makes my circuit work exactly the way I'd like.

Now I want to burn the chip with an HSPLL setting and maintain the exact same internal timing for all my PBP instructions. I know that HSPLL automatically makes the 18F2550 run internally at 96MHz so I tried a /4(/3) scaler and a DEFINE OSC 48 statement but I can tell it's running slightly different than before.

How do I maintain the original internal timing? I need AD readings, pauseus, pause and all instructions to take the exact same time when I burn using HSPLL.

Thanks!

skimask
- 20th August 2008, 18:25
Now I want to burn the chip with an HSPLL setting and maintain the exact same internal timing for all my PBP instructions. I know that HSPLL automatically makes the 18F2550 run internally at 96MHz so I tried a /4(/3) scaler and a DEFINE OSC 48 statement but I can tell it's running slightly different than before.
HSPLL doesn't make it run at 96Mhz internally.
All HSPLL does is take the external (or internal) clock input and multiply it by 4. If you try to run the PIC at 96Mhz internally (i.e. using an external 24Mhz clock with HSPLL turned on), it won't run. The PIC is only spec'd to run at 48Mhz maximum. The HSPLL (assuming you're running an external clock) allows you to use a 12Mhz external clock to run the PIC at 48Mhz (assuming all of your dividers are set correctly). Using a 12Mhz (or lower) external clock is a lot easier to design and a lot less 'fussy' than trying to design around a 48Mhz external oscillator (which would most likely require a lot of shielding, grounding, and so on)...

sstt1976
- 20th August 2008, 19:42
The reason I thought the HSPLL for an 18F2550 ramped the crystal's signal up to 96MHz is from the datasheet which says...

"The PLL is enabled in HSPLL, XTPLL, ECPLL and ECPIO Oscillator modes. It is designed to produce a fixed 96MHz reference clock from a fixed 4MHz input."

...and then the Oscillator Configuration Options table shows 96MHz for Microcontroller Clock Frequency no matter what the Input Oscillator Frequency is when HSPLL is used. It shows different frequency options by way of scalers. The table also shows all the way up to 24MHz as viable Input Oscillator Frequency for HSPLL and an 18F2550.

I could just use trial and error with my DEFINE OSC statement until I get the exact same feel to my circuit but I wanted to understand this theoretically. I tried a DEFINE OSC 40 to account for your explanation but there is still something off from the original HS way it runs.

skimask
- 20th August 2008, 19:51
How far off is it?
If you did this...


main:
high LED
pause 500
low LED
pause 500
goto main

What do you end up with as far as timing goes? Should be a 1 second pulse, 1/2 on, 1/2 off, obviously...

sstt1976
- 20th August 2008, 21:39
I ran the test you suggested and here's what I found out:

18F2550 with a 20MHz xtal, HS, postscaler (/2), DEFINE OSC 20
makes 1ms into 4ms, which is what works perfectly for my situation.

18F2550 with 20MHz xtal, HSPLL, any possible postscaler, any possible DEFINE OSC
can't make 1ms into 4ms.

I would need to use either a higher than possible DEFINE OSC statement or a larger postscaler option. For example, DEFINE OSC 64 with postscaler (/6) would work but 64 isn't compiling.
A postscaler which is (/8) could help too but it's not an option.

Seems I should just use a different xtal. I could get that same 1ms becomes 4ms situation if I use a 12MHz or 24Mhz xtal for this circuit. Are 12 and 24 equally usable? Maybe 12 would be better because less noise?

skimask
- 20th August 2008, 23:37
18F2550 with 20MHz xtal, HSPLL, any possible postscaler, any possible DEFINE OSC can't make 1ms into 4ms.
Like I said before, you can't run a 20Mhz xtal into the HSPLL! The PIC is probably running on the backup internal oscillator (add some code to check for the oscillator fail bit and see what it reads back).

Darrel Taylor
- 20th August 2008, 23:47
Like I said before, you can't run a 20Mhz xtal into the HSPLL!
18F2550 ... Sure you can.

Just need to setup the right divisors in the config's.
<br>

skimask
- 20th August 2008, 23:52
18F2550 ... Sure you can.

Just need to setup the right divisors in the config's.
<br>

There I am thinking about the '4685 again. Can't run 20Mhz into it and expect the PIC to run 80Mhz...
(and I was just about to go back and change it too)

sstt1976
- 21st August 2008, 00:06
The datasheet says 20MHz is okay to go into HSPLL. You just use a /5 prescaler and the resulting 4MHz is then used to produce a fixed 96MHz PLL reference clock.

What I can't configure however is the 4x slower operation (I want 'pause 1' to actually pause for 4ms!).

I just wanted to see if i could pull this timing thing off without having to use a different xtal. I started everything with 20MHz HS but now that I'm forced to use HSPLL, which is new to me, I know 20 won't work so I'm done with it. The reason I'm moving to HSPLL is because my circuit only enumerates consistently on PC's but not Mac's, unless I use HSPLL instead of HS.

I'm sure both 12 and 24 will work but is there any preference?...unless there is some other way to get the timing I want and still use the 20MHz xtal!

sstt1976
- 21st August 2008, 01:11
Actually, it doesn't seem possible no matter what value I choose. Using HSPLL and also somehow getting the program to run 4 times slower is tougher than I thought. Now I will probably start experimenting with changing my ADC_SAMPLEUS value as well as all my PAUSE and PAUSEUS statements...

Bruce
- 21st August 2008, 16:40
Why do you want PAUSE 1 to pause for 4mS? Can't you just use PAUSE 4?

Note you do not have to use HSPLL. With a 20MHz osc you can set the PLL divisor to
/5, USBDIV /2, and the USB core will run at 48MHz. You can set FOSC = HS and set the
CPU divisor to CPUDIV = OSC1_PLL2 and use DEFINE OSC 20.

sstt1976
- 21st August 2008, 17:39
The PAUSE was just an example. I need every instruction and every aspect of the program to run 4 times slower than normal.

I already was using HS as you suggested and everything was fine, except enumeration would not carry out through a USB hub into a Mac. It worked in every other condition, PC and Mac. When I use HSPLL it enumerates every time in any situation. Unfortunately, my program works best 4 times slower than it does at normal speed, which was very possible using HS in the scenario I outlined above, but not possible so far using HSPLL.

Bruce
- 21st August 2008, 19:58
So what did you have the CPU divisor set to when it worked with HSPLL set on the MAC?

I know zero about the MAC, but it could be that your main-line program code is too slow
to meet the MAC USB tming. I.E. it could be that a USB device needs to check in more
often than on a PC platform to maintain the connection.

More details would really help.

sstt1976
- 21st August 2008, 21:00
Here's a simplified question about something I just noticed:

on an 18F2550 with a 20MHz xtal programmed HS with no postscaler and a DEFINE OSC 20...

Pause 2000 pauses for exactly 2 seconds

but with the same setup...

For cnt=1 to 2000
Usbservice
Pause 1
Next cnt

pauses just for 258ms

Why? First off, I thought I wasn't supposed to be able to Pause 2000 and maintain my USB connection but I am. Secondly, what's with the timing discrepancy?

Bruce
- 21st August 2008, 21:54
How do you know it pauses just for 258ms?

If you are not sure PAUSE 1 works, then setup a simple loop to toggle a pin, and watch
it with a scope.

sstt1976
- 21st August 2008, 22:30
I know those pauses are what they are because the circuit outputs a MIDI note across USB to a host computer and an app on that host measures the time between events. Both examples should theoretically pause 2000ms between each MIDI note indicator .

I'll try the pin toggle to the scope idea. Seems like Pause 1 will take just .129ms because 2000 times through the loop is taking only 258ms for some reason.

Bruce
- 21st August 2008, 22:41
I think you may be forgetting to add the time it takes for certain functions to execute.

PAUSE 2000 pauses for 2000 * 1mS.

For cnt=1 to 2000 ' this takes time
Usbservice ' this takes time
Pause 1 ' this should take about 1mS
Next cnt ' this takes time

Obviously, the 2nd version is NOT the same. You have to account for the time Usbservice
takes + the time to execute the for next loop.

sstt1976
- 21st August 2008, 23:51
What you said could make sense if the 2nd version actually was taking longer, but it's running 8 times faster.

remember, pause 2000 is measuring out as 2000ms but the loop example is completing in 258ms!

Bruce
- 22nd August 2008, 00:04
I'm totally guessing here, but it sounds like you might have declared your cnt variable as
a byte VS a word.

sstt1976
- 22nd August 2008, 00:10
You got it. Thanks very much!

Now my question is, in the 1st example, how is my USB staying connected all the while during the 'Pause 2000' statement? I though 'Usbservice' needed to be thrown in there almost constantly?

Bruce
- 22nd August 2008, 00:30
how is my USB staying connected all the while during the 'Pause 2000'
I think you'll find this varies from one PC to the next. Yes, I have tested it, and yes it does
vary. Why? Your guess is as good as mine...;o}

It may also have something to do with the host software, hub or no hub, number of active
USB devices online, your butt angle in your seat, position of the stars, etc, etc, but I have
seen a HUGE difference in time requirements from one app to the next.

I have a 1-wire temp logger that waits well over 1 second that's never failed. Go figure!