Tuesday, July 4, 2017

555 - astable

In my previous blogs, we saw how 555 can be configured as a bistable (latch) or monostable (single pulse) signal generator. In this blog I would be delving into the astable configuration for 555.

So, what is the astable mode? In the context of 555, astable mode is that mode of operation when the output pin (Pin 3) perpetually oscillates predictably between HIGH and LOW voltages without external interventions. I have highlighted some parts of the definition which needs special mention.

  • Predictability is referred to in terms of the value of HIGH and LOW and the time that the output stays in those states.
  • External input implies any input to the astable circuitry apart from a DC power source.

Note that a term 'duty cycle' is used frequently in the context of astable outputs. Duty cycle is quite simple - it is equal to the %age of time the signal stays HIGH in one time period. So for example, if we have a time period of 4 seconds and the signal is HIGH for 1 sec (remaining 3 seconds, it's LOW), the duty cycle of the signal is 25%. capeesh?

Now, let's get into the interesting part - how do we go through the process of building one using 555.

Let's pick up from where we left the monostable circuit.



There we needed a negative (<1/3 Vcc) pulse at the trigger (Pin 2) to set the output high. As soon as the pulse starts, the discharge pin stops grounding and the capacitor starts charging. After a certain time (determined by the value of R and C) the capacitor reaches a voltage > 2/3 Vcc. When this happens the output is set to low and pin 7 gets grounded, causing the capacitor to discharge.

To extend the monostable circuit for astable operation, we need the an automated mechanism to trigger Pin 2 and 6, repeatedly at configurable time intervals.

So, how do we do that? We rewire the circuitry as follows:

The part that is of interest to us is the path from Vcc through R1, R2, C and ground. Also note how the 555 pins are connected, 7 is connected between R1 and R2, 6 and 2 are fused and the cap C1 is connected between 2 and ground.

Lets walk through the step sequence for two operation cycles and see how the circuit works. Let's start at an initial state when the circuit is just powered up, ergo, the output (pin 3) is low and C1 is discharged at the start moment.. but not for long...


  1. Since C1 is discharged, pin 2 is grounded. This meets the criteria of having a low (<1/3 Vcc) at pin 2 and hence the output goes high. 
  2. Once the output goes high, the threshold pin become ungrounded, implying that current now flows through Vcc, R1, R2 and starts charging C1.
  3. The charge on the cap is reflected on pin 6 and 2. Output is still high and the charge on C1 is steadily rising.
  4. The charge on cap touches 2/3 Vcc and rises... wham, the threshold (Pin 6) is triggered and output goes low, causing 7 to get grounded.
  5. Once 7 is grounded there are two separate current flows. First one is from Vcc through R1 and grounded through 7. Second one is the discharge current from the capacitor.
  6. Capacitor starts discharging from 2/3 Vcc and starts sliding down. 
  7. Soon it tips just below 1/3 Vcc and wham.. pin 2 is triggered. Causing the output to go high. So we are back to step 2 and the cycle continues.

Let's overlay the above on a voltage time graph and a real life oscilloscope. Hope this drives the concept home.. next we will delve into a bit of mathematics to understand and control the precise nature of the output waveform.







The mathematics behind

Few important considerations to keep in perspective before we go forward:
  1. The output is high while the capacitor is charging and low when the capacitor is discharging
  2. The capacitor charges and discharges only between 2/3 Vcc and 1/3 Vcc
As a recap, for a RC circuit the charging and discharging equations are:

Here R' is the resistor through which the capacitor is charging towards Vcc and t2-t1 is the time that the capacitor takes to charge from 1/3 Vcc to 2/3 Vcc. Now the discharging part...


Here R" is the resistor through which the capacitor is discharging. Now see the image below which shows the path of current flow during the charge and discharge cycles. It can be seen that the capacitor charges through both the resistors (R1+R2) but discharges only through (R2).

Therefore, substituting R1+R2 for R' and R2 for R" in the above equations we realize that the On and Off times are


Taking it a bit further, the time period is t_on + t_off


and hence the duty cycle is t_on / T, i.e


Limitations


There is something of interest hidden in the formulas above.. do you see that the on time is always greater than the off time, due to R1? This implies that the duty cycle obtained from this configuration can never be less than 50%. This might be a serious limitation in cases where we are interested in pulse type of waveforms which have a very small duty cycles.

To remedy the situation, the circuitry can be wired a bit differently as shown below:

See the parts marked in red. All it does it channelize the charge and discharge currents so as to overcome the limitation of >50% duty cycle. See how the change current is constrained to flow thrugh R1, D2, left part of R2; while the discharge current is routed through right part of R2, R3 and D1. I have take a PWM circuit to explain the concept, and hence the R2 pot. You can just place two resistors in series of the diode to make life simple.

Second big limitation is accuracy. 555 progressively looses accuracy for larger time periods (exceeding a few minutes). This is of the large capacitor tolerances. If you are looking at 555 for very low frequency (0.0x Hz) scenarios, it is better to use IC4060, which is a 14 stage binary ripple counter and can give you time periods in hours and days.

Third limitation is fast switching. If you are operating on the other end of spectrum (tens to hundreds of KHz), a slight load on the output will seriously influence the leading edge taper. See the scope snapshot below.


If you need a sharp leading edge irrespective of driving load (at high frequencies), you are better off driving a high impedance op-amp buffer or a switching mosfet at the output.

Lastly another important thing worth mentioning is the difference between TTL and CMOS 555 varieties. CMOS versions (TLC555 or ICM7555 chips) are costlier but give a much better output as compared to TTL 555. CMOS 555 chips can give close to rail voltages at the output and show much less distortion and ringing even when operating under moderate load.





Sunday, July 2, 2017

USBASP teething woes

For an AVR newbie, there can be nothing more frustrating than the feeling of being ditched by the usbasp programmer the moment he ventures out on his own.

A newbie usually starts with an usbasp programmer and a development board. After the initial struggle of setting up the drivers for the programmer and configuring Atmel Studio with avrdude, life seems joyful when the first blinking LED program work seamlessly.

In my case, I use the following devices. The red one is the usbasb programmer from USBProg and the other one is the development board (with an onboard ATMEGA 16A PU chip) from provotech.in.



Once the initial familiarization is over, the next logical step is to move to a breadboard and be freed from the constrains of the development board. In doing so, we pick up the standard usbasp 10 pin FRC pinout and map it to the programming pins of ATMEGA 16 - simple, right? BTW - one of the reasons I love 16A to start with is because the pins are wonderfully grouped and are not scattered around. Anyway, this is how the ideal in system programming connections look like.


So, where is the problem? The problem is that the above does not work and avrdude keeps saying that it is not able to communicate with the device.

  • First doubt - maybe the connections are goofed up... check.. no they look ok...
  • Second hunch - maybe the chip is fried .. check with another chip... oops the second chip doesn't work too....
  • Third attempt - let's try with the 16A from the board ... lift the chip, place it on the breadboard... try to flash.. nope.. not working.. 
  • Fourth attempt - place the 16A back on the development board.. try with the programmer .. it works.... wow.. 
  • Fifth attempt - Search google desperately... read through the longish message board trails.. you see recommendations of upgrading firmware... but you are already on the latest... 

At this point, nothing really makes sense anymore. Desperation, amalgamated with frustration sets in and you make up your mind to close shop. 

The root cause and solution

After tracing the male FRC pins on the usbasp PCB back to the Atmega8 (in accordance with the official usbasp schematics), I found that - the ISP pinout from the usbasp board was non standard and did not match with the standard 10 pin configuration!



In fact, mine looked like the following.. 


Great revelation, now the connections can be rewired and ..... NOOOO.. it still doesn't work. The usbasp programmer is still not able to communicate with the MCU. Darn!! double darn, it was such a good lead!

Upon further sleuthing it comes to notice that the the programmer is operating at 8 MHz oscillator while our virgin chip is operating at a 1Mz factory default. Ergo, we need to slow down the SCK sync by using the Slow SCK jumper (JP3 in the original schematic).. we do that and voila, the virgin chips start working...

Wonderful!

Now, just for the sake of completeness, we try to see if our solution is able to handle the ATMEGA 16A chip on the development board. So we pry it open, put it on the breadboard, connect the jumpers and poof!.. it doesn't work. Some more head scratching and the realization dawns that the chip on the development board is not a virgin! It has been fused to work with an external oscillator - which makes sense since the the Slow SCK jumper is not required when working with the development board and there is a 8 MHz onboard oscillator connected to the XTAL pins on the board). So, we slap in an external 8 MHz oscillator on the bread board, remove the JP3 and wow, it works now!

Hope this helps someone who is running down the rabbit hole, like me and my son did.

Oh, btw - a nifty tip, if you end up getting yourself a usbasp programmer with a non standard pinout, you are better off desoldering the 10 pin make FRC connector and soldering a 6 strand FRC directly. Furthermore, it is a good idea to make yourself a tiny flash fang at the other end with a 6 pin male berg strip and a tiny strip board cutout. It digs its fangs perfectly onto the breadboard when you want to flash something on the chip.