Sunday, August 23, 2015

Connecting ADC PCF8591 using IsquareC bus to Arduino R3 board

PCF8591 is a 8 bit ADC using sigma-delta conversion method. The chip is i2c bus enabled, which makes it easy to communicate with Arduino R3 board.
The circuit has been wired as shown below:
The A/D converter has 4 channels which can be selected using software. More A/D converters can also be added using the same SDA/SCL lines to connect more number of inputs. The whole circuit can be a template to interface multiple real-world sensors to the Arduino Ecosystem.
The code for the above is:-
// Example 52.4 PCF8591 ADC demo
// http://tronixstuff.com/tutorials Chapter 52
// John Boxall June 2013
#include "Wire.h"
#include
#define PCF8591 (0x90 >> 1) // I2C bus address
LiquidCrystal lcd(4,5,6,7,8,9); // define our LCD and which pins to use

byte value0, value1, value2, value3;
void setup()
{
 Wire.begin();
 Serial.begin(9600);
 lcd.begin(16, 2); // need to specify how many columns and rows are in the LCD unit
  lcd.clear();      // this clears the LCD. You can use this at any time
}
void loop()
{
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Welcome!");
  // prints "Hello" at the LCD's cursor position defined above
  lcd.setCursor(0,1);
  // positions starting point on LCD, column 0, row 1 (that is, the bottom left of our LCD)
  lcd.println("This is GDS!    ");
  delay(1000);
  // note the rest of the line is padded out with spaces

 Wire.beginTransmission(PCF8591); // wake up PCF8591
 Wire.write(0x04); // control byte - read ADC0 then auto-increment
 Wire.endTransmission(); // end tranmission
 Wire.requestFrom(PCF8591, 5);
 value0=Wire.read();
 value0=Wire.read();
 value1=Wire.read();
 value2=Wire.read();
 value3=Wire.read();
 delay(1000);
 //value1 = 0x55;
 if (value1 > 50)
 {
   lcd.clear();
   lcd.home();
   lcd.print("V101 GAS > 60%!!");
   delay(3000);
   //Serial.print("manoj");
 }

 //Serial.print(value0); Serial.print(" ");
 Serial.print(value1); Serial.print(" ");
 //Serial.print(value2); Serial.print(" ");
 //Serial.print(value3); Serial.print(" ");
 //Serial.println();
 lcd.noDisplay();
 delay(1000);
 lcd.display();
 delay(1000);

}

Monday, July 27, 2015

Whistling sound in tv due to Puffed capacitors in Set-top box

whistling noise coming out of the tv when watching tv programs through the set-top box. suspected leaky capacitors. opened set-top box and saw some "puffed" capacitors. the puffed capacitors are shown in the figure with an arrow.


De-soldered the capacitors and checked with multimeter, the capacitors looked ok, no leaks. If a capacitor is leaky, it will show some resistance reading in the meter. In this case, the resistance shown was infinity as a good capacitor should be.


Then I wondered what made the capacitor puffed? I had purchased a digital LCR meter recently. checked using LCR meter showed capacitor value as 100 mu F instead of 1000! , so as a result of deformity, the capacitance value had changed, thus de-stablizing the circuit.


I had a few 1000 mu F capacitors spare, so I checked their value, they also had gone down to 900 mu F, due to ageing perhaps, but, 900 muF would just work fine.

Replaced the three capacitors and connected back to TV. No whistling sound! So, what made three capacitors get deformed? Power supply surges might have taken the toll on the caps.

Investing in a good LCR meter paid off! otherwise, would have just replaced the capacitors. Measurements are good, measurements make you confident.

Thursday, April 2, 2015

mobile phone charger circuit trace-out

A mobile phone charger worth Rs 80/-. (in India). Converts 220 V AC to about 5 V DC.

Bridge rectifier + C1 filter  converts the 220 V to 220 V DC. This is used to switch Q1 and Q2 on/off. The working of circuit was greatly simplified by watching the video of a czech engineer on youtube on his teardown of a powersupply.  I wrote this blog in 2015 and tried to understand from whatever I knew, that text has been pushed to the end into the appendix in light of new info in Nov 2018. Just to get an idea of how my learning was progressing. The link to youtube videos are given in the references.

The circuit has a transformer, but, it is better known as a coupled inductor (ref 2.3), but for simplicity sake, we will call it a transformer henceforth. This transformer  has a primary winding a, an auxiliary winding b and a secondary winding c. The transformer primary winding is the collector load of transistor Q2 (13001). Q2 switches on and off fast, a voltage will show up in the secondary winding c when the transistor switches off due to high voltage induced in the primary winding due to the switch off process. This is the general principle. This process is called flyback and was initially used in old CRT TV sets to produce high voltage from the LOT for 'flying back' the electron beam quickly to its starting point (with some offset ofcourse, else, the same line will be traced again and again. :) ). This is also called a RCC (Ringing choke converter) or self-oscillating flyback converter (ref 2.4)

 The advantage of such circuits is that it can be configured to be buck (like our charger) or boost(like our electron gun flyback) , with high level of isolation (due to transformer) and also permits to have change of polarity ( like producing negative voltage from positive voltage wrt ground) , all with suitable placement of switch (transistor), inductor (transformer) and the  rectifier diode. (in secondary ).

Brief Working
When circuit is powered up, Q2 switches on in active region due to the high value resistor R6 of 1 M ohm, this makes a small collector current flow through the  primary winding. This induces a voltage in auxilliary winding b which is promptly communicated to base of transistor Q2 through C3 and R5, which turns Q2 to saturation. After this point, current falls through capacitor C3 as it gets charged and transistor Q2 again goes from saturation to cutoff as transistor Q1(S9014) starts conducting because when Q2 is in saturation, a voltage has developed on resistor R3, thus turning on Q1 and totally turning off Q2 . The cycle repeats through R6 as given above.

Voltage regulation
Diode D6 charges capacitor C2 to a negative potential (I don't know if our cap is polarized or not, but in analysis of several circuits in internet, it was noticed that this capacitor was connected with negative polarity and the positive leg was connected to ground instead of R3 as in our circuit. R3 is small value of 1.5 ohm, we can also take it as connected to ground). The diode D6 charges C2 to negative potential when the transistor Q2(13001) is off. Actually, the feedback winding and secondary winding are in phase with almost same number of turns (12T, reference is the youtube video #1) , the primary has about 170 turns. The capacitor C2 almost gets charged to same potential as capacitor C in the secondary winding, the zener volage is 7v (ref youtube video # 1) and as capacitor negative voltage increases, the breakdown voltage of the zener decreases, finally, at 5v, of capacitor voltage, the zener breaks down and thus the oscillation in transistor Q2 is turned off. This provides a voltage regulation of output and does not allow the voltage to increase beyond the rated voltage. 

A more reliable method is however to use a opto coupler fired from the secondary and turning on Q1 as shown in video # 3
These chinese people used all the tricks in book to reduce component count to produce cheap charger when making such millions of units, there will be good cost difference when compared to standard competition.

Variations
 lots of variations in all the circuits given in the youtube videos in the references and my own circuit traceout and the one blogged in electroschematics. The differences arise due to the fact sometimes the whole show is managed by Q2 (13001) alone or sometimes the Q1, the aux transistor is also present. Sometimes optocoupler and secondary zener is used for voltage regulation thus, z1,is omitted, D6 is reversed and C2 is used as filter to feed the optocoupler photo transistor a positive voltage which finally appears at base of Q1 and turns off Q2. 

Learning Attempt in 2015 is shown in italics
Q2 biased to just switch on ,and when Q2 switches on, Q1 turns on due to the voltage across R3. When Q1 turns on, Q2 turns off as it looses substantial portion of current. This makes Q1 turn off thereby making Q2 on. The cycle continues.

This result in a square wave with positive and negative cycles at label a (need more explanation on C4, D5 and R7 package) . I am not able to understand why the box portion is required which drives the winding labelled b . My guess is, it kind of reduces the induced voltage on winding c. ( the output). Diode D7 rectifies and cap C5 filters the output voltage giving 5 V dc. (Wish I had an oscilloscope to pull out  some  component and to observe the change in waveform! )

An interesting thing to note is the 220V DC straight-away coming to the transformer. If there is any leak or any short in the windings, it would come to the output, giving a nasty shock ( real nasty as it is DC). So, now it should be clear why one shouldn't attend call with a charger powered on.! X1 should be a pulse transformer with split windings in the primary and single winding at secondary.

Hand tracing of the circuit was a pain! but, helped to understand the principle behind the working.

More Notes After reading EFY March 2004 ed. Article about designing flyback transformers for SMPS. The transformer used in the above circuit must also be in flyback mode. This is also called the Buck topology. The polarity of the secondary winding is opposite that of the primary winding. Therefore, due to the presence of diode in the secondary winding, current flows either in primary or secondary, but not both at the same time.

Also, the winding "b" may be included to give a negative  feedback effect of voltage induced in winding "c". This ensures that in case voltage rises in secondary winding "c", it is taken care by quickly communicating to the base of transistor Q1, quickly turning it on and thereby turning Q2 off.

More notes after reading Power Electronics text R.S.Bhimbra
It appears that Diode D5 and R7,C4 are included to give a flywheel effect. The Diode conducts when the Q2 switches off, because when Q2 switches off, a reverse voltage develops across "a" which has to be returned to the power supply to avoid core saturation. This will ensure that when next cycle begins, the current rises in the winding from zero and not a pedestal. 


All youtube videos are listed in a playlist called smps in my youtube channel
 
Useful YouTube links
1. https://www.youtube.com/watch?v=Z6BpyslpSN8&list=PLAYtq5OyFN1dvXD87ClFQ8GZZBD4SnVpV&t=0s&index=5 (bigclive)

2. https://www.youtube.com/watch?v=bOR9SeYpkj0&list=PLAYtq5OyFN1dvXD87ClFQ8GZZBD4SnVpV&t=417s&index=6 (12 V 2 A power supply , diodegonewild czech guy)

3. https://www.youtube.com/watch?v=grRCx4lgHtg&list=PLAYtq5OyFN1dvXD87ClFQ8GZZBD4SnVpV&t=0s&index=8 (Li ion charger, diode gone wild)


2. Smps theory
1. https://youtu.be/nmUug3WNIZI NXP semi
2. https://youtu.be/8779DJxK3GE foolish engr
3. https://www.youtube.com/watch?v=OXibsOzjipw&list=PLAYtq5OyFN1dvXD87ClFQ8GZZBD4SnVpV&t=0s&index=10 (israeli professor) 

4. https://www.electroschematics.com/12799/diy-rcc-smps-circuits/ (T.K. Hareendran)