Re: Precision PWM in microcontroller
From: Ville Voipio (vvoipio_at_kosh.hut.fi)
Date: 12/29/03
- Next message: John Tan: "Extra addr. lines needed"
- Previous message: Thad Smith: "Re: Precision PWM in microcontroller"
- In reply to: Thad Smith: "Re: Precision PWM in microcontroller"
- Next in thread: Thad Smith: "Re: Precision PWM in microcontroller"
- Reply: Thad Smith: "Re: Precision PWM in microcontroller"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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)
- Next message: John Tan: "Extra addr. lines needed"
- Previous message: Thad Smith: "Re: Precision PWM in microcontroller"
- In reply to: Thad Smith: "Re: Precision PWM in microcontroller"
- Next in thread: Thad Smith: "Re: Precision PWM in microcontroller"
- Reply: Thad Smith: "Re: Precision PWM in microcontroller"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|