Author Topic: 10MHz to 1pps divider  (Read 3894 times)

0 Members and 1 Guest are viewing this topic.

Offline sahko123

  • Frequent Contributor
  • **
  • Posts: 314
  • Country: ie
10MHz to 1pps divider
« on: March 29, 2021, 12:48:25 am »
Simply put i want to know if there is a single ic solution to get a 1pps output from a 10MHz input for a frequency counter im building. The 10Mhz reference is a Rigol DG800 and the counter i need will only count up to at most a few KHz (for audio tuning purposes).
Asking for a friend
 

Offline Algoma

  • Frequent Contributor
  • **
  • Posts: 261
  • Country: ca
Re: 10MHz to 1pps divider
« Reply #1 on: March 29, 2021, 12:56:23 am »
simple low cost 6-8 pin Microcontroller.. you could even make it adjustable.
 

Offline sahko123

  • Frequent Contributor
  • **
  • Posts: 314
  • Country: ie
Re: 10MHz to 1pps divider
« Reply #2 on: March 29, 2021, 12:59:52 am »
would a small micro even be able to count at 10MHz? or do you mean just generate the 1pps with a micro
Asking for a friend
 

Offline TERRA Operative

  • Super Contributor
  • ***
  • Posts: 2278
  • Country: jp
  • Voider of warranties
    • Near Far Media Youtube
Re: 10MHz to 1pps divider
« Reply #3 on: March 29, 2021, 01:01:48 am »
Apologies for linking to my youtube, but I did exactly this a little while back:



Also:
https://www.eevblog.com/forum/projects/easiest-way-to-divide-10mhz-to-1mhz/
Where does all this test equipment keep coming from?!?

https://www.youtube.com/NearFarMedia/
 

Offline sahko123

  • Frequent Contributor
  • **
  • Posts: 314
  • Country: ie
Re: 10MHz to 1pps divider
« Reply #4 on: March 29, 2021, 01:05:07 am »
you see i was trying to avoid using a divide-by-N 5 or so times strategy and hoped that there was some ic that does a 10MHz to 1pps division in one package and then just do the final conversion to get 0.1pps or 0.01pps to be able to measure in the mHz.
Asking for a friend
 

Offline sahko123

  • Frequent Contributor
  • **
  • Posts: 314
  • Country: ie
Re: 10MHz to 1pps divider
« Reply #5 on: March 29, 2021, 01:10:22 am »
i have also just discovered reciprocal frequency counting which may be up my alley to get high res low frequency measurements
Asking for a friend
 

Offline 5065AGuru

  • Frequent Contributor
  • **
  • Posts: 327
  • Country: us
Re: 10MHz to 1pps divider
« Reply #6 on: March 29, 2021, 02:22:18 am »
Hi,

The simplest implementation is the PicDIV.

See http://www.leapsecond.com/pic/picdiv.htm

It uses 12F675 PICs and if you can program your own the code is downloadable and free.

Cheers,

Corby
 

Online magic

  • Super Contributor
  • ***
  • Posts: 5529
  • Country: pl
Re: 10MHz to 1pps divider
« Reply #7 on: March 29, 2021, 06:12:36 am »
i have also just discovered reciprocal frequency counting which may be up my alley to get high res low frequency measurements
For audio frequency that's the way to go. Get any PIC/AVR/ARM/whatever, feed it the 10MHz reference clock and learn to use its input capture function.
 

Offline mvs

  • Frequent Contributor
  • **
  • Posts: 369
  • Country: de
Re: 10MHz to 1pps divider
« Reply #8 on: March 29, 2021, 08:15:31 am »
Get any PIC/AVR/ARM/whatever, feed it the 10MHz reference clock and learn to use its input capture function.
It is a bad idea to sync reference clock to MCU clock... Much better is just to use reference clock as MCU clock directly, like in PicDIV.
 

Offline MIS42N

  • Frequent Contributor
  • **
  • Posts: 446
  • Country: au
