Propeller Frequency Counter?
smbaker
Posts: 164
in Propeller 1
I was toying with the idea of doing a frequency counter project. I would probably use a prescaler, such as the LMX2322. There's numerous PIC-based projects that do this, the prescaler feeds a pin on the PIC that increments a counter, and then the PIC samples and resets that counter at a known interval. By knowing how many events were counted during the interval, you can compute the frequency in hertz. Ideally I'm shooting for something that would work from the low hertz range all the way up to a gigahertz or so.
I've read AN001, and it looks like there are some logic modes that can detect rising or falling edges on an input pin, and then do something with the FRQx and PHSx, but I'm not exactly sure how to put something practical together from this. I was hoping someone had a working example of a pulse-counting configuration.
Thanks,
Scott
I've read AN001, and it looks like there are some logic modes that can detect rising or falling edges on an input pin, and then do something with the FRQx and PHSx, but I'm not exactly sure how to put something practical together from this. I was hoping someone had a working example of a pulse-counting configuration.
Thanks,
Scott
Comments
calculates Freq = Cycles/Time
http://forums.parallax.com/discussion/123170/propbasic-reciprocal-frequency-counter-0-5hz-to-40mhz-40mhz-now
LMX2322 looks to be obsolete ?
Not sure what a modern replacement is.
Si5351A looks to have a bypass mode and divider, but may not get > 200MHz ?
Divider choices are
R0_DIV[2:0] R0 Output Divider.
000b: Divide by 1
001b: Divide by 2
010b: Divide by 4
011b: Divide by 8
100b: Divide by 16
101b: Divide by 32
110b: Divide by 64
111b: Divide by 128
Thanks for the pointer to the reciprocal counter, I'll take a look. I've been mostly away from the prop for a couple years, so prop basic will be entirely new to me!
Scott
CON
_clkmode = xtal1 + pll16x ' Crystal and PLL settings.
_xinfreq = 5_000_000 ' 5 MHz crystal.
Pin = 5 ' Counter Input Pin
VAR
long frequency
repeat
'Pulses are sampled on this pin.
DirA[Pin] := In
CTRA := 0 'Clear CTRA settings
CTRA := (%01010 << 26 ) | (%001 << 23) | (0 << 9) | (Pin) 'Trigger to count rising
FRQA := 1000 'Count 1000 pulses on each trigger
PHSA := 0 'Clear accumulated value
WaitCNT( 80_000_000 + CNT ) 'Wait for 1 second
Frequency := PHSA / 1000 'Calculate Freq based on the sampling
' duration, 1000 ms (1 second)
LCD.DecF(frequency,5) ' This just shows I'm displaying on the LCD you have to add the LCD OBJ.
-Phil
In the meantime, I also want to figure out how to get an accurate clock reference for the prop. Let's say I want to hook up a 3.3V TCXO oscillator. I happen to have a 25Mhz TCXO on hand. Can I just connect the TCXO to the XIN pin, set the PLL to x2, and operate a 50Mhz? Alternatively, I could try to get a 10Mhz or 20Mhz TCXO and operate at the full 80Mhz.
Thanks,
Scott
Data sheet spec's 4MHz <= Xtal <= 8MHz
If you have a 25MHz TCXO, then a 'simple' /5 would be needed for Prop-drive. (ie add HC161 et al)
Maybe? the Prop can work with a 52MHz TCXO in Xtal x 1 mode ? (data mentions to 60MHz) - not quite 80MHz but closer than 25MHz
-Phil
A /4 is a bit simpler, and provides a 6.25MHz clock so you can run the prop at 100MHz.
Another option would be to use a small CPLD to make a Johnson-counter. The sparse grey-code output of the Johnson-counter would avoid the need to gate the pre-counter. Speed wise, 400-500MHz is a realistic max count rate for a FPGA/CPLD. (IO pin speed is the limit)
Marty
The Frequency Synthesizer / PLL parts tend to be
* low cost
* have amplifiers inbuilt
* have a choice of divider, ideally from /1
- but they also suffer from lifetime issues, as the markets move and vendors follow.
Also depends on just how many MHz is considered important.
Many of the Frequency Synthesizer / PLL parts have more than one input choice - up to 3 : Xtal, IF, RF
Hittite seem to be one of the few that include DC as a lower limit.
I tested a Si5351A on a Adafruit PCB https://www.adafruit.com/product/2045
Bypass mode ( Xtal /2^N) works well, and will divide to above 160MHz (my test limit)
However, there is a caveat lurking here :
The XA input will not divide reliably below about 3MHz, and if you GND XA (biasing the Osc Amplifier hard one way) then the /2^N pins output indicate around roughly 60MHz of parasitic internal oscillation.
I tried a square wave drive to XA, with the same results.
( ie Behaviour is like there is some AC coupling internally.)
That means Si5351A is good for direct Divide of Xtals > 5MHz, (eg it could do 25MHz -> 6.25MHz discussed here ) and it can also PLL to any frequency 2.5 kHz to 200 MHz (which is useful as a Signal Generator) and the XA can be AC coupled to a clipped Sine source, so there are many uses in a Frequency Counter design within the timebase.
Whilst it is low cost, and a second one could be used for a Fi prescaler > 5MHz, the way it 'generates it own frequency' outside the range, makes it rather less practical as a general use divider.
The first thing I did was to use a variation of DigitalBob's code and see how well I could make the prop count. With a one second gate time, I'm easily able to count to 25Mhz. There's a little bit of error, probably due to the time to execute a few of the statements that is falling into the measurement loop (I'm off by 700 Hz on a 25 Mhz signal). I figure I can probably correct for that. I'm able to reliably measure square waves up to the limit of my function generator, which is 25 Mhz.
Sine waves are a different beast entirely -- I think I need some signal conditioning. I'm probably going to go with a 74HC4046 PLL chip and use part of it for signal conditioning. This seems to be what a lot of low end frequency counter projects do.
Then I tried out the LMX2322 chip. I set it to divide by 128 for now. It's easily able to function to the limit of my function generator (again, 25 MHz). It bottoms out around 5 Mhz.
I figure my project is going to have two input paths -- one for 1 Hz - 25 MHz using no prescaler, and a second path from 5 Mhz to 2.4 Ghz using the prescaler. I do have some 5 Mhz TCXO on order, and I'll eventually use those to yield a precision timebase.
I need to get my hands on a higher range frequency generator so that I can do some actual tests.
Thanks for all the help
Scott
Did you look at Bean's counter in the link above ?
I presume that 5MHz bottom, is for the 2.4GHz in ? which is not too bad.
Those parts can also count from the XTAL in, which has a sine amplifier portion. - ie you may not need a 4046 - just use the Xtal pathway you already have.
Can you provide details on the TCXO you ordered? Source, part number, price, etc.? I'm trying to make a simple high precision stopwatch and have had trouble finding low-error 5MHz crystals. Also, are these drop-in replacements for the standard 5MHz crystal, or are circuit changes required? If so, can you help me with the schematic?
Thanks,
Jim
for many apps, something like a direct operation from
ASVTX-11-121-19.200MHZ-T
will be ok. ( $1.39 1+, 2ppm 1.8mA VCTCXO)
That gives appx 50ns Stop watch LSB - pretty good for a stopwatch
That one you can trim using a GPS clock.