Pulse Width Modulator
for high-power LEDs

About this project:

Fairly early on in my work with high-power LEDs such the Luxeon 1 and 3 watt devices I considered that PWM (Pulse Width Modulation) techniques would be an interesting means of modulation the LED.  In theory, this should be capable of producing the lowest distortion modulation on an LED because the linearity of the LED's "Current-versus-Luminous Output" curve would be irrelevant:  The apparent brightness would be integrated by the receiver to produce a voltage proportional to the duty cycle of the modulated light source.

In addition to high-power LEDs, PWM techniques are also suitable for driving inexpensive laser pointers provided that suitable circuitry (e.g. voltage/current regulation) is used with the laser pointer.  In other words, the unit described here will NOT safely drive a laser pointer directly without additional circuitry!

For actual audio from the very modulator described and pictured, listen to the audio clips found here.

For information about a simpler PIC-based PWM-type Laser/LED driver, see the page:
"A 'Simpler' Pulse-Width Modulator for LEDs, Lasers and whatnot."

What is PWM?
Figure 1:
How PWM works by varying the duty cycle of the waveform.  These are from the Luxeon link on the Modulated Light web page by Chris, VK3AML and Mike, VK7MJ.

Graphics showing PWM operation

Pulse Width Modulation is widely used nowadays in low power audio amplifiers and the so-called "1 bit" D/A converters and the operation is simple:
As it turns out, the linearity of a PWM generator could, in theory, be absolutely perfect as the duty cycle is timed precisely using digital counters, but what is necessary is that there be enough timer resolution in order to provide the needed resolution of duty cycle.  Take, for example, a 10 bit PWM converter.  Because 10 bits represents 1024 steps, it would be necessary that the original timing clock be 1024 times that of the sampling rate.  If, for example, our original clock were 20 MHz, one 1024th of that would be 19.53125 kHz.

In practical terms it is usually desirable the frequency response of the circuits in a typical optical receiver not be able to respond at the PWM frequency, with the resulting "smoothing" being a voltage that is very close to the original analog signal applied to the modulator as depicted in Figure 1.  This technique usually works as more-sensitive optical receivers designed for speech bandwidth (and/or their following amplifier stages) don't have the frequency response characteristics necessary to reproduce the original PWM waveform.

Some caution should be exercised, however:  If the optical receiver does have the bandwidth to recover the PWM signal - or if there is a reduced (but still sufficient) response of the audio chain at the PWM frequency - this could play havoc with "downstream" audio devices in several ways:
While the above are possibilities, I have not experienced these effects when using my Version 3 optical receiver (with the lowpass filter switched out, or even the "simplified" versions) with digital audio devices - but the fact that this receiver is designed to roll off above 7 kHz is no doubt a mitigating factor:  The caveat here is that all equipment should be tried at both high and low light/signal levels before going out into the field to verify that there is compatibility.

Remember that to detect a PWM signal, the receiver does not need to be able to respond to the switching frequency, but only to the rate at which the pulse width is being changed - that is, the audio modulated atop the PWM.  A "slow" receiver will simply integrate (or smooth) together the PWM waveform into a form that closely resembles the signal that was originally fed into the modulator in the first place.

A PIC-based Pulse Width Modulator:

Having done some DSP programming using the Microchip PIC microcontrollers over the years I knew that it already possessed the hardware to make a nice Pulse Width Modulator for LEDs.  I chose the PIC16F88 for this task as it had some useful onboard peripherals:
Description of the hardware:
Figure 2:
Schematic of the LED PWM circuit.
This schematic doesn't include some of the later modifications - see the comments in the text.
Click on the image for a larger version.
Schematic of the LED PWM woth AGC and tone
                    generators

Signal input stage:

Audio input can be one of three sources:  A built-in electret microphone, an external microphone via J1, or an external line input via J2:  S1, an SPDT switch, selects which source is to be used and if it is a "center off" type switch, that position can serve as a "mute" setting.  Note that J1 is a "disconnect" type of jack and is wired to disable the internal microphone when an external one is plugged in, such as a desk-type computer microphone or a microphone-headset combination.

