Showing posts with label modulator. Show all posts
Showing posts with label modulator. Show all posts

Friday, January 30, 2015

Updated version of the "Simple" PWM LED/Laser modulator

A few years ago, for our friends in the Tucson area, I threw together a "simple" PWM circuit for audio modulation of high power LEDs (but it works just as well for laser pointers) for an optical transmitter - you can read about that here:

A "Simpler" Pulse-Width Modulator for LEDs, Lasers and whatnot and a simpler foam-core enclosure - link
Figure 1:
As-built prototype of the updated PWM transmitter designed to test both
 the AGC and manual gain/tone configurations.
There is currently no circuit board pattern:  If you design one,
please let me know!
Click on the image for a larger version.

As the page describes, this was intended to be comparatively simple and flexible in its operation, providing both modulation of both audio and test tones.  While it worked just fine, it did bother me a bit that it did not have a "manual" gain mode - that is, one could not simply override the audio AGC - which does work quite well - and "ride" the audio level manually, instead.

That was 2009 - so flash forward to 2014 when, at the request of some fellow amateurs in Australia, I finally got the impetus to update the firmware to add the means of selecting a completely manual gain control to the PWM circuit, of so-desired, in addition to various tone modes, all by setting pins on the PIC processor to the appropriate logic levels.  Of course, the original AGC audio mode is still present and may be used exactly as before, if one wishes, and one could even construct the circuit so that it could be switched between manual and AGC mode.

What it's for:

If you have ever been to the Modulatedlight.org web site link  (which I'll admit to having quite a lot to do with...) you will know that it has a lot to do with optical communications - mostly using high-power LEDs, but it also touches a bit on using low-power laser modules as well.

For modulating audio onto LEDs, onto LEDs, one of the easiest ways to do this is via linear current modulation, a process that is explained on the web page Linear Modulator for high-power LEDs - link.

Figure 2:
Examples of waveforms used to generate PWM signals,
from the web page "The Luxeon:  
New Light of Hope for Optical Communications"
by Chris Long

Another way that LEDs may be modulated is by turning them on and off in a manner that simulates linear modulation using a method called PWM, or Pulse Width Modulation - a system that is very easy to do using digital hardware such as counters and is often found in microcontrollers.

For laser diodes such as those found in laser pointers, current modulation is NOT very good for a number of reasons, including the fact that the brightness-current curves of laser diodes isn't particularly linear over a wide range, nor is it predictable at which current a diode will start to laser under a given set of conditions (e.g. temperature, age) or up to what current a specific diode can be safely operated!

For amplitude modulation, it is always preferable that one modulates as deeply as possible to achieve the best-possible signal-noise ratio and if one is trying to current-modulate a laser diode, this becomes problematic as the bounds of safe and reliable operation are difficult to know!  It is more convenient, then, to simply turn it on and off, operating it at a known, safe current when it is on and varying the duty cycle using PWM.

If the switching frequency of the PWM is sufficiently high it will be compatible with a "conventional" analog optical receiver that was intended for amplitude-modulated light sources as the PWM waveform will be integrated by the low-pass response of the receiver's front end.  At the very least, the PWM frequency must be at least twice that of the highest modulating frequency of the audio to be carried  and if necessary, a simple low-pass filter could be added to an existing receiver to remove any residual switching components - see Figure 2 for a pictorial of how a "slow", low-pass response can smooth out the PWM frequency components.

How it works:

Figure 3:
Diagram of the version with audio AGC.
Click on the diagram for a larger version.
This circuit uses a PIC12F683, an 8 pin microcontroller internally clocked at 8 MHz.  Using its PWM hardware, it generates a waveform with a clock rate of 31.25 kHz that is pulse-width modulated at a resolution of 8 bits - suitable for voice.

Audio can come from one of two places:  A built-in tone generator, or an external microphone/line-in audio source.

Using DDS techniques, audio sine waves can be generated at frequencies from a few 10's of Hz to several kHz and these are applied to the PWM generator, producing tones with 100% modulation depth.

Audio from the microphone or line input is first amplified and then low-pass filtered to remove high-frequency content and applied to the 10 bit A/D input of processor where it is digitized at a rate of 31.25 kHz and also passed to the PWM output.

"AGC" mode:

In diagram depicted in Figure 3, the circuit is configured to use an audio AGC to assure that the modulation is kept at a consistently-high level.  The audio level is monitored continuously to determine if its level is within 6 dB of clipping.  If it exceeds that level, a counter is incremented, but if it does not, a counter is allowed to self-decrement.  If the counter exceeds a pre-set value indicating that the audio level has been high recently, the processor pins that control the gain on the amplifier stage are adjusted to reduce the gain to the next, lower step.  If the counter self-decrements below a pre-set value indicating that the audio level has been consistently low, the gain is adjusted to increment.

There is also a built-in 12 dB gain adjustment in software:  If the audio has been low and the audio gain is near maximum, a 12 dB gain step can be switched in which is done by first limiting the A/D values in software to ostensible 8 bit values and then shifting the A/D data to the left by two bits and offsetting.

When switched to the "tone" mode, instead of audio being applied to the A/D input, the voltage from potentiometer R220 is applied instead allowing a variable voltage to be used to set the tone mode:
  • <=0.5 volts:  1 kHz tone
  • >0.5 to < 4.5 volts:  Variable frequency audio tone
  • >= 4.5 volts:  Tone sequence
Having a fixed 1 kHz tone is useful if using a computer or other device when setting up end-to-end alignment of an optical path as narrow detection bandwidths may be employed to maximize the overall sensitivity of the detection scheme.  Because this PIC's oscillator is not crystal-based, the actual frequency can vary by several percent, but it should be easily spotted with spectral analysis programs such as "Spectrum Lab" by DL4YHF, Spectran or Argo (to name but a few).

In the variable tone mode the frequency may be set from a few 10's of Hz (below mains frequency) to a bit over 2 kHz as desired.  Finally, the "tone sequence" mode is designed to emit a musically-dissonant series of notes (C4, E5#, F4#, E6) that really stick out of the noise:  By being dissonant, spanning over an octave and non-continuous they avoid "ear fatigue" and are more likely to be heard amongst other sounds that may be being heard from power mains and electric signage that might be intercepted.

Manual gain mode:
Figure 4:
The version with manual gain control
Click on the image for a larger version.

While the audio AGC works quite well to assure that ones voice fully modulates the LED to maximize "talk power" and signal-to-noise ratio, one may prefer to have a manual gain control instead and manipulation of several of the pins on the processor allows the selection of that mode as depicted in Figure 4.

In this version the audio gain is set with R309, but one can effect a "software" gain setting two switch in an extra 12 dB of gain via appropriate strapping of pin GP4.  As with the "AGC" version, there a variable "tone" mode is available but there are also some "fixed" tone modes that may be selected via appropriate strapping of pins GP3, GP4 and GP5 if you don't wish to use a potentiometer.

Minimalist version:
 
Figure 5:
Minimalist version.
Click on the image for a larger version.

Finally, Figure 5 depicts a somewhat minimal approach to the circuit, using only a single op-amp section with no active low-pass filter, manual gain control and the optional selection of a tone mode if you choose to implement switch SW301.

At its very simplest, one would connect GP3 (pin 4) to the +5 volt line to put the PIC into audio mode all of the time, but the triviality of adding just one SPST switch and a resistor would provide the facility of a tone generator, doing so would be hard to resist!

Getting the code:

If you are interested in building a modulator for an LED or laser using this device and are interested in the .HEX file for programming the PIC yourself, please let me know.  If you don't have a way to program the PIC and want a pre-programmed device, I can arrange that, too.


More information:

For more information about Free Space Optical Communications for the amateur, be sure to visit the Modulated Light page - http://www.modulatedlight.org



[End]

This page stolen from "ka7oei.blogspot.com".

Monday, November 11, 2013

Attention-getting brake light "modulator" for a motorcycle.

Figure 1:
Figuring out how to remove the tail light.  It required
removing the bracket and license-plate holder just to
get to the bolts that hold the light in place.
Click on the image for a larger version.

My brother recently got a Yahama Bolt, a fairly new-model, medium-sized motorcycle.  As is the case with most motorcycle riders, "preventing invisibility" is always a big deal as it is often the case that casual riders of bikes of all sorts (motorized or not!) tangle with a car when the driver of the latter didn't see them!


Among a few other things done to enhance safety and visibility, he wanted to "modulate" the brake light - that is, rather than just going on and off with the application of the brake, that it do "something else" as well.


It is becoming more common that some new-model vehicles blink their brake lights in some sort of attention-getting flash sequence - and doing so makes a lot of sense:  The human brain is very good at detecting when something changes or is out of the ordinary so anything that stands out from the routine is likely to grab a bit of extra attention!  The hope is that if even a single driver is jolted out of a sleepy stupor or their attention drawn from their texting by this sort of thing that it will be worthwhile.


 First, the obligatory warnings and weasel words:
  • The brake light system is a safety device on which your life - and the lives of others - may depend.  Modifying it in any way runs the risk of reducing its reliability, particularly if due care has not been taken during design, building and installation to maximize reliability.
  • There are no warranties or guarantees, expressed or implied, as to the suitability of this project for its intended use, or for any other use.
  • Nothing in this article should be construed as offering an opinion as to the legality of the use of this sort of device.  It is up to YOU to determine if this device is legal/lawful to use.
  • If you choose to construct a device similar to this, it is up to YOU to make it as reliable and safe as possible and YOU assume any risks should any injury to anyone occur as a direct or indirect result of this sort of device!  The author of this article will not be held responsible for any injury or damage or other liability that might result!
  • Improper design, construction and wiring could result in damage to the vehicle's electrical system and/or wiring as well as other safety concerns.  YOU must assure that the work/modification has been done properly to minimize any risks as well as be aware that doing so may void warranties, reduce reliability, cause damage, etc.
  • Finally, the assertion that a "modulated" brake light catching the attention of other motorists and possibly improving overall safety is an opinion rather than a statement based on scientific research or fact and anyone reading this page and/or taking inspiration from it should take it as such!  It is up to YOU to determine if, in fact, this sort of project has positive or negative effects on overall safety!
  • You have been warned!


Figure 2:
 On the bench, the unit  in "dim" (tail light)  mode.
Click on the image for a larger version.
Figuring it out:

First, we analyzed the existing brake/tail light assembly of the Bolt after removing it from the bike.

Using three wires for connection (including a black "ground" wire) it consists of an array of 19 high-brightness red LEDs and internally, it seems to be "diode-ORed" between the two voltage sources.  If voltage is applied to the tail light wire (blue), the 19 LEDs light rather dimly and the entire assembly pulls about 40 milliamps at 14 volts.  If, however, you apply the same voltage to the brake wire (yellow) approximately 400 milliamps is pulled and the result is enough light to give you a bit of a headache and cause you to see red and green spots for several minutes!

Further analysis indicated that the tail light voltage was applied any time that the ignition key was on.  As you might expect, the brake light voltage appeared only when you applied them:  No special PWM (Pulse-width modulation) or anything else was present, this likely due to the fact that this light assembly was (probably) designed to drop in where one might have had an old-style, dual-filament incandescent lamp.

With its using only on/off voltages, this project would be easy!


The build:
Figure 3:
Throwing together the code for the tiny computer.
Click on the image for a larger version.

As strange as it might seem, the easiest way to make a device that flashes the light in a particular pattern is to throw a computer at it!

Fortunately, this is something that is pretty cheap and easy to do these days and I knocked out some very quick "C" code using a compiler for a low-end PIC microprocessor - a PIC12F675.  The device used was an 8-pin DIP (through-hole) processor chip (the same size as a 555 timer) that has a number of useful peripherals like A/D converters, built-in timers and a few other things - but I wouldn't need most of them:  I picked it because it was the smallest, simplest microcontroller that I had laying around.  Some of its features - like the watchdog timer and "brown-out reset" would be used to make sure that it "booted up" reliably and quickly, within a few 100's of microseconds after power was applied, every time.

While the computer code could have been done in assembly, I used C since I have the development tools (suitable tools can also be found for free...) and it was be very easy to bang out quick, dirty, and reliable code just to blink the light!

In the code I defined an array of 0's and 1's in program memory that corresponded to the desired blink pattern (0 = off, 1 = on) and indicating the end of the array is a "255":  The code would simply step through the array from the beginning and stop when it hit "255", leaving the light on.  Between each step a short delay (25 milliseconds) was added to slow down the process and make the blinking perceptible:  Without it, the entire sequence of blinks would have occurred in a few 10's or hundreds of microseconds and may not have even been noticeable!

Figure 4:
 Building the prototype on solderless prototype
board for initial hardware and software debugging.
Click on the image for a larger version.
Just because I was lazy, I defined all of the PIC's pins as outputs (except for the one that can only be used as an input - which I grounded) and the output pin that worked out to be the most conveniently located when I crammed the parts on the board was routed through a series resistor (R3) to an NPN transistor, Q2.  The collector of this transistor was connected to the base of a PNP power transistor (Q1) via another resistor (R2) and when the PIC set the pin to high, the NPN was turned on, yanking down on the PNP's base and turning it on, applying power to the brake light lead.  The total voltage drop across Q1 when the light was on?  Less than 200 millivolts (and a fraction of a watt heat dissipation) - barely even worth mentioning, let alone even noticeable in its effect of the light brightness!

Note:  In the diagram below, I happened to use pin 7 since it was closest to R3, but I could have used any one of the other output pins (shown with no connection in Figure 6) instead.  Do not connect multiple pins together.

To keep the computer happy a 78L05 regulator (U1) was used to drop the 12-15 volts of the motorcycle's power bus to the 5 volts required.  Because vehicular electrical systems are often "noisy" with spikes and glitches, I used a series resistor (R1, 47 ohms) and a filter capacitor (C1, 47 microfarads) to "clean up" the power applied to the regulator.  These components were selected so that not only would spikes be filtered out, but even very brief taps and releases of the brakes would trigger or re-trigger the computer quickly and reliably.  There is also another resistor, R4 which, should the processor NOT boot up for some reason, will pull the base of Q2 high and turn on the light since the hardware default of the processor is to have its pins in a high-Z state:  After all, we do want the light to WORK if your life may be depending on it!

In just a few minutes I had a circuit and its code working on a piece of wireless prototyping board.  After a bit more fiddling of the code to make it flash the desired sequence at the rate that my brother wanted, we were ready to commit ourselves to building a "permanent" version.

Figure 5:
 The newly-built board, ready for testing shown
laying atop the initial version of the
 schematic diagram that was built onto the
prototype board seen in Figure 4.
Click on the image for a larger version.
After analyzing the unused volume inside the tail light enclosure I could see that there was just enough room to cram a small board below the portion of the assembly containing the LEDs (see Figure 8) so I proceeded to build the circuit onto a small piece appropriately-sized phenolic prototype board. As can be seen from the pictures, I didn't make the board any larger or taller than absolutely necessary - at least with through-hole components - nor did I use a socket for the processor since I didn't want there to be the possibility of it falling out.  Were this device to have been built using surface-mount components it could have easily ended up being about the size of a postage stamp!

Once the circuit was built and tested I mixed a big blob of 5-minute 2-part epoxy and liberally coated both sides of the circuit board - this, to completely immobilize the circuitry to protect it from vibration as well as moisture.  Constantly rotating the board for a few minutes to keep the epoxy from dripping off, it soon began to set up and I then used a heat gun to warm it (to about 180F) - just hot enough that I could smell the epoxy, all the while moving the board about since the heat momentarily caused it to re-flow.  After 2-3 minutes of that, the hot epoxy had hardened to the consistency of a rubber pencil eraser so I let it cool.  In another 10 minutes at room temperature it was almost rock-hard, the curing process having been greatly accelerated by the application of heat.

The unit was re-tested and found to be working so we could now wire and mount it within the tail light enclosure.
Figure 6:
 The final version of the schematic diagram of the circuit for "modulating" the brake light.
While pin 7 (CP0) was used to drive Q2, pin 2, 3, 5 or 6 could have been used instead since all of the other pins shown in the diagram as being unconnected flash the sequence as well. While not shown in the above diagram, it is recommended that a resistor with a value of between 10k and 100k be connected between the emitter of
Q1 and the collector of Q2.  Where I to build this again I'd include a 15-18 volt Zener diode across C1 to provide
additional protection against transients.
Click on the image for a larger version.
For wiring onto the existing circuit I bared a short section of the insulation of the light's black wire (ground) and soldered it to the circuit.  Then, cutting the light's original yellow "tail light" wire I put the circuit inline with it, soldering and insulating the connections with heat-shrink tubing.  I then squirted a small blob of silicone seal on the inside of the milky-white plastic housing containing the LEDs where the board would go and plopped it into the small gap where I'd already pre-fit it.  Reassembling tail light housing, it all fit perfectly as seen in Figure 8.

Figure 7:
 The tested and working board, now coated with epoxy and
ready for install.
Click on the image for a larger version.
Testing once again on the workbench to verify that it worked after putting it all back together (it did!) we went back to the garage and after a several minutes of squinting and cramped fingers we managed to get all six of the bolts that hold the light and the shield/license plate holder assembly in place back together using some blue thread locker so that they wouldn't rattle loose.

We now had the light on the bike and working!


What does it flash?

When programming the PIC processor, we changed our minds several times about what, exactly, it would flash.  We first thought of the Morse code "V" which is "di-di-di-dahh" - like the beginning of Beethoven's 5th symphony.

We then tried the word "STOP" in Morse code and adjusted the speed to taste, ending up with a rate of about 44 words-per-minute so that the entire sequence completed in much less than a second.

Ultimately, we ended up with a different Morse message entirely, also sent at around 44 words-per-minute.  This turned out to be a very short, two-word message - the first word being "OH" - the result being a very distinctive, bright, and attention-getting flash sequence.

Can you guess the rest of the message?


Figure 8:
 The completed board, now inside the tail light housing, almost ready to be re-mounted on the bike.  On the underside of the white housing containing the LEDs there is a gap with an angled plastic area, just big enough for the board and the wires entering the enclosure to fit.  Not visible, the board is secured in place to the white plastic using a blob of RTV
(Silicone (tm)) adhesive.
Click on the image for a larger version.


Getting the code:

FWIW, the HEX code for this project - targeted for the PIC12F675 and PIC12F683 - may be found at the link below.

By downloading this .HEX file you indicate your understanding and acceptance of all risks involved in using it, including those that might result in hazard to life and safety and that you have read and understood the warnings near the top of this post.  

There are no warranties expressed or implied and it is up to the end user to determine the suitability and safety for their purpose!

Here are two .HEX files, one targeted for the PIC12F675 and PIC12F683.  The code is identical in function, but allows the builder a choice of processors:
Note:  It was "discovered" that with most programmers, the original .HEX code could not be used due to a hardware conflict with the !MCLR on pin 4.  The .HEX code above and the schematic in Figure 6 have been modified accordingly by tying pin 4 to pin 1.

While I'm not prepared to build custom boards to be installed (it's a matter of time and liability) I can supply a pre-programmed chip at a nominal cost for someone who might be willing to build a board, themselves:  Contact me if you are interested.


[End]

This page stolen from ka7oei.blogspot.com