Interrupts on AVR

Interrupt is neither same  for all hardware’s nor for the compilers. Some hardwares support multi level interrupt or nested interrupt and some chips use single interrupt flag. The Atmel architecture interrupt works as following

1. As Interrupt triggered processor finishes pending instruction

2. Stops fetching further instruction

3. Clear Global interrupt enable bit(This is why arduino denies nested interrupt, but you can use)

4.  Push PC(program counter) on stack

5. Jump to interrupt vector(specific address where the corresponding interrupt handler expected to be)

6. Next is the ISR code in case of C compiler do a lot job for you and if you are using assembly all that have to do youself.

Push the status register to stack and also any other register that you may use in this ISR block

Execute the actual ISR handler code i.e. whatever you want to do when the specific interrupt occours

When the actual task is done, rollback the things you changed i.e. POP the stack to status register and other register you had pussed

7. Now last assembly code RETI which rollback the PC from stack and Reenables Global Interrupt

So in the whole process all except the step 6 and 7 are automatic user need not worry about the steps.


ISR in C

use variables with volatile type modifier other compiler optimiser may think the varible is static(assuming not changed in main())

  • Keep the ISR code as short possible in execution time not in length.
  • Don’t activate or deactivate interrupt inside ISR
  • Don’t call another function that uses interrupt

Now the above rules are for the ideal people, you can do it if u know what the hardware and the compiler does. Suppose you have to do some of the banned things immediately after the interrupt triggered, i have to methods one is the method being ideal another is to break the rules.

A.If your main loop contains things that only run when a interrupt is triggered and interrupt are not overlapping, in this case u can set special flag to activate a part of main code (code u want to run in ISR), the flag need to set in the original ISR and cleared in main loop part of ISR.


B. Next method is really complicated. You need to mess with the hardware and the compiler, you know when interrupt occurs global interrupt enable is cleared ,PC pushed to stack by hardware and Status register and other registers moved to stack by compiler, So here

if you want to get another interrupt you have to set GIE and if interrupt occours it will again push pc and but the compiler part is complex.

Some people make multilevel interrupt with software. The main interrupt handler acts as the first interrupt handler which catches the interrupt event and stores necessary data and exit ISR(the basic isr) and start the secondary interrupt handler. exiting the fast interrupt handler triggers RETI so all interrupts resumed.


MSP430 with IAR

First of all the question is why IAR why not CCS or GCC, here is my answer

You are learning all these not just for fun, if it is then you may with gcc also. but if you are learning both for fun and career then you should prefer one which is used by industry, and both TI’s CCS and IAR EW costs same, so why not choose the one with multiple compilers in the Same IDE design although they sold all of them individually.

Download the installer from IAR Systems page . Now you can install this with two different modes One is code size limited version Second is full Version Time limited Licences validity. Now click Project-> Create New Project, Now you can choose the language C, C++ or assembly and for c and C++ you can choose template or project with main().

Anyway all these things are useless for geeks  like you. The real question is the headers and the libraries, where are the standard functions and MACROs, how is the C C++ standard differ from other C standards(although embedded C is always a NonStandard C).

Step 1 should be to download The Family User Guide, like if i am using MSP430F149, i should read MSP430x1xx Family User Guide i.e.

Default UI based project adds io430.h this includes it need you to define your chip name in define statement i.e. #define MSP430F149

But i will prefer to add the specific header file instead of these chains i.e. msp430f149.h with hardware description of the specific chip.

For delay you may use __delay_cycles(x), which gives delay of x instruction cycles, and one instruction cycles duration=(1/MCLK frequency in Hz)Seconds


Variety of capacitors available in market, some times I discover alien components on PCBs from Big companies. Some are don’t look like capacitors. Some are specific to some unique job, if u replace with another one it may not work at all like the low ESR capacitors in DC DC converters.



A ceramic capacitor is a two-terminal non-polar device. The classical ceramic capacitor is the “disc capacitor”. This device pre-dates the transistor and was used extensively in vacuum-tube equipment (e.g., radio receivers) from about 1930 through the 1950s, and in discrete transistor equipment from the 1950s through the 1980s. As of 2007, ceramic disc capacitors are in widespread use in electronic equipment, providing high capacity and small size at low price compared to other low value capacitor types.