Re: 10MHz to 1pps divider
« Reply #9 on: March 29, 2021, 10:50:06 am »
Get any PIC/AVR/ARM/whatever, feed it the 10MHz reference clock and learn to use its input capture function.
It is a bad idea to sync reference clock to MCU clock... Much better is just to use reference clock as MCU clock directly, like in PicDIV.
I believe some PICs, Timer 1 can be externally clocked at 10MHz (rather than use the instruction clock of Fosc/4) and can be gated by T1G. Arrange to count on gate high and interrupt when gate goes low. At every interrupt accumulate timer 1 count and add 1 to a count of interrupts, reset timer 1 before the gate goes high again. When accumulated timer 1 count is over 5 million at a gate interrupt (assuming the input signal is symmetrical) a second (and a bit more) has passed. Use period = accumulated timer 1 count/count of interrupts. Frequency = 1/(2*period) (because we only counted for half the time).  For frequency less than around 75Hz, counter 1 will overflow so need another interrupt to add 65536 to accumulated timer when this happens. If counter overflow interrupts exceed a certain amount (say 100) then the frequency is very low or DC so stop anyway. Will need a bit of synchronising to ensure the start is clean (don't start counting half way through a high input). I haven't worked out how many instructions are required in the interrupt routines, that will limit the maximum frequency. I would expect > 20kHz if ISR in assembler.

This is independent of the uP clock. However, the slower the uP clock, the longer the ISR needs to run and that determines the minimum measurement period and therefor maximum frequency.
 

Offline sahko123

  • Frequent Contributor
  • **
  • Posts: 314
  • Country: ie
Re: 10MHz to 1pps divider
« Reply #10 on: March 29, 2021, 12:30:41 pm »
so what i can potentially do is use a 10Mhz reference AS the clock input and ensure that an output gives one pulse every 10,000,000 clock cycles that should give a very accurate clock i cant think of a way that can go wrong timing wise. As much as i would love to avoid using micro's seeing as how my only way to program the would be using something i got from my college and may have to give back eventually.
Asking for a friend
 

Offline Gyro

  • Super Contributor
  • ***
  • Posts: 8629
  • Country: gb
Re: 10MHz to 1pps divider
« Reply #11 on: March 29, 2021, 01:02:10 pm »
You can buy picDIVs ready programmed from LeapSecond (the main cost is postage) but I'm sure there must be a fellow member in Ireland who would be willing to burn the Hex code into a PIC12F675 for you.
Best Regards, Chris

"Victor Meldrew, the Crimson Avenger!"
 

Offline sahko123

  • Frequent Contributor
  • **
  • Posts: 314
  • Country: ie
Re: 10MHz to 1pps divider
« Reply #12 on: March 29, 2021, 01:32:53 pm »
someone in my town is selling a pickit3.5 programmer would that work?
Asking for a friend
 

Offline Gyro

  • Super Contributor
  • ***
  • Posts: 8629
  • Country: gb
Re: 10MHz to 1pps divider
« Reply #13 on: March 29, 2021, 04:37:31 pm »
I've just plugged my Pickit 3.5 programmer in and run the standalone Pickit 3 S/W. Yes, the PIC12F675 is included in the supported device list. You'll just need to make up a little matrix board adaptor with a DIP socket for the Pic and 6 way header for the programmer.

Note that the Pickit 3.5 is a clone of the official Microchip Pickit 3, so don't pay more than ebay prices.
Best Regards, Chris

"Victor Meldrew, the Crimson Avenger!"
 

Online magic

  • Super Contributor
  • ***
  • Posts: 5529
  • Country: pl
Re: 10MHz to 1pps divider
« Reply #14 on: March 29, 2021, 06:14:06 pm »
It is a bad idea to sync reference clock to MCU clock... Much better is just to use reference clock as MCU clock directly, like in PicDIV.
I never said to do that ;)
Although I may say that for some applications it wouldn't matter.

so what i can potentially do is use a 10Mhz reference AS the clock input and ensure that an output gives one pulse every 10,000,000 clock cycles that should give a very accurate clock i cant think of a way that can go wrong timing wise. As much as i would love to avoid using micro's seeing as how my only way to program the would be using something i got from my college and may have to give back eventually.
Dunno what your options and resources are, but I would say two things:
- building a frequency counter without MCUs is likely more PITA than dealing with an MCU
- with an MCU it's easy to do reciprocal counting which doesn't require precision 1pps, just a reference clock
- if you don't mind AVR, some Arduino thingy may be self-programmed by USB
 

Offline bingo600

  • Super Contributor
  • ***
  • Posts: 1786
  • Country: dk
Re: 10MHz to 1pps divider
« Reply #15 on: March 29, 2021, 06:30:55 pm »
Ulrich B made a version for an AVR too - An usbasp programmer is cheap


Tiny84 vers
https://www.eevblog.com/forum/projects/divide-by-10000000/msg2815024/#msg2815024

Mega16 & Mega8 vers
http://www.ulrich-bangert.de/html/downloads.html      (Bottom)

/Bingo
 

Offline ve7xen

  • Super Contributor
  • ***
  • Posts: 1138
  • Country: ca
    • VE7XEN Blog
Re: 10MHz to 1pps divider
« Reply #16 on: March 30, 2021, 12:19:18 am »
so what i can potentially do is use a 10Mhz reference AS the clock input and ensure that an output gives one pulse every 10,000,000 clock cycles that should give a very accurate clock i cant think of a way that can go wrong timing wise. As much as i would love to avoid using micro's seeing as how my only way to program the would be using something i got from my college and may have to give back eventually.

