Saturday, November 28, 2009

DSP CourseWare on HawkBoard ?

Designing a series of experiments for conducting Lab courses on what theory is taught in basic Signal Processing Courses like Signal and System , Digital Signal Processing , Speech Signal processing at IIIT-Hyd, seems a very interesting idea to me. Right now there is a complete lack of exposure to DSP Processor among students here and so it would be an achievement if we could take initiative to introduce and establish DSP Lab at IIIT and develop in house expertise in working with DSP Processor.

This would also lead students getting exposure to Embedded Linux and playing around with Linux kernel, creating Device Driver, compiling kernel yada yada ...

I clearly favour HawkBoard as the single Platform for such requirements. It has a Floating point DSP Processor and ARM9 core.These will be easier to deal at the beginners level as compared to ARM Cortex8 and Fixed Point DSP processor on Beagle Board. It is as important a fact that HawkBoard has VGA output(so good old Monitors will work with this) , Ethernet connector(an added advantage) and few more things.

But getting this done is quite a task. First of all I have to learn all what have been mentioned above coding for DSP processor to learning conecepts of Embedded Linux and kernels.
From that onwards, designing the experiments and getting the correct documentation is a very tedious task , which I learned the hard way while doing it for Embedded Hardware Design course.

I have posted this proposal for Early Adopters Scheme of Hawk Board. Hope to get one kit and start  the interesting journey with Hawk Board.

Btw Hawk Board seems to be available here. The price quote(including local taxes and shipping anywhere in India) I got is Rs 6240/- per Board. This is substantially more that $85 which was the initial estimate by Hawk Team, I hope it soon comes down.



Wednesday, November 25, 2009

Optimizing a Software for a Processor

It came as a sort of surprise to me when I got to know that people actually optimize the performance of their software based on what processor they are using , that means that if we say Matlab is a very optimized s/w , them some one would have painstakingly sat down and coded in assembly the functions or routines that Matlab implements so that what all hardware options and advances are present they are utilized to their core.

Now though I am not very clear about the issue but sometimes companies offer cross-compiler so that a normal person could sit down and writing the routines in popular languages like C , he could cross compile the routines to be more optimized for a particular hardware say a DSP processor.

In upcoming platforms like Beagle Board , Hawk Board , which have a different processor than your PC or Laptop , an application will not be able to make full use of the hardware present if somebody has not optimized it for that processor say TMS300 or ARM 9 .

In case of Intel , it has Integrated Performance Primitives which is a library of optimized functions for different utilities. So is the case with other Processor makers.

Beagle Board Validation - First Contact

Today the two ordered Beagle Board arrived from IDA Systems through courier(pretty fast service !!).

We(me and Abinesh) sat down to do the most basic Validation Test of the BeagleBoard.

The most basic minimum things required are :-
1. Beagle Board - Rev C3
2. USB OTG - USB cable ( for powering BeagleBoard)
3. DB9 Connector (for connecting to serial port of PC)
4. 10 pin FRC box connector (for connecting to RS232 pins on BeagleBoard)

Luckily I managed to get USB OTG cable from the Nexys-2 FPGA kit.

The above images are USB OTG cable, comparision of OTG and normal USB connector, 10 pin FRC Box connecctor, DB9 connector.

The first thing to test is to power up BeagleBoard, by connecting the OTG connector to the USB OTG connector just on top of 5V DC supply jack and connect the other end to USB Port of PC.


As soon as power is On , PWR Led(D5) glows and after a delay of few seconds , three other Leds glows up(D6,D7,D12).
Press reset switch and see that Led D6,D7 turn Off and after releasing Reset Switch ,turns on after a delay of around 3-4 seconds.

After Power On test , turn off the power by disconnecting the USB from PC , now connect the 10 pin connector to BeagleBoard RS232 pins as shown above.

On the DB9 connector(female) solder pins no 2(Rx), 3(Tx) and 5(gnd). Now connect pin 2,3,5 to pin 2,3,5 on the 10 pin RS232 pins on BeagleBoard.  
An easy way to identify pins on RS232 connector is to look for pin marking 1, 2, 9, 10 on Beagle Board.

After making the connection between DB9 connector and 10 pin Box connector, connect the DB9 into Serial Port of PC.

Open Hyperterminal on Windows and set the following settings :-
BAUD RATE - 115200,
DATA - 8 bit,
PARITY- none,
STOP - 1bit,
start the session with the above settings.

Now turn on power and you should see the following appear on Hyperterminal Screen.