Multilayer ceramic capacitors are increasingly used to replace tantalum and low capacitance aluminium electrolytic capacitors in applications such as bypass or high frequency switched-mode power supplies as their cost, reliability and size becomes competitive. In many applications, their low ESR allows the use of a lower nominal capacitance value



An electrolytic capacitor is a type of capacitor that uses an electrolyte (an ionic conducting liquid) as one of its plates to achieve a larger capacitance per unit volume than other types, but with performance disadvantages. All capacitors conduct alternating current (AC) and block direct current (DC) and can be used, amongst other applications, to couple circuit blocks allowing AC signals to be transferred while blocking DC power, to store energy, and to filter signals according to their frequency. The large capacitance of electrolytic capacitors makes them particularly suitable for passing or bypassing low-frequency signals and storing large amounts of energy. They are widely used in power supplies and for decoupling unwanted AC components from DC power connections.

Aluminum electrolytic capacitors are constructed from two conducting aluminum foils, one of which is coated with an insulating oxide layer, and a paper spacer soaked in electrolyte. The foil insulated by the oxide layer is the anode while the liquid electrolyte and the second foil acts as the cathode. This stack is then rolled up, fitted with pin connectors and placed in a cylindrical aluminum casing. The two most popular geometries are axial leads coming from the center of each circular face of the cylinder, or two radial leads or lugs on one of the circular faces.


Polyester film

This capacitor uses a thin polyester film as a dielectric. Not as high a tolerance as polypropylene, but cheap and handy, temperature stable, readily available, widely used. Tolerance is approx 5% to 10%. Can be quite large depending on capacity or rated voltage and so may not be suitable for all applications. Temperature stability is poorer than paper capacitors. Usable at low (AC power) frequencies, but inappropriate for RF applications due to excessive dielectric heating.







Tantalum Capacitors


Tantalum capacitors are polarised and have low voltage ratings like electrolytic capacitors. They are expensive but very small so they are used where a large capacitance is needed in a small size such as mobile phones or laptop computers. These capacitors have increasingly become an important as the demand for ever smaller electronic gadgets has grown. Columbite-tantalite – coltan, for short, the ore from which tantalum is refined is mined in Australia, Egpyt. The high demand for the ore has also financed civil wars in the Democratic Republic of the Congo. A UN security council report charged that a great deal of the ore is mined illegally and smuggled over the country’s eastern borders by militas from neighbouring Uganda, Burundi and Rwanda providing the revenue to finance the military occupation of the Congo.


Metalized Polyster Film

No polarity, dielectric made of Polyester or DuPont trade name “Mylar”. Good quality, low drift, temperature stable. Because the electrodes are thin they can be made very very small. Good all-round capacitor.Care is necessary, because the component lead easily breaks off from these capacitors. Once lead has come off, there is no way to fix it. It must be discarded.





Polystyrene capacitors


No polarity, is used as a dielectric. Constructed like a coil inside so not suitable for high frequency applications. Well used in filter circuits or timing applications using a couple hundred KHz or less. Electrodes may be reddish of color because of copper leaf used or silver when aluminum foil is used for electrodes.

Excellent general purpose plastic film capacitor. Excellent stability, low moisture pick-up and a slightly negative temperature coefficient that can be used to match the positive temperature co-efficient of other components. Ideal for low power RF and precision analog applications







MICA Capacitors

This type is an extremely accurate device with very low leakage currents. It is constructed with alternate layers of metal foil and mica insulation, stacked and encapsulated. These capacitors have small capacitances and are often used in high frequency circuits (eg. : RF circuits). They are very stable under variable voltage and temperature conditions. Tolerances range from +/-0.25 to +/-5 percent. Capacitances range from 1 pf to 0.01 uF, with maximum voltage ratings from 100 V to 2.5 k

SMD Codes Transistor Capacitor Resistor

SMD_codesSMD the surface mount devices are the smallest footprint componets. These are enough small to have some surface area write its name in full. So the manufacterers use unique code for each component which are 2/3 alphanumeric characters.

resistance value from SMD resistors easy easy with three digit codes as it is same as the three ring color code. But no data about tolerance. Capacitors also same as SMD resistors for only the capacitance data in pf range capacitors.

am compiling a small book on the common components till search from these sheets.

download this pdf file



you can search here


Microcontroller-powered wet razor

Microcontrollers are everywhere, including the oddest of places, such as a razor—the Schick Hydro Power Select customizable power razor, to be precise. I’m not sure why you’d need microcontroller-controlled customizable power or the packaging, waterproofing, and power issues that go along with it, but I gave it a shot. After all, Schick promises it “allows men to interact with their razor in a new way.” I never realized that I longed to interact with my razor in new ways, but Schick has created a demand—a craving, if you will—and I just had to try it. Alas! It wasn’t all that much better than interacting with my regular arm-powered, hand-controlled razor, so I instead took it apart. It’s a bit more interesting to go inside and see how the designers implemented a wet razor, powered from one AAA battery and featuring three vibration settings, easy-to-read indicators, and a haptic sensor. Why they would do it is another question.

Most interesting thing abou this gadget is that it is powered by two microchip products one is the microcontroller PIC10F222 which generates the PWM signals and other is the boost controller MCP1624 from microchip which makes the system to run with single AAA size batter i.e. 1.2volt (NiCD rechargable).

1. A three-stage power button sets the vibration. The razor rotates through all three settings and then goes into off mode. It required too much pressure to activate due to its sealing cap.

2. A vibration-stage indicator uses LEDs.

3. Batteries are inserted here…..Read more

How the Digital world Sleeps

Have you ever thought about this, Unlike humans they have more options than us, they can Sleep, Standby, Hibernate, Restart and the last one Shutdown !! !

These things is available at both softaware (OS) level and hardware level. In your desktop or laptop u must have used all these options

In this article I will explain both for general computer user and the embedded developers.

In Operating Systems:

Lets first see what happens in MS Windows OS.

StandBy: This option sets the screen off and harddisk stops. All other services continues except those dedicated to the user.

Sleep: This is a bit more than standby useful for power saving. This stops the hard disk, switch off the screen, switch off most of the parts and sets the clock speed low so as to lower power consumption.

Hibernate: Hibernate its very useful if u need your system to start from the last files u r working with as it is, and quick mode. What it does is

As you click hibernate it saves all the Data in RAM into a file Hiberfile.sys (which has size same as RAM size) and write an extra line in the Master Boot Record.

Next you start your PC it starts from MBR as normal but the extra line written in the previous session tells the system that it was hibernated in the previous session. So it searches for hyberfile.sys and loads that data onto RAM, while showing a screen message System Resuming ….

N.B.:There was a similar option in RHEL linux which was very similar to hibernate but not same in bachground. It saves all the session information(which files opened what edited….) and on next start it resumes according to that data, so it is a bit slower and some processes like games videos will not supports this.


In Microcontrollers and Microprocessors:

After dinner…. wait

Temperature Sensor from Butterfly wings


Wings as temperature sensor

Nanostructured Wings as temperature sensor

Many of the shimmering colors in a butterfly’s wings are produced not with pigments, like the melanin that tints our skin, but with nanostructures (pdf). The scales on their wings are patterned with nanoscale channels, ridges, and cavities made of a protein called chitin. Unlike pigments, which create color by absorbing some wavelengths of light and reflecting the rest, the nanostructures are shaped so that they physically bend and scatter light in different directions, sending particular colors back to our eyes. That scattering can also make the wing scales iridescent–meaning the color changes with the angle you see it from.

When heat, in the form of invisible infrared radiation, hits the chitin nanostructures, they expand, changing their shape and therefore the colors they display. Scientists at GE are working to harness this property to make hypersensitive thermal imaging sensors, useful for night vision. By coating the wings of a Blue Morpho butterfly with carbon nanotubes that magnify the effect, researchers there made an insect into a sensor that changes color when its temperature changes a mere 1/25th of a degree.

Testing HTTP request from Python

Before implementing a webserver in microcontroller, I was searching whether I could try
the same on a PC and I got this actually I was searching for raw packet sending method. What I got is as below

  1. import httplib
  2. h2 = httplib.HTTPConnection(‘’)
  3. h2.connect()
  4. h2.request(“GET”, “/index.php”)
  5. r2 = h2.getresponse()
  6. print r2.status
  7. 200 (Server Reply)
  8. print r2.reason
  9. OK   (Server Reply)
  10. print
    now you will get the html code on console window

