Automatic frequency calibration / finetuning of internal PICAXE resonators


Senior Member
The two code snippets given here (for a master and a slave picaxe, connected to each other via a 1K or larger resistor) cause the slave node internal resonator frequency to get aligned with the master node. This is done in a loop in which the master node sends a number of pulses (using PULSOUT) of 10ms width and the slave node measures them with repeated PULSIN commands at CALIBFREQ 15, 14, 13 ... etc. until the same pulse length is found. The slave code then sends the corresponding final Calibfreq parameter to the PC using SERTXD (this parameter could then for example be noted on the back of the slave chip so that only a single CALIBFREQ command is needed in an application). The codes work on any picaxe type (new and old) and at any speed as long as the master and slave speeds are the same.

Although in general with serial comms there is no need to do this type of calibration, sometimes early release chips have larger oscillator margins (for example early silicon PIC18F14K22 (20X2) a few years back), and thus a procedure like presented here can mitigate any potential problems associated with it and thus guarantee stable serial communication and - in general - better aligned execution timing.

Best regards,


Last edited:


Ex-Staff (retired)
That's an interesting idea. For even greater accuracy but with less flexibility of using any pins an option is to use HSEROUT and HSERIN as their timing is completely hardware based.