This is the most you can do without a SD Card. The main page which has details about Validation of BeagleBoard is here .


Saturday, November 21, 2009

Beagle Board Ordered and waiting

So through  Robotics Research Centre I managed to order 2 Beagle Board and also Dell Ultrasharp 1708FP LCD Monitor to hook up to DVI-D connector on Beagle Board.

Right now we have access to one Beagle Board in IIIT-H and till now several things have been tried out like VNC to make use of monitor of PC for displaying the video of Beagle Board.

Once our Beagle Board arrives , I will try to put a lot of documentation on the procedure to follow on Beagle Board


Win Free Hawk Board

Hawk Board community has announced an open contest for Early Adopters. Propose an idea to implement on Hawk Board and you could win your own Hawk Board for free !!!!

Hurry the deadline is 30th November.

Post your proposal  here

 Hawk Board Community Page

Yes I will apply and hope to grab one of it !!!!     :)

Thursday, November 5, 2009

USB Bootloader Kit for ATmega16/32

For working on AVR microcontrollers and particularly if the person is a beginner , it greatly helps if he is shielded from the Hardware or the circuit making aspect for the time being until he gain certain minimum proficiency in programming AVRs.

When this idea of introducing AVR Microcontroller as a new course of Embedded Hardware Design was formulated by Prof RN Biswas based on my request that IIIT already has a legacy of AVR in robotics, so it was required to have a platform which which make this exercise of teaching and doing Lab Experiment on AVR a reality.

Prof RNB is very particular about courses and he takes care that they are structured properly and with indepth planning.
I was already involved in designing the AVR Kits for Robocamp at that time and after seeing its design, he wanted a new design in which only PORTs interconnections and USB link to Laptop is present, so that the breadboarding part is done hands on by the students.

Finally after making lots of layouts of a kit wired around ATMega16 and after taking care o lot of issues, this was the final design of AVR USB Bootloader Kit.

1. USB Bootloader enabled, directly dump your hex file into the controller.
2. LCD(removable) connections through Burg Strip.
3. Connections to all PORT pins.
4. ISP connector
5. Powered through USB cable or external power supply.
6. LCD can be powered independently.
7. Slide Switch for enabling Bootloader.
8. LEDs for power & bootloader condition.
9. On Board 12MHz crystal.

The USB Bootloader firmware was avliable at Thomas Fischl(of the USBasp fame) and from Objective Development.
The Bootloader is the USP of this kit.

This kit was designed keeping in mind the experiments that the Students of Embedded Hardware Design, Microprocessor Based System Design and Embedded Systems-1 for UG2, UG3 and PG1-VLSI respectively needs to perform using Atmega16 microcontroller.

The Silkscreen of the circuit is shown

and also the kit in being use during a stepper motor experiment

Back Side of PCB

                                                                   Front Side of PCB

The Resolution is pretty bad for want of a better Camera, anyways the size of PCB is 10*6 cm.

The base circuit of USB Bootloader Kit for ATmega8 is

For making the kit with ATmega16 , the following changes need to be done in the firmware:
1. Change the D+ & D- pins to what is convenient to your design , though keep D+ to INT0 to avoid major changes in firmware.

2. Change the Bootloader address in the firmware, the compiled code that comes is according to ATmega8 whose memory size is 8KB , so the starting address of the Bootloader program(size 2KB) is 6KB. In case of Atmega16 whose memory size is 16KB , the starting address of Bootloader code 14KB (16KB-2KB).

3. Compile the changed code.

4. Before dumping the Bootloader code into the controller, have a 12MHz crystal connected in circuit and do all three steps together ie setting Fuse bits(High and Low) and writting the Bootloader code.

5. We are using HIDBoot Utility to dump the code into the controller using ISP.

6. In case the procedure is not successful, you can try that again , since the controller does not get bricked.

The Pdf of Layout of USB Bootloader Kit

USB Bootloader Kit User Manual

 - Any Queries are most welcome !!! :)

Saturday, October 31, 2009

Beagle Board & Hawk Board

I am sick with writing about that Travel Memories, so something fresh is the need of the hour.

Some months back EFY(Electronics For You) carried an article about Open Source Hardware and Beagle Board was the main focus for that. Since my interest lied in getting a DSP Board for implementing my Final Year Project, so I kept Beagle Board at the back of my mind. Sometime Later when I searched on net about it, I was hooked with this tiny sexy looking board with a ton of features !!!
(Btw I am trying to get access to an Analog DSP Board for the project work)

