Using alternative crystals.

john2051

New Member
How would you go about using a different crystal frequency with the 40x2?
I would like to use a 19.6608MHz so that in theory the baud rates should be
closer in tolerance.
Any ideas, short of using an ordinary pic?

regards john
 

nick12ab

Senior Member
Just connect it like any other.

You could overclock it with your 19.6608MHz crystal or you can disable the PLL and keep the PIC operating within spec. The PLL enable bit is part of the OSCTUNE register.
 

john2051

New Member
Hi Nick,
What would I use for the serfreq command? something like setfreq em8 and then use this crystal,
or is there much more to it?
regards john
 

nick12ab

Senior Member
It doesn't matter which setfreq emXX command you use as all of them enable the PLL.

I've successfully disabled the PLL manually in a 20X2 using the osctune register and the internal oscillator but I haven't tested it on a 28X2/40X2 with external crystal yet. On the 28X2/40X2, PLLEN is bit 6 of OSCTUNE whose address is $F9B (drop the F for PICAXE pokesfr use - use $9B).

If you want to overclock the PICAXE beyond specification, don't disable the PLL.
 

srnet

Senior Member
Hi Nick,
What would I use for the serfreq command? something like setfreq em8 and then use this crystal,
or is there much more to it?
regards john
EM just enables the external oscillator and x 4 PLL, so whatever EM you put the processor runs at 4 times the speed of the crytal fitted.
 

srnet

Senior Member
I would like to use a 19.6608MHz so that in theory the baud rates should be
closer in tolerance
If your using the hardware UART, you should be able to 'fine tune' the PICs baud rate registers by a bit of pokesfr. By setting the PIC registers appropriatly you can get the baud rate fairly close.

I used this to intialise a GPS, when I did not know the baud rate it powered up in, worked out what the PICs hardware UART baud rate registers should be and wrote the values to change from 2400, 4800, 9600, 19200 etc.

Never tried it on a PICAXE, be interesting to know if it works.
 

g6ejd

Senior Member
Does the calculator take into account that UARTS' take their data reading from the centre of a bit time and not on leading edges, thereby enabling quite a wide tolerance on bit-rates before a data error starts to occur. In effect the cumulative error from the 1st bit to the 8th bit if it's a normal 8-bit data payload. My experience is the tolerance before data errors is at least 6%. A simple spreadsheet model soons provides confirmation.
 
Last edited:

nick12ab

Senior Member
Does the calculator take into account that UARTS' take their data reading from the centre of a bit time and not on leading edges, thereby enabling quite a wide tolerance on bit-rates before a data error starts to occur. In effect the cumulative error from the 1st bit to the 8th bit if it's a normal 8-bit data payload. My experience is the tolerance before data errors is at least 6%. A simple spreadsheet model soons provides confirmation.
The error is not the data error itself, it's the percentage timing error from perfect. As you say the tolerance is 6%, then anything with an error of less than 6% will work.
 

Dippy

Moderator
If you read the PIC data sheet and use USART and do BRG calcs correctly your baud rate will be very good.
In my PIC stuff I tend to use 10.00 and 20.00MHz crystals and have never, ever, ever had a problem.
I would assume the PICAXE settings do the corrects calcs for you.

If you ever want to do things manually then there is a neat drop of software called PIC MultiCalc.
It does a number of functions including BRG settings.
An added bonus is that it is also very useful for PWM parameters , values and errors and steps.
 
Top