Forum Discussion
Altera_Forum
Honored Contributor
14 years agoIts possible to generate something close to these frequencies using a 50MHz oscillator (I assume that is what the DE0 has).
The standard way of generating slower output clocks is to divide the clock using a counter, eg. 50MHz/4kHz = 12500, so use a down counter loaded with 12499, and use the carry-out as a 4kHz pulse. If you want a 4kHz square wave, then load a downcounter with 12500/2 - 1 = 6249, and use the carry-out to toggle a signal. The other frequencies are not simple divisions. So in that case, you can implement something analogous to a numerically controlled oscillator. The NCO is clocked at 50MHz. Note that this NCO generates a square-wave output, rather than a sinusoid; there is no sine ROM, you use accumulator output directly. Its the analogy with an NCO that helps you understand this technique. For example, for 3.372MHz, the frequency tuning word is 50MHz/3.372MHz = 14.873, i.e., for every 50MHz clock, the NCO accumulator has 14.873 added to it. How do you do this in integer? You think in fractional-integer format. Lets say your accumulator has an 8-bit fractional part, then 50MHz/3.372MHz x 2^8 = 3795.9668 ~ 3796 (ED4h). This number in binary is 1110_1101_0100b, and in fractional integer format 1110.1101_0100, which is equivalent to 3796/256 = 14.828125. You can use this along with an accumulator to create (on average) a 50MHz/14.828125 = 3.37197MHz waveform. If this is not close enough, try a larger fractional component. The accumulator technique divides the clock by 14 the first time, and saves the 0.828125 fraction, and adds 14.828125 to that to get 15.65625, so next divides the clock by 15, and saves the fraction 0.65625 and adds 14.828125 to that to get 15.484375, so next divides the clock by 15, etc etc. The 50MHz clock is divided by 14 or 15 multiple times, so that 'on average' the output clock is 3.372MHz. If this is a homework problem, then I don't want to give you the complete solution. This should put you on the right track to solving it though. Cheers, Dave