Beagle Board is a Fan Less Single Board Computer based on TI's OMAP 35x processor.

leaving aside the specs, its clear that this small board 8cm*8cm packs a lot of punch. This offers an opportunity to port a OS on this Board and do all the mouth watering interesting stuffs and Electronics guy would love to do. For me it offers a leap up from the world of Microcontrollers to OS level designs.

As usual after getting hooked up to this, I tried to go through several resources online and found that in India, the cheapest supplier is IDASystems , the present cost being Rs 9K , w/o any thing else other than the board itself.

Later on I digged one more interesting thing - The Hawk Board. This is also a SBC, but based on less powerful OMAP L 138. Right now this board is under development and will be available in near future.

The Best part about Hawk Board is that first it has a VGA port meaning , a normal person need not buy a separate HDMI capable monitor for displaying from Beagle Board, and also it has Ethernet port(RJ45) and the best but not the least it might cost less than half of Beagle Board !!!

But I think if am able to arrange for an HDMI monitor than I am going to buy a Beagle Board soon rather than Hawk Board(since I feel open source support for Beagle Board is more dominant)

I am so much wanting to do some Real Time Image processing on Beagle Board.

Any new developments will be posted :)

Sunday, October 11, 2009

Travel - Part 7 - Madurai

(this post is in continuation of  Travel - Part-6- Reching Madurai  dated Oct 3 2009)
Madurai is said to be the oldest town in peninsular India, and this thing is a surely a big asset of any great city. My first impression of Madurai was very different from other religious cities. The most important thing was that I saw that the city or the ares around the Temple was totally market and most importantly these markets were not catering to the temple inflow, but they were totally supporting the city economy.

It was not a good idea of ours to just take up a room in the nearest hotel that we found from our LZ(Landing zone :P), as a matter of fact there were several Hotels even nearer to the temple. So before it became any dark , I quickly went to a reconnaissance mission of the temple which we planned to visit early morning. I went around the periphery of the temple. It was good impression to see wide and clean walkway which provided lot of convenience to the visitors. Ohh I really forgot to mention, the first time I came near the temple , I was awestruck by the imposing Gopuram. The Gopuram can be said similar to most of the other temples(the other way I mean) , but the important thing was that each and every detail and carving was painted beautifully with different colours. It was a sight to see and the more you watch the more details you can observe.

After my walk around the temple I had I task to do. I had read that there is a Modern Restaurant near the temple and people like Mahatma Gandhi and J.L. Nehru had eaten there , so I was very exited to find this place and eat there. The location was precise just behind YMCA. I had a coffee and Idly at the place, since my purpose was to find out if this was the actual Modern restaurant. I tries asking the proprietor about that but I got a sort of cold response. So sad that a place of such a history is not exploiting or atleast displaying it with proud and though the whole temple was in center of a large market , I cold not find fruit sellers in the market.

Early next morning we went to Darshan of Meenakshi Ammam Temple. Though I was aware that cameras are allowed I did not took it, just because I though it would not be in sync with the serious sentiments and devotion of the people who visit the temple.


Saturday, October 3, 2009

Travel - Part 6 - Reching Madurai

We booked two seats in a 2*2 Pushback type Minibus for getting to Madurai. The minibus was a sort of guided tour as it stopped to some of the Temples in Rameswaram to allow the people to visit them. On the Pamban Bridge the Bus stopped again and hence I got the opportunity to spend some time on the Bridge and more interestingly take some good snaps of this interesting location.

Then the bus started and the rest of the journey was not very consequential and so I just partly slept and partly observed the surrounding , the towns on the way , and the people.

It took around 4 hrs to reach the Madurai and the bus dropped us near the South gate of the Temple.

Friday, September 4, 2009

Travel - Part 5 - Rameswaram

So here I am at Rameswaram , the most memorable part of this whole journey.

We got down at the railway station at around 9 am and it was really hot at that time, we started walking to the end of the platform like everyone else. There was a sort of union of three wheelers, not to be bothered more we took one auto to be taken to the Ramanathswamy Temple. The auto dropped us near the temple and fortunately we got a balcony room with a wonderful view to the Temple. So after the 56hr journey , I got an opportunity to take a bath !!!!. We got our self all freshened up and then immediately set out for paying our regards to Ramanath Swamy. First we walked towards the Akniteertham, where I made my first contact with the holy sea of Rameswaram. But actually I was a bit disappointed, all through the way I had this image in my mind that i could really find a nice place to swim in the ocean here. But seeing the condition here I was sure that with all the people here taking a holy dip , this was definitely not a place to have a conventional swim in the water. After the holy dip we proceeded in the wet clothes itself towards the temple with the guide who was with us since the hotel. He lead us to the main temple where we paid for bathing in the 22 holy ponds.
One of the unique points of Rameswaram Temple are the 22 wells, each of these ponds is a fresh water well. It was a very different experience to feel the water from these wells , as a matter of fact the taste of water of all of them was different. It is a said that Ramji used water from these well to do Abhishek of Shivling. Some people believe that the water has medicinal value, who knows the combination of water and sun might be what it is believe to be. The way in the temple was bit confusing while going from one pond to another. As a matter of fact the corridor of Ramanathswamy Temple are one of the longest in the country. After the holy bath we had the darshan of Shivlinga as well as the Shivlinga brought by Hanumanji.

I would say that overall the Temple was not a beauty and I was a bit dissappointed when I say it at first. The very first impression on seeing the Temple Gopuram painted all in Yellow color was reducing the the beauty by a large factor. The picture of Meenakshi Temple of Madurai in mind made me assume that the Gopuram will be a piece of workmanship and it will be exquisitely decorated in all sort of colors. Inside also several panels, walls and pillars were unpainted. Though it is one of the CharDham tirth , the lack of beauty was a sore sight in the eyes. I hope that all these works get finished very soon and the temple stands above the Holy Shivling with all the grandeur and pride of Hinduism. Later we came back and had our Lunch at a local Marvadi Restaurant(Marvadi are residents of Rajasthan). I liked taking the food a fulfilling and tasty food after being feed up with Train Pantry Car food.
One very important thing that I did not mention, was that the moment that I say Ocean for the first time , I was longing to have a long and nice swim.(A swim is different from getting yourself wet , which is what I find most of the people doing in our country, I guess most don't know swimming and all they can do is to splash water on one another and jump over the waves !!! and this is what they call bathing in the Ocean). I was now a worried man , all through the visit in the temple I was thinking how could I salvage my situation. I was so determined to do scuba diving(which I had read that Rameswaram is a good place for) that I thought I would give a really hard try before giving up.

So just after our Lunch , I picked up my swimming costume and a towel and set out to what turned out to be a "real adventure". Before setting out for that , I tried asking my hotel guy is there is some place where I could do swimming or scuba diving. I tried hard to ask in a way that would make it sound that my intentions are very decent. But it did not help, the guy said in almost a sarcastic way that these things are not done in Rameswaram and for that you have to go to Chennai or Goa !!!. So I set out alone. The only thing I knew that on Wikimapia a location on the eastern side was marked as "Scuba diving" , so I got the impression that there might be someone who would rent out the snorkeling equipment. So for Agnitheertham I set out on foot to the north.(I remember I started from hotel at around 2 pm). So I was in Capri with a cap on my head , but without a water bottle and no watch or cell phone or a Digicam. So I kept walking on and on. After some distance I saw a foreigner coming from the opposite side, I thought that she might be knowing about the place I was seeking. She had also been trying to find a place to do snorkeling and it was also written in her guide book that it can be done here, she had walked on for about an hour, but found nothing. All she saw was that the fisherman were harvesting some kind of sea weeds and drying them up. It thanked her and started to start my own exploration. I was not happy about the situation that we don't even seem to have proper information dissemination mechanism in place , which could tell the tourists what attractions of the place are available. Soon the road turned away from the beach and so I came off the road and started walking on sand along the beach. It was there that I saw a building which was running some program of Microsoft in collaboration with TN govt. I was satisfied to find that atleast in some places poor people have some support from various agencies.

Well it is a known fact that it is much difficult to walk on sand than that on soil. This beach was rocky with sand in places and there were quite a few thorny bushes populating the beach. On top of it I was wearing sandals, so occasionally hot burning sand with a few minute thorns used to get into my feet and create problem in walking comfortably. Inspite of all this I just wanted to find that place to do scuba diving or to find that there is no such place like that at all. So I thought that I would go till the north most point of the island and then I will be convinced that no such place or facility actually exists. But I missed one point that the island was quite roundly shaped up in the north most point and I did not have compass and the sun was almost overhead , so it was not easy to estimate that you have reached the north most point. I had somehow assumed that when I had reached the north most point , I would be standing on a edge with land on my right and on my left. As I kept walking the water became cleaner and clearer. Now and then occupying a small portion of beach there were fishermen engaged in the activity of harvesting the sea weeds and drying them up. I was bemused to see the fishermen were a bit confused to see a stranger walking pass them. They might be thinking what does this guy what and where is he going to ? ( because they knew there in nothing special out there !!) I kept on walking on and on and mind you that too on sand, after some distance I would find that the beach would turn left and this kept on happening that the beach kept turning after I reached the end of one turn.
The small doubt that I had in my mind that there is really nothing out there so I have to decided sometime to turn back. As time passed several thoughts kept coming to my mind again and again. Some of them were absurd like if I was mugged by some of the locals( I am not a coward but , I could help just thinking about it !!!). Well to clarify nothing of that sort happened and I believe that such an endeavor are totally safe specially in broad day light. My mind was also working on possibilities like that what would happen if I would get dehydrated in this hot sun. These thoughts kept on becoming more and more prominent as I kept pushing forward.
After some point of time I was almost sure that I would not find what I was trying to find , but the driving force was that I should verify myself that if such place do not exist or not. I don't know how long I kept on going since I didn't have a watch on me. Though all through this I had been walking pretty briskly and that to at a constant pace, I was just not feeling tired, but the fear of dehydration was always on back of my mind. So at some place I finally decided that there has to be an end to every idiosyncrasy. I had really came a long way and I knew that it was not possible to go back along the beach itself. I had to get to some village and then find a way back to hotel and that too me being all in 1 piece. I rested in the serene water by wetting my feet for some time then I asked the nearest fisherman the way to city, he showed me the way, a path through thorny bushes.
Till the time i was along beach , i knew I could always walk back and find my way, but the way i was going could get me struck in no where. I kept walking on the marked path , but quite some time did not find even one person anywhere in sight. After walking for some distance I could see a long way away, the Doordarshan tower , but more importantly I also saw a temple on a hillock. I reasoned that in this town of temples , this one might lead me to some means of transport to get back to hotel, so I proceeded in that direction. But it still was a long way away but I had no choice and I kept walking and finally reached the Temple. It was often visited temple. It turned out that this temple was the highest point on this island and it is called Gandamadana Parvath. It is an excellent vantage point and it is said that Ramji took stock of his armies from this point and in the temple there was a foot impression of Ramji's feet in stone. It was only much later that I realized that I had actually walked about 1/3th of the island's coastline. It was easy to get a ride back to my hotel from there. By the time I reached the room, it was around 4:00 pm and all this trip or trekking took only two hours !!! Nonetheless I hit the sack and was deep asleep. I waked up again in two hours and we quickly decided that we will visit the 7 places of attraction in Rameswaram.
There are a lot of three-wheeler guys who easily offer a tour to all of these locations. So to ease our efforts we took one such three-wheeler with a deal to visit all these spots except Dhanushkodi. These places are the Sita, Hanuman Temples, temple with floating stones used in building the SethuSamundram Bridge to allow Ramji to reach Lanka. It hardly took 1 hr for these 5-6 places and we got an opportunity to visit the Ramanathswamy Temple once more. It was like getting lost in a maze, with the very long corridors and the temple dimly lit. Mother got an opportunity to do some shopping in the fancy shops in and around the temple selling lots of articles.

We waked up early the next morning and then quickly went to the Agnitheertham. I knew that we are supposed to do Manidarshan and then take bath and then the darshan of Ramanathswamy Temple. Somehow I assumed that Manidarshan meant seeing the Sun rising and it the first ray of Sun would be like a Mani or a pearl. We waited for quite long and the time kept passing and with nobody really taking a bath we got skeptical, so we now go to the Temple and we got to know that Manidarshan actually means the darshan of a sphatik-mani shivling in the Main temple.
So now a funny part was that, I has read quite clearly that there will be two lines for Mani Darshan, one of Rs 50 and other of Rs 15(something) and very surprisingly the Rs 15 line moves faster than Rs 50 line. I had this in mind but when we say both the line at the ticket counter we found more rush at Rs 15 line as compared to Rs 50 line. So I thought that maybe what I read was wrong and we purchased two Rs 50 tickets and quickly got into the Inner Sactorium, now here was the real deal, since lot of people like us had purchased Rs 50 ticket so there was a long line inside of that and a very short line of Rs 15. We being who we are, we got into the line of Rs 15 and even the ticket checker did not object. With this convenient arrangement, we had a very nice and relaxed Darshan as opposed to a rough treatment the Rs 50 ticket holder were receiving.
Next we went into Agnitheertham and I took a bath and since it was morning, so several energetic youths were enjoying themselves by actually swimming in the ocean. This was my first and as I understood as the Last opportunity to swim in the ocean on this trip, so I also took to the water. Now the reality hit me in the face. I was out of practice with swimming and it was almost a year since I had immersed myself in the pool, and all my dashing desire to go on swimming till I touch the horizon melted away in the vast expense of water within a few strokes. I was grasping for my breath :), so I did my best to satisfy these aquatic desire of mine !!!.