In experimentation it has been noted that computer-type electret microphones are wired in one of two ways:  While the audio is always on the "tip", some connectors apply bias to the tip and leave the ring disconnected while others apply the bias voltage only to the ring so the circuit shown accommodates both wiring schemes.  Note that this microphone input is not generally suitable for dynamic owing to the DC bias applied and the low output levels of these types of microphones as compared to the electret counterparts.  Additionally, it is unknown if crystal microphones would work, but these are quite rare nowadays.  Only electret microphones should be used with the circuit shown.

J2, the "line level" input, is wired such that the two resistors will sum (and attenuate) a line-level stereo input to a monaural signal and these resistors (R3 and R4) are necessary in many audio amplifiers because it has been noted that with many audio devices - particularly portable audio players and phones - simply shorting the left and right channels together may result in distortion as the two audio channels' output amplifiers may "fight" each other.

The input signal is buffered by Q1, an emitter-follower, and the source impedance is set with R9 while Q2, a JFET, is used as a variable resistor, controlled by the microprocessor, U2, to reduce gain of the input stage when high audio levels are present.  U1B is a non-inverting amplifier used to boost the low-level audio input signals (from the microphone, for example) to a level suitable for the A/D converter on the microprocessor.  U1C, along with R19 and C8 form a 3-pole 3.5kHz anti-aliasing lowpass filter used to limit the frequency response to below the Nyquist limit of the microprocessor's sampling rate of 19.53125 kHz.

LED Current Driver:

U1A is wired as a precision current sink:  With a closed feedback loop, the drive on the gate of Q1, an N-channel power MOSFET, is adjusted by U1A as necessary to obtain a voltage drop across R32, a 1 ohm resistor, that is equal to the voltage on pin 3 of U1A, the non-inverting input.  In this way, the current through R32 - and thus through LED1, the high-power LED - is exactly proportional to that voltage applied to pin 3.  Because the maximum, peak current through a 3 watt red Luxeon LED is 2 amps, R30 is adjusted to provide precisely 2 volts at the peak of the PWM waveform (from U2) when R31 is all of the way up:  When adjusted this way, with a 50% duty cycle, the average LED current is thus 1 amp.

For current monitoring, R33 and C20 provide a filtered voltage reference where 1 volt equals 1 amp of average current.  For audio monitoring, a pair of headphones may be used with R34 being used to adjust the audio level, R35 limiting the drive to the headphones to a safe level with C21 blocking DC and C22/R35 filtering most of the PWM switching frequency out of the monitor point.  See the comment below about modifications made to the monitor point.

In order to "mute" the LED drive without powering down the circuit (and avoiding the wait for the circuit to re-stabilize when it is powered up) S3 simply disconnects the LED from its voltage source.

Modifications to minimize voltage drop:

In testing, it has been noted that the LM324 used will properly operate down below even 10's of millivolts of "ground" and because of this, it should be possible to reduce the value of R30 down to at least 0.1 ohms and still achieve a wide range of current modulation with the peak current being 2.2 amps.  If a low on-resistance MOSFET is used for Q1, it should be possible to construct a circuit that will fully modulate the LED with less than 0.5 volts of additional voltage drop.  What this means is that with these lower resistances it is possible to run a single Luxeon III from a 6 volt supply, or up to three Luxeon III's in series from a 12 volt battery supply!  (Note that if you were to use a 6 volt supply, you would have to assure that the +5 volt regulated supply could maintain accurate regulation!)

Theoretically, one could use much higher-current LEDs in this sort of circuit but note that the current limiting occurring here is being done in the linear domain and produces heat.

Comments:
Microcontroller:

U2 is a PIC16F88 microcontroller with a built-in 10 bit A/D converter, 10 bit PWM generator (used as a D/A output) as well as other peripherals and the 5 volt PWM signal is applied to the U1A current sink via R28/R29.  U2 also contains a 4 bit voltage reference originally intended to be used with onboard comparators, but it is used in this case as another D/A channel, being filtered by R23/C16 and amplified by U1D and used as the "external" A/D converter reference voltage:  A divided-down version of this voltage is also used to provide a centerline reference for the filtered and amplified A/D input.

Also connected to U2 are two potentiometers, R20 and R21.  These produce variable voltages that are read by the A/D converter and used by the software to change settings such as gain or tones.

Description of the software:
Figure 3:
Top:
  Front panel view of the modulator, which is connected to a Luxeon 3-watt emitter module with a current limiter.  (No, I haven't gotten around to properly labeling things just yet...)
Middle:  The interior of the modulator showing the component side of the circuit board.
Bottom:  Another view of the interior of the modulator, showing the backside of the board and front panel.
Click on an image for a larger version.
The
                    modulator alongside a Luxeon emitter module
Component side of the modulator board
Backside
                    of the board and front panel

Timing:

U2 is clocked by a 20 MHz crystal and this is used to providing timing, including the 19.53125 kHz PWM frequency and the corresponding 19.53125 kHz sampling rate done in an interrupt service routine.  Because of the sample rate, the maximum (theoretical) allowable audio frequency that may be sampled without distortion is just under 10 kHz:  The 3-pole lowpass filter attenuates input audio by about 20dB at the Nyquist frequency, effectively preventing such problems by rolling of frequencies above 3 kHz at a rate of 18dB per octave.

Operation in audio mode:

Automatic gain control (AGC):

When in "audio" mode - that is, when audio from a microphone or line input is being modulated, the voltage at input AN4 is digitized.  When doing A/D conversions it is important to keep the audio level near the maximum input range (numerically speaking) of the A/D converter, yet not overdrive/clip it and cause distortion.  To prevent this the software looks at the incoming digitized audio and if the sample voltage is too close to minimum or maximum (approximately 6dB from clipping) gain is reduced to prevent overdriving the A/D and thus the PWM generator.  Each time a sample of "high level" audio is detected RB1 ("Gain Control Pulses")  is set high, but it is kept low at all other times.

Every time RB1 goes high, charge is added to C5 via R13 (through D2) and R14.  As the voltage on C5 rises, Q2 begins to conduct, shunting away some of the signal being applied to U1B and reducing the audio being input to the A/D converter and resulting in fewer "high audio" conditions that cause a gain control pulse.  If the audio has not exceeded the "gain reduction" threshold, RB1 is kept low and C10 is discharged more slowly via R14.  With this feedback system, the gain is balanced, keeping the audio from getting too high, too often.

Another output, RB7, is used to indicate when the CPU detects that either the A/D input and/or PWM output exceeds a high amplitude (slightly higher than the gain reduction threshold) by outputting a pulse that turns on Q3 and causes LED2 to flash, indicating to the user something about the amount of audio present.  Note that it is normal for this LED to flash every few seconds during normal audio and the audio peaks that occasionally get "hard clipped" by the input A/D don't normally cause objectionable distortion on speech.

The time constants of C10, R13 and R14 are chosen to be fairly fast in order to track speech.  The effect of this is that this audio AGC acts very much like a compressor-type speech processor and can help maintain a tight peak to average ratio - something that can greatly improve intelligibility of speech under conditions of poor signal/noise ratio.

Manual gain control:

Another means of gain control is via R20, a potentiometer:  The voltage from this pot is digitized and internally converted to a value that is applied to the "Comparator Voltage Reference" (Cvref) output on pin 1.  Although this is a 4-bit D/A converter, roughly 8 bits of resolution are obtained via software dithering and using U1D, the Cvref output is filtered with C16/R24, amplified, and applied to pin 2, Vref+, the voltage reference input of the A/D converter while a sample of half this voltage is applied to the audio input through R27 to provide a "mid-scale" voltage reference for the A/D converter.  By lowering the reference voltage, the gain of the A/D converter is effectively increased.

When R19 is fully-counterclockwise (minimum gain) the Vref+ voltage is set to about 5 volts, corresponding with a full-scale range of 0-5 volts of analog input voltage.  When R20 is but fully-clockwise, the Vref+ voltage drops to about 0.3 volts:  Those familiar with this chip will note that the minimum specified A/D converter Vref+ voltage is, in fact, 2 volts, but this is only true if full 10 bits of A/D resolution is required.  The penalty of using a voltage lower than this is simply that the lower-order A/D conversion bits will start to be lost in the noise.  At the lowest voltage, the A/D converter resolution is roughly equivalent to 6 or 7 bits,  but since the lower-order bits contain what sounds like white noise, the overall effect is that as A/D conversion gain goes up with the lowering of Vref+, so does the noise level, which manifests itself as a background "hiss."

While this added noise is noticeable when signals are "strong" it is not really objectionable on a weak optical path - the condition where the gain might be run up to maximum to more-heavily compress the audio for improved intelligibility - and it probably wouldn't be noticed at all amongst the other noise sources.  Note also that under normal conditions, the "manual gain" control would not be operated at maximum, anyway.  In normal operation it has been noted that the gain is sufficient to pick up the voice of anyone within several feet of the modulator when its internal microphone is used.

Note also R11, another gain control.  This sets the maximum gain of U1B, the first amplifying stage.  On the prototype, I'd used a 100k potentiometer, but noted that I had to set it nearly at maximum gain (minimum resistance) so a lower value of potentiometer (50k is suggested in the diagram) would probably be more appropriate.  Note that setting R11 for too high of gain can result in instability of U1B and/or excess noise.

Operation in "tone" mode:

Another feature of the software is tone generation:  Using DDS techniques, low-distortion sine waves can be generated at practically any audio frequency below the Nyquist limit - in this case, with a resolution of 0.298 Hz..  Having this capability allows several tone generation modes:
The selection of tone and audio modes is done by grounding processor pins RB3, RB4 and/or RB6 using diodes D3-D9 and a rotary switch to generate a binary code as follows:
A - Adjustable tone:  RB3, RB4 grounded, RB6 open
B - Selection of 8 fixed tones:  RB3 grounded, RB4 and RB6 open - see below for a list of the audio tones
C - Ascending tone sequence:  RB4 grounded, RB3 and RB6 open - see below for the list of tones used in the sequence
D - Descending tone sequence:  RB3, RB4, and RB6 open - see below for the list of tones used in the sequence
E - Audio with pilot tone:  RB4, RB6 grounded and RB3 open
F - Audio with no pilot tone:  RB6 grounded, RB3, RB4 open
The 8 fixed audio tones available in Mode B are:
1 - Musical note B0 (actual freq. = 30.9944 Hz)
2 - Musical note E1 (actual freq. = 41.1295 Hz Hz)
3 - Musical note C4 - middle C (actual freq. = 261.6674 Hz)
4 - Musical note F4-sharp (actual freq. = 369.8468 Hz)
5 - Musical note A5-sharp (actual freq. = 932.26912 Hz)
6 - Musical note - E6 (actual freq. = 1318.52896 Hz)
7 - 440 Hz - Musical note A4 (actual freq. = 439.907 Hz)
8 - 1kHz tone (actual freq. = 999.9242 Hz)
Note:

Adjustment:

Maximum LED current:
Maximum audio gain:

As mentioned before, R11 is adjusted to provide the maximum desired amount of microphone gain.  Care should be taken to avoid setting R11 to too low a value (e.g. highest gain) to prevent noise and/or instability if the U1B amplifier section.

Comment:  100% modulation is defined as modulation that goes all the way from zero up to twice the average (unmodulated) current as set by R31.



Important note:  It is strongly recommended that you never operate any modulator or LED without having current limiting on the LED.  This may take the form of a resistor, or a current limit circuit such as one using an LM317.  If an LM317-based limiter is used, you may need to install bypass capacitance to prevent distortion of the waveform due to the nonlinear nature of the PWM waveform.

Components:


Comments:

Return to the KA7OEI Optical communications Index page.

If you have questions or comments concerning the contents of this page, or are interested in this circuit, feel free to contact me using the information at this URL.
Keywords:  Lightbeam communications, light beam, lightbeam, laser beam, modulated light, optical communications, through-the-air optical communications, FSO communications, Free-Space Optical communications, LED communications, laser communications, LED, laser, light-emitting diode, lens, fresnel, fresnel lens, photodiode, photomultiplier, PMT, phototransistor, laser tube, laser diode, high power LED, luxeon, cree, phlatlight, lumileds, modulator, detector
This page and contents copyright 2007-2015.  Last update:  20150819
Page count since 201005: