A Simple Programmable 555

“Instead of an Arduino, he could have done that with a 555 timer.” “Instead of a 555 he could have done that with two transistors.” “Instead of a few transistors, he could have done that with butterflies.” These are quotes from various Hackaday comment threads throughout the years. It seems simplicity is the name of the game here, and if you need a timer chip, how about an 8-pin DIP? This, of course, means an I2C programmable oscillator in the form of an LPC810.

[kodera2t] built this circuit after reaching for a 555 timer a few too many times. It’s a one-chip solution with an ARM core that’s able to generate square waves with 1Hz resolution up to 65536Hz.

The source for this chip is a lot of C, but once it’s in the Flash of the LPC810, this chip becomes a programmable oscillator with an I2C interface. Yes, it’s a one-component solution, no, it’s not a twenty cent chip, but try programming a 555 over I2C.

The videos below show [kodera] playing around with this I2C oscillator, sweeping the frequency from zero to inaudible teenage angst.

77 thoughts on “A Simple Programmable 555

    1. The LPC810 is actually an ARM microcontroller in an 8 pin DIP package. kodera2t wrote some code for it in C that listens as an I2C slave device and sets the onboard PWM peripheral based on that. The compiled code is stored in flash so you only need to program the code once and then the LP810 just acts like a I2C controlled oscillator.

    2. “fish, plankton, seagreens and protein from the C”

      I think that means the chips come from the future, probably in logan’s run time.

      just watch out for the blinking lifeclock. there IS no santuary!

        1. Noice.

          Hm. That makes me think… there’s a dude who used an Arduino for a clock controller *and* its timing source. Too lazy to ferret up the link right now, if I can even find it, but IIRC he basically used a PWM pin off a timer, wired to an input, as the clock timing source.

          I wonder if something similar is doable with PICAXE…? (I actually doubt it, but I’ve been wrong before…)

    1. The ATTiny85 internal oscillator will also change depending on the temperature. The factory calibration accuracy is +/-10% and only valid for 25C exactly. You can calibrate it yourself to within +/-1% but it again has to be a fixed temperature.

  1. He could have done that with a watch, some string, freshly shaved Peruvian coconut, chloroform, that actor from Mr. Belvedere who became the lead singer of Garbage, more string and duck tape, not duct but actual tape made from ducks. Square waves, all damn day.

      1. These guys are listing A**uino Uno for $89? Either their currency converter is off, they have some interesting definitions of value or the value of my workbench just soared.

          1. I assume you’re comparing it to one of the many clones which are dirt cheap in comparison. A real Arduino Uno R3 isn’t cheap. Adafruit and Sparkfun both sell it for $24.95 so Seeed selling it for $29.90 is a bit more expensive but not wildly so.

  2. For running a site about (mostly) electronics hacks, HaD spends a lot of time wasting time on spending too much money on over powered chips for simplistic operations. There are only about 100,000,000,000,000,000 8 pin, dip package microcontrollers that can do this that don’t have the overhead and expensive price tag that this ARM chip has that have been around since like 1980 or something. PICs for example. How is this a hack, and a good one at that?

    I’ll go to the grocery store down the street in my Lambo, while I wait on an answer….

    1. Hack (n) (src:Wiktionary
      10.(computing) An interesting technical achievement, particularly in computer programming.
      11.(computing) A small code change meant to patch a problem as quickly as possible.
      12.(computing) An expedient, temporary solution, meant to be replaced with a more elegant solution at a later date.
      13.(colloquial) A trick, shortcut, skill, or novelty method to increase productivity, efficiency or ease.
      This is 10 because it is 13 used as a 12 that enumerates 11 at the hardware level

  3. I wouldn’t call that an oscilloscope. Its name is DSO Nano v3.
    The clock seems very stable… not! He could’ve just used a timer of the chip from the i2c master. Oh, I forgot he only has arduino skills.

  4. Can someone tell me how he gets 1Hz resolution in a microprocessor?

    According to the datasheet, the micro runs at up to 30MHz, which for a 30KHz signal would be a PWM counter divided by 1000. Taking the next larger divisor (1001) results in a difference of 30Hz.

    (And that assumes a full square wave with each count. More likely, each count is one transition, so the divisor would actually be 500, and the difference in resolution is about 60.)

    In other words, is the cited resolution just the API interface, with the actual output mapping many frequencies into one? Or is he actually getting 1Hz resolution?

    I would *love* to be able to run my transducer from a micro with 1Hz resolution – if it can be done. My analysis (“Design Question 3” from the link below) suggests that it can’t be done.


    1. Ok, let’s say you want 29,999hz. Divide by 1,000. Also trigger an interrupt each time a pulse is generated, an MCU can handle 30K interrupts per second no problem. Count the pulses, and on every 30th pulse, set the divisor to 1,001; then reset it back to 1,000 on the next pulse. And voila, you have 29,999hz.

      To put it a more general way, you’re accumulating the error caused by being limited to an integer divisor, until it becomes large enough to temporarily select the next higher or lower divisor.

      You can also reduce the number of interrupts needed. For the 29,999hz example, feed the PWM pulses into a counter. Sometimes you can do this completely in-chip, other times you just externally connect two pins. Set the counter to trigger an interrupt every 30 pulses. This first interrupt sets the divisor to 1,001, and enables a second interrupt that triggers on the next pulse. The second interrupt sets the divisor back to 1,000. Now instead of 30K interrupts/sec, you only have 2K interrupts/sec.

      Sure, not all pulses will be of exactly equal length this way. You get a “jitter” in the signal of 16.5us average and 33us max, but in most cases that’s not important. Probably not in yours, since resonant circuits average over many pulses.

      But let’s go accuracy crazy, and say any jitter is unacceptable. I recall one NTSC video signal generator that used a really neat trick, and I hope I can accurately recount how it worked. It used an external crystal to clock the MCU. You’re supposed bypass each side of the crystal to ground with a capacitor, usually in the 12-18pF range, for stability. But by altering the cap values, you can also subtly tweak the crystal frequency. This generator replaced one of the caps with a varactor diode, ie an electronically variable capacitor. A PWM was output into a filter to generate an analog bias voltage for the diode. By using a second clock as a fixed reference, it was able to measure its main clock frequency and *alter* it, just enough that it was capable of producing the exact signal frequency required – despite the limitation of an integer divisor.

      It most definitely CAN be done… just a matter how how fancy you want to get. ;)

      1. That’s not “jitter”, that’s you actually getting two different frequency signals out of it if you look at it in a spectrum analyzer.

        You’re just generating a 30,000 Hz signal most of the time and interrupting it every 30 cycles, which produces a 1,000 Hz spike in the spectrum on the side. There is no energy at 29,999 Hz in your signal, just like two people singing equally loud in C and E doesn’t make it sound like one person signing in D.

        If you put that through an extremely narrow bandpass filter at 29,999 Hz you get nothing out. A resonant circuit would be excited to some degree, but you lose signal amplitude. If you try to clock another circuit with it you get timing glitches.

        1. “There is no energy at 29,999 Hz in your signal, just like two people singing equally loud in C and E doesn’t make it sound like one person signing in D.”

          Imagine taking a 1khz square wave, and digitally sampling it at 44.1khz. 44.1khz isn’t an integer multiple of 1khz, and therefore pulse lengths would alternate between two values; which would only produce 1khz when averaged over time, not when examined on a pulse-by-pulse basis.

          Yet you obviously don’t hear two notes when playing back the digital audio. So I have to assume you’ve misunderstood something.

    1. No offence, but in what circumstances would you want something like this controled by USB? I2C is far more convenient with any embedded system, as it’s easier to implement.

  5. I’m not sure how valuable an I2C controlled 555-replacement is, because any MCU that can drive an I2C bus probably has a spare PWM output somewhere.

    More generally, though, I’ve been thinking that a project that had a library of common utility functions implemented as firmware for a common MCU like the ATTiny range could be really helpful. Want an IO expander, or a boost controller, or a counter? Sure, just flash this premade firmware onto a device you already have and check out the datasheet.

      1. I’m imagining there’s something to be said for the learning/devel overhead… there’s a programmer necessary, toolchain, etc. I can definitely see sticking with what you’re familiar and have the tools for… And, from the other side, there’s the fact that something like this is a bit of an appeal to AVR/PIC users to attempt ARM programming, knowing there’re options for small projects.
        The thing that I find appealing is that with that few pins it can’t possibly require all the complicated power/decoupling of ‘some other’ DIP-factor 32-bit chips I’ve run into. Start small, and work your way up, in this case…?
        But, like you’re suggesting, it is hard for me to imagine a case where this would be used in any sort of product, it’s like they’re aiming it directly at the educational/hobbiest/hacker market(?)
        Lots of contemplations… Kinda cool to know it’s out there. Maybe some day…

      1. You also need to factor in the die size of the other parts than just the core… RAM, FLASH, I/O cells, I/O pads, peripherals, the usual system stuff: oscillator/PLL, regulator for the core voltage, brownout detector, bus interface, debugger etc.

    1. The problem being that now you need a programming device and a computer to interface to your simple project that is designed to blink a LED or generate a simple servo signal etc.

      The point of the “you can do it with a 555” argument is usually that the device is doing something exceedingly trivial that doesn’t warrant digital access, and is actually made more cumbersome by the requirement to program it instead of just soldering in a resistor or turning a knob.

      Often you see people then add the potentiometer to make the thing stand-alone from the computer, and then spend hours and hours puzzling over how to read analog values, debugging their code, dealing with glitches and special considerations like brown-out-detection and how to prevent the chip from corrupting itself when the battery runs out…

      So-on and so forth, when they could have just started with a 555/556 reference circuit and be done in 5 minutes.

      1. Work hard once so you don’t need to work hard every time.

        I don’t count the effort required to initially develop the code unless you are intending to use the device exactly once.

        There are good objections to this hack, but I don’t think that is one of them. JMO

        1. How many LED flashers or halloween props with servos are you going to make over the years?

          Curiously enough, I see this mentality a lot with hackers. It’s the mentality of, “I’ll spend two hours writing a shell script to do this one specific thing that I’m probably never going to do twice, that would take me one hour to do manually. Isn’t command line powerful!”

          1. I doesn’t have to be same project. I’ve done dozens of microcontroller projects, and a lot of code snippets and knowledge can be carried from one to the other.

  6. I have no idea, why this device is so cool. If the one have a ARM32 M0 with 30 MHz, he definitely can reach high frequency at least 1 MHz, not 65 KHz. Algorithm is simple as it is in description: get a frequency, fill the memory with pre-calculated samples. send values from a memory cell one-by-one to a GPIO. If you’re smart enough, you will get high frequency and complex signal shape at the same time. Jitter will be minimal, while the number of ticks required for a loop is absolutely predictable if interrupts are disabled.
    But anyway, last time I see, that ARMs are more and more preferable than ATxxx, AVR, PIC, MSP430 or STM8. Thanks to the author for a discovering new chip for me. BTW.

    1. I tried it with moths! No damned good at all! There is no conversion, the moth buss protocol is so complicated!
      I’ve found anything with a club antenna works, if it’s feathered, forget it!
      Oh, and use a knife for the duck tape or you’ll be spitting feathers all weak!

      On a similar vein, years back I programmed up some motor speed controllers, using PIC 8pin devices for RC cars etc. Made life so easy! Many parameters could be set on start-up with a press button ;)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.