EE 461 - Section 4a Numerically Controlled Oscillators EE 461 Section 4a - Numerically Controlled Oscillators 1 Numerically Controlled Oscillators • Principle of Operation: ݂ Frequency Control Phase Generator clk ߮݊ L.U.T. cos 2ߨ߮ ݊ ݂ ݊ ݊ݕ Output Phase in Cycles L.U.T. = Look Up Table = cos 2 EE 461 = cos 2 Section 4a - Numerically Controlled Oscillators 2 1 Phase Generator ߮݊ Phase Accumulator Units cycles ߮ ݊−1 ߮ ݊ = ߮ 0 + ݂݊ ∑ sample ݂ cycles/sample (Frequency control, units cycles/sample) clk = − 1 + = 0 + EE 461 Section 4a - Numerically Controlled Oscillators 3 Frequency Control • set the frequency of the output sinusoid • It has units cycles/sample • Can be at most cycles/sample • It makes no sense for to be negative 1 cycles 0 ≤ ≤ 2 sample EE 461 Section 4a - Numerically Controlled Oscillators 4 2 Frequency Control (cont.) Suppose 0 = 0 and = Then = = Could wrap to 0 when ߮ ݊ = 1 cycle 1 ߮݊ cycles 1 2 0 4 8 12 ݊→ Note: cos 2 = cos 2 mod1 Therefore could wrap to 0 when it reaches 1 EE 461 Section 4a - Numerically Controlled Oscillators 5 Frequency Control (cont.) For the general case: Slope = ݂ 1 ߮ ݊ mod 1 in cycles 1 2 0 4 8 ݊→ 12 To find the slope use 0 and 11 since they are round numbers, 0 = 0 and 11 = 2cycles = = EE 461 Section 4a - Numerically Controlled Oscillators = 6 3 Example 4.1 A phase accumulator has input = cycles per sample What is the average time (measured in samples) between rollovers? The question is how many sample times does it take for the accumulator to get from 0 to 1 cycle? Answer: = య ౙ౯ౙౢ౩ భల ౩ౣ౦ౢ EE 461 = Section 4a - Numerically Controlled Oscillators 7 Frequency Resolution • The phase, , starts at zero and increases with so will always be positive • This means it can be represented by an unsigned binary number • Since the phase is an input to a cosine function, when is in units cycles, only the fraction portion is used • For example: = 1.25cycles cos 2 radians × 1.25cycles = cos 2radians + 2 0.25 radians cycle cos 2 0.25 radians EE 461 Section 4a - Numerically Controlled Oscillators 8 4 Frequency Resolution (cont.) • This means the phase accumulator holds a binary number that is greater than or equal to zero and less than one: • The contents of the phase accumulator should be treated as an unsigned fraction • Suppose the phase accumulator is bits in length and its contents are treated as an unsigned fraction: ேೝ ିଵ − 1 = ୀ Phase Accumulator ܾ 1 2 binary point EE 461 ܾଵ 1 2 ାଵ ேೝ ିଵ = 2ିଵ 2ି ୀ ⋯ ܾଶ ܾேೝ ିଶ ܾேೝ ିଵ 1 2 1 4 ேೝ Section 4a - Numerically Controlled Oscillators 9 Frequency Resolution (cont.) ߮݊ Phase Accumulator ߮ ݊−1 ܰ + ܰ ߮݊ ∑ + ܰ ݂ The carry-out for this added is ignored clk • − 1 and are bit unsigned fractions • The carry-out of the adder is the integer bit which has value 1 cycle and so can be dropped EE 461 Section 4a - Numerically Controlled Oscillators 10 5 Frequency Resolution (cont.) • The allowable frequencies are those that can be represented with an bit unsigned fraction • The frequency resolution is EE 461 ࡺ࢘ cycles / sample Section 4a - Numerically Controlled Oscillators 11 Example 4.2 Consider a phase generator with = 4 bits and = .0011binary = decimal: EE 461 Sample Number Accumulator − Adder Output 1 .0000 .0011 or 3⁄16 2 .0011 .0110 or 6⁄16 3 .0110 .1001 or 9⁄16 4 .1001 .1100 or 12⁄16 5 .1100 .1111 or 15⁄16 6 .1111 .0010 or 2⁄16 7 .0010 .0101 or 5⁄16 Section 4a - Numerically Controlled Oscillators carry out dropped 12 6 Sizing the Phase Accumulator • If the phase accumulator has bits, then the available frequencies are: • ಿೝ , = 0,1, ⋯ , ಿೝ • The steps in frequency are: • ಿೝ • The step size is referred to as the frequency resolution • There are applications where the NCO must be frequency agile (frequency of operation is not known in advance) • The are applications where the frequency of operation is fixed and known in advance EE 461 Section 4a - Numerically Controlled Oscillators 13 Sizing the Phase Accumulator (cont.) • The tolerance of a frequency agile NCO is specified by the maximum error, i.e. desired frequency ± the error: • ݂ ± ∆݂ • Normally the application specification will indicate that an NCO is required that can be set to any frequency within a tolerance of ∆ • From this, the engineer needs to calculate the minimum length for the phase accumulator • If the frequency step size is less than 2∆, then can be set to a value that is at most ∆ away from EE 461 Section 4a - Numerically Controlled Oscillators 14 7 Sizing the Phase Accumulator (cont.) Step Size ݇ 2ேೝ ଵ ଶಿೝ ݂ ଵ ଶ Less than the step size ݇+1 2ேೝ ݇+2 2ேೝ Frequencies available from NCO • If is as shown above, then should be chosen ಿೝ • Then will be slightly higher than • The difference between and is at most ಿೝ : − ≤ EE 461 1 1 2 2ேೝ Section 4a - Numerically Controlled Oscillators 15 Sizing the Phase Accumulator (cont.) • The specification says that: − < ∆ • We know that: − ≤ 1 1 2 2ேೝ • Therefore: 1 1 < ∆ 2 2ேೝ 1 < 2ேೝ 2∆ 1 log < log 2 2∆ −log 2∆ > log 2 EE 461 Section 4a - Numerically Controlled Oscillators 16 8 Example 4.3 • An analog sinusoid is synthesized by sending the output of an NCO to a DAC • The application requires a frequency agile NCO whose frequency can be set to an accurate of ±0.05Hz • The sampling rate of the DAC is = 100MHz • Find the minimum length for the phase accumulator EE 461 Section 4a - Numerically Controlled Oscillators 17 Example 4.3 Solution ∆ = = ∆ 0.05cycles/second 100 × 10 samples/second = 5 × 10 cycles sample −log 2∆ −log(2 × 5 × 10 ) > = log 2 log(2) > 29.9 Therefore the minimum value for is 30 EE 461 Section 4a - Numerically Controlled Oscillators 18 9 ܰ for a Fixed Frequency Application • The frequency for the NCO is known in advance • Finding the minimum is a two step process: • First step identical to frequency agile application: • > ି୪୭ ଶ∆ ୪୭ ଶ • Second step: • Find the bit unsigned fraction for is within ±∆ of • Then look at the least significant bit of • If it is zero, we do not need it, so we can shorten the accumulator • We can remove as many of the least significant bits (that are zero) as possible EE 461 Section 4a - Numerically Controlled Oscillators 19 ܰ for a Fixed Frequency Application (cont.) • Start by expressing the unsigned fraction by: • ݂ = , ଶಿ ೝ where ݇ is a positive integer • We want to find such that: ≈ 2ேೝ ≈ 2ேೝ • Since is an integer, the best to use is: ݇ = round ݂ 2ேೝ • can be converted to binary and lowest bits checked for zero • Alternately, if is evenly divisible by 2, it is a binary number with least significant bit of zero: • The number of times ݇ can be evenly divided by 2 determines the number of zeros (bits) that can be removed EE 461 Section 4a - Numerically Controlled Oscillators 20 10 Example 4.4 • An application requires a fixed frequency sinusoid = 13,969,838.57Hz ± 0.01Hz • The sinusoid is generated by an NCO and a DAC that is driven at a sampling rate of 100 MHz • Find the minimum length for the phase accumulator EE 461 Section 4a - Numerically Controlled Oscillators 21 Example 4.4 Solution First Step: −log 2∆ = > log 2 > 32.2 −log 2 0.01 10଼ log 2 Therefore use = 33 Second Step: = round 2ேೝ = round = 1,199,999,996 ே 13,969,838.57 2 ೝ = round × 2ଷଷ ௦ 10଼ is evenly divisible by 2, = 599,999,998 ଶ ସ is evenly divisible by 4, = 299,999,999 is not evenly divisible by 8 EE 461 Section 4a - Numerically Controlled Oscillators 22 11 Example 4.4 Solution (cont.) Since is evenly divisible by 4, the binary unsigned fraction will end in two zeroes which are not needed and can be removed The minimum = 33 − 2 = 31 Check: = = 1,199,999,996 2ଷଷ 1000111100001101000101111111100 2ଷଷ = .001000111100001101000101111111100 Can use = .0010001111000011010001011111111 (31 bits) EE 461 Section 4a - Numerically Controlled Oscillators 23 12