I will Publish more on this some other day

Useful Tools: Wireshark Network Analyser(Free OpenSource) , Python (OpenSource),
Device Monitoring Studio(30 days Trial)

SPI and I2C protocol with PC Parallel Port

Now-a-days most of the sensors comes with an I2C or SPI interface. All sensors and supporting interface devices, energy meter ICs, Network analyzer chips have the I2C port. So it is now a bit complex than before as the interface was Serial (UART). Although all the advance microcontrollers have some extra support for this but for the People interfacing devices to PCs it needs a bit tweaking with the available ports i.e. parallel or serial or USB.

In most of the links on internet people choosed the parallel port although parallel port is rare things on modern PCs, again there is no True USB to Parallel Converter. But u may add a PCI-Parallel port interface in your desktop board.

In all version of windows(for vista and win7 you need some extra tweak to break the security walls) you can test the I/O ports directly from the command prompt with debug tool. You can test the I2C device only with the command prompt also.

Goto cmd type debug the prompt will change from C:/Docum———/user>_ to –

-i 378

The above command will read from port 378 (378 is the pc parallel port base address)

-o 378 FF

This will output FF on the port

If we connect the I2C device as below

then with the following command we can start the communication

i 378 Read the Data Byte.
-o 378 00 Write the Data Byte to 00h. This will make SDA and SCL output a logic high.
-i 378 Read the Data Byte. This should return 00 since we just wrote it to 00.
-o 378 01 This will make SCL low and SDA high.
-o 378 02 This will make SDA low and SCL high.
-o 378 03 This will make both SDA and SCL low
-o 378 00 Make sure SDA high before executing the following command.
-i 379 This returns the state of SDA. If bit 5 is 0, then SDA is high. If 1, then SDA is low. Keep

in mind that to read SDA, Data Byte bit 1 should first be written to a 0 so SDA will be

released by inverter U1A. If nothing external is pulling SDA low, then bit 5 should read as a 0.
-o 378 02 Now force SDA low.
-i 379 Read the state of SDA again. This time bit 5 should read as a 1.


You may try SPI interface with parallel Port there are schematics and supported driver and GUI interfaces for these, below is link to one from freescale and some other site

Freescale SPIGen or SPI Simulator driver for windows


Parallel Port Utilty Software


How to Use PC Parallel Port as I2C interface to PC

Fun with Google Search

For those who haven’t tried it yet, pull Google up on your browser and type in the words “let it snow.” Then enjoy a snow flurry right on your computer screen.

To keep the wintery fun going, Google also added a frosty element to the experience: As the snow continues to fall, your computer screen will fog up. Click the “defrost” button to clear it, or use a mouse to draw hearts, or initials or whatever else you want in the fog. You can click defrost at any time to start over again.

A spokeswoman from the company sent the following statement about the Let It Snow trick in poem form:

“Through the fog, you have to peer 
Because it’s the most wonderful time of the year 
Your page turned into a winter wonderland 
When you typed in that search command 
You can always defrost the window 
Or just let it snow, let it snow, let it snow!”

Well, it’s not a poetry house, but they do like to have fun.

Google has some other neat tricks up its sleeve, and if your work is slow for the holidays, now might be a perfect time to try them.

1. Type in the word “askew” into the search engine. Tilt your head and enjoy.

2. Type in the word “tilt.” Hold your head askew and enjoy.

3. Type in the word “recursion.” Google will wonder if perhaps you meant to type the word “recursion.”

4. Google didn’t forget Jews. Type in the word “Hannukah” for some festive non-Christmas holiday screen decor.

5. Type in “anagram.” Google will wonder if perhaps you meant “nag a gram.”

Unfortunately, some of the Google classic tricks are no longer functioning. It used to be that if you typed in the words “Chuck Norris” you would get a statement that says, “You don’t find Chuck Norris, he finds you.”

There was also a time when if you typed the word “Gravity” into the search engine you’d watch all the copy on the page plunk to the bottom. It doesn’t do that anymore, but you can see what you missed here: .

Merry Christmas!