Frequency reference

Dicky Mint

Senior Member
I'm wanting to build a reference oscillator running at 1kHz to calibrate other equipment.

I'm thinking this could be very easy with a PICAXE although I can't see how at the moment!

I'm using a 555 at the moment.

I would like an accuracy of about <1% or so.

Can't seem to find much on the Forum search

Any help would be appreciated

Rick
 

AllyCat

Senior Member
The PicAxe is no where near 1%.
Hi,

Actually, the 4MHz clock of (at least) M2 PICaxes is close to 1% and can be adjusted with the calibfreq command in steps of about 0.1%. Use the PWM wizard for the 1kHz, 50% settings.

You could calibrate a cheap/small M2 (perhaps even by writing an auto-compensating Program) by comparing the 1Hz time variable increments against pulses from a cheap analogue clock (e.g. from a Pound shop).

Cheers, Alan.
 

BeanieBots

Moderator
Or use a cheap digital clock/watch from the pound shop!
The PICAXE internal oscillator might need temperture compensation to get 1% accuracy.
 

KeithRB

Senior Member
My 18M2 was pretty far off when I tried to use the time variable to implement an RTC.

But the nice thing about my solution (with the DS3234) is that it is temperature compensated, too.
 

womai

Senior Member
Take any Picaxe that can use an external resonator, e.g. 28X2. Then set up PWM, it may be necessary to activate the prescaler to reduce the PWM output frequency to 1 kHz. The frequency will be as accurate as the external resonator or crystal. Resonator - typically 0.5%, crystal - 100ppm or better. As an example for using the PWM prescaler, look at the source code for my Piucaxe oscilloscope at http://www.pdamusician.com/lcscope
 

g6ejd

Senior Member
All xtals are specified in PPM (parts-per-million) and an average specification would be 50ppm, or in percentage terms that's 50/100000*100 or 50/10000 = 0.005% so get your PICAXE to generate a square wave by toggling an output pin and you know it's that accurate. You could slow the count right down and then count the output transitions over a given period of time to determine the absolute accuracy and then adjust the clock as mentioned above.
 

Buzby

Senior Member
... so get your PICAXE to generate a square wave by toggling an output pin and you know it's that accurate. ...
You hope it's that accurate !

The problem with any software based solution is you don't know what the underlying firmware is doing in the background.

Things like interrupts from background timers could cause slight extensions to some cycles of your toggling pin, reducing the long term accuracy.

Much better to use the on-chip hardware, such as HPWM, as they do not get disrupted by interrupts etc.
 

John West

Senior Member
I'd suggest purchasing a surplus 10MHz crystal oven, then using divide-by-10 and/or divide-by-2 (flip-flops) IC's on the output. They can be found for a very reasonable price if you look around.

The reason I suggest this, which is far more precise than what you asked about, is that sooner or later you'll likely need something more precise anyway, and a 10MHz oscillator with a few digital dividers can give you all sorts of other useful frequencies for your projects and workbench equipment.
 

g6ejd

Senior Member
That's why I suggested slowing the whole thing down and to compare with time that way most of the overheads (at 1khz) would be taken care of in the clock adjustment, the only variation being the removal of a delay between toggles which would be negligible
 

eclectic

Moderator
Simple, quick and cheap? Yes.

But how accurate is it?

I've just tried two chips,
08M and 08M2
Code:
#picaxe 08m
Setfreq M4

pwmout 2 , 249, 500 ; set pwm to 4kHz
pause 3000 ; measure frequency at 4kHz
poke $12, 5 ; quarter speed 1000 Hz

stop
and
Code:
#picaxe 08M2
setfreq m8

pwmout pwmdiv16, 2, 124, 250 ; wizard 1000Hz
stop
Measured on my cheapish 'scope,
the results are both within 0.5% of 1.000 kHz

I'd be interested to see the results from others
who have more "grown-up" test equipment.
e
 

geoff07

Senior Member
If you want really accurate, why not use a receiver to pick up a standard frequency tx in your area, and divide it down. In the UK, Radio 4 long wave on 198kHz would do it. Then you are being driven by a crystal that is probably 20 meters down in a hole in the ground and way more stable than anything you could afford to make.

If you use one of the standard time transmissions you could have an accurate wall clock as well.
 

eclectic

Moderator
Good, fast and cheap?
But only two.

Geoff, I agree totally.
(And you have much more experience than I).

But I was simply going on
Dickie Mint's original idea that
1% accuracy would be good.
0.1% accuracy would be excellent.

e
 

Dippy

Moderator
Some time ago I measured a handful of cheap-but-branded crystals 10 and 20MHz.
I simply tested at the the drive side of the PIC connection.
According to my Tektronix (calibration 3 years out of date) they were bang-on to 2 or 3 decimal places.

I'd be more than happy with crystal plus PWM - BUT , as a general statement, remember that you might not get your demanded frequency with PIC registers.
Also, in some cases the register settings for a particular frequency has options.
In (quaintly called 'raw') PIC programming you have the choice but here it depends on Rev-Ed's firmware.

In your case, a quick calc shows, that a 4 or 8MHz xtal can give 1.00kHz - 1.008kHz with pretty good resolution on duty if desired.
 

srnet

Senior Member
If you want really accurate, why not use a receiver to pick up a standard frequency tx in your area, and divide it down. In the UK, Radio 4 long wave on 198kHz would do it. Then you are being driven by a crystal that is probably 20 meters down in a hole in the ground and way more stable than anything you could afford to make.
Sure.

But the practicality of that, for average PICAXE users ?

(I do understand how to do it)
 

g6ejd

Senior Member
If you want really accurate, why not use a receiver to pick up a standard frequency tx in your area, and divide it down. In the UK, Radio 4 long wave on 198kHz would do it. Then you are being driven by a crystal that is probably 20 meters down in a hole in the ground and way more stable than anything you could afford to make.

If you use one of the standard time transmissions you could have an accurate wall clock as well.
AFAIK Radio 4 LW is still the UK's reference frequency to accurate to 1 in 10^12, so you could receive that off-air with a RF front-end and count the pulses for an accurate standard and use a digital phase-lock loop to get a 1KHz output.
 

mrburnette

Senior Member
I'd suggest purchasing a surplus 10MHz crystal oven, then using divide-by-10 and/or divide-by-2 (flip-flops) IC's on the output. They can be found for a very reasonable price if you look around.

The reason I suggest this, which is far more precise than what you asked about, is that sooner or later you'll likely need something more precise anyway, and a 10MHz oscillator with a few digital dividers can give you all sorts of other useful frequencies for your projects and workbench equipment.
Or just buy a GPS w/ 1 sec. output and scale up to the desired freq. Of course, the x-tal oven can be repurposed for a coffee or tea warmer :)

The new GPS SiRF chip sets are amazing... works on my basement lab bench through 2 floors and a roof. Quick to lock and no dropout over 24 hours.

- Ray

Ex: https://www.sparkfun.com/products/10890
 

geoff07

Senior Member
Given the sort of things that Picaxeers get up to I would have thought that an off-air reference would be easy stuff! But it all comes down to what is wanted -there isn't much point in a resolution better than the application needs. However, if the app involves a frequency counter I guarantee that 1% won't satisfy for long!
 

John West

Senior Member
Software frequency correction based on temperature change does indeed work for more sophisticated systems, boriz, and very well. It could well work for something as simple as a PICAXE, too, and quite inexpensively.

Temperature change tend to be the most significant difficulty in many precision time referencing systems, so with built-in temp monitoring and a bit of code the PICAXE chips could reduce such timing errors substantially. However, it would be necessary to characterize the frequency error at all temperatures likely to be encountered in order to produce a curve to work from for calculations. A lot of time involved, to be sure, but not much money.
 

Dicky Mint

Senior Member
Hi

Temperature compensation may be important at a later date if I require that amount of accuracy but, for the moment another question or so

I&#8217;m building a frequency meter and am looking at two ranges, 10kHz max and 100kHz max. It is not of a PICAXE design but I want to upgrade the time base to an accurate 1,000millisecond (and a 100ms) timing period and a PICAXE seemed a good starting point!

How accurate is the &#8216;pause&#8217; command when running on a 08M2 PICAXE for a delay of about (a) 1 second and (b) 100ms

I guess as accurate as the 08M2 itself, whatever that is?

Or if I want an accurate 1second pause would I be better off peeking at the clock of a 28X2 and dividing by a multiple of two in software?

I could also use the 32.768 kHz crystal to give the 1s time base for the frequency meter.

I have some 32.768 MHz crystals which conveniently divide by 2 to the x power to give a 1kHz output for my frequency reference too!


Is it permissible to use such frequency crystals with a PICAXE28X2?
 

Dicky Mint

Senior Member
thanks e

I'll try that hack

The only thing is that I suspect the 1 second time is measured by a whole 'wave'
and what I need is a 1second pulse!

Rick
 

geoff07

Senior Member
If this is to be the clock for a 100kHz counter then you need quite a few digits of precision if you want to count accurately. More like six than two (1%).
 
Top