PDA

View Full Version : 18F2520 clock speed ?



Gixxer
- 14th August 2008, 06:14
Hello,

I recently bought a pic/xbee robotic controller board online from www.droids.it . I must say the price was alright and the pcb quality is excellent BUT I just cant figure this one out. It has an 18f2520 with a 10Mhz smt crystal, according to the docs it is actually running at 40Mhz, I assume that has been accomplished by the provided pre-programmed software. So using my awesome U2 programmer, I dumped a simple program to the pic to have it send "hello world" at 9600 baud and receive it on a serial LCD. The exact same setup was used with a 16f873 at 4Mhz and worked great. With the 18f at 10Mhz I only get garbage on the output. So, I then removed the 10Mhz xtal, installed a 4Mhz xtal and it worked. Obviously the pic timing is off when using the 10Mhz xtal, but can I work around this issue in software or is my 4Mhz Xtal the best solution. Heres the program:

INCLUDE "MODEDEFS.BAS"

start:

low porta.4 ' Status LED
pause 500
high porta.4

serout2 portc.6,84,["Hello World...."]

pause 500
goto start

Darrel Taylor
- 14th August 2008, 06:40
It has an 18f2520 with a 10Mhz smt crystal, according to the docs it is actually running at 40Mhz, I assume that has been accomplished by the provided pre-programmed software.
Most of the 18F's can multiply the crystal frequency X4, using the Phase Locked Loop feature. So you can run at 40mhz with a 10mhz crystal.

The options for using the x4 PLL with the HS oscillator are set in the configs.
This thread explains all that better than I could.

Presetting Configuration Fuses (PIC Defines) into your Program
http://www.picbasic.co.uk/forum/showthread.php?t=543
<br>

Gixxer
- 14th August 2008, 15:03
Hi DT,

Thanks for that reply. I am able to set all config fuses using the melabs U2 programmer software. I did set the 10mhz xtal to 'HSPLL' under xtal setting, which worked but is also the source of my problem. For example, if I flash an led using a 4mhz xtal at 1hz(1000ms) pause between flashes, it will flash once per second. Using the same program, running at 10 or 40mhz, the led flashes very fast, not at 1hz. This is the problem I'm having with the baud, with 4mhz xtal it all works great and with the 10mhz xtal all I get is garbage at the output. So, obviously 9600 baud at 4mhz is not the same as with a 10mhz xtal. How do I make it output 9600 baud at 10 or even 40mhz ?

Melanie
- 14th August 2008, 15:26
PBP assumes you're running at the default 4MHz (regardless what crystal or PLL multiplyer you're using) and bases all it's timings on that unless you tell it otherwise...

Look for DEFINE OSC in your manual...

There's also a whole section entitled "How fast is fast enough?" (section 7.1 in my manual).

Gixxer
- 14th August 2008, 15:44
Thanks Melanie,

That explains my problems with any xtal other than 4mhz. I will check into my PBP manual for info about DEFINE OSC, but will that allow the use of other osc frequencies ?
Also, where do I find your book ?
And one more thing, are there any threads in this forum already explaining the implementation of Xbee's with pics. I do have mine working @ 4mhz, and they are great, just want more info.

thanks alot
John

skimask
- 14th August 2008, 15:56
Also, where do I find your book ?
.....................ffffffffffffffffffftttt

Melanie
- 14th August 2008, 16:03
Close Ski - but no cigar...

The correct answer is "It was in the bottom of the box when you bought your software".

skimask
- 14th August 2008, 16:07
Close Ski - but no cigar...
The correct answer is "It was in the bottom of the box when you bought your software".

Aw....shucks! I knew I should've taken Door #2.
Could I get a consolation prize on my way out the door?
(somebody else around here did say I've been 'off' for the past couple of weeks or something)

Gixxer
- 15th August 2008, 07:11
hmm...

skimask, what does " .....................ffffffffffffffffffftttt" mean ?

As for this manual/book at the bottom of my box, I'll let you know if I ever find that. It's probably still packed as I moved recently.

Back to my last post, do I simply define osc 10 or 40, or is ther more to it ?

thank you

manwolf
- 16th August 2008, 00:26
Melanie you don't keep it under your pillow?
I laugh but at times I kind of wonder if just maybe you did write the book. :)



skimask, what does " .....................ffffffffffffffffffftttt" mean ?


Sound beer makes hitting keyboard or monitor!

skimask
- 16th August 2008, 05:58
Melanie you don't keep it under your pillow?
I laugh but at times I kind of wonder if just maybe you did write the book. :)
skimask, what does " .....................ffffffffffffffffffftttt" mean ?
Sound beer makes hitting keyboard or monitor!

Steam escaping...
A big ol' electrolytic capacitor relieving it's self one last time in a puff of smoke...

Melanie
- 16th August 2008, 10:36
Actually, my old Robosapien walked off with what I had under my pillow (you'll have to do a forum search for that thread) some time back, and I've not seen him or it since... however I think he's earning a good living somewhere as the girls in the neighbourhood seem to always have smiles on their faces...

Archangel
- 16th August 2008, 10:44
Actually, my old Robosapien walked off with what I had under my pillow (you'll have to do a forum search for that thread) some time back, and I've not seen him or it since... however I think he's earning a good living somewhere as the girls in the neighborhood seem to always have smiles on their faces...Hmmmph, Powertools, whoa ho ho ho :D

Gixxer
- 17th August 2008, 04:56
...........zzzzzzzzzzz

wow, thank you Sooo much for such useless information....

John

Melanie
- 17th August 2008, 08:09
John

Get up off your butt and do a forum search for DEFINE OSC (a secret phrase known only to everyone that programs with MeLabs PICBASIC who happens to have read the product manual) that I mentioned back in post number #4 in this thread. Not got the manual? Then go onto the manufacturers website (this forum has got a dozen pointers to it) where you can locate the product manual and look up DEFINE OSC. You do remember who makes your compiler don't you? No? (there's a highlighted clue in this paragraph and Google comes free with every internet connection). In case you missed it - DEFINE OSC is the answer to your problem. Once you've got the manual, go look in the section I pointed you to (again back in Post #4). Don't say that you've had "useless information" when you were told the answer a few hours after posting your question.

Geeze, teach a guy to fish and he'll spend all day in a boat with a crate of beer.

Archangel
- 17th August 2008, 09:31
Geeze, teach a guy to fish and he'll spend all day in a boat with a crate of beer.
That's why I'm learnin' to fish ;)

Gixxer
- 21st August 2008, 01:07
MEL,

Your right, you did explain in post #4 that using DEFINE OSC was needed to adjust all required timings. You then said "There's also a whole section entitled "How fast is fast enough?" (section 7.1 in my manual). "
To which I asked "where do I find your book ?"

How the hell should I know that you have some connection to Melabs.
Honestly, I don't really care who you are affiliated with, I was just trying to get this circuit working. As it turns out, the board is fully functional and has been since the first post, I had already figured out that it would work with a 4Mhz xtal.
I did try the define osc before my first post, I had deleted it from my code because it didn't work. That is what lead to Post #3, which I described how the xtal fuse settings vastly affected the timing, again looking for a constructive reply !

Thanks

manwolf
- 21st August 2008, 01:32
"where do I find your book ?" = Melanie's manual
Melanie's manual = MicroEngineering Labs, Inc. PICBASIC PROtm Compilier manual



In my copy

Section 7.1 is on page 171, look down the page about 3/4 of the ways. Sentence begins "However..."


You should be able to find the answers to your questions there.

The PBP Manual is also known as: the Manual, the ugly green book, the bible, etc. around these parts.



That explains my problems with any xtal other than 4mhz. I will check into my PBP manual for info about DEFINE OSC, but will that allow the use of other osc frequencies ?


If you had checked the PBP manual you would not have asked that question or needed to for that matter.

Gixxer
- 21st August 2008, 02:51
Hi,

Yes I had cheched the manual, just didn't know or cared who wrote it. I don't run and post a question here or anywhere unless I just can't figure something out. I will read anything I can get my hands on, online or otherwise, until I find the solution. Granted, I'm no expert, so this process can take some time, but usually I will succeed. I DID refer to the manual, don't need a forum to tell me to look there first. As I said, I had also ALREADY tried using DEFINE OSC 10Mhz, it did not work. The output baud timing was way off. I also wasn't sure about what config fuses to set with the U2 programmer regarding the xtal. The original crystal is a SMT type, 10 Mhz. I tried all different fuse settings, which of course affected the timing, but none gave the proper result at the pic output. So I installed a SMT 4Mhz xtal and, you guessed it-works great.

Gixxer
- 21st August 2008, 03:46
one more thing....

"where do I find your book ?" = Melanie's manual
Melanie's manual = MicroEngineering Labs, Inc. PICBASIC PROtm Compilier manual
.....ok, thanks for that manwolf...

And from Mel's profile,
"Occupation:
I DO NOT work for MeLabs or Crownhill. Both those companies however continue to get my vote. "
Now I am curious, did you write this manual, or is that an urban legend 'around these parts'.
?
your PBP pal,

John

skimask
- 21st August 2008, 03:51
one more thing....
"where do I find your book ?" = Melanie's manual
Melanie's manual = MicroEngineering Labs, Inc. PICBASIC PROtm Compilier manual
.....ok, thanks for that manwolf...
And from Mel's profile,
"Occupation:
I DO NOT work for MeLabs or Crownhill. Both those companies however continue to get my vote. "
Now I am curious, did you write this manual, or is that an urban legend 'around these parts'.
?
your PBP pal,
John

Melanie's manual <> PicBasicPro Compiler manual...however...
Melanie's REFERENCE manual used way back when Melanie didn't know anything about PicBasicPro may have been the PicBasicPro Compiler manual, written by microEngineering Labs, Inc (at least that's what I've assumed all along). Can't remember the name of the person(s) that are responsible for the upkeep/updating of the core of PicBasicPro itself off hand though...

Gixxer
- 21st August 2008, 04:03
LOL, all I wanted to do was avoid desoldering the original 10mhz SMT xtal with a 4mhz, but the desoldering took far less effort.
Thanks to all that replied anyhow.

John

Melanie
- 21st August 2008, 12:19
I had also ALREADY tried using DEFINE OSC 10Mhz, it did not work.

That's because DEFINE OSC 10Mhz is the wrong syntax.

I didn't write the book - That's urban legend! (but I have seen it once in a previous life). I have never used the paper copy, because I downloaded the pdf and it's a hell of a lot easier to use the Adobe FIND feature to locate exactly what I'm looking for, rather than waste time thumbing through a hundred pages.

And if people can't figure where to download the pdf... then takeup landscape gardening for a hobby!

And finally John, the reason folks are reluctant to help when you haven't got a manual, is it usually applies to someone that has not acquired a legal copy (since the manual comes free with the product).

Gixxer
- 21st August 2008, 14:02
Hey Mel,

If you or others are "reluctant to help when you haven't got a manual" ...because..."it usually applies to someone that has not acquired a legal copy (since the manual comes free with the product).", then thats fine by me. If you happened to read post 9 you would see that I stated I recently moved, which translates in english to I can't locate my PBP book that came with the software. Thats the "book" you told me to look in. What do you do, test people to see if they possess this stupid book ? I too, since my PURCHASE of PBP for $249.95, also use the pdf AND my printed copy of the manual. I also PURCHASED the MELABS U2 programmer as already stated, or do ya think I "acquired" that illegally too(downloading of matter-maybe there is a pbp command for that!). My only mistake in all of this was basically a typo that you pointed out-DEFINE OSC 10Mhz, which was how I typed it in my post because I was tired. However, in my program I did enter it minus the Mhz--it did not work. I don't know why it didn't work, but the timing was still off. Go figure, thats why I posted my question in the first place. The couple of posts I made in the past which were promptly and maturely answered by "Mister E", was how I thought it worked around here-not having someone call you a thief.......geeez !

Melanie
- 21st August 2008, 19:01
I wasn't accusing you personally of anything. I did however reflect on the attitude of a large number of contributors to this forum.