top of page

The end of the 555 vs Arduino wars?

  • q in motion
  • Feb 21, 2021
  • 4 min read

Updated: Feb 22, 2021

A 555 emulated in a Raspberry Pi Pico


If you frequent the comments in electronics blogs, you've probably noticed what I call the Arduino vs 555 wars: Every time someone posts a simple project using an Arduino, there is someone arguing that it could have been done with a 555.


If you don't know, a 555 refers to an integrated circuit, originally the NE555 that appeared in the early 1970's. The 555 was designed to be a flexible timer circuit. The classic modes of operation are astable (free running mode, and can be used to blink an LED), monostable (can be used to stretch a short pulse, or provide an off-delay function), Schmitt trigger and R-S latch. Because the building blocks are basic but flexible, many other circuits were made with it. There are several websites featuring circuits that include a 555, for instance 555-timer-circuits.com. If you want to know more about the 555 and its history, Wikipedia has an interesting article.


The 555 proponents have a point (maybe), as it is good engineering practice to use the simplest solution that will meet the specs for the project. A 555 is undoubtedly simpler than a microcontroller, and a few years ago it would have been the simpler solution. However, nowadays with some microcontrollers costing a few cents and not requiring any external timing components, in the end the solution could be simpler than using a 555.


In any case, the argument still pops up, sometimes more seriously and sometimes more as a joke. Along these lines, a reader posted this comment in a Hackaday post, referring to the new Raspberry Pi Pico:


And I thought: hmm, why not? I also thought that maybe this will bring some peace to the Arduino vs 555 wars, and decided to do exactly that: use a Raspberry Pi Pico as a 555 timer.



The 555 internal structure


Functionally, the 555 is a simple circuit, having 2 comparators, one R-S latch, one output buffer and one transistor configured in open collector. It also has a network of 3 resistors to generate reference voltages of 1/3 Vcc and 2/3 Vcc.


The 555 internal structure, from Wikipedia (public domain)

The software


The software to emulate it is also simple, with only a handful of lines per functional block. The most difficult part was to install the toolchain for the Pico. After downloading and installing several gigabytes in Windows, I couldn't get it to work. When I switched to Linux, everything went much smoother.


Like I said, the C program in the microcontroller is simple. The comparators were emulated with analog inputs and a simple if() statement:

        //Calculate the output of the threshold comparator        
        adc_select_input(THRESHOLD_CHANNEL);
        if (adc_read() > TWO_THIRDS)
            r_input = true;
        else
            r_input = false;

        //Calculate the output of the trigger comparator
        adc_select_input(TRIGGER_CHANNEL);
        if (adc_read() < ONE_THIRD)
            s_input = true;
        else
            s_input = false;


The latch was also simulated with an if() statement:

        //Calculate the output of the RS latch
        if(s_input)
            rs_out = true;
        if(r_input)
            rs_out = false;

Next, we have to emulate the open collector output. This was done simply by switching the pin between input and output. When it is as an input, it is left floating, equivalent to the transistor in the original 555 being off, and when the pin's mode is switched to output, a previously written 0 will cause the pin to pull to ground:

        //manage the DISCH pin (hi-z if the RS latch is ON,
        //otherwise connect to ground)
        if (rs_out){
            gpio_set_dir(DISCH_PIN, GPIO_IN);
        }else{
            gpio_set_dir(DISCH_PIN, GPIO_OUT);
        }

Finally, copy the output of the RS latch to the output pin (and also to the LED pin):

        //copy the output of the rs latch to the output pin        
        gpio_put(OUT_PIN, rs_out);
        //Copy the output to the LED
        gpio_put(LED_PIN, rs_out);

The code above could be optimized in many ways, but I believe it is always best to start with "optimize for clarity" rather than speed or size.


The only pin that cannot be emulated without external components is the Control pin. If necessary, an external resistor network and another analog input could be used.


The source files and the UF2 (compiled file) can be downloaded below.


Does it work?


See for yourself in the video below:



Performance


It works fairly well at lower frequencies. Keep in mind that A/D conversion time in the Pico is about 2 microseconds, and we need 2 conversions per loop. That puts a lower limit of 4 microseconds per loop. Because a full cycle requires at least two loops, the absolute highest frequency that this could work is 125 kHz. In practice, I obtained about 85 kHz max.

Another problem, also related to the ADC, is conversion error. I'm not sure if this is because of offset, non-linearity, or error in the ACD reference, but the Trigger input should have been triggering at 1.1V but is was actually more like 1V. But other than that, it is a good approximation to the real thing.


Why a Raspberry Pi Pico?


I could have used another microcontroller with analog inputs. But the Pico is the latest thing on the market and I just can't ignore the trend :) But speaking more seriously, for instance in an Atmega328 (the controller on the Arduino Uno), the A/D converter has a conversion time of 65 to 200 microseconds, compared to 2 microseconds in the Pico (did I mention the Pico is fast?). This means that this technique will work on other microcontrollers, as long as the time constants set by the external resistors and capacitors are long.


Conclusion


I know, this is a silly project and rather pointless. But maybe this will encourage some of the Arduino fans to experiment with a makeshift 555 and maybe use a real one in their next project.



Comments


Commenting on this post isn't available anymore. Contact the site owner for more info.
Post: Blog2_Post
bottom of page