When I was done after about 30 mins, we again went to have a Darshan in the temple. It was nice to finally being able to get into the religious tranquility of the place.

After this we inquired about the bus to Madurai and the only one available left at around 2 pm , so we decided that there is still a lot of time, hence we checked out from our hotel and took a bus to visit Dhanuskodi. Dhanuskodi is about 18 Km from the city and we waited to board the bus to Dhanuskodi. The bus takes about 45 minutes to reach the last point of the motorable road. At this point there is a post with INDIAN NAVY written on it. And on this post there were a few soldiers manning it. At this point we found several jeeps which take tourist to the lands end. Well just to inquire about Dhanuskodi I went to one of the soldiers. HOLY COW !!!!! it turned out the guy was a MARCOS, who on earth would have thought that a very highly trained Indian Marine Commando will be posted on a distant place. It must be a really necessary and of course highly important task. Anyways I don't know what the commando saw , but he kind of presumed I was some officer or something !!!! :P.

We bargained a lot with the jeep guy and finally boarded the jeep. I took a vantage seat on top of the jeep, just before the jeep was about to leave the Navy Post, I tried to take a pic of the Post but the Marcos guy signaled a No. Nobody in there right frame of mind would like to cross their path with a Marcos guy on Duty , so I obliged and put away my cam.

Very soon the jeep was cruising on the sands rather than a metalled or paved road. So the story goes like this that several years back in around 1964 there was a big Tsunami which struck Rameswaram really hard. AT that time Dhanuskodi was a town with even a railway station. At that fateful night there was a train going towards Dhanuskodi Station and very tragically the train with all the occupants was washed away in the fury of nature. Not only this the whole town was washed away along with the Tsunami waves. The Pamban bridge also took a hit but due to some tireless engineering it was back in service within a record time. Since then nobody inhabited the old town again or neither the road or the rail link was restored again. So all the vehicles have to move over the sands to reach the end of land i.e. the last bit of Indian territory. The sand was really thick and the wheels of the jeep were leaving behind about 6 inches deep scars on sand. This piece of land was seemingly like a desert though surrounded on both sides by oceans. Far away we could see human figures like a very thin stick moving in this desert and even farther back in the north the TV tower was still visible though it became fainter and fainter as we moved ahead. Suddenly the jeep stopped and a middle aged women came out and walked towards a group of abandoned and ruined huts and buildings. Somebody told that she was a teacher and she comes here to teach the children who lives in these huts. I was so impressed that a person would actually come all the way here to nowhere and teach the children of fishermen so that they would actually become someone in their lives. The dedication of the teacher and all the people connected with this effort was worth saluting.

We went further ahead and now the two oceans started coming closer together as we forged our way ahead. Finally we reached our destination. We found a group of men doing some religious offerings. It was not actually a beach or land but technically they call it salt pans. We found it why, I went to wards the water and hardly had I stood for 5 seconds, I sinked till the knees. I just thought that if somebody just became unconscious while swimming then he would just be buried alive. The jeep was to stay for sometime and so I could not prevent myself from thinking about getting myself wet in the blue and serene water of the ocean. I quickly made good use of my Swimming costume and did a little splashing of water etc with the other guys on the jeep. It was a real fun and enjoyment as the water was so clean and cool. Most importantly this place was far away from the rush and madness of the normal tourists spots.
I had a brainwave at this time. It was a place which I knew , if I could I would definitely come back here. This place was idle from get away from the world. How would it be if a person could come here for a week in solitude and live here and reflect upon the Life. The placid surrounding , with the oceans on both ends and nobody really to disturb you, will definitely rejuvenate any wanting soul.

We got back again in the jeep and then the driver took us to a group of Huts belonging to the Fishermen who lives here. To our surprise there was a small Durga Temple present in which we presented offerings and sought the deity's blessings. I saw for a first time a Japanese well which was barely 50mts from the sea shore but the water was still sweet !!.

Then we returned back to the town on the same way by the bus. The entire journey took around 3hrs and after having our Lunch we waited for our Minibus to Madurai.

Thursday, August 27, 2009

Interfacing LCD with Microcontrollers


Tutorial 2009-10/I

