When is an NCO peripheral better than a timer? - Page 1
Forum section: electronics / general

author: igendel
author_rank: Frequent Contributor
timestamp: April 23, 2020, 10:41:15 am
content: Hi all,I recently got a PIC18F57Q43 evaluation board, and started checking out the MCU's peripherals. Never worked with an NCO before, and from reading about it, I can't figure out in what scenarios it would be more useful than a regular modern timer. There are some usage examples around the web, but those I've seen so far kind of turn a blind eye to the critical point.The NCO introduces jitter in the output frequency; and between the jitter events, the output frequency is not exactly the one we want (otherwise the jitter would not be necessary in the first place). So in what kind of application is it still useful? I can see where an 8-bit timer with a significant prescaler will struggle in terms of resolution, but we have 16-bit timers now, which is not so far from the NCO's 20 bits.Of course there are some increment values where the output frequency is accurate and jitter-free; I found 1023 of those for a 16MHz source clock. So yes, if I happen to require a 156.250KHz square wave the NCO isexactlywhat I need...but as a general solution? What am I missing? Apart from being a bit easier to set up, can anyone give me a real-world example where the NCO is superior?Thanks,

author: tszaboo
author_rank: Super Contributor
timestamp: April 23, 2020, 12:16:14 pm
content: Timer will create interrupts, interrupt latency varies, depending what the MCU is doing. Maybe you dont want to have your timer as the highest priority interrupt.Its the same question, like asking why have an UART port, if you can just bit-bang everything.

author: igendel
author_rank: Frequent Contributor
timestamp: April 23, 2020, 12:38:34 pm
content: Quote from: NANDBlog on April 23, 2020, 12:16:14 pmOk, I think I might have mixed up the PIC timers with AVR timers that can have direct access to GPIO pins.Still, within a modern PIC, the timer output can be connected to a CLC or a CCP and from there to an output pin, "core independent". And, on the other side of the coin, the NCO has an interrupt too should you wish to use it...

author: hli
author_rank: Frequent Contributor
timestamp: April 23, 2020, 07:35:40 pm
content: Try to create an exact 3MHz clock from a 16MHz crystal, using a timer. Thats what the NCO is for ("0.0001% step size of source clock input frequency" it says athttps://www.microchip.com/design-centers/8-bit/peripherals/core-independent/numerically-controlled-oscillator).

author: igendel
author_rank: Frequent Contributor
timestamp: April 23, 2020, 07:49:41 pm
content: Quote from: hli on April 23, 2020, 07:35:40 pmIt must be a happy coincidence for Microchip then, that 3MHz just happens to be one of the 1023 jitter-free options I mentioned earlier(So is every other multiple of 15625 up to 16MHz, by the way)But what if I need some other frequency?

author: langwadt
author_rank: Super Contributor
timestamp: April 23, 2020, 08:13:31 pm
content: Quote from: igendel on April 23, 2020, 07:49:41 pmthen you can get that on average over time almost exactly. Another case would be a software PLL

author: Picuino
author_rank: Super Contributor
timestamp: April 23, 2020, 08:33:45 pm
content: NCO is easier to program. It has linear response. Higher values, higher frequency in linear steps.Timer is not linear. It has 1/x response, more accurate at lower frequencies and less accurate at higher frequencies.If you want to make a precise frequency sweep, NCO is the solution.

author: igendel
author_rank: Frequent Contributor
timestamp: April 23, 2020, 09:20:53 pm
content: Quote from: langwadt on April 23, 2020, 08:13:31 pmYes, and that's my question - in what real-world scenarios will I need a correct average over time, and not care about jitter?Regarding PLLs, I don't "see it" yet - with the inaccuracies and jitter, can we really guarantee a locked phase?Quote from: Picuino on April 23, 2020, 08:33:45 pmEasier to program - definitely, but that's a design decision - they could just as well put a 32-bit timer with minimal options, like a TMR0 on steroids, and it'll be simpler.And again, it's more linear and accurate if you average over a long time, but you can't guarantee the duration of any particular cycle (in fact, in most cases you can be sure it will *not* be the exact duration you wanted)...

author: Picuino
author_rank: Super Contributor
timestamp: April 23, 2020, 09:51:04 pm
content: Little jitter is the price to pay for obtaining exact frequencies impossible to obtain with Timers.In the frequency domain the signal is very pure.

author: igendel
author_rank: Frequent Contributor
timestamp: April 23, 2020, 10:07:03 pm
content: Quote from: Picuino on April 23, 2020, 09:51:04 pmBut... isn't the NCO jitter there preciselybecausethe output frequency is inaccurate? If I understand correctly, the small error in each and every cycle is accumulated until there's enough for a "leap cycle", kind of like a February 29th except in the other direction[Edit: No, that's actually the same direction as in a leap year, isn't it?]

author: Picuino
author_rank: Super Contributor
timestamp: April 23, 2020, 10:17:58 pm
content: The frequency is accurate, the phase is not accurate.An example of application. You can replace the timer in high frequency PWM applications. Timers are very imprecise at high frequencies and NCO can make a very precisepulse frequency modulation. It doesn't matter a bit of jitter in the power supply.Edit:https://www.digikey.com/en/articles/the-advantages-of-pulse-frequency-modulation-for-dc-dc-switching-voltage-converters

author: langwadt
author_rank: Super Contributor
timestamp: April 23, 2020, 10:22:11 pm
content: Quote from: igendel on April 23, 2020, 10:07:03 pmthe frequency is accurate over time. Like with leap years, the "jitter" on the number of days in a year means over time there is exactly one calender year per actual yearbefore the pope came up with the calender with leap days, the calender slowly drifted and a summer month would slowly become a winter month

author: igendel
author_rank: Frequent Contributor
timestamp: April 23, 2020, 10:32:20 pm
content: Quote from: langwadt on April 23, 2020, 10:22:11 pmExactly. So what would be an embedded-world equivalent application?

author: igendel
author_rank: Frequent Contributor
timestamp: April 23, 2020, 10:39:16 pm
content: Quote from: Picuino on April 23, 2020, 10:17:58 pmOh! I Answered the other reply before I saw this. Ok, if you're feeding a capacitor or inductor at a high enough frequency, I guess the individual peak-to-peak timing is not that important. Never designed a switching converterThanks, and I'll be happy to hear more ideas.

author: Picuino
author_rank: Super Contributor
timestamp: April 23, 2020, 10:40:03 pm
content: Other application generating sine wave signals:http://ww1.microchip.com/downloads/cn/appnotes/cn561389.pdf

author: igendel
author_rank: Frequent Contributor
timestamp: April 23, 2020, 10:57:23 pm
content: Quote from: Picuino on April 23, 2020, 10:40:03 pmThat, I still don't understand. They add 0x84 (132 dec) to the accumulator each time, according to the fNCO formula that's 2014.16, divide by 2 it's 1007.08Hz, so how did they get such a clean 1.00000000KHz signal? Did they tweak the internal oscillator when no one was looking?

author: langwadt
author_rank: Super Contributor
timestamp: April 23, 2020, 11:20:55 pm
content: Quote from: igendel on April 23, 2020, 10:57:23 pmpossibly,wonder why they used 132 (1007.08Hz) instead of 131 (999.45Hz)

author: PCB.Wiz
author_rank: Super Contributor
timestamp: April 24, 2020, 03:55:01 am
content: Quote from: igendel on April 23, 2020, 10:57:23 pmI suspect they did not geta clean 1.00000000KHz signal, that's merely a marker location.There are no frequency counter readings given.

author: igendel
author_rank: Frequent Contributor
timestamp: April 24, 2020, 08:12:06 am
content: Quote from: PCB.Wiz on April 24, 2020, 03:55:01 amYou're right. The perfect 1KHz frequency is just implied all over the place

author: mark03
author_rank: Frequent Contributor
timestamp: April 24, 2020, 08:21:27 pm
content: Arbitrary frequency square-wave synthesis is a difficult problem. The topic comes up here every once in a while and there are always several correspondents who say things like "just use an NCO" without realizing the limitations. The Microchip NCO sounds interesting; it would be fun to see a better description of how it works. Presumably there is a PLL involved?Otherwise, for square-wave synthesis with anything approaching "reasonable" levels of jitter you have basically two options: (1) analog, e.g. a sine-wave DDS followed by a comparator, or (2) digital black magic, like continuously calibrated delay lines, the sort of thing the experts over at the Xilinx forums tell you not to attempt in an FPGA.

author: PCB.Wiz
author_rank: Super Contributor
timestamp: April 26, 2020, 03:36:55 am
content: Quote from: mark03 on April 24, 2020, 08:21:27 pmThe link in #14 has a diagram, It has no PLL just a 20b adder from sysclk.So it has jitter no better than 1/sysclk - for many uses, that is going to be 'good enough'.Quote from: mark03 on April 24, 2020, 08:21:27 pmYes, and even (1) needs a filter after the Sine DAC, to remove the DAC steps, to give a better sine into the comparator.These days, there are silicon synth devices that can give reasonable results.Here is a table I did of Silabs Oscillators, useful when on-mcu NCO is not good enough.Notice the general price/spec trend - the higher the VCO, the better the jitter, but at the cost of Icc and price.~~~~~~~~~~~~~~~~ SiLabs i2c Oscillators ~~~~~~~~~~~~~~~~~~~~Device SpeedGrade Xtal Out(MHz.CMOS) MinFvco(GHz) MaxFvco(GHz) Icc JitterSi564.A 152.6 0.2~3000 10.8 13.122222222 87mA CMOS 95fs RMS Product Revision (B)Si549.A 152.6 0.2~1500 10.8 12.511886114 87mA CMOS 95fs RMSSi549.B 152.6 0.2~800 10.8 12.206718160 87mA CMOS 95fs RMSSi549.C 152.6 0.2~325 10.8 12.206718160 87mA CMOS 95fs RMS $25/1+ ( >$8.36/10k )Si544.A 55.05 0.2~1500 10.8 12.550082103 74mA CMOS 150fs RMS Si544: 1: $20.38 @ Mouser, 5 part codes.Si544.B 55.05 0.2~800 10.8 12.109728345 74mA CMOS 150fs RMS ( >$6.69/10k )Si544.C 55.05 0.2~325 10.8 12.109728345 74mA CMOS 150fs RMSSi570 114.28 10~160M 4.850 5.670 90mA CMOS 0.62pstyp >$12/1 ONLY in 5x7 packageSi599 39.17 10~810 4.85 5.67 90mA CMOS 0.7ps CML; CMOS; LVDS; LVPECL 3.2x5; 5x7 Single $5.2884Si514 31.98MHz 0.1~250M 2.080 2.500 21mA CMOS 0.8ps DK : $7.53/1 (10MHz.3v3 & 24M.1v8) >$2.71/10k ($5.27/1k+) 5x7, 5x3.2, 2.5x3.2 sizes (Max 2.5G/10)Si5351A.QFN20 25~27 0.002~200 0.6 0.9 22mA CMOS ~40ps pp ~$1.82c/1k SI5351A-B-GM (QFN20 has lower jitter spec)Si5351A.MSOP10 25~27 0.002~200 0.6 0.9 22mA CMOS ~70ps pp ~85c/1k MSOP10

author: Picuino
author_rank: Super Contributor
timestamp: April 27, 2020, 07:48:36 am
content: Good table.Is what I was looking for to test a frequency counter:Code:Device SpeedGrade Xtal Out(MHz.CMOS) MinFvco(GHz) MaxFvco(GHz) Icc JitterSi564.A 152.6 0.2~3000 10.8 13.122222222 87mA CMOS 95fs RMS Product Revision (B)Si549.A 152.6 0.2~1500 10.8 12.511886114 87mA CMOS 95fs RMSSi549.B 152.6 0.2~800 10.8 12.206718160 87mA CMOS 95fs RMSSi544.A 55.05 0.2~1500 10.8 12.550082103 74mA CMOS 150fs RMS Si544: 1: $20.38 @ Mouser, 5 part codes.Si544.B 55.05 0.2~800 10.8 12.109728345 74mA CMOS 150fs RMS ( >$6.69/10k )

author: Ground_Loop
author_rank: Frequent Contributor
timestamp: May 06, 2020, 02:47:51 am
content: I used the NCO as a analog driven clock source to a switched capacitor filter as part of an analog synth module. Easy to program and linear response to register settings.

author: fourfathom
author_rank: Super Contributor
timestamp: May 06, 2020, 04:28:15 am
content: I've used NCOs for lots of telecom designs. The jitter P-P (time) amplitude depends on the NCO clock frequency and the jitter spectral content (phase modulation) depends on the division ratios. While you can use the full output word and feed it into a D/A converter and filter, you can often take the MSbit output and run it through a simple L/C filter, or sometimes a SAW filter, or occasionally an inexpensive PLL, and reduce the jitter to extremely low levels. There are many types of NCOs, including arbitrary fraction types.In my telecom applications, I often needed to synchronize multiple clocks, with mechanisms for carrying asynchronous data on a synchronous channel, and sometimes regenerating the asynchronous clock at the other end. Legacy telecom networks seem to like using prime number-related clocks, so simple dividers just won't do the job. NCOs and their relatives can provide the required precision, stability and flexibility, and can do it at a much lower cost and smaller footprint than the traditional VCXO PLL designs.

author: igendel
author_rank: Frequent Contributor
timestamp: May 08, 2020, 10:20:57 am
content: Quote from: fourfathom on May 06, 2020, 04:28:15 amThanks for the information, but I'm either missing something or it's not relevant to NCO modules in microcontrollers - there's no "output word", just the final output signal...?

author: langwadt
author_rank: Super Contributor
timestamp: May 08, 2020, 12:56:30 pm
content: Quote from: igendel on May 08, 2020, 10:20:57 amand that output is the MSB