PDA

View Full Version : How to proceed with arbitrary Xtal values?



msnm4
- 15th April 2008, 01:15
Hi all,

This is my first post and only based on what I could read, not tried.

As far as I can see, with a "DEFINE OSC xx" command (with xx = 3, 4, 8, 10, etc... MHz), I can tell the PBP the oscillator frequency to produce the correct timing for instructions such as: COUNT, DEBUG, DEBUGIN, DTMFOUT, FREQOUT, HPWM, HSERIN, HSEROUT, I2CREAD, I2CWRITE, LCDOUT, OWIN, OWOUT, PAUSE, PAUSEUS, SERIN, SERIN2, SEROUT, SEROUT2, SHIFTIN, SHIFTOUT, SOUND, XIN and XOUT.

My questions are as follows:

a) Is this list of (timing) affected commands complete? or should I worry for something else?

b) I could read somewhere that for the compiler to work, I have to declare an OSC value belonging to the above mentioned discrete set of values. But how should I proceed if my end hardware has (e.g.) a 6 MHz Xtal??

c) Regarding b): Should I declare 4 MHz to the compiler only, and then write some kind of commands to introduce "corrections" in the timings of the different instructions?

d) Regarding c) How are then these corrections introduced? (if possible).

Thanks a lot

msnm4

mister_e
- 15th April 2008, 01:49
a) those you don't really need to worry about are SHIFTIN/SHIFTOUT, I2CREAD/I2CWRITE as they're synchronous one.
Not sure how bad Xin/xout/Owin/Owout behave.. I never used them.
LCDOUT... well maybe, but in case you have problem with, it will me just a matter to change some DEFINEs values.
SERIN/SEROUT/DEBUG/DEBUGIN will cause problems.. you just can't fine-tune them easy .
SERIN2/SEROUT2... possible to adjust it.
HSERIN/HSEROUT no problem if you manually set the internal baudrate register (SPBRG)
Count/Frequout/SOUND possible to calculate it and adjust their results
HPWM no real need to use it, manually write to the CCP register is easy 3-4 lines of code
PAUSE/PAUSEUS will need to be manually adjusted.

b)it's up to you... let's say you use PAUSE 10 and set OSC 4.... pause will execute in 6/4 of the expected time, if you set OSC 8, it will execute 6/8 of the expected time.

c)once again it's up to you. I think it's a personal choice. I have some ideas... but i think they will mixed-up you more than help for now.

d)Using Macro, create your own routines, "hack" some PBP library... or just comment out some lines in your code. tons of possibilities.

As you see yes it's possible to use ANY crystal speed when really needed. Depending your application you may do some extra work or not. nothing really hard.. just something you don't need to do with the supported OSC speed.

HTH

msnm4
- 15th April 2008, 02:12
Thanks Mr.e for your answer

In fact I was checking with your PicMultiCalc tool which is nice and handy for this kind of things, but I was not absolutely sure if it could solve all my doubts. Let you know.

Best

msnm4