I am starting to write a series of tutorials on programming AVR uCs in C. I plan to write articles covering Interrupts , ADC , timers , internal EEPROM, PWM and USART. This is the first in those series and it covers basic I/O operations. Here is the link to the page.
Every calculus tutorial that i have read , shows the derivation of πr^2 by either adding together tiny rings or by cutting up the circle into triangles and integrating. So , i thought why not derive the formula , by actually integrating the equation of a circle? And voila to my surprise , it actually worked (I’m still a calculus noob)
So , first we need the function for a circle. Every point on the circle is equidistant from the origin. Hence the equation is clearly x^2 + y^2 = r^2 , where r is the required radius.
Rearranging to get a proper function ,
Now , if i take this function and plot it , it should ideally give me a circle. And it does. Unfortunately , for reasons unknown , Microsoft math is seeming to clip off the negative half of the circle. I dont know why. But that really doesnt matter as i will only be taking the part of the circle in the 1st quarant and will be finding its area. Then we can multiply the area by 4 to get the area of the whole circle.
Now since i have my function , i can find the area of the circle by integrating the function between o and r. This integration will give me the area of a quarter of a circle. We can multiply that area by 4 to get the full area.
Ok. To integrate , we need to find the antiderivative of the circle function. Microsoft math tells me that it is :
The Anti derivative
Now , let me call this function F(x).
Finding F(r) – F(0) should give me the area.
F(0) is very clearly 0 , as both the terms in the equation become zero.
F(r) is
as arctan of (x/sqrt(0)) is apparently 90 = π/2 radians. (I dont know why. Maybe by taking the limit of the function?)
and there you have it folks , ( πr^2 /2) , which is (πr^2/4) !!
Which is precisely the area of a quarter of a circle.
So , now if we multiply it by 4 , we get the area of the whole circle = πr^2 !!!
To cut it short , EEPROM is a memory device , similar to the memory stick in your cell phone or camera.
The Pin layout of an EEPROM is very similar for most Static RAMS. So once you know how to program an EEPROM , you also know how to program RAM.
So lets get started.
Before knowing how to use an EEPROM , you have to know how it organizes its data.
The EEPROM is divided into 8912 “houses” with eight rooms in each house. You are allowed to store either a 1 or 0 in each room.
When you wish to write some data to the EEPROM , you have to specify the address of the “house” where you want to store your data.
(Did you ask yourself why the number of “houses” is something as arbitary as 8912? Its because 2^13 is 8912. And there are 13 Address choose pins on the IC.)
Then , using 8 input pins , you have to give 8 values which will be stored in the eight “rooms” of selected “house”.
The procedure is very similar when you want to read the data back.
Again , you will have to select the address of the “house” and the 8 values in the eight rooms will appear through the output pins.
If add up the total number of pins : 8 for input +8 for output + 2 for power + 13 for address + 3 control pins
= 34 pins!!!
So to reduce pin count , Manufacturers have combined the Input and Output pins and made them into a single set of 8 I/O pins. This makes it a bit tougher to use the IC as both the functions have to be done by the same set of pins.
The Procedure :
EEPROMs have 3 control pins : CE (Chip Enable) , WE (Write Enable) , OE (Output Enable)
This truth table should make it pretty clear how the 3 pins work :
CE
OE
WE
IC Status
0
0
0
Invalid Condition
0
0
1
Read Mode
0
1
0
Write Mode
0
1
1
Outputs are Tristated
1
0
0
Chip Disabled – Outputs are Tristated
1
0
1
Chip Disabled – Outputs are Tristated
1
1
0
Chip Disabled – Outputs are Tristated
1
1
1
Chip Disabled – Outputs are Tristated
Here’s the explanation :
The Chip can Read/Write only when CE is low. If CE is held high , then the chip is disabled and the I/O pins are tristated.
When CE is LOW, OE is low and WE is held high , the data in the memory location chosen by the address pins , appears at the I/O pins.
On a new EEPROM which has never been programmed before , all the memory locations are programmed with 1’s by default. So , while reading from a new EEPROM , you will see only 1’s in every memory location.
To write , input the 8 bits that you wish to write at the I/O pins while holding OE high and WE low. Then raise WE to high and then back to low again. Then , the data that you have given on the I/O pins will be written on the rising edge of the pulse to the address that is present on the address pins at the rising edge.
The waveform will be like this :
So , if you have not understood from the above waveform , let me make it very clear.
This is the way to manually write to an EEPROM :
1) Hold OE and CE low and WE high – Read Mode – Whatever is in the location determined by the address pins will appear at the I/O pins.
2)Hold CE Low, OE high and WE high – I/O pins are tristated – disconnect the output leds (or whatever) from the I/O ports
3)Hold CE low , OE high and WE low – Write Mode – Give the data to be written at the I/O port and the address where you want it to be written at the address pins.
4)Hold Ce low ,OE high and WE High – I/O pins are tristated AND data is written – Disconnect the Switches or wires that you used to give data to the I/O port.
5) Hold CE and OE Low and WE high – Read Mode – You are back to step 1. Whatever is in the location determined by the address pins will appear at the I/O pins.
The procedure is same for RAMs as well. The only difference between EEPROMs and RAMs is that RAMs lose whatever has been written when the power is turned off , but EEPROMs dont.
There are many EEPROM and RAM ICs available. The EEPROM that i generally use is AT28C64B from Atmel. It is available at around 100 INR (~2$) here in bangalore. The cheapest RAM IC is 6264 which is available for 35 INR (0.7$)
The writing procedure that i have described above is rather crude. There are better ways of writing to the same EEPROM. But , this is best way if you are using the EEPROM by giving CE ,WE, OE signals by hand.
I now have an entire box of ‘dead’ ics which i have ‘murdered’ by accidentally giving them reverse polarity. I suddenly had a brainwave today as how to prevent this. The idea is very simple :
Connect a diode between the + and gnd rails such that it is normally reverse biased.
Suppose you accidentally reverse the supply , the diode will become forward biased and will short circuit the battery.
Since the battery is short circuited , the IC will be saved (but your battery will be fried).
Hopefully , you’ll realize your mistake in a few seconds after seeing that your circuit is not working and will disconnect the power supply.
WARNING : Dont try this with lead acid or other high AH batteries. Shorting lead acid batteries is not a pleasant experience.
I was getting frustrated of dashing to the computer everytime to refer to a datasheet. So , I’ve decided to make a collection of all 7400 series data sheets and print it into a book. I have uploaded the first set that i have collected – from 7400 – 74150. I hope it will be of use to someone.
PS : I have trimmed the datasheets and uploaded only the first one or two pages of each which really contain most of the important stuff.
I have written a simple program in VB.NET which allows you to perform various calculations that you may require while designing circuits. Currently , the included features are LM317 Output Voltage Calculator , Resistor Color Code Calculator , 555 Monostable and Astable calculator, Ohm’s Law Calculator, LED resistor calculator. I plan to add more features in upcoming versions. Please note that i have not extensively tested this program and so there are likely to be lots of bugs. Please inform me if you find any bugs so that i can fix them
After much patient effort and wasting many dozens of PCB s , i finally learnt the art of making pcbs the right way.
Here are the steps , so that you don’t have to undergo the grind that i had to :
1) Clean your PCB thoroughly.
Rub it vigorously with sandpaper both vertically and horizontally.
Then using some steel wool and a dish washing soap (such as Vim) , clean the PCB thoroughly.
Then dry the PCB using some tissues. Immediately after this , clean the PCB one final time using tissues and acetone. I have found that although alcohol works too , the success rate is much higher with acetone.
All this is done so that the PCB is clean and free of any dust or grease which repels toner. Make sure that you never touch the PCB directly during any point of time. The thin film of oil on your hands will stick to the PCB and will prevent the toner from adhering properly.
Also do not leave the PCB for more than 10 minutes after cleaning. Dust may resettle on it. I learnt this the hard way. Remember thatevery step is important and the PCB will almost definitely not come out right even if you miss a single step.
A word of caution : Do not use the steel wool that you used for any other purpose. Copper particles aren’t too good for health.
‘
2) Preparing for Toner Transfer
This involves printing out your circuit design (though a Laser printer ONLY) on an OHP sheet and then taping it on a PCB and ironing on top of it. This will cause the toner to melt and get transferred onto the PCB. This is the most delicate and most crucial part in PCB making.
a) Design and print out your circuit using a software such as EAGLE or Express PCB on an OHP sheet using a Laser printer. I personally prefer ExpressPCB. Remember that your design will be inverted when it is transferred onto the PCB.
b) Cut the design to the appropriate size and lay it down on the PCB such that the cutout holds to the PCB by means of a ” Suction Lock “.
Then tape it to the PCB , making sure that there are no air gaps ( this is extremely crucial). I have found that the tape that works best is Painters Tape which is available at any hardware store. It is best if you can get tape of width ~ 1 inch ( shown in the pic on left).
3)The actual Toner Transfer
Using an electric Iron set to it highest setting (with the water removed ,please) press on the PCB with the largest force that you can muster for around 20 seconds.
If have taped the cutout properly , then the cutout should neither wrinkle nor blacken due to the heat. Using the tip of the Iron , carefully run over the traces a few times to fix them in place.
After doing this , once again press on the PCB for around 10 seconds. Make sure that at no point of time the traces get smudged or merge together.
At this point you must be able to visually see that the toner has melted. If you feel that the toner has not melted completely in a few places , then feel free to run them over using the tip of the Iron.
Now immediately take the PCB and dunk it in a container full of tap water. This will cause the toner to become solid and stick to the PCB. Leave in the water for atleast 15-20 seconds.
Then remove it from the water and slowly peel off the tape and remove the cutout. Atleast 95% of the toner must have transferred to the PCB.
here is a video which i made to show you how exactly it is done :
However , note from the video that a single pad hasn’t transferred from the sheet to the PCB.
To fix this , just use a permanent marker (blue or black) and just draw over the place where the pad should be several times (this is very important) . The permanent marker will act just like the missing toner.
4) The final part – Etching the PCB
This involves dunking the PCB in a tub full of a chemical that can dissolve copper. Some typical example are ferric chloride , ammonium persulfate , and a mixture of HCL and 3H% H2O2.
Ferric Chloride is most commonly available in india. To prepare the etchant using HCL and H2O2 , refer this link. Ammonium persulfate is said to be better than FeCl2 as the soultion is clear and hence you can overlook the etching process.
The etchant prepared from HCL and H2O2 is faster than FeCl2 , but unfortunately it also dissolves permanent marker ink. So , there is no chance of making any corrections on PCBs after you perform toner transfer. This is the primary reason why i am sticking with FeCl2.
Warning : If you are using FeCl2 , let me tell you that it stains anything , including skin upon contact. The stains are nearly impossible to remove. If you get FeCl2 on your skin , wash it off immediately using water.
Ferric chloride is available in the form of dry (and rather messy) power. The instructions say to dissolve 500g of the powder in 1 liter of water. I have found that dissolving around 700g makes a more potent solution.
After you prepare the , dunk the PCB in it and leave it for a while. At room temperature and with no heating or agitation , it takes around 4 hours to complete. With heating , it (reportedly) reduces to 1 hour. I have never tried heating myself so i really dont know much.
UPDATE : I bought a new 500g FeCl2 pack and dissolved it in 500ml of water ( The recommended amount is 1 liter). And i heated it by placing the container full of FeCl2 in another tub full of hot water. Amazingly , it finished etching in just 10-15 mins!!
I don’t know what had such a major impact on the etching time ; Was it the heating or was it the more concentrated solution??
Use ONLY PLASTIC TWEEZERS to remove the PCB from the etching solution. After it is done , clean the PCB thoroughly with water and soap. To remove the the toner , use either sandpaper or acetone.
And voila…You’re done…
Note : Always remember to sand the PCB once before soldering , as the oxidized copper will repel solder.