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
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
For information about a simpler PIC-based
PWM-type Laser/LED driver, see the page:
'Simpler' Pulse-Width Modulator for LEDs, Lasers and
What is PWM?
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,
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:
- For producing a "steady state" DC output at "mid supply" voltage (that is, no modulation is
being generated) a 50% duty cycle square wave is generated
at a frequency several times higher than the
highest-frequency component in the audio to be
reproduced. While this frequency could theoretically
be as low as just twice the highest audio frequency, it is
usually several times higher than that to simplify lowpass
filtering and to cut costs.
- To increase the output voltage, the duty cycle of this
square wave is increased, with 100% being "full on."
Conversely, to decrease the voltage, the duty cycle would be
decrease, down to 0% being completely off. In reality,
most PWM circuits involving audio avoid getting too close to either 0% or
100% as either extreme would produce objectionable "hard"
- The PWM output is filtered to average out the square wave,
the ultimate result being a voltage that is directly
proportional to the duty cycle of the original square wave.
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
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
. 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
Some caution should be exercised, however: If the optical
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:
- The audio amplifier may be capable of amplifying the PWM
signal, robbing power from the audio-frequency
components. In this situation, the audio amplifier is
putting out its normal power, but some of it may be wasted
at the PWM frequency and be inaudible to human
hearing. In this case, the audio amplifier may
overload at lower-than-normal volume levels.
- Aliasing artifacts on digital audio devices.
Computer sound cards and digital audio recorders may not be
able to sufficiently filter the PWM frequency from their
inputs and this may result in odd aliasing artifacts, which
may include noise, distortion, or odd mixing effects.
While the above are possibilities, I have not experienced these
effects when using my Version 3 optical
(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 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:
- A 10 bit PWM generator. With a 20 MHz crystal, it
could generate a PWM signal with 10 bits of resolution at
19.53125 kHz - a frequency sufficiently high enough for
voice bandwidth communications without having to use
elaborate anti-aliasing filters.
- A 10 bit A/D converter. Again, this is a useful
feature if you want to take an analog signal and do anything
with it, and the ability to use multiple analog inputs
allows several analog voltages to be digitized.
Another useful feature was that the A/D converter could be
configured to use an external voltage reference.
- Onboard timing. This processor has several onboard
hardware times, allowing very precise generation of clock
periods - something that would be useful for generating
audio tones for testing.
Description of the hardware:
- An onboard 4-bit R-2R D/A converter. This
peripheral, originally intended as a voltage reference for
the onboard comparators, would prove to be very useful when
used in a unique manner.
Signal input stage:
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.
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
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"
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
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
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.
- Since drawing the schematic, a simple low-pass filter and
headphone driver was added to the "monitor" jack (J3) to
remove the PWM energy. The presence of the PWM signal
on this lead caused some aliasing problems when a digital
audio recorder was used to record the transmissions.
- Some of the phase/frequency "compensation" components
around U1A have been later modified to improve stability. While
the circuitry around U1A shown in the schematic proved to be sufficient
for the first LED module, changes were made later to allow stable and
consistent operation with other devices such as other LEDs and laser
pointers. One of the challenges has to do with the fact that the
gain-bandwidth product of the LM324 is marginal at the PWM frequency
and a bit of "coaxing" was required to get it to work. While
other, faster "rail-to-rail" input op amps have been tried in place of
U1 with different circuit modifications - including the complete
removal of these "compensation" components - none have been proven to
work any better than the LM324 although I suspect that additional work
on this circuit with those devices would likely yield positive results.
I have yet to redraw the schematic to reflect these (and other)
changes but feel free to send an email via the link at the bottom of
this page if you have questions. The author is well-aware that
the methods shown in the digram to achieve stability are less than
ideal - although they work quite well in this particular case.
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:
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
Click on an image for a larger version.
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:
- Continuously variable frequency. Using R21, the
audio frequency can be adjusted from 20 Hz to 2457 Hz.
In this mode the rotation of R21 is "de-linearized" to make
it easy to adjust the tone frequency over a wide range.
- Selection of fixed frequencies. When in this mode,
one of 8 precisely fixed tone frequencies may be selected
using R21 as noted below.
- Ascending or descending tone sequence. The tone
sequence consists of four dissonant tones that are very easy
to pick out of the noise. R21 is used to adjust the
- Activation of a pilot carrier. In this mode, a 4 kHz
tone (12 dB below 100% modulation) is digitally mixed in
software with the microphone (or line input) audio.
The software takes the presence of this pilot carrier into
account and prevents overmodulation of the LED with the
combined audio sources. At the receive end, this pilot
tone can be filtered out and is available for analysis of
scintillation or used for peaking the receiver.
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,
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
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
F - Audio with no pilot tone: RB6 grounded, RB3,
The 8 fixed audio tones available in Mode B
1 - Musical note B0 (actual freq. = 30.9944
2 - Musical note E1 (actual freq. = 41.1295 Hz Hz)
3 - Musical note C4 - middle C (actual freq. = 261.6674
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
8 - 1kHz tone (actual freq. = 999.9242 Hz)
Maximum LED current:
- The ascending sequence (Mode C) consists of tones
are #'s3, 4, 5 and 6 (C4-F4#-A5#-E6) in that order) while
the descending tone sequence (Mode D) are the same
tones in reverse order. R21 adjusts the rate at which
these tones are sequenced.
- If you are musical, you may realize that this sequence of
tones represents several instances of the "Devil's Interval"
(a.k.a. "Tri-Tone", Augmented fourth or Diminished fifth) -
a rather dissonant chord when played simultaneously - or
even adjacent to each other and this is why they were
chosen: The really stick out when you hear them!
For more information about this interval, see the Devi's
Interval Wikipedia page.
Maximum audio gain:
- The LED connection is shorted out
- R30 is turned all of the way down (wiper grounded)
- R31 is turned all of the way up
- R30 is then adjusted for 1.1 amps as measured at the LED
Current Monitor point by observing 1.1 volts.
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.
100% modulation is defined as
modulation that goes all the way from zero up to twice the
average (unmodulated) current as set by R31.
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.
- Diode D1 is a 3-6 amp, 50 volts diode or greater
- Diodes D2-D10 are small-signal diodes, such as 1N914 or
- Q1 is an N-channel power MOSFET. A recommended
device is one that has a current rating of 10-20 amps at up
to 100 volts. Note that high voltage/high current
devices have more gate capacitance and could make gate drive
- Q2 is an MPF102
- Q3 is a general-purpose NPN transistor.
- All potentiometers are linear taper.
- J1 is a disconnect-type 3-conductor (stereo) 1/8" (3.5mm)
- J2 and J3 are 3-conductor 1/8" jacks
- S1 is an SPDT switch. A center-off switch is nice to
have, but not necessary.
- S2 is a 6-position, non-shorting rotary switch. I
used a 6 position switch (from Radio Shack - P/N
275-1386.) If necessary, several toggle switches could
be used to set the various modes.
- S3 is an SPST switch
- U1 is an LM324 quad op amp: DO NOT SUBSTITUTE!
do insist on a substitution, the op amp must be capable of
good bandwidth as well as operating down to the negative
supply rail. Other rail-to-rail op amps were tried, but did
not work very well: I need to look into this...
- U2 is an appropriately programmed PIC16F88
- U3 is an 78L05 (or 7805) 5 volt regulator.
- R11 - Trimmer potentiometer, 20k-50k maximum.
- LED1 is a high-power LED. The use of a red (or
red-orange) 3-watt Luxeon is assumed here, but other units
may be used provided that R28 is adjusted for maximum safe
current. It is strongly recommended that the LED
itself be equipped with a current
- LED2 is a normal indicator-type LED, probably red.
- TH1 is a self-resetting, 3 amp "thermal" fuse. A
device as low as 1.5-2 amps would be usable with a 3-watt
LED. It is recommended that the "hold" rating of this
fuse be at least twice the resting current setting of the
- It is normal for the "Overload" light to flash on
occasional audio peaks. With high input levels and/or
excess audio gain, this indicator may flash much more
frequently causing some some minor clipping, but it may
sound overly "compressed." Under conditions of low
signal-noise ratio a heavily compressed audio
signal may be more intelligible than one that isn't as
compressed even though it may not sound as nice.
- S3 disconnects the LED to allow "muting" of the light
output, but leaves the rest of the circuit powered up.
This keeps the circuit active, thus eliminating the need to
wait for things to stabilize were the entire circuit powered
down: The current consumption with the LED off is
about 40 milliamps.- Note that as the LED current is
decreased, the audio output from J3 will also
decrease. When S3 is opened, the audio output will
also go away.
- TH1 is a 3 amp self-resetting thermal fuse that is used to
protect the circuit in the event of an internal power supply
short, or in conjunction with D1 to provide power supply
- Some time after building this circuit, I joined the Optical
DX Yahoo Group and noticed that David Smith,
VK3HZ, had taken a similar PWM approach - it might be
interesting to compare notes.
- This implementation of the Pulse Width Modulator does not
offer much power efficiency over a linear modulator because
it still uses linear current regulation to limit the LED
- I have also built a linear modulator
that uses the same "Precision Current Sink" circuit but does
not use a PIC to process the audio. I did this
circuit mainly to see how well it works, but having built
both, I would recommend the "linear" version instead as it
is somewhat simpler, and it does not have the audio
frequency response limitation of this circuit.
- Philips has phased out the Luxeon I, III, and V
lines in favor of the lower-power Luxeon Rebel
devices. Since I have not used those other devices,
the techniques described here may not directly apply unless their current limits are taken into account.
For the time being, however, the Luxeon III devices are
still available from various sources and other high-power LEDs are available from many different manufacturers.
- For this circuit to drive a laser pointer, a shunt
resistance (about 20 ohms) was used to provide a reasonable
amount of sink current for the output stage and a simple
3-volt regulator was used across that resistance to provide
"safe" operating conditions for the laser module.
Return to the KA7OEI Optical
communications Index page.
- I've never been very happy with the stability of the U1a
circuit used to as a current amplifier for the modulated
LED. While it is generally stable with the values and
configuration shown in the diagram, it could probably stand
a bit of re-working. For example, if a faster op amp
is used for driving the LED, it is not particularly stable
indicating the need to rework its frequency compensation
properties. Note that if a different op amp is used,
it must be capable of operating down to the
negative rail on both its input and output.
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.
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