Author Topic: When is an NCO peripheral better than a timer?  (Read 3932 times)

0 Members and 1 Guest are viewing this topic.

Offline igendelTopic starter

  • Frequent Contributor
  • **
  • Posts: 359
  • Country: il
    • It's Every Bit For Itself (Programming & MCU blog)
When is an NCO peripheral better than a timer?
« on: April 23, 2020, 10:41:15 am »
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 is exactly what 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,
Maker projects, tutorials etc. on my Youtube channel: https://www.youtube.com/user/idogendel/
 
The following users thanked this post: Jacon

Offline tszaboo

  • Super Contributor
  • ***
  • Posts: 7392
  • Country: nl
  • Current job: ATEX product design
Re: When is an NCO peripheral better than a timer?
« Reply #1 on: April 23, 2020, 12:16:14 pm »
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.
 

Offline igendelTopic starter

  • Frequent Contributor
  • **
  • Posts: 359
  • Country: il
    • It's Every Bit For Itself (Programming & MCU blog)
Re: When is an NCO peripheral better than a timer?
« Reply #2 on: April 23, 2020, 12:38:34 pm »
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.

Ok, 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...
« Last Edit: April 23, 2020, 04:58:18 pm by igendel »
Maker projects, tutorials etc. on my Youtube channel: https://www.youtube.com/user/idogendel/
 

Offline hli

  • Frequent Contributor
  • **
  • Posts: 255
  • Country: de
Re: When is an NCO peripheral better than a timer?
« Reply #3 on: April 23, 2020, 07:35:40 pm »
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 at https://www.microchip.com/design-centers/8-bit/peripherals/core-independent/numerically-controlled-oscillator).
 

Offline igendelTopic starter

  • Frequent Contributor
  • **
  • Posts: 359
  • Country: il
    • It's Every Bit For Itself (Programming & MCU blog)
Re: When is an NCO peripheral better than a timer?
« Reply #4 on: April 23, 2020, 07:49:41 pm »
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 at https://www.microchip.com/design-centers/8-bit/peripherals/core-independent/numerically-controlled-oscillator).

It 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?
Maker projects, tutorials etc. on my Youtube channel: https://www.youtube.com/user/idogendel/
 

Offline langwadt

  • Super Contributor
  • ***
  • Posts: 4427
  • Country: dk
Re: When is an NCO peripheral better than a timer?
« Reply #5 on: April 23, 2020, 08:13:31 pm »
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 at https://www.microchip.com/design-centers/8-bit/peripherals/core-independent/numerically-controlled-oscillator).

It 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?

then you can get that on average over time almost exactly. Another case would be a software PLL

 

Offline Picuino

  • Frequent Contributor
  • **
  • Posts: 730
  • Country: 00
    • Picuino web
Re: When is an NCO peripheral better than a timer?
« Reply #6 on: April 23, 2020, 08:33:45 pm »
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.
 

Offline igendelTopic starter

  • Frequent Contributor
  • **
  • Posts: 359
  • Country: il
    • It's Every Bit For Itself (Programming & MCU blog)
Re: When is an NCO peripheral better than a timer?
« Reply #7 on: April 23, 2020, 09:20:53 pm »
then you can get that on average over time almost exactly

Yes, 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?

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.

Easier 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)...
Maker projects, tutorials etc. on my Youtube channel: https://www.youtube.com/user/idogendel/
 

Offline Picuino

  • Frequent Contributor
  • **
  • Posts: 730
  • Country: 00
    • Picuino web
Re: When is an NCO peripheral better than a timer?
« Reply #8 on: April 23, 2020, 09:51:04 pm »
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.
 

Offline igendelTopic starter

  • Frequent Contributor
  • **
  • Posts: 359
  • Country: il
    • It's Every Bit For Itself (Programming & MCU blog)
Re: When is an NCO peripheral better than a timer?
« Reply #9 on: April 23, 2020, 10:07:03 pm »
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.

But... isn't the NCO jitter there precisely because the 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?]
« Last Edit: April 23, 2020, 10:14:29 pm by igendel »
Maker projects, tutorials etc. on my Youtube channel: https://www.youtube.com/user/idogendel/
 

Offline Picuino

  • Frequent Contributor
  • **
  • Posts: 730
  • Country: 00
    • Picuino web
Re: When is an NCO peripheral better than a timer?
« Reply #10 on: April 23, 2020, 10:17:58 pm »
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 precise pulse 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
« Last Edit: April 23, 2020, 10:30:40 pm by Picuino »
 
The following users thanked this post: igendel

Offline langwadt

  • Super Contributor
  • ***
  • Posts: 4427
  • Country: dk
Re: When is an NCO peripheral better than a timer?
« Reply #11 on: April 23, 2020, 10:22:11 pm »
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.

But... isn't the NCO jitter there precisely because the 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  :)

the 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 year

before the pope came up with the calender with leap days, the calender slowly drifted and a summer month would slowly become a winter month


 

Offline igendelTopic starter

  • Frequent Contributor
  • **
  • Posts: 359
  • Country: il
    • It's Every Bit For Itself (Programming & MCU blog)
Re: When is an NCO peripheral better than a timer?
« Reply #12 on: April 23, 2020, 10:32:20 pm »
the 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 year

before the pope came up with the calender with leap days, the calender slowly drifted and a summer month would slowly become a winter month

Exactly. So what would be an embedded-world equivalent application?
Maker projects, tutorials etc. on my Youtube channel: https://www.youtube.com/user/idogendel/
 

Offline igendelTopic starter

  • Frequent Contributor
  • **
  • Posts: 359
  • Country: il
    • It's Every Bit For Itself (Programming & MCU blog)
Re: When is an NCO peripheral better than a timer?
« Reply #13 on: April 23, 2020, 10:39:16 pm »
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 precise pulse 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

Oh! 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 converter :)  Thanks, and I'll be happy to hear more ideas.
Maker projects, tutorials etc. on my Youtube channel: https://www.youtube.com/user/idogendel/
 

Offline Picuino

  • Frequent Contributor
  • **
  • Posts: 730
  • Country: 00
    • Picuino web
Re: When is an NCO peripheral better than a timer?
« Reply #14 on: April 23, 2020, 10:40:03 pm »
Other application generating sine wave signals:
http://ww1.microchip.com/downloads/cn/appnotes/cn561389.pdf
 

Offline igendelTopic starter

  • Frequent Contributor
  • **
  • Posts: 359
  • Country: il
    • It's Every Bit For Itself (Programming & MCU blog)
Re: When is an NCO peripheral better than a timer?
« Reply #15 on: April 23, 2020, 10:57:23 pm »
Other application generating sine wave signals:
http://ww1.microchip.com/downloads/cn/appnotes/cn561389.pdf

That, 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?  ;)
Maker projects, tutorials etc. on my Youtube channel: https://www.youtube.com/user/idogendel/
 

Offline langwadt

  • Super Contributor
  • ***
  • Posts: 4427
  • Country: dk
Re: When is an NCO peripheral better than a timer?
« Reply #16 on: April 23, 2020, 11:20:55 pm »
Other application generating sine wave signals:
http://ww1.microchip.com/downloads/cn/appnotes/cn561389.pdf

That, 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?  ;)

possibly,

wonder why they used 132 (1007.08Hz) instead of 131 (999.45Hz)



 

Online PCB.Wiz

  • Super Contributor
  • ***
  • Posts: 1548
  • Country: au
Re: When is an NCO peripheral better than a timer?
« Reply #17 on: April 24, 2020, 03:55:01 am »
... it's 1007.08Hz, so how did they get such a clean 1.00000000KHz signal?
I suspect they did not get a clean 1.00000000KHz signal, that's merely a marker location.
There are no frequency counter readings given.
 

Offline igendelTopic starter

  • Frequent Contributor
  • **
  • Posts: 359
  • Country: il
    • It's Every Bit For Itself (Programming & MCU blog)
Re: When is an NCO peripheral better than a timer?
« Reply #18 on: April 24, 2020, 08:12:06 am »
I suspect they did not get a clean 1.00000000KHz signal, that's merely a marker location.
There are no frequency counter readings given.

You're right. The perfect 1KHz frequency is just implied all over the place  :)
Maker projects, tutorials etc. on my Youtube channel: https://www.youtube.com/user/idogendel/
 

Offline mark03

  • Frequent Contributor
  • **
  • Posts: 711
  • Country: us
Re: When is an NCO peripheral better than a timer?
« Reply #19 on: April 24, 2020, 08:21:27 pm »
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.
 
The following users thanked this post: igendel

Online PCB.Wiz

  • Super Contributor
  • ***
  • Posts: 1548
  • Country: au
Re: When is an NCO peripheral better than a timer?
« Reply #20 on: April 26, 2020, 03:36:55 am »
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?

The 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'.

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.
Yes, 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         Jitter
 Si564.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 RMS
 Si549.B         152.6    0.2~800      10.8            12.206718160    87mA CMOS   95fs RMS
 Si549.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 RMS   
 Si570           114.28   10~160M      4.850           5.670           90mA CMOS   0.62pstyp   >$12/1  ONLY in 5x7 package
 Si599            39.17   10~810       4.85            5.67            90mA CMOS   0.7ps       CML; CMOS; LVDS; LVPECL   3.2x5; 5x7           Single     $5.2884
 Si514           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

« Last Edit: April 26, 2020, 03:40:02 am by PCB.Wiz »
 

Offline Picuino

  • Frequent Contributor
  • **
  • Posts: 730
  • Country: 00
    • Picuino web
Re: When is an NCO peripheral better than a timer?
« Reply #21 on: April 27, 2020, 07:48:36 am »
Good table.

Is what I was looking for to test a frequency counter:

Code: [Select]
  Device SpeedGrade Xtal    Out(MHz.CMOS) MinFvco(GHz)    MaxFvco(GHz)   Icc         Jitter
 Si564.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 RMS
 Si549.B         152.6    0.2~800      10.8            12.206718160    87mA CMOS   95fs RMS
 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 )
 

Offline Ground_Loop

  • Frequent Contributor
  • **
  • Posts: 645
  • Country: us
Re: When is an NCO peripheral better than a timer?
« Reply #22 on: May 06, 2020, 02:47:51 am »
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.
There's no point getting old if you don't have stories.
 

Offline fourfathom

  • Super Contributor
  • ***
  • Posts: 1884
  • Country: us
Re: When is an NCO peripheral better than a timer?
« Reply #23 on: May 06, 2020, 04:28:15 am »
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.
We'll search out every place a sick, twisted, solitary misfit might run to! -- I'll start with Radio Shack.
 

Offline igendelTopic starter

  • Frequent Contributor
  • **
  • Posts: 359
  • Country: il
    • It's Every Bit For Itself (Programming & MCU blog)
Re: When is an NCO peripheral better than a timer?
« Reply #24 on: May 08, 2020, 10:20:57 am »
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

Thanks 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...?
Maker projects, tutorials etc. on my Youtube channel: https://www.youtube.com/user/idogendel/
 

Offline langwadt

  • Super Contributor
  • ***
  • Posts: 4427
  • Country: dk
Re: When is an NCO peripheral better than a timer?
« Reply #25 on: May 08, 2020, 12:56:30 pm »
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

Thanks 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...?

and that output is the MSB
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf