This is more of a general EE question than an 8-bit MCU question, but one that folks here might have good insight on.
For many applications (eg. switching power supplies) it is useful to have a PWM in the >500 kHz range, with a duty cycle that can be finely tuned. A typical MCU is not fast enough to provide this signal off of the main bus clock.
Is there a cost effective way to implement a PWM operating at 500 kHz, finely variable duty cycle, with an MCU? Say, by converting (directly or indirectly) a 500 Hz PWM from the MCU into a 500 kHz signal using an external IC, or simply a crystal oscillator with some clever analog circuitry?
I have been googling around on this and have found some rather inelegant possible solutions, but I was wondering if anybody had quick advice here.
I have generated high-speed PWM signals two ways. I don't think either way is all that "elegant", and "cost-effective" will be determined by your application. They were cost-effective for me.
The first was to use the PWM circuit in a DSP. With the Freescale DSP56721 (which I would NOT recommend) running at 200mHz (100mHz for the timer), I was able to get 10-nanosecond resolution, which gives you one part in 200, if set for a 500kHz period. The period is also adjustable with 10-nanosecond resolution. It was cost effective because I needed the DSP for math anyway.
Less cost effective, but more elegant, is to build the PWM in an FPGA and control it from the MCU. Since most of my designs use an FPGA anyway, it was an easy choice for me. An advantage is that you can build the PWM circuit to your exact specifications, limited only by the clock you have available.
I would also like to hear of ways to do it directly from a 8-bit MCU.
Maybe what I am about to describe is one of those "inelegant" methods that you have already examined.
The traditional method of generating an analog PWM signal is to utilize a triangular or sawtooth waveform, in this case with a frequency of 500kHz, and an analog comparator. The width of the output pulse from the comparator would be determined by an applied DC offset. With only a 2 microsecond period, it would need to be a very fast comparator for transition to occur with only a few nanoseconds delay. Other analog components would be required to generate the waveform. In this case you might generate a triangular waveform using a relatively fast operational amplifier and maybe extra comparator.
Digital control of the pulse width would be possible by use of a well filtered PWM signal from the MCU to provide the DC offset.
Thanks, that is a very helpful concept. Come to think of it, I think I remember doing something like this in a circuits lab in college, but had completely forgotten about it.
I'm guessing somebody has already implemented this concept (probably including improvements) in a single IC package - such that one could input an analog level (or a low-frequency PWM) to control the duty cycle of a fixed-high-frequency PWM output. I'll be hunting around for something like this and will post back if I can find it.