Oftentimes in EE classes we learn about AC analysis and phasors and other stuff heavily based on analog signals. I also know that many digital applications approximate analog signals using PWM. But does everything we learn regarding analog signals still apply to PWM signals? For example, I can see why the integral of a PWM and analog signal would be (almost) the same, but wouldn't the derivatives be drastically different?
PWM vs Analog Signals
analogcircuit analysispwm
Related Solutions
The simple answer is that you can't. There are several things going against you:
would be that for good audio quality you'd need to be very precise in your PWM generation. This is fairly difficult, as your master clock frequency (the freq that the logic used to generate the PWM from) would have to be around 100 MHz just to get the equivalent of an 11-Bit DAC. There are ways to generate PWM that good without that, but then you'd be starting with an analog signal and thus wouldn't have this problem.
as noted you would need a super steep rolloff of a filter. Just to match your 11-bit DAC equivalent you'd need something like 60 dB/octave-- which is unreasonable even for the pro's. There is a lot of difficultly in doing this kind of filter which is why everyone went to Delta-Sigma DAC's for their audio, which require about a 6 db/octave filter.
If your filter is not 60 db/octave then you'll need the PWM frequency to be super high. If you have 60 db/octave then you could have a PWM freq of 40KHz. At 54 db/octave then maybe 80 KHz will work. 48 db/octave = 160 KHz. Etc. Very quickly you get into the high MHz range-- and then your master clock frequency would have to be into the GHz.
All is not lost, however. Do you really need to filter out the high frequency stuff? In many applications (not all) you can either not filter it or use a simple RC filter at 1-5 MHz. There will still be high frequency stuff getting though but either the speaker or your ear will filter it all out. But the audio will still sound bad. AM Radio on a bad day quality. That's just the way it is.
Update: My numbers for #3, above, are somewhat wrong. But before I get to that, let me explain where I got all the numbers from.
Let's say that you are generating the PWM using digital logic (FPGA, Microcontroller, etc.). And then let's say that your audio sample rate and thus your PWM frequency is 48 KHz. And you want 8-bit resolution. That means that your master clock frequency should be 12.288 MHz. I calculated that this way: Master_Clk_Freq = Sample_Rate * 2^n_bits. Doing that again for an 11 bit resolution is 98.304 MHz.
The theoretical best noise level of an ideal DAC is about -6dB/Bit. So a 24-bit DAC has no better than -144 db noise. (Note: I'm playing a little loose with the terms here, lumping SNR, THD+N, and dynamic range all together.) Of course, no real 24-bit DAC can do this, but we're talking theoretical here. What this means is that an 11-bit DAC has about a -66 db noise level, so there is little point in making a filter that works better than this. AM Radio has approximately 60-ish dB signal to noise ratio, for comparison.
Ok, here's where I royally messed up the numbers. Assume that the PWM Rate = 48 KHz, and filter Cutoff=24 KHz (to make the math easy). With a -60dB/Oct filter we'll be -63dB @ 48KHz. If our filter were changed to -54dB/Oct then we'd be -57dB @ 48 KHz and -62.4dB @ 50.4KHz. What this means is that by changing our filter from -60db/oct -54db/oct we would have to change the PWM rate from 48 KHz to 50.4KHz to achieve the same filter blocking performance. Not a doubling of PWM frequency as I mentioned before. In the same way, if the filter were changed to -18dB/Oct (which is a manageable design) then the PWM frequency would have to be 104 KHz to still have -63dB filter attenuation at the PWM frequency. I calculated this by making a small spreadsheet and playing with the numbers.
Given: Cree XM-L LED.
Want: Up to 2A drive, PWM controled by PC via USB.
This can be two parts. ie actual LED drive and PC to LED drive interface. These may or may not be integrated.
A "very easy" approach is to
1. use an off the shelf USB to "output" device. "Output" may be analog level, PWM, 8 bit port etc to control ...
2. An off the shelf LED driver that uses analog or PWM input.
For example, the circuit below using a RT8482 requires an analog input level or PWM with a simple RC filter (to convert the PWM to analog). The analog could be provided by a USB to analog output I/O device (COTS) or by a USB to parallel port device (not a printer port per se) (COTS) with a simple R2R digital to analog converter (about 16 resistors plus maybe a cheap op-amp).
Many examples of R-2R ladders here - links live
Or a microcontroller with USB capability could have a relatively simple program written to provide PWM or analog output. A USB enabled Arduino or a Raspberry Pi would do this. (USB has to be slave not host mode).
LED drive:
(1) "Off the shelf" complete units that do the LED drive part of this job well are available at good prices from eg ebay, or Mouser and similar. Using such is a good default solution unless you have some reason to do otherwise.
(2) DIY LED driver.
Digikey LED drivers are found here. Alas the parametric search is poor in this case (which is unusual).
Searching using LED driver 2A gives better results.
There will be a nummber.
Example only: For $US1.52/1 in stock Digikey you get
1
Ricktek RT8482, buck or boost, LED driver.
Drives external MOSFET so LED current capability essentially unlimited.
Looks like a good start. 350 kHz for smallish inductors.
- High Voltage Capability : VIN Up to 36V, VOUT Up to
48V
Buck, Boost or Buck Boost Operation
C u r r e n t M o d e P W M w i t h 3 5 0 k H z S w i t c h i n g Frequency
Easy Dimming : Analog, PWM Digital or PWM
Converting to Analog with One External Capacitor
Programmable Soft Start to Avoid Inrush Current
Programmable Over Voltage Protection
VIN Under Voltage Lockout and Thermal Shutdown
16-Lead WQFN and SOP Packages
RoHS Compliant and Halogen Free
A MOSFET suitable for use as M1 would be eg ONSEMI NTD4960 $US0.40/1 in stock Digikey, 30V, 9A, 9 milliohm on resistance nominal, logic gate - data sheet curves show good at 4V gate and say 4A.
ADDED:
Should I be looking at specific types of inductors for this sort of application
Inductors are very special for best results. If this is a one-off then off the shelf inductors from eg Digikey or similar are wise. We can give advice in this when final real spec is known.
I'm assuming all of the caps in this type of application would be ceramic?
Ceramic capacitors will work well for all capacitors shown. At least 10V rating. More or much more voltage OK.
D1 is Schottky and should have current rating equal or greater than LED max current.
Now I just need to figure out how to generate the PWM signal.
PWM is "easy" [tm] and may not be needed. Above LED controller example can use analog or PWM control.
USB to I/O
This USB to paraell FIFO I/O module](http://www.ftdichip.com/Support/Documents/DataSheets/DLP/usb245r-ds-v10.pdf) uses FTDI's FT245R USB-parallell FIFO interface IC - datasheet here .
Vast amounts of related FT245 information here
FT245 available from Digikey ~= $US4.50/1 from here
FT245 based module from Digikey for about $40/1 here
This page discusses a DIY USB printer port which, as you have complete control over the hardware and how it acts, could "easily" meet your need. Based on a PIC18F4550 microcontroller and not much else. All software PCB patterns, circuit etc free.
Best Answer
[General remark: Treat hobby-grade sources like SparkFun with a pinch of salt. Their objective is to make things easy, fun, exciting, practical without getting bored with integrals and derivatives. As a result, you get loose statements occasionally.]
In some books, PWM is called a pseudo-analog signal. It has only high and low voltage level, but timing is continuous. Timing is either truly continuous, or it has high enough digital resolution where it can be considered continuous for practical intents and purposes. When PWM is converted to an actual analog signal, that's always done with a low-pass filter of some sort. Here's are some examples: