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

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!


Sensor Fusion:

A Potential Application of the Ersatz Brain Architecture


One possible application of our Ersatz Brain architecture is to the important and difficult problem called sensor fusion.


Sensor fusion roughly means integration of information from different types of sensor into a unified interpretation.


Humans are so effective at doing information integration that it is not appreciated how hard it is to do.


This observation also has been made, usually after the futile expenditure of great amounts of money, for:


  • computer vision,
  • machine translation,
  • natural language processing, and
  • text comprehension.




The De-Interleaving Problem.


About a decade ago, I was involved in a project in collaboration with, at first, Texas Instruments and, later, with a local company called Distributed Data Systems, Inc.


The project was an attempt to solve the de-interleaving problem
in radar signal processing using a neural net.


This problem is from military electronics but in fact is a cognitive one.


In a complex radar environment, the problem is to determine how many radar emitters are present and whom they belong to.


Biologically, this corresponds to the behaviorally important question, “Who is looking at me?”


To be followed, of course, by “And what am I going to do about it?”



A receiver for radar pulses provide several kinds of quantitative data:


  • frequency,
  • intensity,
  • pulse width,
  • angle of arrival, and
  • time of arrival.



The user of the radar system wants to know qualitative information:


  • How many emitters?
  • What type are they?
  • Who owns them?
  • Has a new emitter appeared?


The way we proposed to solve the problem was by using a “concept forming” model from cognitive science.


Concepts are labels for a large class of members that may differ substantially from each other. (For example, birds, tables, furniture.)


We built a system where a nonlinear network developed an attractor structure where each attractor corresponded to an emitter.


That is, emitters were valid concepts.






A weakness is that it does not allow development of the kind of structures that characterize human concepts.


One of the most useful computational properties of human concepts is that they often show a hierarchical structure.



Examples might be:


animal > bird > canary > Tweetie




artifact > motor vehicle > car > Porsche > 911.





Sensor Fusion with the Ersatz Brain.


We can do a kind of sensor fusion in a simple and way in the Ersatz Brain.


Let us use a radar-like example.


The data representation we suggest is directly based on the topographic data representations used in the brain.


The appropriate software approach to the Ersatz Brain array it is topographic computation.


Spatializing the data, that is letting it find a natural topographic organization that reflects the relationships between data values, is a technique of great potential power.


It is a natural and effective way to compute for the two dimensional cortex.


And our two dimensional Ersatz Brain architecture.


Spatializing the problem also provides a way of “programming” a parallel computer.


(See our arithmetic application, Anderson, 2003).


Topographic Data Representation



We initially will use a simple bar code to code the value of a single parameter.




The precision of this coding is low.


This was one of the aspects of our approach that most disturbed traditional radar engineers: we deliberately threw out their hard won precision.






For our demo Ersatz Brain program, we will assume we have four parameters from the source.


An “object” is characterized by values of these four parameters, coded as bar codes on the edges of the array of CPUs.




Our architecture assumes local linear transmission of patterns from module to module.




The geometry we have used for the demonstration gives many two parameter interference patterns, the straight lines.


Each pair of input patterns gives rise to an interference pattern, a line perpendicular to the midpoint of the line between the pair of input locations.





Higher Level Features.



There are often places where three or even four features coincide at a module.


The higher-level combinations represent partial or whole aspects of relations of data in the input pattern. T


In this sense the higher level combinations have literally fused a number of spatial relations of the input pattern.


They have represented it as a new activity pattern at a specific location.





Formation of Ersatz Hierarchical Concepts.


This approach allows for the formation of what look like hierarchical concept representations.


Suppose we have a set of “objects”.


We have three parameter values that are fixed for each object and one value that varies widely from example to example.


The system develops two different types of spatial codes.


  • In the first, a number of high order feature combinations are fixed since the three input core patterns never change.


  • In the second, based on the additional spatial relations generated by the widely different examples, there is a varying set of feature combinations corresponding to the details of each specific example of the object.


Two kinds of pattern can potentially be learned.


  • The first learned pattern corresponds to the unchanging core and might correspond to an abstraction of the commonalities of many examples.


  • The second learned set of patterns corresponds to the core, plus the patterns associated with each specific learned example.


  • The specific examples are related by their common core pattern.

Core Representation


Three Input Patterns.



The group of coincidences in the center of the array is due to the three input values arranged around the left, top and bottom edges.


There is no right hand value.


This group of three constant values plus their feature combinations constitutes the core.



Below are two examples when there is a value on the right side of the array.


Examples Core


Note the presence of a number of new three or four
feature coincidences.


The original group based on the three core values is still present as we would expect it to be.


There are many more feature coincidences present with all four values. The coding rapidly becomes richer in terms of its possibilities for interaction as more information is added because there are more possible coincidences.

Development of A “Hierarchy” with Spatial Localization.



The coincidences due to the core (three values) and to the examples (all four values) are spatially separated.


We have the possibility of using the core as an abstraction and representation of the examples since it is present in all of them.


We could use it by itself as the descriptor of the entire set of examples.


It acts as the higher level in a simple hierarchy, that is, all examples contain the core.


The many-to-one relationship here – many low level examples, fewer high level examples — is typical of hierarchical semantic networks.





The Ersatz Brain Project has led us down an interesting path.


If we start to require software to use the general constraints that we feel characterize a real brain-like computer,


Then some new ways to tackle old problems emerge.


  • New “analog” control structures: Programming patterns to do arithmetic. Looks more like attention than anything else.


  • Spatializing problem data both as initial representations and to form feature combinations.


  • Potential emergence of hierarchical structure.


  • Disambiguation using context and semantic networks.


But these tasks are elements of some important software applications.


These ideas might be of value for current computers.


But I feel that their real domain of application will be to the computers of the future.


  import javax.swing.*;
  import javax.swing.event.*;
  import java.awt.*;
  import java.awt.event.*;
     This class demonstrates the basics of setting up a Java Swing GUI uisng the
     BorderLayout. You should be able to use this program to drop in other
       components when building a GUI 
  public class BasicGui{
      // Initialize all swing objects.
      private JFrame f = new JFrame("Basic GUI"); //create Frame
      private JPanel pnlNorth = new JPanel(); // North quadrant 
      private JPanel pnlSouth = new JPanel(); // South quadrant
      private JPanel pnlEast = new JPanel(); // East quadrant
      private JPanel pnlWest = new JPanel(); // West quadrant
      private JPanel pnlCenter = new JPanel(); // Center quadrant
      // Buttons some there is something to put in the panels
      private JButton btnNorth = new JButton("North");
      private JButton btnSouth = new JButton("South");
      private JButton btnEast = new JButton("East");
      private JButton btnWest = new JButton("West");
      private JButton btnCenter = new JButton("Center");
     // Menu
      private JMenuBar mb = new JMenuBar(); // Menubar
      private JMenu mnuFile = new JMenu("File"); // File Entry on Menu bar0
      private JMenuItem mnuItemQuit = new JMenuItem("Quit"); // Quit sub item
      private JMenu mnuStore = new JMenu("Store");
      private JMenu mnuHelp = new JMenu("Help"); // Help Menu entry
      private JMenuItem mnuItemAbout = new JMenuItem("About"); // About Entry
      /** Constructor for the GUI */
     public BasicGui(){
         // Set menubar
         //Build Menus
          mnuFile.add(mnuItemQuit);  // Create Quit line
          mnuHelp.add(mnuItemAbout); // Create About line
          mb.add(mnuFile);        // Add Menu items to form
          // Add Buttons
         // Setup Main Frame
         f.getContentPane().setLayout(new BorderLayout());
         f.getContentPane().add(pnlNorth, BorderLayout.NORTH);
          f.getContentPane().add(pnlSouth, BorderLayout.SOUTH);
          f.getContentPane().add(pnlEast, BorderLayout.EAST);
          f.getContentPane().add(pnlWest, BorderLayout.WEST);
          f.getContentPane().add(pnlCenter, BorderLayout.CENTER);
         // Allows the Swing App to be closed
          f.addWindowListener(new ListenCloseWdw());
          //Add Menu listener
          mnuItemQuit.addActionListener(new ListenMenuQuit());
     public class ListenMenuQuit implements ActionListener{
          public void actionPerformed(ActionEvent e){
      public class ListenCloseWdw extends WindowAdapter{
          public void windowClosing(WindowEvent e){
      public void launchFrame(){
          // Display Frame
          f.pack(); //Adjusts panel to components for display
      public static void main(String args[]){
         BasicGui gui = new BasicGui();

Programming in Java To introduce you to developing Java programs, we
break the process down into three steps. To program in Java, you need to: