Re: Precision PWM in microcontroller

From: Ville Voipio (vvoipio_at_kosh.hut.fi)
Date: 12/29/03


Date: 29 Dec 2003 09:03:59 +0200

Thad Smith <thad@ionsky.com> writes:

> Are you wanting to generate different frequencies? If so, an external
> Direct Digital Synthesizer (DDS) will do what you want. These can be
> programmed to generate an accurate frequency. They require an
> external reference frequency.

In case of a uC, this is easy to do in s/w. The interrupt frequency
has to be more than double the highest output frequency. The algorithm
itself is simple:

---
uint32_t accu, incr;
interrupt timer_int()
  {
  accu += incr;
  /* check the MSB of accu */
  if (accu & (1 << 31))
    OUTBIT = 1;
  else
    OUTBIT = 0;
  }
---
The output frequency depends on the interrupt frequency and the
overflow value. For a 32-bit integer, the output frequency is:
  f_out = f_intr * incr / 2^32
Or, as usually the increment is required::
  incr = 2^32 * f_out / f_intr
This gives a very high resolution. In some cases it is possible
to use a shorter accumulator (e.g., 16 bits).
Making a software DDS is simple, but there are a few things
which have to be taken into account:
- While the frequency and duty cycle accuracy in the long run
  is extremely good, there is a lot of jitter due to the limited
  sampling frequency. A single cycle may have a very bad duty
  cycle (1:2 in the worst case). RMS jitter is sqrt(1/12) of
  the base cycle time, IIIC (if I integrated correctly). So, if
  the interrupt frequency is 50 kHz, maximum jitter is 10 us,
  and RMS jitter around 6 us.
- This jitter cannot be made any smaller by using a f/f. (Using
  a f/f is the same as halving the output frequency.)
- Increasing the base frequency decreases jitter and resolution.
  Usually the resolution is not a problem, so using as high
  base frequency as possible is a good idea.
- In order to preserve spectral purity and avoid  peaks, it is
  highly advisable to use only odd increments. This makes the
  period longest possible (2^32 cycles).
A DDS is simple enough to be made with a CPLD or even discrete
logic. Using a CPLD makes rather high base clock frequencies
possible (sacrificing the low power consumption and cost, though).
In case something else than a square wave is required, the use
of a simple look-up table and a MML DAC (Mickey Mouse Logic DAC,
a discrete resistor R/2R) may fulfill the requirements.
- Ville
-- 
Ville Voipio, Dr.Tech., M.Sc. (EE)


Relevant Pages

  • Re: Precision PWM in microcontroller
    ... >> programmed to generate an accurate frequency. ... are basically low cost vs. low jitter. ... A single cycle may have a very bad duty ... consecutive values for the interrupt duration. ...
    (comp.arch.embedded)
  • Re: Where are the LCD or OLED bitmapped displays?
    ... On Jan 1, 9:53 pm, John Larkin ... have the pre-production version (with the OSRAM display) really ... There is a lot of trickery involved to get the jitter down. ... Are you planning to reduce the DDS jitter to sub-clock levels on-chip, ...
    (comp.arch.fpga)
  • Re: Pipeline induced interrupt latency jitter
    ... Not pipelined does not mean one cycle per any opcode. ... Blackfin has a pipeline of 8 clock cycles deep, plus 32 bytes of prefetch, ... Yet 0 IRQ latency jitter would be quite a feature, ...
    (comp.arch.embedded)
  • Re: DDS issues...was sine generator ic solution
    ... >>The concept of DDS frequency synthesizers comes up frequently. ... the filter is easier. ... little amplitude modulation probably won't affect you much. ... > got a bit less jitter, ...
    (sci.electronics.design)
  • Re: Pipeline induced interrupt latency jitter
    ... Not pipelined does not mean one cycle per any opcode. ... Yet 0 IRQ latency jitter would be quite a feature, ... words that the CPU pipeline appears to cause jitter of the interrupt ...
    (comp.arch.embedded)