Many microcontrollers these days include bootloaders from the factory, some even over USB, so you may not need special hardware at all (either a USB-TTL UART or just a USB cable). You will pay some extra for this, but it's not expensive. For example the controller on the $3 'Black Pill' STM32F401 dev board can be programmed over its USB port. You can also get generic programmers from China for the same price (e.g. STLink or USBasp).

All you need to accomplish your original goal of deriving 1PPS from 10MHz is the timer peripheral of any modern microcontroller, clocked by your external clock source (either via an external clock pin, or via the processor's clock tree), and set up to toggle a compare output every 5M cycles. You can do this with virtually any microcontroller, but the exact mechanics of doing it will depend on the timer peripheral. Setting this up should be just a couple lines of code, after which the controller can go to sleep and let the timer do the work. It feels dumb, but I've done it several times when replicating vintage hardware that used 'unique' crystal frequencies, it's much cheaper/simpler/smaller than the alternatives.

Doing reciprocal counting with the peripheral instead would be nearly as simple, same clock setup (though you may need to handle overflow and avoid prescaling, especially if you don't have 32b timers), and use the input capture peripheral. It would be more work once you figure you have to get the data off the controller somehow.
73 de VE7XEN
He/Him
 

Offline David Hess

  • Super Contributor
  • ***
  • Posts: 15271
  • Country: us
  • DavidH
Re: 10MHz to 1pps divider
« Reply #17 on: March 30, 2021, 03:19:48 am »
would a small micro even be able to count at 10MHz? or do you mean just generate the 1pps with a micro

If the counter/timer unit is not fast enough or not available, then the clock input for the microcontroller can be driven with the 10 MHz input.  After that, it is just instruction cycle counting.
 

Offline sahko123

  • Frequent Contributor
  • **
  • Posts: 314
  • Country: ie
Re: 10MHz to 1pps divider
« Reply #18 on: March 31, 2021, 12:54:50 am »
i will most likely have to go with a reciprocal counting method and find a different way to utilise the VFDs i was planning on using (soviet iv6 vfd displays). Reciprocal would have a faster update rate for use down in the tens or hundreds of mHz which would take 0.01PPS to do with conventional counting which i wanted to do with basic counters and display latches so i could tile it a long.
Asking for a friend
 

Offline jmelson

  • Super Contributor
  • ***
  • Posts: 2607
  • Country: us
Re: 10MHz to 1pps divider
« Reply #19 on: March 31, 2021, 01:16:29 am »
you see i was trying to avoid using a divide-by-N 5 or so times strategy and hoped that there was some ic that does a 10MHz to 1pps division in one package and then just do the final conversion to get 0.1pps or 0.01pps to be able to measure in the mHz.
Well, you could probably do this in a CPLD.  You need to divide by 10 million, or a bit less than 2 ^ 24.  So, some device with at least 24 FFs and enough logic to compare the count against 10 million would do.  If you want a square wave, divide by 5 million, and then go through one final divide by 2.

The Xilinx 9636XL might be able to handle this, or a 9572XL surely could.

Jon
 

Offline Melt-O-Tronic

  • Frequent Contributor
  • **
  • Posts: 254
  • Country: us
  • Brilliant with a slaughtering iron in my hand!
Re: 10MHz to 1pps divider
« Reply #20 on: March 31, 2021, 05:51:30 am »
I've been tinkering with PicDivs for a couple of months.  I've fallen in love.  Now I'm running Allen variance analyses on everything.  I'm currently trying to figure out how to divide the dog by 10^6 so I can measure her stability too.
 

Offline rfclown

  • Frequent Contributor
  • **
  • Posts: 369
  • Country: us
Re: 10MHz to 1pps divider
« Reply #21 on: March 31, 2021, 06:02:47 am »
I followed the links of those that suggested the picDiv. That seems to me the easiest choice since you can buy it programmed. I saw the links of similar AVR solutions. I usually program AVRs in C, but thought I'd try assembler with a attiny85 since I had one already in a breadboard from a long ago abandoned project Put a 10 MHz ocxo on the board. Sine wave out, so I used series R and shunt diode to bring it above ground. Didn't square it up, just ran it in AVR clock input. Fumbled and Googled to see how to do command line avr assembly. I usually do command line gcc C compilation and program with avrdude.  I'm using gcc and avrdude as installed by Arduino. Got 10 Hz output. Didn't take it farther since I don't have an application for this. From reading about the picDiv, I just wanted to try the technique. It's just accounting for instruction steps. Output is solid with input (see pic with persistance). With 10 MHz and 1pps out of a GPSDO the 1pps jumps around the 10 MHz (see pic with persistance).

The code is b.asm. I just made a couple nested loops and added nops even up the numbers. batch files to assemble (j.bat) program (prog.bat) and write fuses (wf.bat). I use a USBisp. I've had good luck with that. You can use it in the Arduino environment by selecting Sketch>Upload Using Programmer so you don't have to use a bootloader. Changed .bat files to .txt

Checked the cost of a attiny25 on Digikey. It's $0.54 for one, but if you buy a reel of 2000 they'll let you have them for only $1.02301 each. What a deal!
https://www.digikey.com/en/products/detail/microchip-technology/ATTINY25-20SHR/3441453
 

Offline MIS42N

  • Frequent Contributor
  • **
  • Posts: 446
  • Country: au
Re: 10MHz to 1pps divider
« Reply #22 on: March 31, 2021, 10:42:30 am »
I am a fan of using the hardware timers for the sort of counting you are doing. E.g. you could set up timer 0 with a prescale of 8 and count to 124 (or is it 125, I would need to read the specs again), then auto reset and interrupt. You would get an interrupt every 100us, then in the interrupt routine (ISR) use SBIW to subtract 1 from a register pair (effectively a 16 bit counter) preloaded with what ever count you want - e.g. for 10Hz out you would start with 500. On software count = 0 invert output and reload software count. It requires a bit of setting up, but the logic is much clearer than nested loops with delays. And much easier to modify - you could add a second output in the ISR just by adding another load/test/invert bit of code, no change to the 100us loop, no working out nop delays. After setting up the counter and enabling interrupts the mainline just spins on a RJMP *-1 (jump to itself). I didn't set up a program to test this, but I'd take a bet there's less instructions needed.

Just putting this as an alternate. Does require more knowledge of the processor. If you master the ATMEL timers, PIC timers are easy.

It's a while since I did any ATMEL programs, so this is rough and may be wrong

SETUP
set Waveform Generation Mode = CTC
set OCRA = 124
set Clock Select = prescale 8
set Timer/Counter0 Output Compare Match A Interrupt Enable
LDI R16,low(500)
LDI R17,high(500)
enable interrupts
spin
 

ISR - since there is only one enabled interrupt, could code this at address 0x0003
Code: [Select]
SBIW R16,1
BRNE gobak
LDI R16,low(500)
LDI R17,high(500)
SBI pin
gobak: RETI
 

Offline rfclown

  • Frequent Contributor
  • **
  • Posts: 369
  • Country: us
Re: 10MHz to 1pps divider
« Reply #23 on: March 31, 2021, 02:00:01 pm »
Something I learned trying AVR assembly:

before Googling and finding the right answer, I just looked for the assembler in the Arduino tool chain, and found avr-as. So to assemble a file named b.asm, I did:

*** DON'T DO THIS *** IT DOESN"T WORK ***
avr-as --warn b.asm -mmcu=attiny85 -o b.o
avr-objcopy -O ihex b.o b.hex

it produced a hex file, but it turns out the reference labels weren't resolved. I thought that the "--warn" would warn me of things like this... NOT. Turns out you need to use gcc, but say it's assembler, so it can link and resolve references like this:

DO THIS
avr-gcc -c -mmcu=attiny85 -x assembler b.asm -o b.o
avr-gcc -mmcu=attiny85 b.o -o b.elf -nostartfiles
avr-objcopy -O ihex b.elf b.hex

This is on a Windows machine using the stuff installed with Arduino IDE. This will work on the command line as long as the path is set:

PATH=C:\Program Files (x86)\Arduino\hardware\tools\avr\bin;%PATH%

when I boil things down to the simple essentials like this, I find that I can go back years later and remember how to do it again. I started on this path because when I saw the picDiv, I found myself looking at PicKits on eBay (I started with PICs in the 90's). But when I thought about the bank switching stuff, I decided to fight the urge to buy and just grabbed what I had lying around.
 

Offline bingo600

  • Super Contributor
  • ***
  • Posts: 1786
  • Country: dk
Re: 10MHz to 1pps divider
« Reply #24 on: March 31, 2021, 06:50:39 pm »
I am a fan of using the hardware timers for the sort of counting you are doing. E.g. you could set up timer 0 with a prescale of 8 and count to 124 (or is it 125, I would need to read the specs again), then auto reset and interrupt. You would get an interrupt every 100us,

Your solution would never pass a real time-nut.
The AVR ISR is not deterministic , and would produce "unacceptable 1-PPS jitter".

Have a look at TVB or Ulrichs programs , and notice no interrupts are used , all is done w. pure instruction timing.

If you have Glitch free 32bit timers like on the larger ARM's you might get away with a CTC , but NO using of the PLL ... Jitter

/Bingo
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf