It is quite easy to flash a light in say, 0.5 seconds on, 0.5 seconds off. But what if I wanted to flash it say 0.5 on, 0.5 off, 1.0 on, 0.5 off? Are there any IC's that would allow that?
-
16\$\begingroup\$ Hundreds. We call them "microcontrollers". \$\endgroup\$– Ignacio Vazquez-AbramsAug 14, 2015 at 18:57
-
\$\begingroup\$ Most aftermarket flashlight mods that allow patterns or fading are done with general purpose microcontrollers. \$\endgroup\$– PasserbyAug 14, 2015 at 18:58
-
1\$\begingroup\$ If you're negatively microtropic you could create the particular pattern you mention with a 555, a 4017 and three diodes, but these days most would use an 8-pin micro of some description. \$\endgroup\$– Spehro PefhanyAug 14, 2015 at 19:04
-
2\$\begingroup\$ Wouldn't microfoob be an easier term? \$\endgroup\$– Wouter van OoijenAug 14, 2015 at 19:16
-
\$\begingroup\$ Perhaps you were trying to say, microphobe? \$\endgroup\$– gbarryJan 27, 2016 at 21:46
5 Answers
The keyword from your text is "say". You apparently do not know exactly the pattern yet. This usually calls for an microcontroller. You can let your light flash with nearly any pattern using an microcontroller for less than 1 € or dollar. The best thing is: You can change your pattern without using a soldering iron.
Of course there are possibilities with logic ICs too. Try to use a shift register like the sn54166. Preload the shift register with a dip switch. Give it a clock, e.g. from a NE555. Add another button to trigger the load input.
The output will allow you to send a sequence with multiple durations of the clock cycle. If you need more elements to send, use a shift register with 16 bit. If you want to output the sequence continuously use a shift register with Input/Output and connect both the serial input and output.
As many here will simply say: "Go and buy a microcontroller" I'll give you some backup for trying it with logic circuitry. So why should you do that? It seems you have little experience with logic circuitry otherwise you would not ask :). I consider a basic understanding of logic circuitry and the related nits and pieces as very valuable for fiddling with electronics in any way. And there is no better learning than by doing.
The next thing is: Using a microcontroller may solve many problems with the very same platform or at least the same methodology, but it involves some rather difficult steps to get a grip on it. You need to get programming knowledge and you need do get knowledge about computing platforms in general to use it to your advantage.
If you want to learn more about logic circuitry go forward and try using them. If you just want to have a programmable flashlight and a programmable coffee machine and a programmable cat feeder and a programmable automatic TV station changer go and try an Arduino :)
-
\$\begingroup\$ And get a breadboard for experimenting with your logic ICs. \$\endgroup\$– TEMLIBAug 16, 2015 at 17:52
Pretty much every question like this comes down to the same fundemental question - at what point does a state machine become a waste of time compared to throwing on an 8-bit microprocessor?
If you read up on digital logic, you can build an IC to go through different "states" and repeat. However, the more cases you add, the more typical it is to just end up using a $1 8-bit microprocessor.
If you're new to that world, I highly suggest getting an Arduino (essentially a highly popular SW platform that -typically- runs on an Atmel chip)
While I agree with the others that this project would be better served with a microcontroller, I'm going to go against the grain and show how it also could be done using discrete logic -- using a 555 timer as a clock and a CD4022 octal counter as a state machine.
Here is the circuit.
(Right-click and use View Image for a larger view.)
The 555 timer chip, configured in astable mode, generates a clock pulse every 1/2 second. That is then fed into the 4022 counter. The outputs of the counter are diode-OR'ed together to light the LED.
In the initial state (1), i.e. turning on the power, the LED is on. A 1/2 second later, the counter advances to state 2. Since there is nothing connected to the output, the LED turns off (the pull-down resistor keeps the N-channel MOSFET off). Another 1/2 sec, the counter is in state 2 and the LED goes back on. It stays on in state 3, so that provides the one second on period. Then it goes off again in state 4. In state 5, the counter is reset, and it goes back to state 0, with the LED on again.
The CD4022 can only sink or source a few mA, so I added a high side switch using a P-channel MOSFET to control the LED. It can handle 280 mA (way more than needed even for super bright LEDs). It in turn is driven by an N-channel MOSFET connected to the counter.
If you were to code this in C for a microcontroller, one would probably use a switch statement to implement the state machine something like this:
int state;
state = 0;
while (1)
{
switch (state)
{
case 0:
led(ON);
break;
case 1:
led(OFF);
break;
case 2:
case 3:
led(ON);
break;
case 4:
led(OFF);
break;
}
if (state < 4)
{
state++;
}
else
{
state = 0;
}
delay_ms(500);
}
Advantages with this discreet logic: cheap, the parts will cost under $10. An Arduino Uno (a real one, not a cheap knockoff) will cost $25. If you use a stand-alone microcontroller, you'll need a programmer (an Arduino has a bootloader instead so it doesn't need one).
With the discrete circuit, there is a zero learning curve; you can put it together on a breadboard in under an hour. It's easy to change the timing around (for example you want 1 1/2 second on period) just by moving a couple of wires.
Disadvantages with this approach: The timing, being analog, won't be as accurate as with a microcontroller. Even as designed, the closest I could get to a 500 ms period using standard resistor values was 502 ms (I used this to calculate the values). But then you're going to have to deal with tolerances, especially with the capacitor, so you will end up "fine-tuning" the timer if you it to be spot on.
If you want times in increments of 1/4 second instead of 1/2 second, you would need to change the 555 timing components, and also redo the counter wiring. With the firmware approach, it would be only a few lines of code.
Instead of the 555, if you had a 32,768 Hz crystal, and a divide by 14 counter like the CD4060, then divide down the 32,768 Hz down to 2 Hz, this would be about as accurate as the microcontroller.
Advantages with using a microcontroller: Although you have to go through a steep learning curve, you will learn a lot of valuable stuff. Easier to modify parameters (timing rate, how long LED stays on).
Disadvantages with using a microcontroller: higher cost, and lots of hours you will need to come up to speed.
-
\$\begingroup\$ And aren't 555 timer based astable multivibrators fairly temperature sensitive, so the clock rate will vary depending on the temperature of the components? (especially the resistors) \$\endgroup\$– Duncan CAug 14, 2015 at 21:51
-
\$\begingroup\$ @DuncanC I agree, the 555 will be nowhere as accurate as the microcontroller. To be more like the latter, you could use a 32,768 Hz crystal and count it down to 2 Hz. I didn't want to add that additional complexity, just trying to show the basic principals.. \$\endgroup\$– tcrosleyAug 14, 2015 at 23:14
-
\$\begingroup\$ Added bonus, you could get lots of different timings from the crystal using different dividers. \$\endgroup\$– Duncan CAug 14, 2015 at 23:16
-
\$\begingroup\$ But use a microcontroller. An Ardunio is great for tinkering/learning/prototyping, but for production, a simple microcontroller is much more cost-effective. \$\endgroup\$– Duncan CAug 14, 2015 at 23:17
-
\$\begingroup\$ @Duncan And that's why I mentioned the Arduino. I assumed the OP was just interested in experimenting around (if they wanted to actually build something at all). Someone else had mentioned getting an Arduino also. Using a stand-alone microcontroller would entail buying a programmer, which would cost a least another $25. \$\endgroup\$– tcrosleyAug 14, 2015 at 23:26
Stupid and expensive answer, but an FPGA or CPLD can eaisly do that. So can the things those are derived from (NAND logic)
-
\$\begingroup\$ LOL, come on, even Relay logic can do :) I've seen that you can make an oscillator from a relay (making it oscillate like an old electro-mechanical bell, and use additional weights to slow it down a little). Then you can make flip-flops from relays, and can build up your own counter! :-D I guess nowadays the right tool for this task is a microcontroller. One chip standalone takes care of this alltogether. Let's not make it more complicated than necessary, what do you think? :) \$\endgroup\$– Gee BeeMar 17, 2016 at 1:21
These days it would be done with a micro because of flexability and there are more people that can program micros .Also the micros are better and cheaper than 25 years ago.Over a similiar time frame other chips like digital logic havent improved much.OK if you are microphobic you could use one chip with an odd number of invertors connected in a ring with RC delays ,Maybe a 40106 schmitt trigger.This will give you enough states to diode OR and have something reasonably general .It wont be stunningly accurate and it wont be good for very long delays but it will sure flash a lamp.