[This is a tutorial written for Embedded Hardware Design Course here at IIIT-Hyd]

LCD (Liquid Crystal Display) has become very popular option for displaying in Embedded Applications. Since they are very cheap and easy to interface with microcontrollers, they are widely found in devices like telephones, vending machines, washing machines, toys etc.

LCD comes in several varieties i.e. 16*2, 20*2, 20*4 etc. These different LCD varieties can display different number of characters i.e. 16*2 can display 32 characters at a time.


The LCD module that we will be using is 16*2 JHD162A. This model has 2 lines and 16 rows of display blocks. Each block can be used to display 1 character. So there are total 32 such blocks. One block has 8*5 pixels. Depending on which pixel is ON and which is OFF we can display several Alpha-Numeric characters. This model also has a green backlight, which helps us to see the display even in dark. In reality this module consists of a controller chip, a segment driver chip, LCD display and some passive components.

There are total 16 pins in the LCD module.

Pin Number

Pin Name

Pin Function

Connection to ATMega16



GND Supply



+5V LCD Power



Contrast Adjustment



Register Signal Select(Command/Data)




Read/Write Select




Enable (read/write enable)




Data pin




Data pin




Data pin




Data pin




Data pin




Data pin




Data pin




Data pin




Backlight Power +5V



Backlight Power GND

These connections have already been made to the USB BootLoader Kit so when you insert the LCD module properly, the connections are made as mentioned in the Table.

While using LCD, we can think a simple analogy for its operation. Each of the 32 blocks is a memory, as soon as we write an ASCII number into one of these 32 memory locations the corresponding character is displayed on that block. The function of displaying the character after decoding the data is done by an onboard controller chip.

In reality the LCD module consists of several memory locations apart from the 32 dedicated for the display. Since LCD module can be used in several ways we need to select one of these modes and configure the LCD for this mode.

The various operations that we need to perform are:-

1. Write to LCD memory to display data

2. Configure LCD module by writing commands to memory location

3. Read data in Memory locations

4. Perform some special operations like Clear Screen , Bring Cursor to starting position etc

The various pins that are provided like RS, R/W etc acts as a way to do all these operations.The 3 control pins have important functions

1. RS The LCD has 2 modes of operation Character and Instruction. Depending on its value the data on the data line (DB0-DB7) is treated as either command or character. If RS is LOW then the data on DB0-DB7 is an Instruction and if RS is HIGH then data on data line is character

2. Enable – The pin acts like a clock for the LCD module, when there is a falling clock edge then the data on the data lines is taken in by the LCD module and processed.

3. R/W - This pin identifies if the operation to be performed is a read or write.

If R/W = 0 write operation R/W = 1 read operation

RS = 0 Command RS = 1 Character

E -> falling edge , data processed by LCD Module

To be able to correctly perform an operation we have to assign the values of these 3 control pins and data lines in a proper sequence.

Let’s look at one example i.e. displaying a character by writing to its memory location. The steps are:-

1. Set the data on the data lines i.e. the 8 bits of data are assigned to each of the 8 pins (DB0-DB7) like LSB -> DB0 and MSB ->DB7.

2. Set RS pin i.e. make RS pin HIGH.

3. Clear RW pin i.e. make RW pin LOW.

4. Toggle E i.e. make E high, wait for some time, make E low.

Another example, if we want to write a command, the steps are:-

1. Set command on the data lines i.e. the 8 bits of data are assigned to each of the 8 pins (DB0-DB7) like LSB -> DB0 and MSB ->DB7.

2. Clear RS pin i.e. make RS pin LOW.

3. Clear RW pin i.e. make RW pin LOW.

4. Toggle E pin i.e. make E high, wait for some time, make E low.

A very important point to note is that the sequence of these steps can be done manually using toggle switches only and the microcontroller is only used because the repetitive steps need not be performed manually again and again.

In the above examples we used 8 data pins and 3 pins for control signal i.e. total 11 pins of the microcontrollers are used. An efficient way is to use 4 data pins instead of 8. In case we are using 4 data lines , the higher nibble is send on these 4 data lines first and then we send the lower nibble on the 4 data lines. In this case we are using 7 lines of the microcontroller. This mode is called the 4-bit transfer mode. By default when we are using 4-bit mode the data transfer happens only through DB4-DB7 (the LCD pins) whereas DB0-DB3 are unconnected.

In the datasheet of LCD module we find a table shown below. This is the Instruction set of the LCD Module JHD 162A.

Let’s look at first row - SCREEN CLEAR. This Instruction tells the LCD module to return the cursor to the starting position i.e. (1, 1) and also to clear the screen of any characters. The code for this instruction is 0x01. If we want the LCD module to clear the screen, then we should write the command 0x01 to the LCD Module.

Similarly we have DISPLAY SWITCH instruction. It selects options for the display like Turning the display on/off, turning the cursor on/off, turn blinking of cursor on/off.

If we want to turn display on we set D (DB2) to 1, to turn cursor on we make C (DB1) 1 and to select blinking cursor B (DB0) is set to 1. Hence the final code of Display switch is 0x0F.

If we write a command 0x0F, then the LCD module will perform the above mentioned 3 actions.

Finally we will look at FUNCTION SET- this Instruction selects the 4-bit/8-bit mode (DL =0 means 4-bit transfer mode selected whereas DL=1 means 8-bit mode selected), N selects the number of lines in LCD (N=1 means a 2-line display), F select font type (in our case we have 5*7 type font which means F=0).

Hence to select a 4-bit mode, 2-line display and 5*7 font the value of FUNCTION SET becomes 0x28.

If Instruction INPUT SET is not given then by default after every character write, the cursor moved to next block. [But this does not implies that after writing to (16, 1) the cursor will automatically come to (1, 2)!!! you will have to set the address of cursor to (1,2) yourself.]

Instruction Set of LCD Module














Memory Address of Display Block on the LCD Module

The Memory addresses of blocks on LCD display are as shown above. So if you send a Command say 0x80, then the cursor will reach to the first block i.e. (1,1) similarly if you send a command 0xC5, then cursor will reach location (5,2) and so on. In this way you can move cursor to any position.

To make the LCD work with microcontroller you will proceed in this way:-

1. All the functions of the LCD will be written in a separate file named lcd.h, so that whenever you need to use the LCD functionalities, you will just include this header file lcd.h, and call the functions written in lcd.h to display or configure LCD module.

2. In the lcd.h you should have the following functions:-

(a) LCD_init(void)

(b) LCD_Send(char c, unsigned char DC)

(c) LCD_Send_String(char *s)

(d) LCD_GotoXY(unsigned int x, unsigned int y)

(e) LCD_Print(int data, unsigned int x, unsigned int y)

LCD_init – This function initializes the LCD module by setting 4-bit data transfer mode, turning the display on, turning the cursor on and setting the cursor to blink.

LCD_Send – This function takes two arguments c, DC. Here c is the data which we want to write and DC identifies this data to be a command or character (data) i.e.

if DC=1 => Data

if DC=0 => Command

LCD_Send_String – This function takes a string as input and after parsing it ,send character by character to LCD_Send() function , to print the character on by one on the display.

LCD_GotoXY – This function takes the cursor to position (X, Y) in the display.

LCD_Print – This function takes 3 argument i.e. data (a numeric value), and x, y co-ordinate of the starting position of the printing of the data. First this function calls LCD_GotoXY to move cursor to (x, y). Then the function calls itoa() function and send the resultant string to LCD_Send_String().

The Pseudo code of the functions are written as follows:-



Clear RS pin, clear RW pin.

Write a command to clear the screen

Write a command to turn display on, turn cursor on, turn blinking of cursor on.

Write a command to select 4-bit mode, 2 line display, 5*7 font.


// when we say write a command it means that the function LCD_Send is called.

LCD_Send(char c, unsigned char DC)


Break the 8 bit value of char c into 2 parts, upper nibble and lower nibble.

If it is command

Write upper nibble on data line

Clear RS pin, clear RW pin

Toggle E pin, put some delay (~1ms)

Write lower nibble on data line

Clear RS, clear RW pin

Toggle E pin, put some delay (~1ms)

If it is Data

Write upper nibble on data line

Set RS pin, Clear RW pin

Toggle E pin, put some delay (~1ms)

Write lower nibble on data line

Set RS pin, Clear RW pin

Toggle E pin, put some delay (~1ms)


// you will need to put delay while toggling E i.e. Set E, put 1 ms delay, Clear E.

LCD_Send_String(char *s)


Break string s into characters, say c1, c2, c3…

LCD_Send(c1), LCD_Send(c2), …..


LCD_GotoXY(unsigned int x, unsigned int y)


If it is line 1, send the command corresponding to address of 1st line.

If it is line 2, send the command corresponding to address of 2nd line


LCD_Print(int data, unsigned int x, unsigned int y)


Call LCD_GotoXY(x,y)

Break integer data into character and call LCD_Send_String().