You are on page 1of 1018

INDEX

S. No Topic Page No
Week 1
1 Introduction 1
2 Introduction continued with Project demos 25
3 Modular Approach to ESD 60
4 Modular Approach to ESD Continued 79
Week 2
5 Salient Features of Modern Microcontrollers 97
6 Salient Features of Modern Microcontrollers Continued 118
7 Elements of Microcontroller Ecosystem 145
Week 3
8 Elements of Microcontroller Ecosystem Continued 161
9 Power Supply for Embedded Systems 178
10 Power Supply for Embedded Systems Continued 196
Week 4
11 Introduction to MSP430 216
12 MSP430 Architecture 235
13 MSP430 Architecture- Continued. And Introduction to Lunchbox 258
14 Programming Methods for MSP430 285
Week 5
15 Physical Interfacing -1 301
16 Physical Interfacing -2 319
17 Physical Interfacing -3 333
Week 6
18 Physical Interfacing -4 351
19 Physical Interfacing -5 370
20 Physical Interfacing -6 388
Week 7
21 GIT, CCS Installation and Embedded C 401
22 MSP430 Digital I/O 445
23 MSP430 Digital I/O: Switch Interfacing 478
Week 8
24 MSP430 Clock System and Reset 494
25 Interrupts in MSP430 540
26 Interrupts in MSP430- Continued 555
Week 9
Interfacing Seven Segment Displays with MSP430; Low Power Modes in
27 MSP430 585
28 Interfacing Liquid Crystal Displays(LCD) 607
29 MSP430 Timer Module: Introduction and Timer Capture 643
Week 10
30 Pulse Width Modulation, PWM using Timer Capture 668
31 Analog to Digital Converter in the MSP430 706
ADC and DAC using R2R Ladder and Random number generation using
32 LFSR 729
Week 11
33 Serial Communication Protocols, USCI Module in MSP430 752
34 MSP430 Timer in Capture Mode 796
35 Coding Ninja 825
36 Building an Electronics Project 853
Week 12
37 Circuit Prototyping Techniques 880
38 Single Purpose Computers 935
39 Single Purpose Computers - Continued 964
Recap of Course Coverage and Project Demonstration from Concept to
40 Final 985
Introduction to Embedded System Design
Professor Dhananjay V. Gadre
Electronics and Communication Engineering
Netaji Subhas University of Technology, New Delhi
Lecture 01
Introduction

Hello, welcome to the first lecture of this online course on Introduction to Embedded System
Design. I am Dhananjay Gadre, I teach at the Electronics and Communication Engineering
division of Netaji Subhas University of Technology in New Delhi. During this course I will be
joined by Doctor Badri Subudhi who is a faculty at the electrical engineering department of IIT,
Jammu.

Before we start with this course I would like to go through the course objectives so that you are
aware as to what you are going to learn out of this course. What we are going to do is to learn
about Embedded System Design and the applications of these embedded systems. We will teach
you how embedded systems can be visualized in a 6-box model that we have developed
overtime.

These 6 boxes include the input box which has human inputs and environmental inputs. The
output box which has outputs for humans as well as for actuators, the power supply block which
powers the entire embedded system. Communication block which allows the embedded system
to communicate with the outside world if needed.

A storage block which allows the embedded system to store user data or information and the
most important of it all the embedded commuter block. And all these blocks will also be glued
together with the help of what we call as electronic glue then we will do details of how the
embedded computer is implemented. There are many ways of implanting the embedded
computer. One of the popular methods is using a microcontroller. Microcontrollers are nothing
but it is like a complete computer on a single chip.

1
(Refer Slide Time: 02:10)

These microcontrollers have great diversity in terms of size and in terms of capabilities that is
their performance. In this slide you can see 3 examples of microcontrollers. One which is smaller
than a grain of rice and the right most example is something which is about 1 square by 1 square
inch in size.

What we will also do is we will for this embedded computer implemented through a
microcontroller we will take a real example and we will cover Texas instruments MSP-430.
Texas instruments is supporting this course as I mentioned in the introductory lecture, they are
giving a kit for MSP-430 microcontroller that was designed in my lab.

We will teach you about the MSP-430 architecture, the programming and interfacing to the
outside world. We will teach you embedded C programming and how to write debug and
download the program that you write on your desktop computer after compilation, how to
download the object code or the binary code that it is called into the memory of the
microcontroller.

2
(Refer Slide Time: 03:22)

We will also learn about various aspects of system design including testing and debugging and at
the end of this course you can expect to be able to design, visualize design and implement an
embedded system from scratch to finish. However, these are the objectives, specific to this
course, I have certain objectives beyond this course and my objective is to do things so that you
as a participant, you as a student of electronics fall in love with practical electronics.

I would love to do in this course something that would enthuse you to build circuits and systems
starting from simple circuits to complex circuits and eventually to be able to visualize and built
complete systems and products so as to make India self-reliant. After we have covered the course
objectives let us go through the prerequisites which we expect you to know.

3
(Refer Slide Time: 04:22)

We expect you that you would be aware of basic electronic components and circuits that you are
aware of how digital circuits work, how digital circuits system work and you have some idea
about the finite state machine. It would also help if you have some experience in C programing
and computer architecture.

(Refer Slide Time: 04:46)

Beyond this let us talk about the logistics as part of the requirement of this course there would be
lot of hands on activities during this course. And the hands-on activities will be around a

4
MSP-430 evaluation kit which we call as the MSP-430 lunchbox, this as I mentioned has been
designed in my lab, selected and registered participants of this course would receive this kit for
free. Beyond that we expect you to have certain common electronic components and here is a list
of those components.

(Refer Slide Time: 05:23)

You may, you would like to, we would like you to have some switches, a few ICs, a driver IC
called ULN2003 and 555 basic input-output devices such as a buzzer, a thermistor, an LDR
which is a light detector, some presets, resistors, capacitors, couple of potentiometers and LEDs.

5
(Refer Slide Time: 05:52)

Beside that we would like you to have a 7-segment display, a liquid crystal display, a bread
board on which to fabricate these circuits and also hook-up wires and jumper wires. Beyond
these we expect you to be aware of what is called as fritzing, fritzing is a freely available
software with which to create wiring diagrams.

Many of the experiments that we do as part of this course we will share the schematics on a
fritzing method and we hope you would be able to use it and it would help if you are also aware
of the Eagle CAD which is a schematic capture and PCB design software. This is, this covers the
logistics of this course, now let us start with some of the definitions and characteristics of
embedded system.

6
(Refer Slide Time: 06:42)

Now, embedded system is such a vast field and such a diverse field that it is very difficult to use
a single definition to describe an embedded system in completeness. So, there are a few
definitions and I would like to go through many of them. One definition is that an embedded
system is nothing but a combination of computer hardware and software and perhaps additional
mechanical or electro-mechanical parts with the purpose of providing a dedicated function.
Another definition says that any computer whose end objective is not primarily computational
would qualify as an embedded system.

7
(Refer Slide Time: 07:25)

Yet another definition is a computer system other than the traditional laptop or desktop system
would be an embedded system and in today in that list I would also add a smart phone because
smart phone today people are using it for many-many diverse applications where they can also
add to the applications.

Therefore, a smart phone is an example of a general-purpose computing system so anything


other than a laptop, a desktop or a smartphone would qualify as a embedded system, any system
which uses a computer but which is not any of these 3 is an example of an embedded system. In
some cases embedded systems are part of a larger system and you are not even aware that you
are using such a system and case in point is anti-lock break system in a car or the deployment of
airbag system in a car are examples of embedded system.

8
(Refer Slide Time: 08:22)

Okay, let us see how Ubiquitous the embedded systems are. In our daily life we encounter
embedded systems at home, at work around us all the time and I have put together list of such
devices at workplace we use printers, scanners, network switches. In the banks we use ATMs
passbook printers. In hospitals we have all kinds of medical equipments.

In industry we have industrial control systems, automation devices, we also have agriculture in
which drip irrigation systems, equipment to test this soil quality are examples of embedded
systems. In the supermarkets we have point of sale terminals, we have scanners for scanning the
commodities that you buy, we also have defense and in the area of defense and space, we have
missile systems, we have rockets, satellites, drones these are all examples of embedded systems.

In transport we have locomotives, metro rails, cars. In the telecom sector we have mobile
broadband equipment, we have switches, we have telephone exchanges and for entertainment we
have projection system in cinemas halls as well as 4D seats where you seat and you get out of the
world experience because as you watch a movie based on content of the movie the seat vibrates
or it moves from side to side and so on and so forth. So, these are all examples of embedded
systems.

9
(Refer Slide Time: 10:00)

From a applications area point of view I have created a certain list, these embedded systems
applications have several classification and one of them would be small and single
microcontroller use whereas in an application you use a simple small microcontroller in fact the
microcontroller that we are going to illustrate during this in this course would qualify in that
category and with such a small microcontroller you can probably design small toys or gadgets at
home.

Then we have control and automotive systems such as ABS that is Anti-lock Breaking System,
cruise control system in a car. For distributed in embedded control another classification of
embedded system you would have network, industrial equipment, you would have automotive
applications then you have network in classification where all the network switches would fall in
that category.

You have critical systems where the reliability of the system is very-very important and in that
category, you would have nuclear power plants, you would have aviation the domain of aviation
and in medical applications. Then you have robotics where you have warehouse robots or
assembly line robots then computer peripheral applications where you have portable hard drives,
printers and scanners and for signal processing applications such as RADAR or security cameras.
These are application areas of embedded systems.

10
(Refer Slide Time: 11:33)

Now since we spend most of our time at home I have put together a list of examples in a typical
middle class Indian home which are examples of embedded systems. For communication we use
mobile phone, landline phones, modem to connect to the internet, for entertainment we have a
television, a television remote, a setup box to receive television programs, we have music
systems recently this Sa Re Ga Ma music player became very, has become very popular.

Then you have noise cancelling headphones in fact I am going to talk more about it in a couple
of slides. We have digital picture frames then for convenience we have washing machines,

11
reverse osmosiss water purifiers, we have microwave oven, we have shaving razors of certain
categories. Again I have an example which I will go through in little more detail.

Then for comfort we have air conditioners these days you get fancy water heaters where the
heater tells you the conveys you the water temperature by changing the color. We have wood
lamp then for health we have treadmill, we have fitness tracker devices, we have blood pressure
measurement, we have blood sugar measurement.

For utilities we have electricity meters these days you may have noticed that electricity meter at
your home has a LCD display that is an example of embedded system. We have RFID tags again
I am going to go through that example. For transport we use cars or motorcycles, scooters and
increasingly electric bicycles and electric rickshaws these are all examples of embedded systems.

(Refer Slide Time: 13:16)

Now, since I mentioned a few examples which are unbelievable that these are examples of
embedded systems I have here this is Gillette Fusion proglide razor, it uses a battery for its
operation and it has a microcontroller inside. In fact interestingly the microcontroller that is used
in this razor is a MSP-430, I have shared the link for this webpage which describes which
microcontroller in detail I encourage you to go through that. The reason why it uses
microcontroller and that is why it is an example of an embedded system is as you use the battery
and the battery gets discharged over time the, let me start again.

12
The way, the reason why it uses a battery is that the when you turn this razor on, the razor head
vibrates apparently it gives you smoother shape. Now, as you would keep using the battery the
battery voltage will reduce it will discharge and that will reduce the vibration of this razor. To
maintain the vibration they use pulse width modulation, so as to maintain a uniform vibration
over the lifetime of the battery for that you need this embedded computer.

Secondly there is only one switch with which you turn it on or you turn it off. When you turn it
on and if you forget to turn it off it will auto turn off in about 8 minutes. And to do all this you
need a embedded computer. So, this is interesting example of an embedded system application.

(Refer Slide Time: 14:51)

The second example is this I have this Sennheiser noise cancelling headphones. Now, normal
headphones are mere headphones but this one requires a battery for operation. Also, on of the
cups there is a little hole there which is basically there is a microphone inside, what this does is it
samples external sound that sound which is also leaking through the cups of the headphone and it
enters you ears.

This noise cancelling headphones samples that sound produces an anti-phase version of that
sound and mixes into the speakers in these cups so that you are actually hearing 3 sounds. The
music that you are playing, the external sound that is leaking through the cups and entering your
ears and the anti-phase version that this headphone is creating that anti-phase version cancels the

13
noise which is coming from outside and you hear only the music that you are playing. And so it
gives a great example of an embedded system.

(Refer Slide Time: 15:48)

And the third is this RFID card, we have taken it apart to actually show how where is the
computer here, if you see I do not know if it is possible this is Delhi metro card and I heated it up
to sort of strip the covers part and inside you see there is a bit of wire and little chip here that
chip is the embedded computer and using this you are able to buy credit and store that credit on

14
the metro network on this card and use it whenever you are travelling on the metro rail. So, these
are all examples of embedded systems, interesting examples of embedded systems.

(Refer Slide Time: 16:30)

Now, the question arises that for gadgets at home why do we really need embedded computers?
Do we need embedded computers? Is it possible that these gadgets can work without these
embedded computers? Many of them did, in fact I am going to consider two examples, one is an
air conditioners and the other is a washing machine to show that these two devices actually
precede the development of a computer or the embedded computer.

You had washing machine or an air conditioner which did not require a an embedded computer.
How did it function and how today we are, we have improved the performance of these devices
by including an embedded computer and therefore today it makes a lot of sense to have the an
embedded computer in an air conditioner or washing machine and likewise it goes for all the
other gadgets at home. So, let me go through that with the help of a sketch.

15
(Refer Slide Time: 17:26)

So, in an air conditioner the old style air conditioner what all things we had? We had a
compressor which used an AC motor together with a coolant and heat exchanger, this was one of
the things that you needed. Then you had a mode selector switch, mode switch which probably
offered 3 modes of operation: low, medium and high cooling. 3, you had mechanism to turn the
compressor on and off with the help of a relay.

Often times it will also called a contactor and 4, you had a thermostat and in the olden times it
used a bimetallic wire type of thermostat. Now, with the help of these 4 devices user would
select how much cooling they wanted in low cooling the compressor would be on for small
period of time and it will turn off and then after sometime it would turn on again and then it
would turn off on and so on.

Now, ofcourse if the thermostat indicated that the temperature that the user desired has been
reached it would turn the compressor on earlier. In the medium mode it would turn the
compressor on for a longer duration of time and so on so that you could get higher cooling and
so on. And in the high mode it would turn on for much longer so that it would cool even more
than the other settings and so on and so forth.

16
And in this mode you did not have much choice about the temperature you wanted the air
conditioner to give you in that room. Now, let us add a embedded computer to this and let us see
how things have changed overtime.

(Refer Slide Time: 19:55)

Now, the compressor part remains the same you still have you need a compressor with AC motor
and all that but now you expect a digital display on the air conditioner which indicates the set
point you would you can set what temperature you want the AC to operate at so it will allow you
to show set point temperature.

And after that as the air conditioner starts working it will display the ambient temperature so it
has ambient temperature display. Now you wanted to do all this without touching the air
conditioner, so you wanted remote control for that. Now, instead of 3 settings low, medium, high
you have wide variety of settings you can set the temperature to 20 degrees if you want or 25
degrees if you want.

Also it would have some modes where you say okay I want to have a night mode when you go to
sleep you do not want the AC to cool as much. So, the air conditioner would cool less. Once you
select the night mode of operation, also it has the same relay or contactor and for the temperature
measurement it uses a semiconductor sensor or a thermocouple.

17
And so given the additional feature that you expected the air conditioner to offer it was
imperative that you embed and a computer in the air conditioner as to offer all these features. So,
having embedded computer in a air conditioner to get better performance is quite justified. Let us
take another example and that is a washing machine. I am going to start with the washing
machine example that was there before embedded computers were included in them and what all
you had?

(Refer Slide Time: 22:10)

You had a outer enclosure which is the main enclosure, you had a middle container and then an
inside container. In the middle container here you would have 2 pipes, one for inlet of water and
one for outlet and you would have a selector switch to select how much time you want the
machine to operate and the inner container had holes so that you could fill it up when you are
filling the middle container with water that water enters the inner container wets the clothes and
then there is a motor which is usually a AC or a universal motor to spin the innermost container.

And you had absolutely no other control over it, you would put clothes in it and you would run
the machine and at the end of that washing cycle you would inspect whether the clothes are clean
or not. Maybe if they are not clean and if the clothes are cotton you might add hot water in this
cleaning process and so there was lot of iteration you had to do to get your clothes really clean.
Then you add, then comes the modern times where you can add an embedded computer. Now
what do you have?

18
(Refer Slide Time: 23:30)

You have the same structure pretty much that an inner and a middle container and then you have
instead of just a time setting you have a selector switch which allows you various modes of
operation what we call as wash cycles. So, you can select oh do you want to wash silk clothes or
do you want to wash cotton clothes, if you have selected cotton clothes your modern washing
machine would also have a mechanism to heat water.

It would also include display to indicate what modes you are selected, it would have a
mechanism to sense whether water is optimally filled in the washing machine or not. It would
have a dirt sensor so that when you rinse the clothes and the dirt of the clothes is apparent in the
water it would know should the washed cycle be performed for half an hour or 50 minutes
alright.

And to do all this obviously you need a microcontroller or an embedded computer to achieve this
performance. It would also give you a facility that if you wash cycle is to happen for 50 minutes
and unfortunately if the electricity goes off and when the electricity resumes it would know how
much time it has already spent and it would only run the machine thereafter for the left time
instead of starting all over again. And so to give you all these features is only possible when you
embed a computer in a washing machine that is what is happening in a modern washing
machine. Let us go back to our presentation.

19
(Refer Slide Time: 25:25)

So, we have justified that having embedded computers in these home gadgets give you better
performance .more efficient devices, more user friendly devices and so they all justified.

(Refer Slide Time: 25:45)

Let us now let me share some observations. One of the observations is an embedded system just
because of the Ubiquity of embedded applications embedded system is a big and fast growing
industry. It has been estimated that for India alone this year in 2020 we would be looking at
something like 500 billion Dollar worth of equipment.

20
Now obviously who are going to satisfy all these requirement? You, the engineer in works you
when you graduate if you all the skills you can get jobs in these areas or you can be one of the
persons who creates designs, builds the next generation embedded application. Microcontrollers
are one of the common features of implementing embedded applications and which is the reason
why we are going to include a microcontroller in our course. Ofcourse microcontroller is only
the hardware without an appropriate software running on this microcontroller, it is not possible
to have a efficient embedded application.

Not just efficient it is not possible to have an embedded application without the software, so it is
very important that we teach programming such devices in appropriate fashion so that real value
of these embedded applications can be brought out.

(Refer Slide Time: 27:06)

Now, apart from embedded systems as a term there are couple of other terms which are going
around which have become very popular they are related to embedded system so I find it
pertinent to discuss them. The first term is physical computing, physical computing is described
as any computing system which is aware of the physical environment which means a computing
where it can sense the environment, process that information in that program and then produce
an output so as to control or visualize or present the outputs. So, it is a very generic term.

21
The second term which is becoming very popular is called cyber physical system. Cyber physical
system means as the cyber term indicates that the physical systems are connected, distributed in
space and they are connected with some sort of network. The important point to note here is that
network need not be internet. It could be internet but there is no necessity, it could be a private
network.

And the third term that is becoming common is called internet of things. As the important word,
here operative word here is the internet IOT types of devices are a subset of cyber physical
systems in that, that they necessarily use the internet. Internet is a common resource available to
anybody on this earth and therefore devices that use IOT are a subset of cyber physical systems,
they allow the humans to interact with their these gadgets over the internet. And ofcourse the
embedded systems. So, I am going to draw a Venn diagram to indicate the relative position. The
most common term is ofcourse the physical computing.

(Refer Slide Time: 28:49)

So, let me draw a circle the biggest circle to indicate physical computing devices. It is a generic
term that means any computing device which is aware of the physical environment is able to
sense the environment, process that information using a computer program and then output some
useful result it could be to control an actuator or may be to plot some diagram, plot some maps or
something like that.

22
Since there is no restriction on the physical form of that computer it could even be a desktop
computer. A desktop computer does not have any mechanism to sense the environment but you
can attach a bunch of sensors through the USB port which is a common connectivity option on a
desktop computer and then you write an appropriate application program on your desktop
computer.

You can convert the a desktop computer into physical computing device but this is not an
embedded system because you cannot carry it around it is a general purpose device where you
are using it for this specific application of physical computing. Then as a subset of physical
computing devices you have cyber physical systems that as the term indicates there is
connectivity between devices which may be distributed and what are examples.

Autonomous vehicle is an example of cyber physical systems, remotely piloted drone is an


example of cyber physical systems. In this particular case it may not use the internet at all it
would have a its own dedicated may be through satellite or something like that to remain in good
control of that drone. So, that is an example of cyber physical system.

Then I would have a smaller subset of this which I call as an IOT device and what is a, what
would be an example of an IOT? May be these days you get reverse osmosis water purifier
systems at home, now these are suppose to filter water but how long the water purifiers continues
to work without servicing will depend heavily on the quality of the water.

If the water quality deteriorate these filters would clot and they would stop providing you with
clean water and you would require them to be serviced before you could use it and that is where
introduction of a IOT device into IOT system into the water purifier would make it much more
user friendly, why? It would keep on sensing the quality of the dirt that has been accumulated on
these membranes and would send a message to the service provider, who would alert you that
your water purifier is going to stop working in a weeks time.

And therefore it would be prudent to do what is called as preventive maintenance so that you
continue to receive good quality water without any disruption, so this is an example of IOT and
last but not the least we want to put our embedded system in this. Now, because there is no
necessity that the embedded system should have some connectivity therefore, I would draw a
circle like this to indicate embedded systems.

23
And ofcourse all the examples that we have seen are embedded system examples and so these are
the 4 terms related terms and it is important that you as a participant are aware of it. We are
going to take a short break here and we will resume our discussion from this point onwards
which would be to compare embedded systems and general purpose computing systems, see you
in a bit, thank you.

24
Introduction to Embedded System Design
Professor Dhananjay V. Gadre
Electronics and Communication Engineering
Netaji Subhas University of Technology
Badri Subudhi
Electrical Engineering Department
Indian Institute of Technology, Jammu
Lecture 02
Introduction Continued with Project Demos

Welcome back. So we are going to resume our discussions and in this session we are going to
compare embedded systems and general purpose computing systems.

(Refer Slide Time: 00:33)

So the first difference is that embedded systems are dedicated for specific tasks. They maybe
one task or there may be few tasks, there may be more than one task, but that number is fixed.
As against general purpose computing system where you can put any applications, you can
add applications embedded systems are different from such general purpose system.

As an example if I have a microwave oven the embedded computer in the microwave oven is
designed only to cook food. I cannot reprogram it and expect it to wash clothes that is a kind
of glaring difference that I have and between an embedded computer and a general purpose
computer.

The second difference is that embedded computers can be implemented using a wide variety
of processors. As you saw a processor microcontroller smaller than a grain of rice and on the

25
other extreme big microcontroller more than an inch square, but when you look at general
purpose computing devices usually you use the highest performance processor that is
available. The third difference is that embedded systems are cost sensitive.

What is the meaning? Because you are buying a product you are not buying a computer. The
embedded computer that form part of that embedded system gadget carry the small fraction
of cost and therefore embedded computers, embedded systems are very cost sensitive and the
fourth difference is that embedded systems are supposed to offer and work under real time
constraints.

The meaning is that whenever there is a input change, environmental change, the embedded
systems are supposed to react to that change and provide an output in a timely fashion. If
there is delay in producing the output it may lead to fatality, it may lead to loss of life. As an
example if the embedded computer which is flying an aircraft and the pilot wants the aircraft
to climb and the embedded computer does not perform appropriately and keeps on flying at
the same level it may lead to a crash.

Now you do not expect such a behavior out of a general purpose computing systems often
time you may have noticed that you press a key and your laptop or desktop does not respond
it is all right because it is not going to kill anybody and so there is vast difference between the
expectation of an embedded computer in terms of requiring real time response.

(Refer Slide Time: 03:10)

26
The fourth difference or fifth difference is that embedded systems are designed to operate in
an extreme environmental conditions. Take a example of missile system that missile could be
launched from glacier environment or it could be launch from deserts and they must perform.
Usually embedded systems run out of a ROM.

Meaning that the program that is stored in the embedded computer is stored in the ROM that
is read only memory a permanent memory. But often times not often times most of the times
the program that runs on your desktop or laptop computer is running in the RAM. Yes a
desktop or a laptop system also has a ROM which is used at the beginning when you power
on your device and that program is called boot up program call BIOS Basic Input Output
System.

Once that completes execution the transfer the control is transferred to the operating system
on the hard disk and then to the program that you would like to run. These programs are
loaded in the RAM of the general purpose computing system so that is a vast difference
between how an embedded system operates and how a general purpose computing system
operates. Another difference is that embedded system has resource constraints. What are
resources of a computer?

The computational capability is a resource the way the embedded system or the computer
communicates with the outside world is resource and you see when you have a general
purpose computing system such as your laptop or desktop it has many ways of
communicating with the outside world. It has Ethernet, it has WiFi, it has FireWire, it has
USB and so on.

But does your microwave have Ethernet connection can you control it with your phone
through Bluetooth most probably not. Although, in recent times there are certain examples of
such embedded applications with connectivity, but that connectivity is based on the
requirement not because you want to flaunt that your computer has so many ways of
communicating with the outside world.

So embedded systems have resource constraints, there are examples of for example a washing
machine which is called IOT washing machine that washing machine can communicate with
the outside world through internet and the purpose is not that you would want to control this
washing machine sitting in your office.

27
But when the washing machine is operating at home and encounters loss in performance it
can communicate that to the service provider the maintenance guy so that they can come and
provide preventive maintenance before the washing machine actually stops working. So this
is an example where you have a communication protocol, communication link on your
embedded device but it is out of necessity as a feature not because you have you want to say
that your washing machine has so many ways of communicating with the outside world.

Embedded systems are infrequently reprogrammed. What is the meaning? That once you load
a program in an embedded applications you do not ever change it, you do not change it most
of the times and in most cases you do not ever change it, but in a general purpose computing
device every time you run an applications a new application you are reprogramming that
device.

How many times have you encountered a situation that somebody has come to your home
saying that they would like to upgrade the firmware of your washing machine I have never
encountered it, it does not happen and so that is the meaning of this point that embedded
systems are infrequently reprogrammed. Embedded systems have hard reliability and
correctness constraints.

All computers must operate correctly, but embedded systems have an additional
responsibility that they must continue to provide service reliably not all most of them, many
of them, some of them. Why because failure to do so may lead to loss of life. As an example
medical devices like an x-ray machine you do not want the computer in the x-ray machine to
fail and it may give needlessly high dose of x-ray to the patient under the x-ray machine.

And in an aircraft you do not want the computer flying the aircraft to fail leading to loss of
life and so embedded computers are expected some of the embedded computers are expected
to have hard reliability requirements.

28
(Refer Slide Time: 07:50)

Now that we have seen major differences between embedded computers and general purpose
computing devices it is time to go through certain terminologies that we use. And for many of
you or some of you it may be a repeat of things that you already know, but it does not heard.
So the first terminology is what is a computer? A computer is nothing, but a system which
has a CPU that is a central processing unit, memory and input output ports. Let me draw a
diagram to illustrate it.

(Refer Slide Time: 08:27)

So this is your CPU, this is your memory and usually you would require two types of
memories. One is the ROM which stores your program the other is the RAM which we use

29
for variables and then you would have certain IO devices maybe an input device and an
output device let me erase this and write it here and how does the CPU communicate with
these devices through buses.

These buses are for data and for address and another set of bus is what we call as the control
bus which tells whether you are reading information or writing information and all these. So
this is the diagram for a computer here is the CPU, ROM, RAM that is memory and input
output ports.

(Refer Slide Time: 10:18)

The second terminology is a microprocessor. A microprocessor is nothing but a CPU on a


single chip. How did it happen? In the 50s and 60s the CPU was made with discrete
components or discrete integrated circuits in the 60s. In 1971, a start up at that time that was
called Intel. And today Intel is a giant made an interesting device what it did was it integrated
the functionality of a CPU on the single substrate of silicon. What does a CPU entail?

30
(Refer Slide Time: 10:56)

A CPU has 4 components it has, so a CPU has control unit. It has registers in which
temporary information is stored. It has a ALU through which it can perform mathematical
and logical operations and it has a bus interface unit through which the CPU can
communicate with the outside world to the memory and to the IO ports.

Now all these were originally in the 50s and 60s implemented using discrete components,
discrete integrated circuits and what Intel did in 1971 is that it integrated all these on a single
substrate of silicon and made a IC out of it and that IC will named 4004 microprocessor and
the term microprocessor came about so that is the definition of microprocessor then what
happened?

31
(Refer Slide Time: 12:25)

When people started using a microprocessor to create computers it drastically reduced the
size of the computers. In the earlier days the computers would probably fill half a room, but
now suddenly you could fit the entire functionality of a computer on a single printed circuit
board and such computers were called microcomputers. So a microcomputer is nothing, but a
microprocessor plus memory plus IO devices on a single printed circuit board.

In the same scalability fashion the entire functionality of the microcontroller people thought
could be integrated on a single piece of silicon and what happened? It led to a
microcontroller. So a microcontroller is nothing but a microcomputer on a single chip. Who
did that?

32
(Refer Slide Time: 13:20)

It turns out incidentally that the world’s first microcontroller was in 1974 it was TMS 1000.
And this was by a company which is incidentally also supporting our program this course
here Texas Instrument. This was a 4 bit microcontroller I am going to use this terminology
Mu C to indicate that it is a microcontroller.

Now obviously you may have heard of Moore’s Law that says that it is not really a law it is
an observation that every 18 months that is one and half years the number of components,
number of transistors that you could integrate on a piece of silicon would double.

Now what would you do with these increasing number of transistors ofcourse you could fit
more and more functionality on a single piece of silicon and so this is the reason why you add
microprocessor and from the microprocessor you had a microcontroller, what next? Now
when you use a microcontroller in any control or embedded application.

Apart from the microcontroller here is your microcontroller. You still need analog
components for example I may have a certain sensor and the output of this sensor may need
to be amplified with the help of an operational amplifier and so I need to provide a certain
amount of gain, so I am going to put components like this. This is going to, so this is my
sensor here, the sensor the output voltage of the sensor is going to be amplified with this.

Maybe with another op-amp circuit I am going to amplify I am going to filter this signal in
some way and eventually feed it to the microcontroller maybe to the ADC input, will come to
more details about this ADC input, but you see if I have to design a system out of a

33
microcontroller apart from the microcontroller which has already integrated so many
components on a single integrated circuit I still need these additional components.

These are analog devices analog components and it is very difficult to make analog device
and program them meaning if I have an amplifier how do I write a program to change the
gain of the amplifier, how do I write a program to change the cut-off frequency of a filter or
the slope of that filter or the order of that filter it is very difficult.

(Refer Slide Time: 16:07)

But interestingly that also happened and that led to a definition called system on chip. A
system on chip in this context is a microcontroller plus analog components which are
programmable and this was by company called Cypress semiconductors. What they did was
they added microcontroller plus analog building blocks and you could change the
functionality of these analog building blocks by merely writing a program.

So you could decide that today I want the analog building block to function like an amplifier
with a certain gain or change the topology of the amplifier to be inverting or a non-inverting
or a differential amplifier or you want that analog building block to be of, to provide
functionality of a filter in which case what is the cut-off frequency, what is the topology of
that filter do we want it to be of the low-pass, band-pass, high-pass, band reject, notch and so
on and so this provides great functionality.

34
And so having a system on chip which integrates not only the microcontroller, but also
analog building blocks will reduce the size of the eventual system to a single integrated
circuit and that is a great improvement and we will see how.

(Refer Slide Time: 17:32)

Here is an example of a single board computer using a microprocessor you see a single
printed circuit board has been used. This is just to show you how from the earlier times when
the entire computer would be a big device has been shrunk to the size of a single PCB.

(Refer Slide Time: 17:50)

35
Anyway now in the context of system on chip I want to clarify that there are certain
interpretations of this system on chip. One is that system on chip is nothing in our context of
embedded systems that system on chip is a microcontroller plus programmable analog
components on a single substrate of silicon.

But in general when people refer to this term system on chip they mean probably a
microprocessor or a microcontroller together with some custom functional unit or units on a
single piece of silicon and that they mean the system on-chip and so it is very important to
know the context is the person talking about an embedded application where it might mean a
microcontroller and analog components or in a general context.

(Refer Slide Time: 18:42)

Now we come to this point we have mentioned this earlier that a microcontroller is a popular
method of implementing the embedded computer, but what are the other methods we must be
aware of them. So first method by which we can implement an embedded computer is
through a general purpose processor meaning a microprocessor for example. Another method
is to use what is called as application specific processor.

What are the examples of application specific processors? Well, a microcontroller is an


example of application specific processor also a digital signal processor which is a
specialized processor which can perform digital signal processing more efficiently than it is
possible with a general purpose processor and the third method is what we call as single
purpose computer.

36
I would like to elaborate on these 3 approaches. In a general purpose processor basically you
are saying I am going to use a microprocessor, but a microprocessor is only one part of the
entire ecosystem of a computer. Apart from the microprocessor what you need is you need
external memory of the type of ROM or of the type of RAM and then you are going to need
ports.

And so it would lead to is that it would not remain a very efficient from a size point of view.
It will not be a very efficient implementation because a microprocessor offer certain amount
of memory that is if for example your let us write this down.

(Refer Slide Time: 20:08)

If my microprocessor has certain amount of data lines let us say this is data and common
example are 8 or 16 bits or 32 bits. It also has this data is by the way bidirectional it would
have address lines let us say it has 20 address lines.

If it has 20 address lines that means it can access how many memory locations? 2 raise to the
power 20 which is equal to 1048576 memory locations that is 1 million. Now it can
communicate or it can talk to 1 million memory locations it is up to you to provide the
requisite amount of memory maybe you realize or you anticipate that your application is
going to need 16 kilobytes of ROM another 16 kilobytes of ROM.

So you have to add appropriate memory devices to fulfil the requirement. So this would lead
to a physically large system as far as implementation is concerned. On the other hand when
you choose to implement that application using an application specific processor such as a

37
microcontroller, a microcontroller is going to have a microprocessor that is a CPU on that
silicon substrate.

Apart from the CPU it is also going to have RAM and ROM in various types of a fixed
amount maybe it has 8 kilobytes of ROM and 8 kilobytes of RAM. If you find that this
amount of memory is suitable for a particular application it may make a better sense to use a
application specific processor such as this microcontroller to implement that system because
it would lead to reduction in size and reduction in cost.

It would improve reliability because there are less number of components to solder, so it
would be a more reliable system. And so often times you would implement your application
with a microcontroller as an example of application specific processor, but that is not all. You
can also implement the same system with a single purpose computer and I am going to
illustrate these 3 approaches using certain block diagrams.

(Refer Slide Time: 22:25)

Now when I implement an application using a general purpose processor here I have drawn a
block diagram. This is an alternative view to view to understand what is the meaning of a
microprocessor? Now one way to understand microprocessor which we have seen is that a
microprocessor is nothing but a ALU, registers, control logic and bus interface unit on a
single piece of silicon that is to indicate these 4 components as functional units.

There is an alternative view to understand how a computer works and which is through this
diagram that we have two blocks one is called the sequencer and the other one is called the

38
data path. The sequencer consists of the control logic it has instruction decoder and a program
counter and the sequencer talks to an external memory device such as the ROM or EPROM
or other types of memory devices.

And the reason why you can implement any different type of application is by changing the
contents of the program. The sequencer understands the instructions and based on the
sequence of these instructions which you as a user have to write it can implement a different
application. It does that by providing inputs to the second part of the building block which is
a data path and data paths consist of the registers for storing temporary values and the
registers feed the arithmetic logic unit.

So, essentially the sequencer and data path form the CPU. This CPU could be in the form of
individual ICs or it could be in the form of a microprocessor and that is the alternative view
to look at a general purpose processor. You are going to need external program memory and
data memory. Program memory feeds the sequencer, data memory is connected to the data
path so that you can store variables.

So while this is the log diagrammatic approach of alternative approach of looking at the
general purpose processor let us see if we were to implement an application using a general
purpose processor what would it look like.

(Refer Slide Time: 24:37)

And for example we have a anyway before we come to that example let me show you the
block diagram for a application specific processor also. This application specific processor

39
also has a sequencer which consists of the control logic, it has the instruction decoder and the
program counter which is connected to the program memory.

The program memory is populated is filled up with instructions by you as the designer. The
sequencer reads the contents of program memory and executes whatever that program
memory instruction expects you to do.

And then controls the operation through the data path which consists of registers and ALU.
Now in the previous case the ALU was a general purpose ALU, but for a application specific
processor it maybe a custom ALU meaning you would want to do certain operations more
often. Therefore you provide that arithmetic logic unit with that additional functionality like
in the DSP, a DSP operation requires repeated multiplication and addition of numbers.

And so in a DSP you have a ALU which has a feature called MAC Multiply and Accumulate.
Apart from that the program memory and data memory could be integrated on the same chip.
If you see this block diagram I have drawn a dotted line around the components to indicate
that these 4 block diagrams are actually could be integrated on a single piece of substrate to
give you a more efficient implementation.

(Refer Slide Time: 26:11)

Now let us look at the block diagram of a single purpose processor which consists of a
sequencer which is implemented as a state machine. State machine is another word for finite
state machine or a straight machine. It is usually implemented with memory building blocks
such as a flip-flop that sequencer communicates with data processing element.

40
Now in contrast to the data processing elements that is the data path in a general purpose
processor or application specific processor where you have registers and ALU to perform
those operations nothing is fixed for the data processing elements in a data path of a single
purpose processor why because the purpose is fixed and it is only one purpose that you want
to design it for.

You put appropriate data processing elements which could be decoder, adder, it could be an
encoder, multiplexer, de-multiplexor and so on and so forth. And ofcourse the data path
would want to store some information so it has memory usually in the form of a RAM and so
when you design a system which is expected to perform only one task and you specifically
designed this hardware just to do this and nothing else this would be called a single purpose
processor and any application could be implemented in any of these 3 ways.

And it would depend on you as a designer of embed systems to decide whether you want to
go through a general purpose processor route or you want to use microcontroller which is an
example of an application specific processor or do you want to go single purpose computer.
Now I have an example where particular application was implemented using these 3
approaches. The first one was implementation of a particular project which is a Roulette
wheel game using 8085 microprocessor.

(Refer Slide Time: 28:05)

This is the block diagram if you see this it has so many building blocks one block let us go
from the left you have the microprocessor which is 8085 in this case. Microprocessor requires

41
RAM and ROM which are indicated on the middle blocks these have to be decoded the
address of these devices have to be decoded.

So there is a decoding circuitry and then you need certain output ports to indicate the state of
the game to the user and so for that we have 4 ports which is connected to 4, 7-segments
displays, few discrete LEDs, a buzzer and a ring of LEDs, 2 rings of LEDs to indicate the
game that you are playing that you want to place your bet and then you want to roll to let the
Roulette wheel roll and then it will stop the speed of rolling will slow down.

And it will stop somewhere if that matches with the bet that you have placed you win
otherwise you lose and this was implemented using 8085.

(Refer Slide Time: 29:02)

42
And here is a schematic diagram as you see it uses so many integrated circuits I also have a
picture of the actual implementation on the left you have a PCB where the middle top IC is
8085 microprocessor at the bottom you have ROM and RAM.

The ROM is in the form of a E-square PROM and you have these latches on the left and right
and on your right is the actual input output board where you see two rings of LEDs, the red
and the green and at the centre you have the 7-segment displays and obviously as you see it
uses far too many ICs. My student implemented the same design, same application using a
microcontroller.

43
(Refer Slide Time: 29:45)

This is the block diagram of a Arduino which is a microcontroller. Basically Arduino uses
AVR microcontroller this is an application using Arduino and you can see these block
diagram you see suddenly the number of blocks have reduced why because the
microcontroller has integrated the microprocessor and memory and ports into a single chip
therefore the size reduces.

(Refer Slide Time: 30:08)

44
Here is the schematic diagram of the microcontroller based Roulette wheel as you see the
components have reduced. And here is the photograph as you see you have very small PCB
on your left which is just one microcontroller a switch and so on and on your right you still
have the LED rings, red and green and the 7-segment displays. This is the second
implementation of the Roulette wheel gain.

(Refer Slide Time: 30:39)

And then we also have the implementation using this single purpose computer
implementation using a CPLD, CPLD stands for Complex Programmable Logic Device. This
is a device that you can program to implement a custom circuit and this is the block diagram.
You see this block diagram is split in two parts which is exactly what we had discussed

45
earlier that it consists of a sequencer which is the finite state machine in this case. The finite
state machine controls the data path where the actual operations the processing of
information, processing of data takes place.

In this case several building blocks of processing that data are being used for example this
uses a counter it also has a comparator for comparing the numbers that are being generated
and on the right most side you have decoders for controlling 36 red LEDs and another
decoder for controlling 36 green LEDs which you form the inner and outer ring of the
Roulette wheel.

(Refer Slide Time: 31:41)

46
This is the schematic diagram as you see it has a CLPD and all these LEDs and all that and
you see there are no almost no other ICs being used other than a clock generator based on a
555 timer IC and here you can see the actual implementation a single printed circuit board
pretty much which has the LEDs on the outer periphery and at the centre you have the CPLD
IC.

So you see it is possible to implement any embedded application in 3 ways: the general
purpose processor approach which usually involves lot many components. There may be
some good reason for you to use that approach, but from the point of view of cost and
reliability and economics maybe you would want to implement the same application using
embedded computer.

Using a microcontroller and the third approach ofcourse is the single purpose computer and
there are many-many applications which are done using this approach.

(Refer Slide Time: 32:38)

I want to show you how things used to be designed earlier in 60s and 70s integrated circuits.
On your left is a picture of design engineer inspecting the layout of an IC. You see the IC
itself is very small probably a millimetre square or couple of millimetres or thereabouts.

But you cannot inspect the design on such a small piece of substrate and so you blow it up by
several magnitudes and then it occupies almost big room and you see these design engineers
are inspecting the design and today you do not have to do that at all because you are using

47
CAD tools and languages which are created for implementing and designing hardware and so
on the right you have the synthesizable code to implement a 8085 microprocessor.

Ofcourse this is just an example and today you would not implement 8085 microprocessor.
You would implement whatever fancies you whatever is in your mind and you can use
language such as VHDL or Verilog to implement that circuit.

(Refer Slide Time: 33:52)

Till this time we have discussed implementation of the embedded system from a processor
that is the embedded computer point of view. But that is not the complete story because we
would like to build a complete system. So at a system level what are the various approaches it
turns out that there are two popular approaches. One is that you build everything from scratch
on your own meaning you decide what embedded computer you are going to use for that
what kind of circuitry is required, what kind of additional components are required.

You would need a printed circuit port for that, you design it you get it fabricated and then you
integrate all the components on that PCB and usually you take this approach when you are
expecting large volumes because you would benefit from economies of scale, but when your
applications are not when your requirements are not that large volumes are not that large
there is a alternative method and I call it COTS approach that is Components Off the Shelf.

Meaning you buy things that are available and you quickly integrate it and implement your
design and these days you could implement this COTS approach using popular single board
computers which are very powerful computer today such as Raspberry Pi or Beagle Bone

48
Black single board computer. In the earlier times or even today if there is such a need you
would use a regular PC motherboard to implement what you want.

So, at this point we are at a stage where we have seen all these things you can do with
embedded systems, how you implement the processor, how you implement the system.

(Refer Slide Time: 35:29)

And I would like to now give you a small demonstration of MSP-430 based projects that have
been designed in my lab. So that you the student, you the participant can feel confident that if
my students can do it in my lab you sitting wherever you are sitting can also design such
systems. So let us have a look at some of these projects.

(Refer Slide Time: 35:58)

49
For that let me start with simple project first this is a project which is a battery-less electronic
dice, but it has only one display often times you play a game where you need 2 dice.

(Refer Slide Time: 36:09)

50
And so here is another implementation this has two displays and use it again this is
battery-less so I will shake it and when I stop you see 2 numbers, 2 random numbers are
being printed here. Again I shake it when I stop it produces two random numbers. What does
it use? It uses MSP430 microcontroller in the middle you have the tube which produces
which converts mechanical energy into electrical energy for the circuit to operate and on this
side you have capacitor which store the voltage that is produced so that this circuit can
operate and you see this entire system has been fabricated.

In my lab these PCB have been fabricated locally and the entire system has been integrated
here, this is the second project.

51
(Refer Slide Time: 37:03)

52
Continuing with the LED projects here we have another system we call it the colour mixer
because it is going to mix 3 primary colours green, blue and red and create a custom colour. I
have the power supply for this comes with the help of in the form of this power bank I am
going to connect it to show to you.

Now this is how it works I am going to reduce the colours so this is green 256 levels of green,
blue colour again 256 levels here again 256 levels of red and I can add two certain levels of
red I can add certain amount of blue you see I get various shades of magenta or instead of
blue I can add green and I get various shades of yellow or into this now I can add blue and I
get various shades of white and so on.

53
And this user MSP-430 microcontroller it controls these 3 LEDs using a concept called pulse
width modulation that we are going to cover and because each primary colour has 256 levels
the total number of colours that can be made out of this colour mixer are 256 cube which is
16 million colour this is the number of colours that can be made with this.

(Refer Slide Time: 38:39)

Then I have this project which we call the electronic birthday blow out candles. These are
supposed to be birthday candle so that they function without using real candles, real candles
with small kids can lead to a fire hazard and here so we have done away with real candles and
instead used LEDs to mimic the function of a candle. Now, if these are candles or if these are
mimicking the operation of a candle then I should be able to blow them off like I can blow
off normal candles.

And that is the magic here we have used a sensor thermistor which will detect air blow when
I blow on it. The microcontroller here is going to sense the air blow on the thermistor and
will randomly turn these LEDs off. So let me try and as you see it is also making a sound it is
playing happy birthday sound. So this works like a replacement to traditional birthday
candles. It is perfectly safe to use any number of times you or your kid would want to.

54
(Refer Slide Time: 40:06)

Let me show you another project now and this is electronic sandglass. So instead of sand
falling from one part of the sand glass on to the other side here we use LEDs as you see as I
am holding it this is the LED indicate as if sand is falling. Now if I turn this around this sand
should come to the neck and you see now it is falling in the other direction and normal sand
glass when it empty the sand it does not say anything.

But because this uses a embedded computer it will tell you that the time has elapsed. Now if I
turn it around again it is falling on the other side and this has been program to empty the so
called sand in about a minute of time. These has also uses another MSP430 microcontroller

55
and the sensor for the orientation is also integrated in this project and in fact it was conceived
and designed in the lab.

And this project actually I will show you this is the enclosure which was made in the lab
using a CNC machine this is the embedded computer here, this is the sensor part here and it is
being powered with 2 AA sized alkaline batteries.

(Refer Slide Time: 41:21)

Let me show you another project and in this case this is a LED Kaleidoscope, normal
Kaleidoscope has glass pieces in the form of bangles and 3 or 4 mirrors where the external
light is reflected, refracted through the glass pieces, glass bangles and you see multiple
reflection through the mirrors.

56
In this case we have done away with the natural light and which means you can use it
anytime you want whether there is outside light or not inside there are RGB LEDs several of
them and there lighting pattern change as you move it around why because we have
integrated certain sensors in this.

And ofcourse there are mirrors also and embedded computer MSP430. As you can probably
see as I am turning the Kaleidoscope tube around the lighting pattern inside have changed
and if you have to look through this you would see interesting pattern. In fact what I will do
is I will share pictures with you of the closer pictures looking through this hole so that you
can see how the lighting patterns look like.

(Refer Slide Time: 42:34)

57
Now I have another project this is slightly advanced project based on MSP430 and this is
called Talking Tom and this is the hardware implementation of a Talking Tom application
you may have seen on a mobile phone what this does is on what that application does is that
it will record your sound then it will play back at higher pitch. So this project we call Talking
Tom.

We actually call it Talkative Tom because we did not want to have issues of copyright names
this does that and it also adds another features that in the second mode it can play back the
recorded sound and it will sound like an alien. So let me give you a demonstration of that I
have two selected switches in which I turn it off and on and with the other switch I can select
the mode in this case I have selected the high pitch mode.

Hello this is the project demonstration of Talkative Tom. Let me change the mode and make
it the alien mode. Hello this is the project demonstration of Talkative Tom in the alien mode.
The entire enclosure was fabricated in the lab as you can see the circuit board was also
fabricated and soldered in the lab. It has integrated battery source, charger and audio
amplifier and speakers.

(Refer Slide Time: 44:12)

And last but not the least the project I am going to show you is what we call as the levitating
doll, I am going to power it with the adaptor 12 volts adaptor. In my hand is a 3D printed doll
and in the hat of the doll there is a small magnet there is a microcontroller on top and here I
have a electromagnet. At the bottom of the electromagnet there is a hall effect sensor which

58
senses the position of this magnet when I hold it there and the microcontroller will maintain
the position of this doll suspended in the air let us see how it works.

It is floating in the air, why? it is sensing the position if because of gravity the doll tries to
fall, it turns on the electromagnet if the doll tries to come too close it turns off the
electromagnet and this operation it is doing 1000 of times the second to maintain the position
at a given location and all these are implemented by my students using MSP-430
microcontroller and so my students can do it I am very sure you as my remote student can
also do it. Thank you.

We are going to continue our next lecture and talk about other issues related to embedded
systems, but at this point I would like to summarize what we have discussed here. We have
gone through various definitions of embedded systems, we have seen application areas of
embedded system. We have seen how embedded systems could be implemented using a
general purpose processor or application specific processor or using a single board computer.

We have seen what are the characteristics of embedded systems and at the end we have seen
some applications which I hope you found to be very encouraging. Thank you very much and
I will see you in the next lecture, bye.

59
Introduction to Embedded System Design
Professor Dhananjay V. Gadre
Electronics and Communication Engineering
Netaji Subhas University of Technology
Badri Subudhi
Electrical Engineering Department
Indian Institute of Technology, Jammu
Lecture 03
Modular Approach to Embedded System Design

Hello, welcome to the next lecture in our course on introduction to Embedded System Design as
you know, I am the ​Dhananjay Gadre and I will be conducting this session in the last session we
discussed the definition of embedded systems the application areas and in how many various
ways we can implement the embedded computer.

Before we start this lecture I want to follow-up on some of the issues we discussed in the last
lecture namely if you recall in the last lecture I mentioned that there are 3 methods of
implementing the embedded computer.

(Refer Slide Time: 01:10)

The first one is using a general purpose processor, the second is using an application specific
processor and the third being single purpose computer. I did not discuss that what is the source
of these 3 approaches meaning that if you wanted to implement the embedded computer using a
general purpose processor where do you get a general purpose processor now it turns out that

60
general purpose processor you can have readymade provided by some manufacturer and this
would be called generic commonly available device.

For example, you could take 8086 or you could take 68000 these are examples of general
purpose processors this is one method. The second method could be that you could design your
own you could design a processor of your choice using contemporary techniques and this would
be a custom approach.

And the third is this existing companies could license you the code, the hardware description
code for their processor and you could acquire those codes in whatever way and target that code
into a programmable logic device such as FPGA these are the 3 methods.

If we want to implement our embedded computer using application specific processor then again,
we can choose the first method that is select available microcontroller or a DSP or create our
own custom application custom chip and the third you could take the hardware description code
for that particular micro controller or DSP and target a programmable logic device.

Single purpose computer on the other hand because, there is no special chip available to do that
there are usually two methods: one is that you design your own single purpose computer and
then get it fabricated in a custom way or once you are designed it you could target the actual
implementation in a field programmable gate array device. One more point I would like to
mention here.

61
(Refer Slide Time: 04:35)

If you look at the general purpose processor scenario if I take an example of say 80486 as an
example, there is usually not many varieties of 80486 microprocessor available there may be few
based on maybe the speed performance of that microprocessor or maybe the packaging but
varieties are limited.

On the other hand if you go to a microcontroller, which is an example of a application specific


processor you would find because not one implementation may satisfy all the requirements that
you would find that for a given family of microcontrollers usually there are hundreds of physical
devices available each device offers various amounts of memories and ports and other peripheral
features.

And once you are looking for your requirements, you could survey the available devices and
select one which best fits your needs and so, that is the fundamental difference between the
general purpose processor availability and the availability of microcontroller families. Now, we
are ready to resume our current lecture. Now, we want, we have seen the ways we can implement
the embedded computer but we want to look at what are the parameters by which we approach
design of an embedded system.

62
(Refer Slide Time: 06:13)

And it turns out as a commercial implementation that there are two methods two metrics which
we must keep in mind when we end our design the first one is called time to market meaning that
once you decide that you want to create a certain product you must complete the design, task the
fabrication task and launch your product quickly into the market.

Various surveys have shown that if there is a 4 week delay in the launch of a product it can lead
to loss of market up to 30 percent drop in market you could experience. And this is very similar
to an age old wisdom that they say early bird catches the worm so, time to market is an important
consideration when you are designing an embedded application.

And the second consideration is that whatever application you are designing it must be cost
effective, the overall system cost will dictate your success even if you can launch a product
quickly if it is not affordable if people cannot afford it then your product will not be successful.
So, both these metrics must be kept in mind both these points must be kept in mind when you as
a professional embedded system designer start designing a product.

Now, we will see how our choices that we exercise are affected by these two metrics. Now
because we are doing this course with the assumption that using a microcontroller is a very
popular method of implementing an embedded system so, we are going to see what are the

63
various ways in which we can select the right microcontroller for our job in fact this topic we are
going to revisit often times in subsequent lecture also.

(Refer Slide Time: 08:06)

I am going to discuss this idea of how to choose the microcontroller that is suitable for your
application in different perspectives right now we are looking at it from the point of view of time
to market and overall system cost. So, time to market being an important consideration when you
select a particular microcontroller based on other considerations of whether it is suitable
functionally or not question arises is the microcontroller architecture is easy to use?

Meaning the design team that is going to take up this design process are they able to understand
the architecture can they understand it and quickly start implementing the design because, if they
do not then it would impact the time to market metric. In that objective, one of the important
considerations is to find out the microcontroller that you are choosing for your application does it
support high level languages?

Now, in this age it may seem like a very odd question but, remember about 40 years ago when
microcontroller started appearing the amount of memory available on chip for these
microcontrollers was very limited and therefore, to make the best use of that microcontroller the
preferred method of programming these devices was using the assembly language programs.

64
And assembly language programs for a same objective if you decide to write your application in
assembly language program it would take more time compared to the time it would take if you
wrote the same application in a high level language, why? Because the high level language
allows you complex constructs with which to manipulate the data and therefore, you can quickly
achieve your objective.

And so, if you even today if you are going to select a microcontroller you must find out whether
the microcontroller has software tools which support the language of your choice. Usually these
days people do not use assembly language program they prefer C or C++ and there are many
other languages which are being used for programming microcontrollers in a for embedded
applications.

And therefore, you as a designer must find out whether the language of your choice is supported
through various software tools for the microcontroller that you want to use if not, it will impact
time to market. Now, once you have decided to use a particular microcontroller and you start
using it in your application.

What if, a few days into the development process you realize that your original estimates were
all wrong and that this device does not have the resources in terms of maybe the memory or
maybe in terms of the peripheral devices that it is not possible to convert your product using this
particular microcontroller. Then, you must find out whether there are other compatible devices
with more memory or different features that you may require.

And you want to retain that family meaning you do not want to find a completely new device.
Because, then it would waste your development process and time that you have spent is now do
you want to reuse it simply switch over to a new device and therefore, it is very important to
know what are the what is the eco system of parts variety of parts that are available in a given
family again this will be useful to meet the time to market objective.

Now, to develop an application using a microcontroller, it requires several development tools


again we will see a list of such tools subsequently but, quick list of such devices to be able to
program a microcontroller you need a compiler the compiler usually comes with an assembler.
Once you have compiled your code you would like to test the validity of that code you would

65
like to see whether the code works correctly or not without committing it into the
microcontroller.

And so, you would like to have what is called as a debugger or simulator using which you will
see the correctness of logic of your program. And after you have verified that you may want to
test the code in real hardware, which is where you would require a evaluation kit and as you as I
mentioned in the earlier lecture that as part of this course, you are going to receive MSP430
microcontroller evaluation kit, which will allow you to test programs in on the hardware for this
microcontroller.

And similarly, when you are developing an application in a professional way you do not want to
commit to making a printed circuit board right away you want to get a feel of the development
process you want to see how your code is running on the hardware platform and therefore,
having a readymade computer made by somebody is very useful this is where the role of
evaluation kit comes into picture.

And apart from that you also need something called an emulator. And emulator is a mechanism
to emulate the functionality emulate the behavior of that microcontroller in hardware and these
days it is very easy to have that functionality in the olden times you would actually get a
specialized device called in-circuit emulator it was an expensive piece of equipment.

But today almost all modern microcontrollers are equipped with the on-chip emulator on chip
debugger, which allows you to emulate the function and verify whether, the program is working
or not and if it is not working, what is the reason. So you need all these development tools. And
in case things do not work out are there any support forums which can address your concerns or
your difficulties or your problems.

Having a support forum maybe by the manufacturer or by the online community can be useful
resource and therefore, given two devices which are suitable for your job one which has a better
support which has better popularity probably should be chosen so that it helps you resolve
different difficulties that you might face. Let us see more points.

66
(Refer Slide Time: 14:37)

Now, the earlier slide was a talking about time to market in this slide we are going to talk about
the overall system cost. Now the overall system cost of your product is determined by several
factor one of which is the cost of the microcontroller but, a microcontroller alone is insufficient
to create an application usually it would require external components. These external
components may be in the form of analog operational amplifiers or filters and so on and so, forth
and therefore, you must consider the overall cost of not just the microcontroller but, also the
external components.

Now you see in this slide if I say if one were to choose the piece of microcontroller which has
programmable analog components on chip it would reduce the cost and would do further that it
would also reduce the cost of the PCB.

So, the cost of the PCB is an important consideration in the overall system cost having less
number of components because, you choose a microcontroller which has higher integration of
the requirements that you need would lead to smaller chip count it would also increase the
reliability of your product and it will lead to a reduced cost of printed circuit board thereby
giving you a more economical product therefore, it can be more competitive.

Now, having designed product using a particular microcontroller often times it is seen that there
is a demand in the market of a higher upgrade to that product. Now, if you are in that happy

67
situation you would like to know is it possible to reuse the resources that you have accumulated
for the development of that earlier version, could you use those resources and find
microcontroller which has higher capabilities so as to fit more functionality in the new upgraded
product.

Having this knowledge or having the satisfaction of family, which has upgrade paths available
would be beneficial in the long run. And usually the performance is improved because you can
fit in more software features into the device. And then what you must also consider is the hidden
cost of the development or the production what I mean by hidden cost? For example, suppose
you are making your company is making 5 products and if these 5 products use 5 different
integrated circuits, if it uses 5 different microcontrollers.

Then, the impact is that for maintaining a certain supply of your products you will have to create
you will have to maintain an equal inventory of all those large inventory of all those 5
microcontroller chips that you are using for 5 products. On the other hand if those 5 products use
common microcontroller the amount of inventory that you have to maintain to be able to offer
you all your products get significantly reduced.

And therefore, having a smaller inventory leads to a better cost that you can offer to the
customers and therefore, your product will be more competitive besides that you cannot be
expected to stock infinite amount of, infinite quantities of these devices and therefore you must
rely upon the manufacturers to supply those to you.

You must also consider how quickly can you acquire a new stock in case you need one. Is there
waiting time? Is there turnaround time, does the manufacturer take too much time to fulfill your
requirements? You must consider all these aspects because, eventually these are going to impact
either time to market or the overall system cost. Now, since we have seen the development of the
choices we make for the microcontrollers let us look at the classification of microcontrollers so,
that we understand the overall ecosystem.

68
(Refer Slide Time: 18:50)

Microcontrollers and also microprocessors for that matter are classified at various levels. One of
the methods of classification is the memory architecture. Memory architecture refers to the way
the microprocessor or the microcontroller addresses the memory for its use and memory as we
have discussed is required for two purposes. One is to store and execute the program and second
is to store data which may be variables maybe stack and so on.

So, before we discuss the memory architecture, it may be impertinent to discuss what sort of
memory devices exist and what are the interface is these memory devices offer, although for a
microcontroller these memories would be integrated on the chip but, it helps to understand the
way these memory devices work.

69
(Refer Slide Time: 19:51)

So, broadly we need two types of memories: one is the ROM and the other is RAM. A ROM
device would have ofcourse all electronic devices need a power supply pin that goes without
saying so it requires a VCC and the ground and right now, we are considering the ROM so I am
going to cross this. The ROM would have data lines and because, you are going to read the
contents of the ROM you do not have the freedom to write into a ROM at runtime meaning in
your application.

So, I have shown the direction of the data bus to be unidirectional these are data bus data bits
then, to access the location you need to specify what address do you want to read the data from
and for that you have the address bus. This is the data bus the number of bits on the address bus
would indicate what is the capacity of this ROM device meaning how many locations there are
the number of bits on the data bus will indicate that for each location how many bits are
simultaneously being stored.

As an example, I could have a data bus D equal to 8 and A is equal to say 12 if that is the case
that means this ROM device A 12 leads to 2 raise to power 12 locations, which is 4096 and
therefore, this would be a 4KByte 8 bits mean a byte so this is a 4 Kilo bytes capacity ROM
device. Apart from the data bus and the address bus it also requires a few control signals and
these control signals are referred to as chip select.

70
And you see I have drawn a bar over that signal meaning chip select bar and to also indicate that
the this is active low signal there is a bubble which means to select this chip out of perhaps
several other chips that you would have connected on the microprocessor buses to enable this
chip this pin must be held low and if you do not hold it low then, this chip will not interact with
you will not provide you the data that you expect.

Apart from that it also has a pin called OE bar that stands for output enable bar. So, not only do
you have to hold the chip select low you also need to hold OE bar low and then for the value of
the bits provided on the address bus it will enable that location in the wrong device and the
contents of that location would be available on the data bus this is how a ROM device works.

(Refer Slide Time: 23:16)

71
Similarly, the way the RAM works is for a RAM device we have almost identical configuration,
except a couple of one more extra line so we have the VCC here, we have the ground. The data
bus I am going to write it here now, because it is a RAM meaning you can read as well as write
data. The data bus is by directional and again it may have certain number of bits. Let us call them
let us call them D, number of bits.

The address is unidirectional address bus and this may have A number of address lines and it
also requires control signals again a chip select and output enable signal this is till now, it is
identical to a ROM device. But, now because you want to be able to write data into this so, you
have an additional signal which I will call write bar and this is also active low signal.

The reason why control signals are often active low have to do with the fact that there are legacy
issues that in 60s and 70s where the technology for logic devices was TTL, TTL preferred active
low signals control signals and therefore even today many of the control signals on modern chips
are also of active low variety.

These two signals exercise great caution must be exercised in issuing these signals that is you
cannot turn on the output enable and the write bar signal at the same time because, if you did that
the ram chip is going to be confused do you want to write data into it or do you want to read data
from it and it will actually lead to a condition called bus contention.

72
Because, you might provide external data and since you have enabled the output enable signal
the RAM would provide internal data and there might be a conflict of logic levels. And so, these
two never should never be enabled at the same time but, the chip select has to be enabled
together with either the output enable signal or the write bar signal. And where do these signals
come from? These signals come from the control bus of the microprocessor or the
microcontroller to which they are connected.

Now, let me go to the earlier slide here, we just functionally meant that we need a ROM device
there are many varieties of ROM the first one is itself is ROM meaning you get a manufacturer
to provide this chip, which is pre-stored at the factory level with the contents that you want then
there is a type of device called P-ROM meaning programmable read only memory you get a
blank chip and using a special programmer you load your required contents into this device.

But, thereafter you cannot use it if you want to reuse then there are a couple of varieties. One of
the older ones was called E-PROM that is Erasable Programmable Read only Memory. This
device could be raised with the help of ultraviolet light shine which was put onto the chip using a
special window at the top of the chip and then you could erase it using this light and you could
program it using a special programmer electrically.

And then, the fourth device you have these days is called EE-PROM where the erasing of the
device can also be done electrically. So, this is electrically erasable programmable read only
memory and a variety of E square PROM as it is popularly called is the type called flash
memory, flash memory is type of E square PROM except it is faster to erase. And therefore, that
is why the name flash you can perform that operation in a flash these are all examples of read
only memory devices.

When we look at the RAM devices primarily you have two types of devices called SRAM and
DRAM. SRAM stands for Static Random Access Memory and DRAM stands for Dynamic Ram.
Static RAM is easier to use because, you simply provide the address you provide the control
signals and data would come out or you could write data into it. DRAM on the other hand is
more efficient because, it can it packs more data bits into the same area.

And but, it is little complicated to use it as it requires of frequent refreshing it also has a different
method of providing the address, the number of address lines are less and to indicate that you

73
have two signals called RAS and CAS. So, it is like the memories arranged in the form of a array
and first you supply the row address then you supply the column address using the same address
lines.

And so, the number of address lines address bits required to access this memory is reduced and
you also need to frequently refresh the contents otherwise, it would lose the contents and
therefore, useless as a RAM and so, using it is slightly more complex but, because it is more
efficient it is more dense modern applications often require often use DRAM chips. If the
requirement is small then you might go with SRAM. And this functionally from a block
diagrammatic point of view that here, is a device where you store read and write data this model
is okay.

Now, let us go back to the actual presentation and see where this fits now, we are talking of
memory architecture meaning how does the microprocessor connect to the memory devices and
we certainly need two types of memory devices a ROM and a RAM the first memory
architecture that we would like to discuss here is called Von-Neumann.

Von-Neumann refers to the way the microprocessor talks to the available memory and as I
mentioned for any microprocessor for any microcontroller or any computer in general would
require two types of memory ROM for the program and RAM for the data so, let us see how
does a microprocessor communicate with memory under the Von-Neumann architecture.

74
(Refer Slide Time: 30:15)

So, if this is your processor and I am going to use the word processor little loosely it could be a
microprocessor or it could be a microcontroller does not matter in a Von-Neumann architecture
you would have a single data bus this is data bus you would have an address bus and outgoing
pins for address and you would have suitable control signals to generate the chip select and
output enable and write bar signals and so on. So, let us call this control bus now, depending
upon the number of address bits address lines.

Let us say 16 address lines that means this processor can uniquely address 2 raised to power 16
locations and this is equal to 65536 locations and is commonly referred to as 64 kilobytes of
memory, 64 kilo locations. Now, each location how many bits can it store will depend on the
width of the data bus.

If it is 8 that means this processor can talk to 64 kilobytes of memory location so, let me show
you that memory map. So it is going to start from first location and we will call this 0000 four
nibbles to specify the address each nibbles is 4 bit so, 4 digits means there are 16 address lines
and the last location will be f f f f that is all ones and therefore, this as 64000, 64k locations.

The microprocessor designer the system designer using this microprocessor must put suitable
amount of ROM into this memory map and let us say the first few locations it decides to dedicate
to ROM and then maybe from here, to certain a lower value it has RAM. so it is going to use a

75
unified bus to read the program from the ROM and maybe read and write variables and store
variables in the RAM.

What is the problem with this? What is the characteristics of this architecture? It is very simple.
The number of pins required by the microprocessor to connect to memory devices is the lowest
that you can find but, there is a little problem in this approach in terms of the number of activities
that it can do. Because, there is only one common bus you can either read the memory contents
or you can write to it. You cannot do both the things.

And when that need was felt that you wanted to improve the performance of your processors by
including certain parallelism that is you would like to read the instruction while at the same time
you may want to store the results from a previous instruction it called for certain modification of
the memory architecture and so, a new architecture was devised and that was that is referred to
today as Harvard architecture. In Harvard architecture what happens?

(Refer Slide Time: 33:50)

Now, instead of us unified memory bus we have two memory maps so, this is my processor I am,
I put it in the center for a particular reason now, you can have type of memory devices which
store the program we call them ROM and for that it would have data bus in this case the
direction can only be this address lines, so this is data this is address and this is control signals.

76
Now, I call this the ROM or here, I am going to store program so, we commonly refer to this as
program memory and therefore these buses which connect to a program memory are called
PMDB that is Program Memory Data Bus, PMAB Program Memory Address Bus and PMCB
Program Memory Control Bus you want parallelism in the activities that this processor does so,
you have one more set of address map which allows you to connect to a data memory.

Now, data memory is could be RAM most often it is RAM but, it could also to be ROM because,
you want to read some constants and so on. So, this is I will refer to it as data memory and again
here you would require the data bus but, now they are bi directional because, you want to be able
to write data you have address like the other memory and you also have the control and these are
this set of buses is referred to as DMDB, DMAB Data Memory Data Bus, Data Memory Address
Bus and data memory control bus, what advantage it offers?

You can do two simultaneous operations, what are the, what is the disadvantage of this
approach? You require perhaps you require twice as many pins on the physical microprocessor
and so, it will lead to a bigger package. But, that is a trade of you as a designer must evaluate
whether performance is more important to you or the size of the chip is more important to you
and these two architectures are available.

(Refer Slide Time: 36:30)

77
This is one method of classifying microprocessors or microcontrollers that is does the
microcontroller that you are choosing does it of does it offer Von-Neumann architecture for
memory access or Harvard architecture? Then, at a different level of classification it is bit
handling capacity that is how many data bits can it handle simultaneously? And what options we
have? We have 4 bit data 8 bit data this is the size of the data bus.

And if we are looking at we are we are microcontroller is of the Harvard architecture then, it
refers to the data bus size of the data memory not necessarily the program memory and so we are
talking of 4 bit data bus 8 bit data bus 16 and so on and so forth. And then we have what is called
as the instruction set architecture. I am going to continue with the description of the instruction
set architecture in the next session and I will see you shortly. Thank you.

78
Introduction to Embedded System Design
Professor Dhananjay V. Gadre
Electronics and Communication Engineering
Netaji Subhas University of Technology
Badri Subudhi
Electrical Engineering Department
Indian Institute of Technology, Jammu
Lecture 04
Modular Approach to Embedded System Design (Continued)

Welcome back. So we are going to resume our discussions and we are going to consider
another classification of microcontrollers or microprocessor. And this one is called
instruction set architecture. As the term suggests the classification, the types of
microprocessors are often classified in the way the instructions are designed for a given
microprocessor. Now to understand that let us first of all describe what are instructions and
all that.

(Refer Slide Time: 01:04)

Now, what are you going to write in the memory of the microprocessor is a program. And
what is a program? A program is a sequence of instructions. Often times when I asked this
the meaning of a program people mentions it is a program is a set of instructions. That is
wrong because set can be rearranged and it would not be the same program. So the correct
definition is a program is a sequence of instructions.

Therefore, what is an instruction? An instruction is the lowest level atomic command that a
processor understands. What does an instruction consist of? It consists of 2 things. The first
part of the instruction is called the op-code. This indicates the basic operation that the

79
instruction is going to perform. And the second part is the operand meaning what is it going
to work on.

For example, an op-code could be to perform an addition and so the op-code refers to add.
Operand is what is it going to add? Is it going to add 2 numbers? How are the 2 numbers
specified? Are the 2 numbers part of are stored in 2 registers or the format could be Add R1,
R2, R3. If it is of the first type, it means that R1 gets the value of R1 plus R2. And in the
second type, it could mean that R1 gets the value of R2 plus R3.

Whether it is of the first type or second type would have a lot of bearing on the size of the
instruction. But needless to say, the operation to be performed is described as the op-code.
And the operation to be performed on what numbers is the operand part of the instruction.
And this is where things can take large variety lead to different types of instruction set
architecture. And before we go to that, let me also classify the instructions.

(Refer Slide Time: 04:01)

The types of instructions broadly can be classified in 4 types of instructions. The first
instruction refers to what is called as Data Transfer Instructions. As the name suggests, these
instructions deal with moving data from one storage location to another storage location in a
microprocessor or in a computer system.

What are these locations? These locations are, could be registers. They could be memory and
they could be ports. And so, you would want to move data between these entities. So
instructions that move data between two registers would be available. Instructions that move
data between registers and memory location would also be available.

80
Instructions that move data between the register and port would also be available. And if we
look at other combinations, you may expect that instructions to move data between memory
location and a port may also be available. But if you consider this act, this requirement.
Memory is outside the CPU; the port is outside the CPU. Why would you want to involve a
microprocessor or the CPU in this transfer?

It is only going to slow it down because the microprocessor is not adding any value to this
activity. It will have to do this transfer in 2 steps. One it will have to first read the content of
the port and then read the content of the port into a register and from the register it may move
the content to a memory location.

And therefore, this is a slow process and usually there are no instructions to perform this
operation. But this is a very desirable operation and therefore, most of the time this is
available as a hardware feature of the processor and it is called Direct Memory Access. Apart
from moving data between these entities, sometimes you would like to initialize the register
with the immediate value or a literal value.

For example, you want to initialize a register with some known constant or something like
that. So, you would have instructions to support this kind of transfer. Then the other type of
instruction would be for what is called as Math and Logic. And this would include
instructions such as add, subtract, maybe multiply, divide, bit operations such as AND. So,
you are going to AND the bits of two operands or you may want to OR or other similar
logical operations.

Then the third type of instructions are what are called as branch. Branch instructions are those
instructions which change the sequence of instructions being executed. Normally, the
microprocessor or the microcontroller fetches the contents of a memory location. After it
executes it, completes it, it goes to the next sequential memory location and so on and so
forth.

But once in a while, you may want to alter this sequence. You may want to jump to an
arbitrary location. Why? Because maybe at that arbitrary location you have stored a
subroutine that you would like to execute. So, the instructions of such nature where the
control of the microprocessor is altered from the current location to a unspecified or a
different location which is not necessarily sequential such instructions are called branch
instructions.

81
What are the types of instructions? So, you would like to jump to a arbitrary location, a
particular location. You may want to jump it without any condition or you may want to
involve a condition. Maybe there are things like flags in the microprocessor; so you would
like to jump if the if a certain flag is set or you may want to jump to a location if this flag is
reset.

Similarly, you may want to call a subroutine. So, that instruction is for call. Again, call could
be unconditional or it could be based on certain flags. Similarly, for call corresponding to call
once you have to jump to that subroutine address, after you have finished executing that
subroutine, you would want to resume and come back to the main program from where you
had called this subroutine.

So, you would have instructions for return. And again, return instructions could be
unconditional or they could also be conditional. Apart from this any other instruction that
you may have would be in this fourth category and I call them miscellaneous instructions.
And one very common instruction that is available across all microprocessor platforms is
called NOP that is no operation.

It is usually to if I want to use the word waste time or to spend time. There could be an
instruction to change the operating mode of the processor. Maybe you want to switch to a low
operating mode or it may want to modify certain flags for say, interrupts it may want to
enable disable interrupts.

So, instructions of such nature as you see they do not fall in the first 3 categories would be
classified under the miscellaneous categories. Now, these instructions irrespective of the
processor architecture, these are the 4 types of basic instructions that any processor has.

82
(Refer Slide Time: 10:24)

Now, another concept that is built into these instructions is called addressing modes. We are
going to talk in more detail about addressing modes but let me use this opportunity to give
you a brief idea because it is required to explain the concept of instruction set architecture.
Addressing mode refers to the way in which foreign instruction which has a given op-code.

How is the operand specified? Meaning if I want to add 2 numbers, those 2 numbers could be
available in 2 registers or 2 numbers could be such that one number is available in the register
and the other number is in the memory location. Or one number could be in the register and
the other number is immediate number. So, these modify or these offer more variety in the
basic instruction like add.

Similarly, you want to fetch, you want to transfer data between two entities. Do you want to
specify the address of the location? How do you specify the address of that location? Is it in
another register? Or is it in a memory location? Are you specifying the address of that
memory location completely as part of the instructions or you are saying no use the contents
of another register to go into the memory based on the contents of; so, you are using a
register as a pointer or you are adding an offset to that pointer.

To the basic data transfer instruction, you can create more varieties by the help of this
concept called addressing modes. And because of which the total number of instructions that
are available in a given architecture microprocessor can increase or decrease. And
traditionally, the number of instructions that were available and now the number of

83
instructions means not just the basic operations but the variety is available with each basic
operation.

(Refer Slide Time: 12:26)

If you keep on adding more and more variety, it would be called it would be classified as a
complex instruction set computing architecture. Earlier architectures were of this category, of
this type CISC. And then people figured that large number of instructions do not necessarily
improve the performance of the processor.

It is the same thing as there may be thousands of words in the English language but most of
the time you only use a very small subset of those words to convey whatever you want to say
most of the time and that argument led to the development of a new architecture. And this
was called Reduced Instruction Set Architecture or Reduced Instruction Set Computing.

And in this architecture the number of varieties available for any given basic type of
instruction was severely curtailed. And it is not that processor designers can arbitrarily
choose to have more variety or less variety. It has to be supported by the architecture, the
hardware of the microprocessor, in terms of the available registers and the way memory is
accessed and so on. But, to put on record, this is another popular architecture.

The third architecture was when this Reduced Instruction Set Architecture came into being,
the designers of CISC type of processors started borrowing ideas from RISC architecture and
vice versa. RISC architecture developers started borrowing ideas from CISC architecture.
And that probably angered certain purists and they said, no, we do not want to increase the

84
number of instructions and they brought out a new architecture which is called MISC:
Minimal Instruction Set Computer.

Unfortunately the number of actual devices available in this family probably one or two only,
this idea died a quiet death and one largely only hears about RISC or CISC. But there is one
more architecture and that is called Very Large Instruction Word meaning that in a single
instruction word, you have several instructions so that it can improve performance by
parallelizing the execution. So, these are common instruction set architectures.

Having gone through this, it would be now imperative to see what is available in the market.
Since we are looking at microcontrollers, we must know what are commonly available
microcontrollers. And based on these previous knowledge we can see whether a particular
microcontroller is whether it is of CISC type or RISC type and so on so forth. So, I am going
to class list some of the microcontroller, available microcontrollers based on the number of
data bits.

(Refer Slide Time: 15:29)

So, this is a list for some popular 8-bit microcontrollers. One of the most popular and one of
the oldest microcontroller families is the 8051 from Intel. Although, currently Intel does not
manufacture any microcontrollers in this family. It has outsourced; it has licensed the
technology to other manufacturers. And more than 100 manufacturers worldwide
manufacture integrated circuits microcontrollers based on this architecture.

And there are more than 1000 types of microcontrollers in this family. It is of CISC nature.
Then we have a company called Microchip. It has a microcontroller family called PIC. That

85
is a RISC architecture. It is also one of the very popular microcontrollers. Then we have
Cypress Semiconductor. You may recall me talking about the system on-chip paradigm and
they produce a microcontroller family called PSoC.

This is our CISC architecture, programmable system on-chip. And then microchip which
acquired a company called Atmel which produced a microcontroller family called AVR
which has more than 200 chips in its portfolio. It is of a RISC architecture. And the very
popular Arduino platform uses AVR microcontrollers. So, these are top 8-bit microcontroller
devices.

(Refer Slide Time: 16:55)

From 8-bit, people would migrate perhaps to 16-bit devices and the available
microcontrollers are our very own Texas Instruments MSP430 which we are going to use in
this course. It is a 16-bit architecture. Then we have Microchip has a 16-bit family called
PIC24. It has ST10 which is a STMicroelectronics offering and NXP which was previously
Motorola and then Freescale has a HC12 and HC16 microcontrollers.

86
(Refer Slide Time: 17:29)

From 16, you could have 24-bit architectures. But there are not very many examples and
usually people go to 32-bit devices. And we have 16-bit or 32-bit ARM microcontrollers.
ARM is one of the largest microcontroller designers and they have 1000 of variants.
Incidentally, ARM does not manufacture the actual silicon products. It licenses the
technology to third-party vendors who then integrate their own ideas of peripherals and create
physical devices.

In fact, Texas Instruments make ARM varieties of microcontrollers called TIVA. Many other
companies do that. And we also have the Intel's x86 family and IBM's PowerPC. It is heavily
used in telecom applications and earlier Apple computers used to use PowerPC. But more
than 10-12 years ago, they switched over to the Intel family and then they became very-very
popular and successful. But these are the 32-bit, popular microcontroller architectures.

87
(Refer Slide Time: 18:38)

Having seen the available varieties in microcontrollers, it is now time to look at a modular
approach to designing an embedded system. This is an approach that we have developed here
at NSUT in the past few years. As the name suggests that it is possible to look at any
embedded system design in the by-way of few modules. So, let us look at this.

(Refer Slide Time: 19:07)

So, we have created what we call as a 6-box model for embedded system design. Any
embedded system application could be partitioned in 6 boxes. Each box has a certain
characteristic. Let us go through these boxes. You have an input block or input box which is
which consists of devices through which a user would interact with the, would provide inputs

88
to the embedded system. These are also devices through which the embedded system would
acquire information regarding the environment, maybe sensors and other devices.

The inputs provided by the input block are passed on to the microcontroller that is the
embedded computer block. Then we will consider what types of embedded computers? We
already seen how they are implemented. The embedded computer acquires the information
from the input block, processes this information and produces an output. Processes this
information by way of executing a program.

So, the embedded computer block has all the elements to execute that program meaning
various types of memory devices. And then produces an output which may be for the user
(humans) or it could be to actuate certain controls that are described in the output block. Most
of the embedded systems applications would require at least these 3 blocks and the power
supply block. Because without power supply, it is not possible to run any electronic circuit.

It may also certain embedded applications may require to communicate with the outside
world and so you have a communication block. And sometimes it may require to store data
locally, beyond the capacity of the microcontroller so you would have maybe a hard disk or a
serial storage device. It may also want to visualize that data in the form of connecting to a
host. And so, the sixth block is a host and storage block.

And all these individual blocks are connected tight to the microcontroller or with each other
using binding glue that I call as electronic glue. And these are basically electronic circuits
which are specific to a particular application. And so we have not classified it as a box but it
is dependent on a given application.

Now, what we are going to do is we are going to dive deep into each of these blocks and see
what are the available options? How do you when you have a particular requirement, what all
options you have?

89
(Refer Slide Time: 21:48)

So, the input block consists of could be of user inputs for the user to provide input to the
embedded system. And these are the various options: you may have a push button or toggle
switch which is on and off. You could have switch with multiple settings like you have on a
fan speed control: low, medium, high, and so on. These are called SPST or SPDT, or multi
pole multi throw switches.

You could have a matrix of switches. You could have a mechanism to interact with the
system using a capacitive touch like I am doing with my pen here. You could have a resistive
touch which used to be available on older mobile phones. You could also use a Reed switch
to interact with the system using a magnet. These are the various options of interacting with
the embedded system for the user.

Apart from that, you may want to record or you may want to capture sound. And for sound
you could use a microphone or an ultrasonic sensor to sense sound which is beyond the 20
kilohertz range. You may also want to sense the magnetic field in some certain applications
and the options are you could use the Hall Effect.

Yesterday, in the last, one of the previous lectures I showed you this levitating doll project. It
used a Hall Effect sensor. You could also use an inductor if the especially the magnetic field
is of a varying nature and inductor is a good sensor to sense the magnetic field. You could
also use a reed switch. It is a binary sensor meaning it will sense either the magnetic field is
present or it is absent. And you could also use a magnetometer.

90
You could, you may want to read the distance to certain object. So, for that you may use the
ultrasonic ranger, you could use infrared proximity sensors. You may want to read the
temperature of the environment and for that many-many options are available. You could use
a thermistor, you could use an RTD device, you could use a thermocouple or you could also
use a semiconductor sensor.

In fact, MSP430 microcontroller has on-chip semiconductor-based temperature sensor, so


that you could also sense the temperature of the chip. You may want to input information
regarding ambient light and for that you could use LDR. And as you know, an LDR is part of
our inventory. We could use a photodiode. It turns out that even LED which is otherwise an
output device that is with which you can generate light, a LED can also be used to sense light.

Then you may want to input strain and or force information and for that you have a strain
gauge or FSR that is force sensitive resistor. You could use a piezo-sensitive device, piezo
sensor measure strain and force. You may want to measure the relative position with respect
to certain object and for that you may use a shaft encoder which is usually used when you
own your modern instruments like an oscilloscope.

When you are changing the voltage setting or the time setting, the knob that you are moving
is actually connected to a shaft encoder. Or in your car stereo when you are changing the
stations with the help of a tuning knob, a varying knob, that knob is actually connected to a
shaft encoder. You may you could also use a gyroscope or you could use an opto-coupler.
You could use linear potentiometers.

Potentiometers which have knob where you move it up and down. And ofcourse, you could
use a GPS which is a Global Positioning System. You may want to input image of an input
and this image is basically light arranged in either an array or in a straight line. And for that
you can use a camera sensor or a linear CCD array. CCD stands for Charge Coupled Device.
It is a type of image sensor.

And most importantly, you may want to measure time and for that you could use some
internal mechanism to count time or you could use a specialized device called real time clock
for keeping track of time. These are all the; not all these is a big list of input devices that
would go into the input block.

91
(Refer Slide Time: 26:19)

Okay apart from the input block we have the output block and these are this is the block
through which the embedded system outputs information to the user or to the environment.
And you may want to create light or you may want to control light. For that you have an
LED, you may have a RGB LED, that is led with red, green and blue together. You may have
you may want to control a laser or you may want to control the infrared LED like you would
do in a TV remote.

You may want to provide visual information and for that you could use a 7-segment display
and we you know that we have a 7-segment display in our experiments inventory,
components inventory. You may also have alphanumeric display. You may use a LCD and
we have an LCD in our inventory. Or you could use graphics LCD, such as you have on
mobile phones or you may want to output information on a television.

You may want to generate sound. And for that you would use a speaker or a buzzer or ultra
sound generator so that it generates frequencies in the ultrasound domain. You may want to
control the temperature and for that you have largely two devices. One is a heater. Resistor is
a good way to generate heat or you could have a Peltier module. The advantage of a Peltier
module is that you can heat or cool the environment or at least one side of the surface of the
Peltier module.

Then you have, you may want to control the position and for that you would use various
types of motors such as a stepper motor, DC motor, a servo motor and so on. You could also

92
use a solenoid where you can move the contacts on and off. You may want to control the
flow of liquids and gases. And for that you would use a valve or a pump.

You may want to provide haptic feedback to the user. This haptic feedback happens on your
mobile phone whenever you input device, it vibrates a little bit. That is a haptic feedback.
And for that, you use a vibration device which consists of a motor and asymmetric load. And
you may want to output information in a printed form for which you may have a thermal
printer or a dot matrix printer. These are some of the output block components.

(Refer Slide Time: 28:38)

Then you have the power supply block. For power supply, the first important thing to
consider is what is the actual source of energy. Are you getting it through the wall outlet, 220
volt or 110 volts as the case maybe. The energy from the source of energy may be sporadic. It
may not be stable and so you may want to, you have to consider a regulator. Regulators are of
two types: linear or switching regulators.

Then, if you are going to use a switching regulator, what type of regulator? There are 3 broad
types called buck, boost and buck-boost Are you going to use, are you going to need batteries
in your application? Because the input sources sporadic and you want to perform your system
wants to operate during those times where the input energy may not be available. And
therefore, you create a battery backup.

Or are you going to use a super capacitor to store energy during times when the main source
of energy is not available? All these considerations go into the design of the power supply
block.

93
(Refer Slide Time: 29:45)

Then, you want to consider various ways of communicating with the outside world. Broadly
these are of 2 types: inter-device and intra-device. Inter-device means within the device if
certain components want to communicate with each other for sharing information, what are
the various protocols available? Or intra-device, oh that is the inter-device- between two
devices.

And intra-device means communication within a given like a television within the given
system would be classified as intra-device communication protocols. And for intra-device,
we have a UART, SPI and I squared C bus. For inter-device, we have several protocols such
as UART, local internet interconnect network, we have control area network, WIFI, Ethernet,
USB and Bluetooth. These are some of the inter-device communication protocols.

94
(Refer Slide Time: 30:39)

Then we have the host and storage block where we may have device to store information and
you could use a serial E squared PROM or you could use SD card.

(Refer Slide Time: 30:50)

Then we have the electronic glue which connects to all these devices. And what are examples
of electronic glue? You may require amplifiers you may require filters as the case may be or
for the output you may require to switch high amounts of large amount of voltages or
currents. For that we have 3 types of drivers. One is called low side driver, high side driver
and a both sides switching device which we will consider in detail in subsequent lectures.

95
(Refer Slide Time: 31:18)

So, here we are at the end of this current lecture where we have seen the various parameters
in choosing the microcontroller appropriate for a given application through time to market
and cost considerations. Then we have seen the classification of microcontrollers based on
the way it communicates with talks to memory, the way the number of bits are available and
the instruction set architecture.

And we have introduced to the idea of visualizing an embedded system through 6 blocks and
we will go in further detail into each of these blocks in subsequent lectures. I hope you
enjoyed this lecture as much as I did in presenting it to you. I will see you very soon. Thank
you very much.

96
Introduction to Embedded System Design
Professor Dhananjay V. Gadre
Netaji Subhas University of Technology, New Delhi
Lecture 5
Salient Features of Modern Microcontrollers
Hello, welcome to this new session on introduction to Embedded System Design. In the last
sessions, we discussed various metrics for selecting the right microcontroller for our embedded
applications. Then we looked at six box models with which to visualize various elements that
make up an embedded system application. And then we are now here trying to look at more
details by which we select a microcontroller for a given application.

So, let us start at, so I am going to discuss what are the salient features of contemporary
microcontrollers. What do we want from them? And based on these needs, how to select an
appropriate microcontroller while we may be using Texas Instruments, MSP430 microcontroller
for our course. As a professional, one uses very different metrics for using a given
microcontroller. Yes, awareness of a microcontroller is often a significant factor, but there are
other professional and economic factors for selecting the right microcontroller.

(Refer Slide Time: 01:49)

So, in this slide, we are going to look at what are the functions that we as a designer, you as a
designer would expect from a microcontroller because the microcontroller is a central piece in
this six box model, six block model or six box model it does not mean anything different.

97
It interacts with the inputs, it interacts with the it provides outputs and so on. So, it has to
perform all those functions. So, the first very important function that embedded microcontroller
must perform is that it should be able to read digital inputs. The reason is that a microcontroller
is a digital integrated circuit. It may also have capabilities of reading analog voltages and so on.

We come to that shortly, but primarily microcontroller is a logic device and therefore it is very
natural for a microcontroller to be able to read discrete digital values. These values, even if they
are discrete, they must conform to certain voltage levels. What we call as low voltage and high
voltage or oftentimes represented as 0 and 1. So, the microcontroller should be able to read
digital inputs.

Then it should be able to once it reads these inputs, it might be processing those inputs and
would provide an output. And the natural way for a logic device such as a microcontroller to
provide an output would be in a digital form, which means it can produce a logic 1 or a logic 0.
Let me show you what are the kind of outputs that may be expected from a microcontroller of the
digital input and digital output nature.

(Refer Slide Time: 03:50)

So, if this is my microcontroller, the most common method would be to be able to naturally read
inputs which are digital in nature, which are discrete in nature, such as a switch. A switch does
not produce a 0 and 1 voltage. Instead, it has two states which we call as open and close, so we

98
will see in the subsequent lecture in a subsequent session how the two states of a switch, open
and close, are transformed to 0 and 1.

Similarly. It must produce digital outputs 0 and 1. And the common methods of using these
outputs would be to connect to a LED, say in this fashion or to control a relay. Relay has this
symbol. And so if it is possible to connect this relay directly to the microcontroller, you would
do that. Most often that is not the case. And so some intermediate components, what we have
defined as electronic glue would be required to connect such a relay to a microcontroller.

But yes, a relay has discrete states either the relay is on or the relay is off, and therefore it is very
natural for device like a microcontroller to control a relay.

(Refer Slide Time: 05:40)

Let us go back to the expected functions out of a microcontroller. Apart from reading digital
inputs and outputs, it must be able to measure time or keep a record of time. And why is that?
Because the microcontroller part of the embedded system is interacting with the external world.
The world is continuously changing, inputs are changing, and therefore the microcontroller must
be able to read these inputs, process them in a timely fashion and provide timely outputs, and
therefore it must be able to maintain record of time. There are many examples of where this
might be used maybe you want to plot the variation of temperature in the room as a function of
time. Therefore, you may very well require to measure time.

99
We will see more examples. It may also be expected to measure time between two events. For
example, suppose I am in this room such as this and I open the door and I want to know what is
the time between arrivals of two people that would be classified as time between two events,
arrival of a person could be classified as an event. I can put a sensor on the gate of this door
which provides me a pulse, which provides a logic value, which I can read from the digital
inputs.

And after the detection of that signal that a person has entered, I could start counting time till
such time that another person enters. So, I would be able to measure time between these two
events, events relating to entry of two people in this room. It may also be required to measure
duration of a complete event, not just duration between two events, but duration of an entire
event.

And again, we can define what we mean by an event, whether the act of a individual passing
through the gate is an event or I am holding a program here and the event would be defined as
the time and the first person enters the room till the last person exits the room maybe I can define
that as a event, what the definition I want to have depends on the application what do you want
to define an event and here also you may be able to maybe required to measure the time between
events or duration of an event.

I already discussed time between two events. Then a microcontroller would be expected to
generate random numbers. We would see applications in subsequent lectures that where do we
need random numbers? What are the various methods of generating random numbers?

100
(Refer Slide Time: 08:26)

The next function that I may I would expect out of a microcontroller is to respond to what I call
as asynchronous events, meaning events that happen without telling, without being synchronized
with the clock of the microcontroller. So, all human inputs or all environmental inputs in a way
are asynchronous events. And a microcontroller is expected to take cognizance of these events
and respond appropriately. And for that, it uses a concept called interrupts. We will see how
microcontrollers are able to process such events through the concept of interrupts. Then a
microcontroller would be expected to measure voltage or current or resistance.

If it is able to measure voltage by itself and if not, we must add some feature by which we can
measure voltage. Then we can easily be able to measure current or resistance and for that matter
any other parameter. Let me explain how.

101
(Refer Slide Time: 09:38)

So, let us say that I want I have a microcontroller which is able to read voltage and so that will be
called an ADC input where it has a range of say, 0 to Vmax, that is any voltage, any voltage
between 0 volts and Vmax volts can be applied to this pin. And now instead of measuring
voltage, I want to measure current. Now, current obviously would be passing through some
circuit maybe I want to measure this current and I would use the same mechanism that a
multimeter and ammeter for example uses to measure current and what I would do is I will
introduce a very, very small resistance R very small, so I designate it as R low and I would
connect maybe I would need this voltage that is generated is so small that I do not get enough
resolution for my ADC.

So, I put it through an amplifier. And say this resistance is grounded and so the current that is
passing is also passing through this and then using some gain I can connect it to the ADC input.
Now, since I know the value of this low value resistance. Then if I know the voltage, I am able to
measure the voltage, if I can divide, if I if my microcontroller can divide that measured voltage
by the value of the resistance, my system would be able to measure current.

In case the resistance is not grounded as I am, I have shown, because measuring the current in
which it is going into the ground at the point where it just entered the ground is very easy to use.
But what if my I want to measure current, which is floating, meaning I have I put a resistance,

102
but none of the ends of these resistors, a resistor is grounded, which means I would need to
connect. It still has to be a very low value R low.

But now instead of a non-inverting amplifier, as I have shown in this case, I would need to use a
differential amplifier, which takes the difference between the two terminals here. And then
produces a voltage, so I will connect it to another channel. And so whatever current is going
through this, this node need not be grounded but the current flowing through this low resistance
value can be converted through a differential amplifier.

This is not the correct circuit for a differential amplifier will come to that. But here I am showing
that we will be using a differential amplifier, which takes the difference of the voltage at this
point and at this point A B it takes the voltage difference of Va minus Vb that is voltage across R
low and then it converts it into a voltage and the DC can read it. And then when we divide that
voltage by the value of this resistance, I get the amount of current that is flowing through this
resistor. The third expectation would might be to be able to read resistance. Now, there are,
again, many methods of measuring the resistance. One is I can create a potential divider.

(Refer Slide Time: 13:25)

So, say this is R reference, I know the value I connected to a reference voltage Vref. And then I
connect an unknown resistance and I ground it so this is R unknown. And then I connect it to my
microcontroller the same ADC input. Now, since the system knows the value of Vref, the system

103
knows the value of reference, therefore the voltage that is produced at this point is equal to R
unknown divided by R unknown plus Rref into Eref. This is the VADC the voltage at the ADC
input is this volt. Here I know the value of this. I do not know these values. And from this
equation, I can calculate the value of the unknown resistance.

So, I once I have the ability to measure DC voltage then I can measure any other parameters such
as current or resistance and for that matter any other physical parameter also, as long as I have a
appropriate mechanism to convert that parameter into voltage.

(Refer Slide Time: 15:11)

Similarly, beyond being able to measure voltage, current and resistance, a microcontroller would
be expected to create or generate varying voltages, not just discrete voltages that discrete voltage
is also varying voltages or digital output is a varying voltage 0 and 1 is varying. But it is not
continuously varying. I may want to create voltage which is continuously varying and a
microcontroller can do that in two ways. One, it could have a device such as an ADC for reading
analog voltage. It can have a device called a DAC, a digital to analog converter in most cases, in
many cases, in lot of cases microcontroller does not have an explicit digital to analog converter.

But there are other methods of converting digital voltages or digital numbers into analog voltages
or current and then so on, using a method called pulse width modulation. And why would I need
to do that? Let me take an example that we considered in a previous lecture that is the speed of a

104
DC motor in the Gillette razor that we considered. The speed of a DC motor depends on the
applied voltage.

The voltage that is applied to the terminals of a DC motor determines the speed. If I want to
increase the speed of the DC motor, I would increase the voltage. If I want to reduce it, I will
have to reduce the voltage and therefore in such application I may require to be able to produce
analog voltages and therefore a microcontroller must be able to do that. Later in this lecture, we
will see how a microcontroller is able to achieve that requirement.

Then another application that another function that a microcontroller would be expected to
perform is to be able to store data. Now, while the program executes a microcontroller, uses
RAM, or it uses the internal registers to store data temporarily. But sometimes you may want to
store data in a more permanent medium so that you can inspect it later. You can transport it when
you do not have the mechanism or a communication channel to transport it right away. So, you
store it.

And so you may require large amounts of capacity to store that data more than the internal
registers, more than the RAM that your system may have. And so this function will be performed
by connecting to external devices which have larger, higher storage, such as a hard disk drive or
serial E square PROM devices or serial flash memories. Another function that is expected out of
a microcontroller is to be able to visualize data.

Imagine that you want to plot how the temperature in this room is varying as a function of time
over 24 hours or continuously. What would you want to do? You would want to have a display
which can create a graph and then fulfill this requirement. Another function that is expected is to
be able to print data, print data in a portable fashion or print data whenever you want it.

An example is these days in India, there are a lot of these parking lots and the parking lot
attendant is carrying a portable device. As you enter the parking lot, they will enter the car
registration number and quickly punch a button and a printout is produced. So, you may want
your device to be able to print information. And last but not the least, an embedded
microcontroller would be expected to control motion.

105
As we saw, whether it is the speed of a DC motor or the position of a certain device, maybe you
are designing a printer then the print head needs to be located appropriately. And so we are
talking of being able to control motion. So, these are all the common functions that one expects
that microcontroller should be able to perform. Now, let us see how it does that or what all
features are available on microcontrollers to be able to satisfy these requirements.

(Refer Slide Time: 19:43)

Now, before that, let us see what does our contemporary microcontrollers have to offer. This is
not related to a single microcontroller, but in general, a survey of the features that modern
contemporary microcontrollers offer. So, all microcontrollers are as we have seen nothing but a
complete computer on a single chip and therefore the CPU part of the microcontroller would be
able to handle certain amount of data bits at a time and that is the bit handling capacity of that
device and it can range from 4 bits or 8 bits or 16 up to 64 maybe even more.

The instruction set architecture of such microcontrollers could be of RISC or could be of CISC
types. Now, we have observed over time that there are no very strict boundaries between RISC
and CISC. Good ideas from one architecture are often borrowed and implemented in another
architecture. We see traditional RISC or manufacturer defined architecture if the manufacturer
says there is a RISC architecture you might find certain features which actually belong to the
CISC category and vice versa.

106
But yes, these are two dominant architecture that are available and then from a memory access
point of view, we have two architecture that are available von Newman or Harvard. And
therefore, when you look at the microcontroller, essentially it would it could be that it is a 16 bit
microcontroller, which is of a RISC nature and it has a von Neumann or it has a Harvard method
of connecting to the memory that would be the complete description of the microcontroller in
those aspects.

Apart from that, it may be able to connect. It has on chip memory. The question is how many
types of memory it has usually it would require two types of memories. One is permanent to
store the program and the other being volatile to store data or to store pass parameters to a
subroutine or to store the return address when you are calling a subroutine.

We will go get into the details of all these things that I am mentioning here once we start talking
about the actual microcontroller. But these are the requirements that these memory devices have
to perform and therefore you would require a permanent memory for the E square PROM or it is
more common these days to find such permanent memory of the type of flash and for volatile
memory, it is usually SRAM for the data storage.

Microcontrollers offer pins, general purpose pins, which can be programmed to behave as a
digital inputs or as digital outputs, they often have several communication interfaces what we
mentioned intra devices or inter device. It may have UART it may have LIN it may have CAN, it
may even have USB and we will see our microcontroller that we are going to use. What all does
it have.

To be able to program download the program from your development platform into the memory
there would be pins, which support these days what is called as In system programming and
through some pins you may also be able to debug the program after you have downloaded it into
the memory of the microcontroller in case your application is not working in the way that you
expect it to.

And for that it uses a SPI bus as well as another interface specialized for debugging called JTAG.
Our MSP430 microcontroller has another format called SWD which is Serial Wire Debug. And
so these are all the programming and debugging options that you would find on these

107
microcontrollers. Then it would have peripherals, peripherals with which you can measure time,
you can count events, you can generate pulse width modulation signals.

And I want to add here that pulse width modulation signals are primarily used by
microcontrollers to convert digital numbers into analog voltages and we will see how then it
most modern microcontroller often have a specialized timer. It has a dedicated function and it is
called a watchdog timer. And just like a watch dog at home, when there is a burglary or when
there is an unusual event happening at home, the dog is expected to bark and alert the owner, the
residence of the house.

In a similar fashion the watchdog timer, if it appears to the watchdog timer that things are not
going well, things are not in the way not going in the way they are expected to on the embedded
system. It will do something to alert the system. And usually it is in the form of resetting the
microcontroller. To do that, it has an independent oscillator so that one if one enters a low power
mode and in low power mode usually you fiddle with the value of this clock signal.

You do not want to affect the operation of the or the function of the watchdog timer. So, usually
these watchdog timers are equipped with independent oscillators. They also have analog to
digital converters and in some cases, they may also have digital to analog converters and all
these functions, all these functions that we have listed here are available in packages which vary
between 6 pins to 200 pins.

(Refer Slide Time: 25:42)

108
Here again, I am repeating the same picture I showed in the earlier lecture that we have a great
diversity of size, a microcontroller which is smaller than a grain of rice in fact it is comparable to
the rest of the components that you can see on my thumb and in the middle we have one of the
larger microcontrollers. This is a cortex M4 from Texas Instruments. And on the extreme right is
another arm cortex M3 microcontroller from ST microelectronics.

These are the kind of varieties that are available. Obviously, the one with bigger package would
be more expensive, would have more features and would be used in such applications that have
higher demands. Then, for example, the one on the left, which is a 6 pin microcontroller. Okay,
now we are here looking at what are the features of modern microcontrollers.

Previously we have just we have listed what we expect these microcontrollers, what functions we
expect these microcontrollers to perform to be able to perform those functions, what features it
has. I have called out information from contemporary microcontrollers and sort of made a list of
good features, desirable features of all these microcontrollers put together.

Obviously, when you are going to consider a particular microcontroller for your application, you
have to check the datasheet whether the features that you are looking for are available in those
microcontrollers or not. But this is the current state of the art. And we as a designer, we as
practitioners of this engineering realm should be aware of the possibilities.

(Refer Slide Time: 27:32)

109
The first important feature that modern microcontrollers offer are programmable pins. These pins
can be programmed to either behave as input or output. Now, why is it important? Is that when
we are talking of a microcontroller, we are talking of a single integrated circuit and a single
integrated circuit, whether it is small or big, would have a limited number of fixed number of
pins. Let us say we have a 20 pin IC.

Now, any 20 minutes or any IC for that matter, electronic circuit would require power supply,
pins and so we would have to discount 2 pins for power supply application that would leave us
with 18 pins. Now, you could use all this if this 20 pin device that I am talking of here is a
microcontroller. You are left with 18 pins and you could decide that, oh let us do a equitable
partition. Let us say 9 of the pins are digital inputs and 9 of the pins are digital output.

So obviously, any application which requires less than 9 inputs or less than 9 outputs could
possibly utilize this IC. What if I still need total number of input pins and output pins to be 12,
but I want 10 input and 2 outputs or 10 outputs and 2 inputs. Now, in principle, these 18 pins or
20 pins IC is quite capable of satisfying the requirement. But if the inputs and outputs are equally
partitioned and fixed, then this specific application where I need 10 input pins and two output
pins will not be able to use such a microcontroller.

Thankfully, that is not the case that all the pins, general-purpose pins that are available apart
from the specialized function pins such as power supply and there maybe other specialized
function pins, rest of the pins are programmable, and by writing an appropriate program, the user

110
can decide which of the pins will function as inputs and which of the pins will function as
outputs.

So, we have seen how the pins on the microcontroller are programmable and you can program
them to be of input or output types. Now, let us see the next point. And it says that the output
pins, if you define a pin to be of output type, then it has the capability to provide about 30 to 40
milliamperes of source or sink current. Now, what is the meaning of source and sink current let
us look at a sketch.

111
(Refer Slide Time: 30:20)

Now, when I have a microcontroller, I can connect LEDs which we saw earlier. I can connect
LEDs in two ways I can connect LEDs in this fashion. In this case, the LED this is a pin let us
say P1. This LED will light when the P1 voltage, even logic is 1. So, it is going to LED lights up
when P1 is equal to logic 1.

When the logic voltage level on P1 is 1, the LED lights up, the question is how much current
flows through the LED and it will depend on the resistor R and the nature of this LED. The
voltage across the LED depends on the color of the LED and therefore you need to find out from
the datasheet what is the voltage drop across that LED.

And you can involve these numbers parameters in an equation and estimate the amount of
current and the current will be the voltage output of at P1, which would be called as VOH that is
the voltage when the output is high minus the voltage across the LED divided by the resistance
R. So, if this current that you want pass through the LED is less than 30 milli ampere that means
you can easily connect this resistor and LED combination to the pin without needing any current
amplifiers.

What are current amplifiers, if you need more than this current will see subsequently. But right
now, suffice it to say that this current which goes through the LED, goes out of the pin is called
source current. So, in this case, it is a source current. And modern microcontrollers offer up to 30

112
or 40 milli amperes of source current. There is another way to connect this LED and this is the
method, let us say I have another PIN P2.

I connect the resistor exactly like that, but now reverse the LED instead of the anode of the LED
connected to this register here, I connect the cathode. And on the anode side I connect it to VCC
which incidentally is also the VCC and there is a ground also of this microcontroller. Now, the
first thing is a, that the LED lights up when P2 is equal to 0, this is called active low. In this first
case, the LED lights when P1 is high is active high, that is that activity happens when the signal
is logic 1 logic high, here it is active low.

The current now is I, is flowing into the pin. I have this resistor the current is flowing into this
pin, this current is called sink current because it is sinking into the microcontroller pin and the
amount of current is now Vcc minus V LED minus VOL that is the voltage at pin 2 when the
logic is 0, when it is low logic, it does not mean 0 volts. It may be some nominal voltage. You
have to refer to the datasheet of the microcontroller to know what is the value of VOL.

This is the voltage across the resistor and therefore divided by the value of the resistor would be
the current that flows through this LED. The intensity of light that is coming out of the LED is
proportional to the current flowing through the LED. And so if the intense if the intensity that
you are going to get for this current, which if is less than 30 or 40 milli amperes, you would be
able to connect it directly to the microcontroller.

In case you want more intensity, you want higher intensity, and you have to have much more
than 40 milli amperes of current. We will have to resort to some other circuit configuration. But
30-40 milli amperes is a significant amount of current with which to control small LEDs. And so
they do not need any other driver circuit to handle them. Also, you can probably turn on small
relays with this amount of current.

And so having a capability to drive 30-40 milli amperes of source or sink current is a good
feature that these modern microcontrollers offer. In case you choose to have these pin, these pins
as input pins, then sometimes we need these pins to offer a feature called a pull up resistor. Let
me explain.

113
(Refer Slide Time: 36:16)

So, if I have a microcontroller and I want to connect a switch, as I mentioned earlier, a switch
does not produce any voltage. It has two states and the two states of the switch are open and
close. And these two states have to be then translated to logic levels. And 1 way to do that is to
connect a resistor. And this point, this junction of the resistor and the switch I can connect it to a
Din pin of the microcontroller. Now, when the switch is not pressed because of this resistor R
and this resistor is called pull up resistor, it will be able to provide logic 1 to the input pin.

When the switch is pressed, it will ground the, this terminal A and therefore the logic voltage
applied to the Din pin will be 0 and so the open and close state of a switch have been converted
to logic 1 and logic 0 with the help of this resistor. This is called a pull up resistor. If the value of
resistor is small, it is called a strong pull up. If the value of the resistor is large, that is the amount
of current going through it is small, it is called a weak pull up.

Modern microcontrollers often times give you options to 1) have a pull up 2) select the amount
of select the nature of the pull up to be either of strong nature or weak nature. And in some cases,
if you do not want to have the pull up, it would function with what is called tri state capability.
Also, we in the previous slide, we saw that a microcontroller is supposed to measure time,
measure analog voltages, maybe even produce analog voltages, it is expected to measure time
between events.

114
(Refer Slide Time: 38:18)

How is it possible to fit all these functions on a limited number of pins of a microcontroller other
than to share the functionality of these things, and that is the meaning of fourth point, that each
Pin offers multiple functions. One of the important functions is that the Pin is digital input or
output fine, but besides that it will also offer additional functionalities and the user must write an
appropriate program to select which of these offered functions on a given pin would they like to
use in that application.

(Refer Slide Time: 39:02)

115
Let us see what is the meaning of this inner pin diagram from 1 of the MSP430 microcontrollers
here. As you see, this is a 28 PIN device, pin number 1 and 28 are VCC pins. They do not have
any other function and rightly so. They are used to connect power supply voltages to this
microcontroller. Other than that, almost every pin, if I look at PIN number 14, it has two
functions listed P3.3 slash PA 1.2.

These are two functions let me let us look at another pin, for example this is pin number 26 is X
out slash P2.7. Now, in case you want to use PIN 26 for X out, then you will have to forego the
other function that is listed there such as which is P2.7 that is port 2 pin number seven. And one
hopes that you could use other pins for that function, which P2.7 was otherwise going to provide
you.

Because you want to use pin number 26 for X out functions. This is the way multiple functions
can be shared on a small on a chip with limited number of pins, and this is the meaning of each
Pin offers multiple functions.

(Refer Slide Time: 40:31)

Let us take another example. This is from one of the AVR microcontrollers. In fact, this is the
microcontroller that is used in Arduino platform. And you see here also in the middle, we have
four pins, pin number 7, 8, 21 and 22, even 20, which are of single functions. And these are
related to the power supply as well as the reference voltage.

116
Other than that, almost every pin has two or three functions. For example, PIN number 1 is PC
int14 that means it is pin change interrupt number 14. It is also a reset pin and it is also Port C bit
six. And you can see that let us take another example PIN number 23, it is PC0 that is, it can be
programmed as port C bit 0 or it is ADC channel 0 or it is pin change interrupt number 18.

So, this is the meaning of fitting multiple functions on each pin and leaving it to the judicial
judiciousness and the knowledge of the user to decide which exact function they would like to
select of all the multiple functions that a particular PIN offers. We will finish this lecture here
and we will continue with the rest of the important features that modern microcontrollers offer.
Thank you.

117
 
Introduction to Embedded System Design
Dhananjay V. Gadre
Netaji Subhas University of Technology, New Delhi
Lecture 6
Salient Feature of Modern Microcontrollers Continued
Hello, welcome back to the next part of the session. In the last session we discussed how modern
microcontrollers offer multiple functions on any given pin. And this allows us to fit more
functions within the limited number of pins available on a microcontroller. And it becomes the
responsibility of the programmer that is the system designer to ensure that writing an appropriate
program to select whatever functions they need for a given application are appropriately selected.
Now, it may also happen that you need 2 functions and unfortunately on a given microcontroller,
both those functions are mapped to the same pin.

(Refer Slide Time: 01:10)

I can take an example, let us look at this diagram here, and imagine that you do want to use pin
number 23 because it offers you ADC channel 0, it also offers you interrupt on this pin called
P​CINT8, and you want both these functions at the same time. Now, the way they are mapped on
a single pin, it will not be possible.

118
(Refer Slide Time: 01:50)

And therefore, you may either have to compromise by finding some other pin which has similar
functionality, or if you were to use more recent more, you know, advanced microcontrollers you
would find that in such microcontrollers given function may be available not only on 1 pin it
may be available on multiple pins and so, you can judiciously use a function on a different pin so
that you can continue to use the other function on that pin that you wanted to use. And so, this
point and I will illustrate it by looking at the datasheet of such a microcontroller.

(Refer Slide Time: 02:25)

119
This is the datasheet that I have for you to illustrate this point of how multiple or how functions
could be available on multiple pins. Here, if you look at this pin, this function this is I square C
module and this is the clock for the I square C module. It is available on 2 pins, pin number 34
and pin number 74 also.

Now, if this pin happens to if on pin 34 happens to have another function you can forego that
function and instead use pin number 34 to provide I square C clock, which in the earlier case
where a given pin would have 2 or 3 functions and if those functions were not available on other
pins, you would be stuck. And so, this is an important point which you could which you may
consider while selecting an appropriate microcontroller.

(Refer Slide Time: 03:25)

Then you need a microcontroller to store your program. So, what is the kind of memories is
available, so, it turns out that program memory of the in the range of 1 kilobyte to a few
megabytes are available on contemporary microcontrollers. Obviously, you will choose a
microcontroller with less amount of memory. When your application is small. It would also
reduce the cost of your application cost of the microcontroller. And in case you need more
memory you would choose an appropriately large amount of memory on a microcontroller that
you want to consider.

120
(Refer Slide Time: 04:30)

There is another feature that these have and this is called, what is the meaning of lock? Now, let
me illustrate this point, especially in the context of the 3 methods of implementing a given
application, 3 methods of implementing the embedded computer. And you would remember, you
would recall that the first method was the General Purpose Approach. The second was the
Application Specific Processor, General Purpose Processor Approach.

Now, in the case of General Purpose Processor, you would have the microprocessor here and you
would connect it to a ROM of appropriate variety, maybe E square PROM and you would have
RAM. Now, this ROM device consists your program which is the intellectual property of your
product. Now, a competitor may find it very convenient to buy your product, remove this ROM
from the circuit put it into a device that is commonly called EEPROM programmers.

They are also capable of reading the contents of EEPROM and they can replicate your system by
copying the contents of your program. So, if your product is implemented using the General
Purpose Processor Approach, it has the potential of being duplicated very easy.

121
(Refer Slide Time: 06:10)

And therefore, a good better method is to use these microcontrollers with integrated program
memories, specially which have a lock function, you can invoke this lock once your program
development is complete, you can secure the contents of these memories by selecting the lock
feature.

And thereafter, nobody will be able to read the contents of this memory by connecting it to the
programming pins. And this is a very important feature to consider, especially when you are
making a product. Then, these microcontrollers have SRAM which is used as data memory. And
the value of these the amount of SRAM available on these microcontrollers ranges from
anywhere from 0 kilobytes. That means no memory at all to 10s of kilobytes.

122
(Refer Slide Time: 07:15)

Now, there is a important question that comes to our mind, that if the amount of memory
available on a microcontroller, data memory that is SRAM on the microcontroller is 0, is 0. That
is no memory. How are we going to store our variables? 1, because the data memory is used for
several purposes, 1 for storing variables, 2 for passing, passing parameters from the main
program to the subroutine, and very importantly, to store return address, what is commonly
called as a stack.

On the stack, you would store the return address of the program from which you would call a
subroutine. So, before going on to the subroutine you would store that address to which you have

123
to come back after the subroutine has been executed. And typically you would use data memory
to store that. Now, the big question in front of us is, if we have selected a microcontroller in
which there is no RAM, how are we going to perform these 3 functions?

And the answer is very simple. Typically, such microcontrollers which do not offer any RAM
would usually be of the RISC category, RISC architecture and in RISC architecture, there is
usually large number of internal registers, and therefore, you could use these registers for storing
your variables. And you could use the same registers for passing the parameter to a subroutine.
Of course, if your application is large that you cannot do with the number of registers available.

Clearly this is not an appropriate microcontroller for this application, you must find a
microcontroller which has some or suitable amount of SRAM available, but for very small
applications it is possible that you may get away without using the, without using any RAM, It
still poses how do you store the return address? In such cases where the microcontroller does not
have any SRAM instead of using RAM for the purpose of stack, such microcontroller offer what
is called as hardware stack.

What is the hardware stack? Meaning there is a dedicated storage memory specified for the
purpose of storing return addresses. Now, because if you have the regular microcontroller with
some amount of RAM, the entire RAM could be used for storing return addresses when does the
size of the stack grow? When you call a subroutine from within a sub routine from within a sub
routine what is called as nested sub routines, when you have too many nested sub routines, they
would increase the size of the stack as you return from sub routine, it would vacate the stack and
therefore, the stack would stack size would reduce.

In the case of hardware stack, the storage is limited usually 3 or 5 return addresses and therefore
you cannot have too many nested sub routines in such microcontrollers which do not have RAM
and instead there is a dedicated hardware stack. In such applications, in such microcontrollers,
you cannot involve too many you cannot write too many nested subroutines. So, this is a
compromise that you would have to do.

And the compromise is so that you can continue to utilize this inexpensive microcontroller for
some cheap applications. But this is an important feature to keep in mind. And that is the
meaning of SRAM with 0 amounts of memory. So, we have considered the availability of

124
function on multiple pins, we have considered how much flash memory may be available in
various microcontrollers.

We have considered how SRAM, the amount of SRAM available now let us come to another
point and that is apart from flash memory, and SRAM. Another type of memory is usually
available on microcontrollers and that is the E square PROM, E square PROM stands for
Electrically Erasable Programmable Read Only Memory and I use a term which I have coined, I
call it semi constants and the amount of E square PROM available could be anywhere from 0
kilobytes which means no E square PROM to a few kilobytes.

What is semi constant? You may not have normally heard this term, I specifically sort of created
it to indicate constant a value which is constant most of the time, but once in a while, you may
want to change it.

(Refer Slide Time: 12:55)

125
Can I give an example most certainly, imagine that you are a manufacturer of bicycles and
modern bicycles? People like to have a computer on those bicycles, which are called bicycle
computer. What does a bicycle computer do? Usually it will tell you the distance traveled the
acceleration, the amount of time you took for a given journey.

Now, how would it, how would it measure all these parameters on the wheel of the bicycle, these
are the axle and these are the spokes. And then from this you have probably the fork, which is
holding the wheel at the center. On the fork on the on the spokes of the bicycle, you attach a
small magnet and on the fork, you attach a Hall Effect sensor.

When the wheel rotates, this magnet passes in the vicinity of the Hall Effect sensor and the Hall
Effect sensor indicates that by maybe a pulse, and so as the wheel rotates, you will keep on
getting pulses the time between 2 pulses is the time that the bicycle took for 1 complete rotation
of the wheel. And therefore, if I know this time, I also know that during this time I have traveled
the bicycle has traveled 2 pi r, where r is the radius of the bicycle, I have traveled this much
distance.

And so if I know the time and I know the distance d is equal to 2 pi r, if I divide it by time I get
speed, and so on, and from that, I can calculate acceleration and so on. Now, if a man is typically
a manufacturer of bicycles does not manufacture 1 size of bicycles, they manufacture several
sizes, and the sizes are classified in terms of the wheel radius. And so would it mean that this
manufacturer if he is making if they are making 10 different radius bicycles, that they would

126
have to stop 10 different bicycle computers, that would be very impractical and it would lead to
needless stocking of inventory.

What we should have is a mechanism so that the end user or maybe the dealer be just before
making the sale of the bicycle, adjust the radius in the bicycle computer to reflect the radius of
the bicycle and thereafter, when the user uses that computer on that particular bicycle, it
computes the distance and velocities appropriately. Now, the problem is where should the value
of the radius be stored?

If the radius is told on the flash memory, that is a program memory, it cannot be altered, if it is
stored in the RAM, then every time this bicycle computer is switched off, it would be lost and
that is where. So, I call this radius the value of the radius as a semi constant, most of the time it
remains constant. But once in a while it may change in the case of this bicycle computer, if this
computer is removed from this bicycle and has to be fitted on a bicycle with different radius,
then this radius has to be changed.

Otherwise it would remain constant for the rest of the time that it is used on that bicycle. So, this
is a semi constant. And where would you store it?

(Refer Slide Time: 16:21)

This is where we go back to our slide and say, the place we would store it is an E square PROM,
because E square PROM is runtime, you can modify the contents of E square PROM at runtime,

127
meaning as the application is running, you can change the value of the value stored in the E
square PROM.

So, in our application, the value of the radius could be stored on an E square PROM. Through
the menu, the user can select that they want to change the value of the radius. Maybe on their
bicycle computer, there is an up and down switch, and you can adjust the value reflected on the
display to reflect the correct radius of the bicycle.

And then you press enter, it will update the value of the radius stored in the E square PROM and
thereafter when you use the bicycle computer it would show the correct it will use the correct
radius to compute the distance and velocity and so on and so forth. So, this is the meaning and
function of E square PROM on modern microcontrollers. Let us see another the next slide.

(Refer Slide Time: 17:27)

Now, on modern microcontrollers, you do not have to worry about the limited number of pins
with the interrupt capability because now most of these microcontrollers offer almost all the pins
with a feature called interrupt on pin change.

128
(Refer Slide Time: 17:48)

And I could show you the diagram of a microcontroller here. The pin diagram here if you see
PC​INT is actually pin change interrupt. That is almost every pin has an additional feature called
pin change interrupt and therefore You could use these to take care of handling asynchronous
events, if there are several asynchronous events, you could use such a microcontroller and such a
feature on these microcontrollers. Now you need a clock to operate a microcontroller.

And the reason is that a microcontroller as an example of a logic circuit is of the type what we
call as synchronous and it has a sequential synchronous. So, for that you need a clock signal. So,
you have to derive the clock signal in a signal in some way. one of the methods is that you would

129
use an internal source of clock internal oscillator and you connect an external component to
determine the frequency of that clock.

That would increase the cost because that external component would take up 2 pins, maybe 3
pins, maybe 1 pin and it would be an additional cost. If you want to keep the cost down you
would like the microcontroller to be able to generate a clock signal internally and such a feature
is called internal and external clock sources. And usually the very convenient way of generating
internal clock signal is by way of an RC oscillator you can create RC oscillator I can show you a
simple example of a RC circuit to generate clock.

(Refer Slide Time: 19:31)

Here is my NOT gate and I will take a NOT gate of the type of Schmitt inverter, this is a Schmidt
inverter, this is input and this is the output I connect capacitor here and I connect a resistor here.
And we can consider let us say the input is 0, because this is an inverter this the output becomes
1. It charges the capacitor through this resistor using the time constant R and this capacitor C. As
the capacitor gets charged and the voltage on it increases, goes beyond the Vih threshold, it
turns the output low.

And now the capacitor discharges through this and so it leads to an oscillation if you see the
waveform here between 2 thresholds, you would see the waveform on the capacitor going like
this and the output would be a rectangular waveform and the frequency will be determined by the
R and C and you see you can integrate all these features on the substrate of a microcontroller.

130
The only problem is that the value of R and C are affected by temperature and voltage variations
and so the clock frequency may not be very accurate. And so in such applications where not a
very accurate clock is good enough.

(Refer Slide Time: 21:04)

You could use the feature of an internal RC oscillator, because it will keep the cost down. In case
you want higher precision, then you could use the same internal oscillator but with external
frequency determining components such as a quartz crystal to give you higher accuracy clocks.
Now, another interesting feature that these microcontrollers offer is what is called as clock
scalability. And in fact, MSP 430 offers this feature.

What is the meaning of clock scalability? Meaning that you can change the system clock the
internal clock or external clock signal that we are we were just talking about, you could change
the frequency of that clock at runtime. Normally, you would fix the frequency and you may not
want to change it. But today, because our modern microcontrollers are CMOS based the power
dissipation of a CMOS circuit is directly proportional to the frequency of operation and in case
the microcontroller application deems it necessary that there is no available job to do.

Why to waste power by continuing to clock at a higher frequency during that time it can reduce
the participation by scaling down the clock and when some activities expected or some activity
becomes available, it can clock increase the clock frequency to a higher value, so, as to be able to
perform the program perform the tasks in a timely fashion. So, it has it should have the ability to

131
change the clock frequency at runtime depending upon program logic having this feature will
make a more battery efficient system.

And so, you as a designer when you are looking for various features you should see, read the
datasheet of that microcontroller to find out whether clock scalability is an option or not. Also,
modern microcontrollers operate at high a lot of great high frequencies in which case the power
dissipation may increase and to control that, often times the chip is partitioned in multiple
voltage domains, and therefore, you will find that your microcontroller requires 2 or 3 different
supply voltages.

We will come to that feature when we talk about the ecosystem of a microcontroller. MSP 430 is
the ones we are going to use is a simple microcontroller and it requires just 1 voltage supply. But
many arm and advanced microcontrollers may require 2 or even 3 supply voltages and it
becomes the responsibility of you the designer to provide those voltages. Modern
microcontrollers operate at very low currents and typically these currents range in this these
currents are in this range roughly 1 milliampere per megahertz to roughly 0.1 milliampere per
megahertz.

So, which means, if your microcontroller offers 0.1 milli ampere per megahertz kind of a feature
and if you are going to clock it at 50 megahertz, then you can expect that the total supply current
what we will call an ICC will be about 5 milli ampere this you can you will have to provide that
the power supply should be capable of providing 5 milli amperes specifically to the
microcontroller and this is a very low current. This is a great advancement that has happened.

132
(Refer Slide Time: 24:56)

Also to continue to optimize the available source of energy, battery modern microcontrollers
operate in multiple modes of operation and they are invoked to ensure that batteries are used
optimally and these modes are called active mode, sleep mode and power down mode. In active
mode is the normal mode is the mode you would like the microcontroller to operate at when you
want it to give the best performance, but in case the microcontroller system can find out that it is
not being used, it could switch to the sleep mode of operation where the clock signal is cut off to
certain functional units inside the microcontroller.

And when the clock is removed from a microcontroller functional function block it reduces the
power consumption. So, you invoke sleep function so that power dissipation is reduced and in
case there is no activity happening you can even go to what is called as a power down modes of
operation. We will see this in the context of the microcontroller features when we discuss them.
They operate modern microcontroller operate at using a wide power supply voltage ranges some
between the range of 0.9 volts to 6 volts.

They offer or they have several sources of interrupts where they are called power on reset, user
reset, brown out detector reset and watchdog reset and we will again consider these in detail
when we look at the ecosystem of a microcontroller in detail. Watchdog timer is if it is available
would be available with an independent clock. And the reason is when you consider it with this
feature that you your microcontroller can operate in various modes of operation in case the

133
microcontroller goes in power down mode, it would cut off the clock for the watchdog timer
making it ineffective, and therefore you do not want that to happen.

So, usually watchdog timers come with an independent clock that will not be shut down in case
you choose the power down mode. Also, the brown out detector reset has a programmable
threshold brown out detector means whenever there is a low going voltage spike on the power
supply, this low going voltage spike may potentially corrupt important registers inside the
microcontroller.

And 1 way to ensure that the corrupted values do not doom the system, it does not block the
system, 1 way to counter that is to reset the system completely. And you can set the threshold of
voltage at which this feature this reset will kick in that is the meaning of programmable threshold
up on BOD reset sources.

(Refer Slide Time: 27:54)

Then, our model microcontrollers are great examples of what we call this mixed signal circuits.
Mixed signals means it is not purely digital. It is not purely analog, but it is primarily a digital
circuit with analog capabilities and therefore, it is classified as a mixed signal circuit. And for the
mixed signal capability 1 important feature is that it should have an integrated analog to digital
converter.

Analog to digital converters are of various types and what we have is successive approximation
type of ADC or dual slope type of ADC or delta sigma type of ADC and the resolution of these

134
ADC range between 8 to 16 bits and therefore, when you are selecting a microcontroller,
specifically from the point of view of analog performance, you should read the details in the
datasheet to find out what kind of ADC it offers.

What is the resolution of this ADC and also the speed of this ADC because speed is heavily
dependent on the architecture of the ADC meaning is it successive approximation or a dual slope
or a delta sigma, dual slope ADCs are not that fast if you want high speed of conversion higher
rate of conversion, then you may have to choose SCR successive approximation type of ADC or
delta sigma type of ADC and this information is available in the datasheet.

We will consider this in detail, when we are looking at the way a microcontroller samples
external signals in that context we will look at this feature again. Therefore, resolution and speed
of ADC is an important consideration important feature to for you to verify before you select an
appropriate microcontroller for your application. As part of the mix signal capability. A
microcontroller may offer hardware DAC meaning it has an integrated digital to analog
converter.

You simply load a number into it and the DAC will convert it into a corresponding proportional
analog voltage. Or if it does not have a dedicated DAC, it would offer you that feature through
what is called as pulse width modulation, we will go in detail of how to get DC voltages or
analog voltages out of a pulse width modulated digital signal. As part of the mixed signal
requirement, you would see that such microcontrollers have multiple power supply pins
dedicated to supply power to the digital part of the circuit and some pins dedicated to supply the
voltage to the analog part of the pins.

This is so that the digital power supply pins often the voltage there gets corrupted because of this
switching action inside a logic circuit and this may leak into the analog circuit. So, best way is to
have an independent power supply pins. So, you have to be careful when you have multiple
independent power supply pins to ensure that those power supplies are fed correctly and that the
noise on logic the supply voltage for logic circuit does not leak into the power supply pins of
analog circuits on those microcontrollers.

135
(Refer Slide Time: 31:32)

Here we can see go back and look at the pins of this AVR microcontroller. And you notice that it
has a AVCC and VCC. This VCC means it is for the logic part of the circuit inside the
microcontroller and AVCC means it is for the analog VCC specifically the ADC and the voltage
reference source. And it also has 2 grounds although it does not explicitly mentioned this ground
is paired with this VCC here, digital VCC and this ground is paired with the analog VCC.

(Refer Slide Time: 32:09)

It turns out that on our MSP 430 there is no separate power supply pins for analog and digital in
digital part of the circuits even though MSP 430 is also a mixed signal type of circuit, it has

136
ADCs but they have not deemed it necessary to separate the power supply pins. So, this is an
important point to keep in mind when you are designing a circuit system using a microcontroller
whether it has individual pins or independent pins.

I mean, does it have a common pin or does it have independent pins for power supply for VCC
for the analog part of the circuit and the digital part of the circuit.

(Refer Slide Time: 32:58)

Then for measuring time and other events, the mod microcontrollers would offer you a timer as
well as a counter and the resolution of these timers and counters range between 8 and 16 bits,
which means it can count 2 raised to power 8, which is about 256 events or it can count 2 raised
to power 16 events which is about 65,000 or so, and if you can have a clock signal for such 8 or
16 bit counters, it would be able to measure that much time that is that me explain.

137
(Refer Slide Time: 33:41)

If I have a timer with 16 bits that means, it can count 2 raised to power 16 clock pulses, which is
equal to 65536 clock pulses and if the clock period is TCLK, if it is a 1 microsecond, then the
total time that the timer will be to measure for you is 65.536 milliseconds. If you want to
measure more time, 1 way would be to increase this period, which means reduce the frequency.
And you if you divide it by 10 you will get 10 microseconds and then you can measure up to 655
milliseconds and so on. So, you can trade off the resolution with the dynamic range that is the
maximum time that you can measure and that choice would be available to you what do you
want to have.

138
(Refer Slide Time: 34:45)

It also offers high frequency pulse width modulation signals with various options. 1 of them is
called dead zone. Dead zone allows you some rest time between 2 signals so that some
specialized devices require it you should read the datasheet of your microcontroller to find out
what are these options available to you.

(Refer Slide Time: 35:08)

Modern microcontrollers may need to communicate with the outside world through in your
application and so, they offer general purpose communication protocols such as UART, SPI,
Serial Parallel Interface, Serial Peripheral Interface, I square C which is inter IC communication

139
and something called a 1-wire protocol. It may also offer some of them may also offer
specialized communication protocols such as CAN C​ontrol A​rea N​etwork, Lin, Ethernet, USB
and if it is USB you have to find out whether what type of USB option is available.

Some of them are called device USB. There are other varieties called OTG like you have on your
phone, mobile phone, smartphone, and on your desktop computer, the USB type is what is called
as host USB. So, you must find out what is your application when you are when you want USB
functionality, you want to know where what do you want to connect through this USB so that
you can select the appropriate type of USB function.

Then it may offer you Wi-Fi , built in Wi-Fi, it may offer you regular Bluetooth or low energy
Bluetooth and other RF communication protocols. Some microcontrollers may even offer
specialized functions such as floating point unit or floating point ALU will perform floating
point operations quite quickly. It may or they may also offer encryption units to encrypt the data
before you save them.

And these are called hardware accelerators they may there may be hardware accelerator for other
activities. Most modern microcontrollers will offer in System Programming. And some of them
may also offer in application programming, our MSP 430 that we are going to use offers both
these modes and in fact, our kit operates through the in application programming mode, we will
be able to upload program while the system is still on.

And so, this is 1 of the modes of programming the microcontrollers. Modern microcontrollers
also offer on chip debug capability which means while you have built your system you would if
your system is not working properly you can invoke the on chip debug function to find out what
is wrong by inspecting the internal registers and memory locations.

Modern microcontrollers may offer JTAG which is a J​oint Test Action Group protocol which
allows you to invoke the on chip debug function and many high end microcontrollers may offer
maybe using the DMA capability to speed up the communication between memory speed up the
rate of transfer of data between memory and ports.

140
(Refer Slide Time: 38:23)

For developing applications, you need tools. And these are the application development tools,
you need a development platform usually these days PC, whether a desktop or a laptop is used
for application development, it must be able to run an assembler and a compiler. It should have,
you should have simulator and debugger. You should also have evaluation boards so that you can
test your small programs.

And you should have a mechanism to download code from this platform into the memory of your
target microcontroller. And oftentimes, you may be required to emulate or debug your code. So,
you should have an on chip debugger facility to access the on chip debugger through the JTAG
interface.

141
(Refer Slide Time: 38:57)

Apart from the application development tools, you may also be required some system
development tools and for that, once you have finalized your requirements, you may want to
create a circuit board. So, you need some circuit prototyping facility. You may also need
schematic capture and PCB layout tools.

We, I mentioned that in the first lecture that it would be nice if you could download and use
EagleCAD which is a PCB layout software, you should have circuit soldering facility maybe a
soldering iron for small jobs and increasingly as the sizes of components are reducing, you may
want a pick and place machine as well as a soldering oven for automatic soldering of these
components.

You may need a microscope or a magnifier to magnify and inspect your fabricated circuit board
to ensure that there are no shorts or no tracks are open. For electrical observations, you may need
an oscilloscope or logic analyzer which is nothing but like an oscilloscope except you are able to
look at multiple channel as a function of time.

142
(Refer Slide Time: 40:18)

So, an oscilloscope does this an oscilloscope allows you to look at time versus voltage plot of
any waveform. This is your oscilloscope, on the other hand a logic analyzer allows you
inspection as a function of time but of logic levels. So, you can look at signal and it will show
you on this waveform like this is the way it. And unlike oscilloscope which usually is 1, 2, or 4
channels a logic analyzer this is oscilloscope and this is logic analyzer will give you 8 or 16 or
32 or 64 simultaneous signal observations capability.

(Refer Slide Time: 41:19)

143
So, logic analyzer is a very useful device to have. But increasingly because my microcontroller
system is a mix signal system I need new instrument called Mixed Signal Oscilloscope. A Mixed
Signal Oscilloscope is a oscilloscope which is a combination of normal oscilloscope and normal
logic analyzer function integrated in a single instrument, it is called Mixed Signal Oscilloscope
apart from that you would need a digital multimeter, LCR bridge is good tool to have, good
instrument to have in your lab.

And variable bench power supply so that you can use that to power your system while testing.
These are the system development tools. Now, we come to the end of this lecture. In the next
lecture we will talk about, we will discuss various elements of microcontroller ecosystem, how to
make sense of these elements and how to use them in our application with the ultimate goal of
creating a successful embedded system design. Thank you very much, I will see you soon.

144
Introduction to Embedded System Design
Professor Dhananjay V. Gadre
Netaji Subhas University of Technology, New Delhi
Lecture 7
Elements of Microcontroller Ecosystem
Hello, welcome to a new session on this course on introduction to embedded system design, in
this lecture we are going to consider the ecosystem that a microcontroller requires for its
operation and once we complete that we will look at the power supply building block as part of
the six block representation.

(Refer Slide Time: 00:53)

So, let us start, what are the elements of a microcontroller ecosystem? Meaning what does a
microcontroller require to function independently as you know now that a microcontroller is a
complete computer on a single chip it is able to perform whatever it is programmed to do just if
few elements of its required ecosystem are provided to it., What are these elements?

145
(Refer Slide Time: 01:19)

So, I titled it as “Roti, Kapda, Makaan and internet” for a microcontroller this is crazy sounding
title has been derived from a previous slogan which said for a human survival you need three
things roti that is food, kapda clothing and housing. In recent times, even the lowest level of
society requires internet for survival and therefore, a human being requires four things, food,
clothing, housing and internet and we found interesting parallel that even a microcontroller
requires four such things and what are these four things for it survival and active working.

It requires a clock we will see why it requires a clock? It requires a reset circuitry usually that
reset circuitry is integrated in the microcontroller itself. It also requires a power supply different
from perhaps different from the power supply requirement of the rest of the embedded system
application and then it requires a mechanism to download code from the development platform
which often is your desktop or laptop computer into the memory of the microcontroller. So, we
have to ensure that microcontroller is provided for with these elements then only it can function
properly and if the microcontroller function properly then the rest of the embedded system can
function properly.

146
(Refer Slide Time: 03:00)

So let’s start with the first element of this ecosystem, the clock subsystem. Why do we need a
clock? Can we design microcontroller systems without a clock? Most of the time you would
have seen that an analog circuit does not require a clock but a microcontroller is different
because it is an example of a digital circuit now digital circuits can be designed in two ways what
is called as asynchronous sequential circuits and the other type is synchronous sequential
circuits.

(Refer Slide Time: 03:33)

147
So, any digital circuit or system could be designed in two ways synchronous sequential mode
and asynchronous. Now, asynchronous sequential circuits are very efficient they consume little
power but they are very difficult to design and even more difficult to debug and verify and
therefore, almost 99 percent of all logic circuit implementations are of these variety synchronous
sequential. Now, the term here synchronous means that it uses a clock circuit for its operation
and therefore you need a clock. So, this defines or this justifies the need of a clock because a
microcontroller is an example of the synchronous sequential circuit.

(Refer Slide Time: 04:49)

Then the next question arises so we have answered this the next question arises as to what should
be the clock frequency? Now, there are two contrasting two diverse diverging arguments that the
clock frequency should be as low as possible. Why?

148
(Refer Slide Time: 05:10)

Because in a CMOS logic circuit, the power dissipation consists of two parts the static power
dissipation plus the dynamic power dissipation. The static power dissipation is a function of the
technology the way the system was built but the dynamic power dissipation in a CMOS circuit is
equal to the capacitance that the circuit sees at its load into the frequency of operation into the
VCC square which means the dynamic participation is directly proportional to the frequency
operation.

So, if you increase the clock frequency that would consume the battery faster. If you double the
clock frequency it will double the power dissipation which means it will empty the storage that is
your battery in half the time. Now, this is one argument why you should keep the clock
frequency low. What is the argument towards keeping the clock frequency high? Well if the
clock frequency performance of a computer is directly proportional to frequency.

For a given a computer if you double the clock frequency then it will execute the same program
in half the time and so these are two arguments which are pulling in opposite direction and
therefore in as a efficient embedded system design you must strike a balance, one which
optimizes the power dissipation and the other side where the frequency is high enough for the
system to work properly.

149
So, we have seen why we need a clock? We have seen what should be the clock frequency we
have also considered the implications of this clock frequency that if we keep the clock frequency
very low it will certainly provide a longer operation on a given battery but its implication could
be that it may not be able to fulfill the requirements, the timeliness of a program and therefore
you may want be increase it and as a designer as a engineer you would have to strike the right
balance trade of between low enough frequency to keep the power down and high enough for it
to perform its designated task.

(Refer Slide Time: 07:59)

150
What are the various topologies for generating this, the clock for microcontrollers? Now if we
look at the pin out of typical microcontrollers, you will see that it offers you a couple of pins on
which you can connect an external component such as a quartz crystal and often times it also has
an internal RC oscillator.

(Refer Slide Time: 08:34)

Let us see what this circuit looks like. Or in general how do we create a clock signal? So, one
simple method we already discussed in a previous lecture was to use a schmitt trigger with a
capacitor and resistor to generate the frequency this is this could be used. Another one you could
use very popular IC called the 555 timer IC.

It has 8 its a 8 pin IC. You connect 4 and 8 pins to VCC then you have pin number 7 you connect
a resistor R1 and
​ then pin number 2 and 6 you short them and you have another resistor this is R2
and from here you put a capacitor to ground C. you have pin number 5 which would decouple
and put a capacitor and on pin number 3 you get the output voltage. The frequency of such a
topology is 1.44 divided by R1 plus
​ 2R2 into C. And you can tally the values of the resistances
and the capacitors to get your required frequencies.

Now, what happens is the typical 555 oscillator timer will require a power supply in the range of
4.5 Volts at least to 15 Volts for operation and if your microcontroller also operates in a similar
power supply range you do get microcontrollers which works at 5 Volts then you could use a 555

151
timer. In case you have a microcontroller which requires a lesser operating voltage say 3 Volts,
then instead of regular 555 timer you can use CMOS variant of this timer called 7555 with
identical pin configuration, but with the much diverse power supply requirement it can operate
from 3 Volts to 18 Volts.

So, you could perhaps use such a external clock generator. The output of this or output of this
would be connected to your microcontroller. Here is a microcontroller and you may have pins
called X1 and X2 on which if you do not want an external clock generator then you connect an
appropriate crystal, a quartz crystal between these two pins. It may also require you to use some
small value capacitors these will be mentioned in the datasheet of your microcontroller and you
must follow those specifications.

In case you do not want to use this crystal. Then instead of this crystal the output of such a clock
generator one or say 555 or 7555 this output be could be connected to X1 or X2 input as
mentioned in the datasheet. There is another interesting method of generating clock and that is by
way of what is called as ring oscillator.

(Refer Slide Time: 11:55)

152
Ring oscillator as a name suggest is a ring of components in fact it uses a NOT gate an inverter
an odd number of inverters. So, if I take 3 inverters and I put them connect them like this power
it with appropriate supply voltage then at any point here it will show oscillations and the
frequency of those oscillations will be equal to 1 upon 2 times the delay period of this device into
n. In this case n is the number of elements in this case 3.

From the datasheet of this inverter you can find out what is the delay time for typical TTL family
components TD is of the order of few nanoseconds. Therefore, you might get may be 1 by 2 into
3 into 5 nanoseconds so this is about 1 by 30 nanoseconds that will give you roughly 30
Megahertz of operation if you want a high frequency.

Please note that 555 or 7555 timer cannot provide a very high frequency beyond couple of
megahertz and so it may be suitable for some applications. Anyway, these are the method of
creating a external clock signals with which you can feed your microcontroller. It turns out that
such a need is usually not required such a topology is not required why? Because
microcontrollers have built in oscillators, they have built in RC oscillators and you can choose do
you want a regular oscillator or do you want to use an internal RC oscillator.

The internal oscillator you can imagine would be of this type and therefore since it uses these R
and C to provide the clock frequency. The variation in the resistor and capacitor values would
change the frequency and therefore it may not be used for very accurate measurement of time but

153
if your application is ok with the little degraded performance of the clock generator as in its not
as accurate as you would want then this could be a good low cost solution.

In case you want higher precision in time measurement then you would use this option where on
the designated pins of the microcontroller X1 and X2 you would connect a crystal of appropriate
frequency together with some capacitors if the datasheet say so and typically the values of these
are of the order of 10 to 20 Picofarads here and the crystals are could be in the range of the
lowest crystal that you may get.

The lowest crystal incidentally happens to be 32768 Hertz and I will come to this I have also
mentioned it in the past but we will go through this again and going up to 1 Mega Hertz, 2 Mega
Hertz and so on going up to few tens of megahertz 20, 30 megahertz crystals may be available
and you could use them for determining the clock frequency. The oscillator part the active part of
the oscillator is inside the microcontroller. Therefore, all you need is external couple of
components and this provides the source of clock.

As I mentioned in the previous lecture, if the microcontroller offers clock scalability then you
should start with the lowest clock frequency crystal because internally you could use a multiplier
to increase a clock frequency to high value that you would want at given point of time. And if
you so desire that you do not require a high enough clock frequency then you can scale it down
to the lowest value which would be the crystal value in this case 32768 hertz. So, that would be a
good choice for a crystal to be used in such microcontrollers which have this option of run time
clock scalability.

154
(Refer Slide Time: 16:35)

So, now we have seen what topologies of the clock generators and also what are the desirable
features of the clock generator we have seen that we would like to have the clock generator the
frequency of which we can change at run time but this is usually a inherent and built in feature of
a microcontroller and you must evaluate whether your application requires such a function then
you must choose a microcontroller which offers that functionality.

Apart from the clock frequency that is required by the microcontroller you require an additional
clock a complete clock system and that clock system is called a real time clock. A real time clock
is a dedicated function dedicated circuit which provides a certain functionality which is to
maintain a real time.

155
(Refer Slide Time: 17:30)

So, RTC maintains real time that is it can be used to know what is a current time of the day at
whichever location you may be. Of course for this it requires a source of frequency and usually
the source of frequency is a crystal and that crystal is usually 32768 hertz and this frequency this
seemingly odd number is not that odd for computer and electronics engineers because this
number is exactly equals to 2 raise to power 15 is equal to 32768.

Historically these crystals were used in digital watches when they started appearing in late 60s
and early 70s and this low enough frequency was chosen because again this clock signals circuits
were CMOS based and the power dissipation had to be kept low because they were battery
operated and therefore a balance was achieved that frequency should be low enough and the
crystal should be not large enough therefore they found that 32768 is good trade of it is small
enough in size and would to relatively less per dissipation.

Although for record I may mention here that the very first digital quartz crystal based clock that
came on the market was the Seiko clock and it actually used 8192 hertz crystal but subsequently
the common frequency of use was this and this frequency has since been adapted and adopted for
use with RTC chips, usually this is a 8 or 16 pin IC, it has power supply pin it also has a battery
backup.

156
So you would have additional pin Vbat and it would have a mechanism to communicate with the
microcontroller, usually this would be the I square C or SPI interface we have discuss that
communication protocols are inherently some of the some of the communication protocols are
inherently available on certain microcontrollers so this microcontroller could talk to this real
time chip through these communication protocols it may also have alarm out alarm pin so that
when you program this real time clock to wake you up on certain alarm when the time is reached
this signals the alarm pin would go from 0 to 1 and this could be used to interrupt the
microcontroller to do whatever was expected to be done.

The frequency as I mentioned again is 32768 hertz, the accuracy of the crystal here would
determine how good the real time is being maintained and typically these crystals have
temperature coefficient which is of the order of few parts per million per degree centigrade and
therefore the traditional real time quartz crystal based real time clocks offer roughly a drift of
few seconds per months kind of numbers.

If you want even more accurate maintenance of time then there are two options one is to
regularly correct the frequency or the time that this clock is maintaining and one way to do that is
to get the actual time from the internet there are services which offer the time and in fact your PC
and laptop often fetch the time from the internet sources and correct the clock in case it has
drifted, the other is to used more accurate source of clock and one way to do that would be to
maintain this crystal and this circuit at a constant temperature.

157
(Refer Slide Time: 22:11)

Let us go back to presentation to see what we are talking of. You can stabilize the clock using
technique called TCXO meaning temperature compensated crystal oscillator, this is basically a
small enclosure where the temperature of that enclosure is maintained to a fixed value
irrespective of the outside ambient temperature and this ensures that the crystal does not drift.

(Refer Slide Time: 22:54)

Another method uses a unfortunately this method consumes a lot of power to maintain that
temperature, another method uses a temperature sensor and a varactor diode and the way these

158
crystal works the circuit diagram of crystal oscillator is like this that you would have an inverter
and you would have big large value of resistor another resistor here and you would have a crystal
between these pins and you would have couple of capacitors as I mentioned low value
capacitors.

Now, this is typically say 10 Pico farad is also 10 Pico farad and say this could be say 1 mega
hertz now if I change this crystal if I change this capacitor I can load the frequency operation and
I can change it a little bit, similar way I can add a therefore instead of changing it manually I
could add a varactor diode say a varactor diode is nothing but a diode which is operated in
reverse bias.

I need to decouple the varactor diode here by using a large capacitor and I apply a bias voltage
here say some V bias by changing the bias voltage the capacitance between this two points can
be changed and therefore the effective capacitor as seen at this point A would change which
would tweak the frequency operation and so in many circuits where they want to offer a better
temperature stabilization they use a temperature sensor to monitor the temperature and to
compensate for any variation in temperature.

(Refer Slide Time: 24:46)

They change the bias voltage on this varactor diode which has been placed in parallel to one of
the capacitor of the crystals so as to maintain fixed clock frequency. So, these are various

159
methods of having higher accuracy clock frequency signals in application where you require
more precise measurement than what would be available with just the quartz crystals or with the
RC oscillator.

160
Introduction to Embedded System Design
Professor Dhananjay V. Gadre
Netaji Subhas University of Technology, New Delhi
Lecture 8
Elements of Microcontroller Ecosystem Continued
(Refer Slide Time: 00:35)

Here I have listed out certain checkpoints that you would consider when you are selecting
embedded microcontroller and they would be rather your microcontroller has peripheral features
whether it has enough memory for your application what about the packaging because packaging
would be a important consideration is it available in the package that you want because you
application may not offer to much physical space.

IC are produce in many grades the commercial grade is the most common grade this is used for
commodity consumer products typically the temperature of operation of such IC in the range of 0
to 70 degrees, industrial temperature range is higher than that automotive is even higher and
military grade components operate at much wider temperature ranges because that is what they
expect in a military application.

Then you would look at the price availability and lead time but an important component is since
you are going to use microcontroller in a real time application in a real time application where it
is going to sample external parameters such as temperature or sound therefore it must be able to
sample that signal appropriately and whether a particular microcontroller is up to the job or not
is determined by the maximum frequency component of that external signal.

161
Let me take two examples if I am looking at regulating the temperature of this room using an air
conditioner. I would need to know what is the temperature of the room so I need to sample that is
I need to collect the temperature sensor and digitize the value of this temperature sensor every
few seconds that is enough because the room temperature is not going to vary very fast. On the
other hand if I want to look at an application such as the noise cancelling headphone then the
noise cancelling application has two sample external sounds the maximum frequency of the
external sound is 20 kilo hertz we can’t hear beyond that.

(Refer Slide Time: 02:40)

So, we must sample 20 kilo hertz at an appropriate sampling frequency and I have illustrated that
here that the time between two samples we call it inter sample interval and this would vary from
application to application like I mentioned for measuring temperature the inter sample interval
will be very large for sampling sound frequencies if I am going to sample 20 kilo hertz signal I
must sample it in keeping with the sampling theorem nyquist rate and I have to sample that
signal at least twice the maximum frequency component.

So, 20 kilo hertz signal a signal which has a maximum frequency component of 20 kilo hertz
must be sampled at 40000 times per second at least and so you would sample it probably at
45000 samples per second which means the time between two samples is going to be less than I
would say this is about 20 micro seconds is that right? Yes.

162
Therefore, what would happens in this 20 micro seconds? At this point the micro controller
receives one sample. After 20 micro seconds it is going to receive one more sample. It must
process the current sample that it has received here and produce an output before the next sample
is due. Now we have taken three cases. Let us say we choose microcontroller of type A, if the
program that runs and processes this sample it would and if we take more than 20 micro seconds
to complete this task it is not suitable for this application.

How can we still make a usable in this situation may be we can increase the clock frequency so
that the resultant time is B such that it is less than the inter sample interval than it may be a
marginally acceptable solution, if we can increase the clock frequency even more that is the
internal clock frequency of operation on this micro controller even more such that it takes less
than half the time then it’s a very comfortable situation.

In case you are not able to bring down the possessing time to less than the inter sample interval,
you may be forced to replace this micro controller which offers you higher performance and
before you that you would consider can I increase the clock frequency operation so as to manage
the completion time of the sample before the next sample is due and so therefore the value of the
clock frequency is very important when you are looking at physical signals which had to follow
the nyquist rate.

(Refer Slide Time: 06:02)

163
Let us look at the next aspect of the ecosystem which is the reset. Micro controller requires a
reset signal, why does it require a reset signal well the answer is very simple and obvious that a
micro controller uses as CPU a CPU has a control unit a control unit utilizes flip flops and the
values of this flip flops they are important when you apply power to the micro controller for the
first time your want this flip flops to start with the known state.

Similarly, apart from the control unit you have a important register in your micro controller or
micro processor which is the program counter also sometimes called instruction pointer, let me
write them here program counter or instruction pointer, this is nothing but a few flip flops
arrange together to provide the initial address when the micro controller is reset.

Now, if the value of this flip flops take arbitrary values that would mean that after reset the micro
controller at some point may go to a certain memory location to fetch the first instruction at some
other time it may go to different location and if that happens you will never be able to execute
your program properly. All micro controllers require that after reset a fixed location a known
location is accessed to access the first instruction stored in the memory.

In many cases that address is 0000 say another 0 if you like this address, so this address must be
output on the address lines connected to the program memory if you do not reset the initialize the
flip flops that make the program counter or instruction pointer then it may emit arbitrary values
on the address bus and it would be a very chaotic situation.

So, to ensure each time every time power is applied to micro processor or the micro controller,
its starts with a known state internal state of the computer, it is very important that you reset,
why? Because we know that a flip flop are represented with the signals say D type flip flop
would have D input Q output, a clock signal this is the very minimum signals that you require
but it will also offer you reset which when asserted will reset the value of Q to 0 it may also offer
a signal called set if you assert set that will make Q equal to 1.

And so when you use such flip flops to create various registers the reset or set signals are utilize
together by the control unit so that they can be initialized with a known value and therefore this
act that when the micro controller is applied power for the first time the micro controller start
with a known state this is called the resetting the microcontroller. So, we see why need a reset so
that our system is going to start from the known state each time every time.

164
(Refer Slide Time: 09:25)

Now, there are many sources of reset, one of them as I mentioned the term every time you apply
the power to the microcontroller or micro processor it should reset itself without having to be
prompted and such a source of resource is called user reset. We will see other sources of reset
but before that I have classified the resets to be of two types, warm reset and cold reset.

A warm reset means that the system power has not been disabled it has not been switched off and
you would still like to reset the system without turning the power off. Other source of reset
would be a cold reset meaning you turn the power off and when you turn it on again it would be
classified as a cold reset, of all the resets that are available and here is the list of those resets you
have power on reset which I have discuss that is a reset signal internally which is generated when
you turn power to a micro controller system that is called power on reset.

165
(Refer Slide Time: 10:34)

Another reset source is the user reset source and let me show you in the next slide here if you
look at the pinout of these devices you will notice that on pin number if you see here this is the
reset pin of this AVR microcontroller and on this MSP 430 microcontroller you have reset signal
somewhere here.

And these pins which are designated as RST bar or reset on this two micro controller refer to the
user reset meaning you would user can assert a logic level on these pins and it would reset the
system even if the power system was not taken off even if the power supply was applied and
usually the way to do that is you would on these pins RST bar you would connect switch.

166
(Refer Slide Time: 11:30)

So, every time you want to assert a user reset the user simply presses this switch, it pulls the reset
pin to ground this reset the internal circuitry and when the switch is released it would allow the
circuit to reset and then it will start performing its expected task.

(Refer Slide Time: 12:00)

The third type of reset is called BOD, BOD stands for Brown Out Detector, so what is the brown
out condition because you have a detector which detect the Brown Out Condition, brown out
condition is that if this is my as a function of time this is my VCC that is the supply voltage, If at

167
any time it deeps below certain level and for the entire duration of time it remains below that
threshold again rising to expected levels if it has fallen below this threshold here then this may
be detrimental to this operation of the processor.

It may corrupt some register values it may write wrong value into flash memory or E square
PROM if the controller was performing some right operations and it may be better to reset the
system rather than go ahead with this corrupting activities and this is where a Brown Out
Detector plays a role if this Brown Out Detector has been enabled then it would generate an
internal reset which will hold the internal circuit in microcontroller in a perpetual state of reset
till the power supply voltage level resumes and exceeds the minimum threshold that is required.

(Refer Slide Time: 13:37)

Let me explain the operation in using an external circuit, suppose you had you take a comparator
and I would have minus and plus signals of a comparator it would have an output here what I
will do is it is also powered with a power supplier say VCC which is a power supplier of a
microcontroller, I am going to take a voltage divider made out of two equal value resistor and
therefore the voltage here would be 0.5 VCC if both this resistors are of equal values.

Let us say that VCC is 5 volts therefore the voltage you expect at this point when the supply
voltage is 5 volts will be 2.5 volts. I take another little circuit using a resistor and a reference

168
voltage diode such as a Zener, I connect it to the positive input and let say this is 2.25 volts
reference diode.

Now, as long as the power supply is 5 volts the input is going to be 2.5 volts and therefore the
output here is going to be 0. But at any point of time if this power supply instead of being steady
at 5 volts instead of that if it falls to a low value such that the voltage here becomes less than
2.25 volts the output here will go to 1 and this signals could be use to reset the internal reset
circuitry of the microcontroller and hold it in the reset till such time the voltage resumes back to
the normal values or at least exceeds above the threshold at which the brown out detector kicks
in.

So, this one can use one can think of such a circuit that has been integrated inside the
microcontroller but it functions in this way that I have illustrated using op-amps and couple of
resistors and a reference diode. So, this is how a brown out detector works internally and one has
to be aware that their microcontroller offers such features and in case they expect the power
supply to be you know show such behavior where the power supply voltage is fluctuating then
they should enable the brown out detector so that their entire system keeps working properly.

(Refer Slide Time: 16:12)

The fourth type of reset source is this what is called as watchdog timer and watchdog timer is
common feature these days in microcontroller as a name suggest it is like a watchdog at home

169
which would start barking if it finds anything other than usual intruder or something like that in a
microcontroller system if the program gets stuck for a whatever reason the watchdog timer could
be used to redeem the system to comeback out of the stuck situation and start operation again
and simple way would be to reset it. Unfortunately, if the system is out of human reach where it
cannot be manually reset using the user pin then the only way would be watchdog reset and let
me illustrate again with a small circuit diagram how it works.

(Refer Slide Time: 17:03)

So, imagine that you have a counter and this counter would have can be fed with the clock
source and let say it is an independent source of clock and let say this is a n bit counter, so it
would count 2 raise to power n clock pulses at the end of which overflow pin of the counter over
flow let me write it completely pin would become 1 and if this would becomes one it can be use
to reset the system.

Now, obviously you do not want this timer, this is your watchdog timer you do not want this
watchdog timer to overflow, so how do you ensure that it does not overflow because that
overflow situation is going to reset the system that any counter can also have its own reset we let
us call it C-reset that is counter reset and this pin could be connected is actually part of the
register and the microcontroller program would periodically so if I know that 2 raise to power n
into the clock frequency here T I will use a name so there is not confusing with the clock
frequency of the system WDT watchdog timer frequency.

170
Let us say this is 1 mega hertz clock so therefore it is a one micro second time period, let say n
16 therefore it is 2 raise to power 16 clock pulses required to overflow this, this is about 65536
clock pulses. So, roughly this will gives you a 65 milliseconds period within which if you can
reset the timer it will not reset you, if you forget to reset it for whatever reason that imagine that
the program has stuck and cannot reset this timer then the timer will overflow and it will then
reset the system bringing back sanity into the system this is how a watchdog timer reset works.
So, we have seen at all the various ways resetting the microcontroller now let us move forward,
this I have already illustrated the user reset pins on two popular microcontrollers.

(Refer Slide Time: 19:43)

The other aspect that you require as part of the microcontroller ecosystem is the ability to
download program from the development setup in to the memory of the microcontroller and I am
going to go through little bit of history here in the past one of the popular method was to use
EPROM to store the program memory and to erase the EPROM you require a source of ultra
violet light, so to erase it you would have a box which have UV lamp with the lid you put your
EPROM inside it, it would have a timer to say 15 to 20 minutes of dosage of the UV light
required to erase the contents of the EPROM, EPROM typically would have a window.

171
(Refer Slide Time: 20:39)

So, if this is your if this is your IC and this are the pins I am just drawing it for the sake of
reference you would actually have a window this is a quartz glass window, why quartz why not
normal glass? Because normal glass absorbs UV light and so these windows were made of quarts
glass which is expensive type of glass, which is why these IC’s were also very expensive but
there were no other option and so they would use a EPROM to first erase it and then put it in a
special system special programmer connected to your PC through some protocols, on this
programmer you would have socket with a lever where you raise the lever it opens up the pins
you drop the EPROM into the pins of the sockets and then you press that lever.

That special socket with something like this, these where the pins of the socket this was the
special socket this is still in use in test equipments is called ZIF socket and it stands zero
insertion force type of socket why? Because if you put a regular socket and you were to insert an
integrated circuit in an out of it tons of time or hundred times a day that socket will go bad it will
not make connection appropriately with the pins and may not be able to program it and therefore
you wanted a rugged socket which can take insertions and removals of external IC’s hundreds of
times a day over several of years of its operation and therefore special socket was used ZIF
socket.

So, you would have this EPROM programmer or a device programmer which such a socket you
would insert your EPROM into the socket after you have erased it then you would burn the

172
so-called burn the program into the EPROM then you would take the EPROM out of it and put it
back into your target system and test it and if it did not work again you would repeat this cycle,
so obviously it was slow process of compiling and downloading program into the memory of the
microcontroller.

(Refer Slide Time: 23:13)

In the mid nineties there was introduction of E square a special type of E square PROM memory
which was called flash and the flash memory started getting integrated into microcontrollers for
the program memory that allowed user to program these memories without having to take it out
of the system, without having to take the microcontroller out of the system you could program it
using a feature called ISP that is in system programming.

To offer in system programming some communication interface was required and the most
popular interface that is used is the SPI bus we have seen that SPI is one of the communication
protocol that is available on almost all varieties of microcontroller and so this was used to off
implement the ISP functionality. In more advanced microcontrollers they would have JTAG
Joint Test Action Group protocol which had dual use, one of the use would be to program the
internal memory and the other is would be to use it for testing the microcontroller using the on
chip debugger that I mentioned.

173
Another popular protocol would be for testing would be serial wire debug this is a more efficient
protocol which uses less number of pins than the JTAG and another way to download program
into your code is a method code in application programming meaning you do not even stop your
application from running while the system is running you can download a code into it using a
technique called boot loader.

(Refer Slide Time: 25:01)

Bootloader, let me illustrate that also so the entire program memory of your system would be
split in two parts, the chunk major chunk of your program, this is your program memory the
major chunk of your program memory would be this one which would be called user program
memory and a smaller chunk would be called bootloader program memory and when you reset
the system it would normally go into the first location of the user program memory.

But if the bootloader has been enabled it would the program counter will take the program and
start executing the bootloader, the bootloader would communicate using a onboard
communication protocol, it would communicate and usually this communication protocol would
be Uart or if it as USB it would be USB and we will try to establish a contact with the host
computer the host computer would have a corresponding program which would establish
communication with the bootloader and then it would transfer the memory bytes the program
memory bytes, sequentially serially one after the other the microcontroller the bootloader
program would receive it and would actually write into the user program memory.

174
After the program transfer is complete it would transfer the control to the first memory location
of the user program memory and user program execution would begin, this method is called in
application programming and using the bootloader method this is commonly used in your
Arduino platforms and low and behold the MSP430 lunch box that you all are going to be
working with, also uses this bootloader method to download code from your PC into the memory
of the microcontroller.

MSP430 microcontroller come with the default bootloader program loaded into the memory at
manufacture times so we do not have to worry about having to write or load this program into the
bootloader program memory area and so it is a good to go system MSP430 as long as invoking
the in application programming feature of MSP430 and we are going to use that.

This completes the program download capability or rather the feature of microcontrollers and
you as designer must select one or the other option so that you can download code from the
desktop computer into the memory so that your system can work the development of the system
can continue unhindered.

(Refer Slide Time: 28:25)

The last part of the ecosystem is power supply, we are going to subsequent to this we are going
to have dedicated session on power supply design including that for the microcontroller but I
thought I would use this opportunity to illustrate that on your microcontrollers typically you

175
would here see two pins DVCC and DVSS are two pins on MSP430 whereas on AVR
microcontroller this is the AVR atmega microcontroller, there are two sets of pin as I mentioned
earlier this is the digital supply voltage and this and this is the analog supply voltage. Pins which
are available you have to refer to the data sheet as to what is the supply voltage that the
microcontroller expects.

(Refer Slide Time: 29:24)

For example, MSP430 the expected supply voltage is 3.3 volts typically whereas for MSP430
whereas for AVR microcontroller it offer wider range anywhere between 3 volts to 6 volts they
can operate and therefore it becomes your responsibility as a designer to provide smooth DC
voltage of this or this value so that your microcontroller can function properly.

When it has two sets of power supplies as in the case of the AVR, one for the digital pins digital
part of the circuit inside the micro controller and the other for the analog part of the micro
controller then one has to deal with that situation with little more care if this is DVCC to
represent the digital input, one very good method is first of all to put decoupling capacitors two
decoupling capacitors connected in parallel and the purpose is not to add the two capacitance
values which is actually happens but this is typically 0.1 micro farad ceramic capacitor.

And this could be 10 micro farad electrolytic capacitor and then this is your ground and this is
your ground so I ground that pin and if you have analog AVCC also you would connect a

176
capacitor two capacitors actually and please note that I am actually using different grounding
symbols to indicate that these do not share the same ground with the ground of the so this is I
would call it AGnd and this I am you see I am grounding like this.

This could be +5 volt this could also be +5 volt but because I have connected the ground here
separately the source of the pin per supply is say +5 volts here and this is my ground the way to
ensure that these analog grounds are not directly connected to the digital grounds on the
microcontroller pin is to route them separately using separate tracks similarly you have separate
tracks to go here, these are all connected together and then they go here.

If you keep the track separate it would serve the purpose of isolating the noise which is often
generated on the power supply pins because of the internal switching actions in the logic circuit
and it would not corrupt this supply voltage. How to achieve that in real life in practical we
would consider when we are looking at system design issues where we will show how to design
PCB from a power a schematic, what you do to ensure that there are two parallel tracks one for
providing power to the supply to the analog voltage and the other to supply voltage to the digital
part of the circuit.

We will consider that but this is an important point to keep in mind in case your micro controller
has separate pins for analog and digital components subsystems within your microcontroller that
you design the routing you design the PCB appropriately so as to do justice to the internal
components we will continue our discussion in a next lecture where we will look at the design of
power supply in more detail and I will go through the various options that are available. Thank
you for watching, bye bye.

177
Introduction to Embedded System Design
Professor Dhananjay V. Gadre (NSUT) & Badri Subudhi
Indian Institute of Technology, Jammu
Lecture 9
Power Supply for Embedded Systems

Hello, welcome to a new session for this online course on introduction to Embedded System
Design. In the previous lecture, we looked at various aspects of the ecosystem that
microcontroller requires and one of the important components was the design of the power
supply or the requirements of the power supply by the microcontroller. In this lecture, we are
going to look at power supply building block from a comprehensive point of view in terms of the
requirements of the subsystems other than the microcontroller. What are the various ways we can
design the power supply elements. We are going to discuss those.

(Refer Slide Time: 01:03)

So, here is the here are the elements that we have to consider when we design the power supply,
power supply is a very important component. The first question that we must answer as designers
of embedded system is what is the source of power. Usually, if you have a embedded system
which is going to be powered by mains voltage, then you would derive it from the wall socket,
what we call as the grid power that is most common source of powering your embedded systems.
But, if you are going to connect a cable between the source of power and your embedded

178
product, then it would be restricted to a physical space. In some cases, you may want to involve a
battery.

But battery is not a source of power it can only last so long depending upon the capacity of the
battery and battery may need recharging if you are going to use rechargeable batteries or they
may require that these batteries be replaced if they are non rechargeable. And the other option is
that we may be using alternative sources of power.

Once you decide what is the source of your power, then the next question is, is the source of
power very stable, even if it is stable if it is of a high value most embedded systems, the
components that make up the embedded system require a low voltage low DC voltage and so,
you must reduce the voltage and you must ensure that the reduced voltage is stable that there is
no noise on it, it is not fluctuating.

And so, if it is fluctuating then you consider a question regarding the stabilization of that voltage,
what we call as the voltage regulator that may be pressed into service to ensure that even though
the input voltage may fluctuate or may vary or may even blank off, you may want to continue
operating the system using some mechanism and it could involve a voltage regulator.

If the voltage the power source is sporadic, that is it may not be available at all times, then you
must consider options of a backup. What are the various ways that you can create backup and
last but not the least, given that you have some source of energy some source of power, you
would still want to optimize the available power and this is very important in case the source of
your primary source of your battery a source of your power is a battery.

You would want to optimize it utilization and so, the optimum the modes of operation which are
dependent on the microcontroller features as we discussed in the previous lecture, you would
want to invoke those modes, so, as to conserve available power.

179
(Refer Slide Time: 04:16)

Let us go to the next slide. The sources other than the grid power, which is available through the
wall socket, you could consider is it solar? If it is solar, solar itself is of two types one is
photovoltaic which uses solar panels solar cells and the other is thermoelectric which uses the
temperature difference applied to a peltier module to generate a voltage difference and this could
be used to power your embedded system. Another option could be hydroelectric which means
that your system is nearby a source of water which could charge which could power run a
dynamo or a generator.

The third option is vibration or resonance based on Faraday's law and you may recall a project or
a couple of projects that I showed where I had used a tube consisting of enclosed magnets and
outside the tube there was copper windings and when the magnets went pass through the copper
wires, it produces more produced voltage based on the Faraday's law and this could be used to
power your system.

In case you do not have these options, another possible popular mechanism to power your
embedded system is the availability of Ambient RF radio frequency source, whether that radio
frequency source is available in free space, such as radio transmissions from broadcast
transmitters or these days through the cell phone towers, you could use them and in fact, the one
of the applications I showed the RFID card used radio frequency transmissions to receive the
radio waves to convert them, and then use them for powering the microcontroller of the

180
embedded system. So, these are some of the alternative sources of power that you could consider
when you are designing your embedded system.

(Refer Slide Time: 06:35)

If the primary source of your power is the grid, then the grid voltage is typically 220 volts in
large parts of the world. In some cases the voltage is 110 volts. So, grid power would be either a
220 volts or 110 volts and these voltages even if it is 110 volts is way beyond what you would
require also these are AC voltages and so you have to consider the first option, first requirement
of stepping it down to usable levels and then to rectify it meaning convert from AC to DC.

If you are going to reduce it, step it down to usable levels and if you are going to, for that you
would use a transformer the transformer would give you AC voltage, you cannot just connect it
to your system because the transformer would have a polarity, you do not want to apply a reverse
polarity to your circuits.

So, some sort of polarity proof design of the input stage of your power supply which is polarity
proof or polarity safe you would have to incorporate and in the next slide will show the two
options that we have. Another way is that instead of using a step down transformer which is the
case in most of the situations, can you reduce the voltage by any alternative means? Because a
step down transformer is bulky, is expensive. Is there a way to reduce the voltage in some way
and one method that is often used is using a capacitive voltage divider, think of it like this, that if

181
I were AC voltage source, I can create a voltage divider using two resistors. But I can also create
a voltage divider using two capacitors.

If I use two capacitors, then here is my AC source and I tap the voltage here. Then, because the
capacitors are reactive components, they do not dissipate any power. I would have a more
efficient power supply system, I would ensure the ratio of these two capacitors C 1 and C 2, such
that the voltage across C 2 is within usable limits and then I would rectify it and I would I could
use it to power my system.

In fact, many of the LED bulbs that are becoming available the cheap varieties often use
capacitive power supply and these are very low cost, but the there are some disadvantages that
such a power supply is not isolated and therefore, human interaction has to be stopped you
cannot interact with such a power supply because it is likely to give you a shock but LED lamp
you usually put it in the socket and you never touch it. And therefore, using a capacitive drop
power supply is a good option, it is inexpensive and it serves the purpose.

Another option is and it is a very very common approach is to use a switching mode power
supply. In this switching mode power supply, which is being used in phone and portable device
chargers, you without the weight and bulkiness of a traditional step down transformer, what it
does is it takes the AC voltage and rectifies it right away.

And usually such switching power supplies are also called as Universal Power Supplies which
means, that the same power supply will operate in a 220 volt domain as well as 110 volt domain
because when you are producing a when you are creating a product, you do not want to have
alternative options that if this is to be sold in countries which have 220 volt supply then this is
the power supply to be used and if it is to be sold in countries which have 110 supply then you
have a separate power supply.

These power supply power supply solutions are designed so that they can cater to any supply
voltage from 100 volts to 250 volts. In these they take the AC input rectified directly, which
would give them a maximum rectified voltage of about 340-350 volts and then they power a
small electronic circuit, that electronic circuit produces a switching waveform which is in the
high frequency domain. The typical power line switching frequency is 50 or 60 hertz, which
increases the size of the transformer. But if you increase the frequency the relationship between

182
size of the transformer and the frequencies inverse proportionality and so, if you increase the
frequency it reduces the size.

So, switching mode power supply use about 100 kilohertz or a few hundred kilohertz of
switching frequency which lead to a very small tiny transformer. Having a transformer also
isolates the power supply DC side of the power supply from the mains. And so, most of the
chargers whether they are for cell phones or for whether they are for your laptop computers fall
in that category. So, you could consider using a switching mode power supply also and after you
have rectified your voltage you would want to filter it before you stabilize that voltage.

So, let us see what all elements are required for creating the power supply. If you have rectified
and you have reduced the input voltage from the mains supply to a low voltage and you want to
power your system, you want to ensure that the polarity of the voltage does not affect your
circuit.

(Refer Slide Time: 12:50)

So, we have two options one what I call as polarity safe so this is a polarity safe option, let me
choose a different color of the pen. So, this is a polarity safe option meaning if the polarity here
is not plus and minus here, it would not damage the system because this diode will block. If the
polarity applied here is minus and plus like this, this diode will block and will prevent damaging
the rest of the components.

183
If you want polarity proof meaning irrespective of the polarity, your system should still continue
to operate, then instead of a single diode, you can utilize a bridge rectifier configuration as seen
here, this is the bridge rectifier component configuration. This will ensure that whether you apply
a DC voltage or a low AC voltage, you will get a fixed polarity which is plus here and minus
here and then this could have further filtering and regulation to power your embedded
application. So, these could be considered.

(Refer Slide Time: 13:58)

Now once you have rectified or reduced the voltage and then rectified the AC voltage and you
have filtered it, you would want to employ a voltage stabilization circuit and these voltage
regulators are of two categories, two types, one is called the linear regulator and the other is
called switching regulator. Both use electronic components and yet and they use the same
components for example, they use transistors they use rectifier diodes they use reference diodes
and yet one class of circuits is called linear regulator, the other is called switching and what is
the difference? How is the difference?

184
(Refer Slide Time: 14: 44)

You know, how does it reflect, one the if I look at a BJT transistor then there are four modes of
operation in which the BJT works. One is forward active, the other is reverse active mode of
operation for a BJT, the third is saturation and the fourth mode of operation is cut off. Usually,
the transistor is operated either in the forward active mode or in the saturation mode or in the
cutoff mode, reverse action is reverse active mode is often not used.

Now, such circuits in which the transistor primarily operates in the forward active region, they
lead to class of circuits and class of regulators what we call as linear regulators. On the other
hand, if you do not want the transistor to operate in the forward active region, you could operate
it in the switching region using saturation and cutoff.

And when you build a power supply regulator using the transistor which operate in primarily in
the saturation and cutoff region, such regulators are termed as switching regulators. Each one has
an advantage over the other. And we will consider the advantages and disadvantages of both
these types of regulators.

185
(Refer Slide Time: 16:22)

Linear regulators where the BJT or the active element operates primarily in the forward active
region, they are very easy to use, they are inexpensive and they do not require any other
component other than the voltage regulator, if it is of a integrated nature. The classic example of
a linear voltage regulator is what is called as the 78xxx series for example, you may have used a
7805 in your electronic circuit design. And this provides a plus 5 volt power supply when the
input could be anywhere from 8 volt to more than 20 volts.

So, you can provide this as the DC voltage and this regulator will give 5 volts and there are many
other components, many other output voltage options available 5 volts is one of them. But this is
historically, this was designed in 60s and 70s they were very popular at the time, but nowadays
there are a lot of reasons why people are not using these anymore. One of the reasons is that they
require a large dropout voltage, what is a dropout voltage? Let us look at.

186
(Refer Slide Time: 17:52)

So, if this is the if this is the regulator, if this is my regulator and I apply a DC voltage here
which is unregulated meaning it could be fluctuating in nature and I want Vout which is fixed
and stable. The difference between this and this is called dropout, v dropout is equal to VDC
minus Vout and V dropout has to be greater than 3 volts for the 78 series of regulators. Also,
even if I have not connected any load, if this is the place where I could connect load, even if I do
not connect any load, you will find that these linear regulators consume some current and this is
called the Quiescent current this current If it is not, if it is going into the regulator.

This is your regulator if certain amount current is going in, even though there is no current going
out. And obviously, this current has to come out through the ground terminal reference terminal.

187
(Refer Slide Time: 19: 11)

This is the Quiescent current and these 78 series of regulator suffer from a large Quiescent
current, how large this is typically 10 milli amperes and the dropout voltage has to be more than
3 volts, which means 3 volt into 10 milli ampere roughly 30 milli watts of power is being wasted,
just to power the, just to keep the regulator working and in current technology environment 30
milliwatts is a huge amount of power which you do not want to waste merely as heat.

What are the alternatives? Well, instead of using traditional 78 series types of voltage regulators,
they have developed a low dropout voltage regulators they are called LDO regulators and they
also offer low Quiescent current.

188
(Refer Slide Time: 20:05)

Let us see what are the numbers in if I look at the 78 series of regulators, I have roughly 3 volt
and IQ is of the order of the Quiescent current is of the order of 10 milliampere. But if I look at
other options that is use LDO, then LDO will give you a V dropout as low as 0.1 volt and IQ as
low as 10 to 100 micro ampere. So, if you are going to design your power supply for embedded
application and you are forced to use a linear regulator for various reasons it is advisable to use a
LDO type of linear voltage regulator instead of their traditional 78XXX series.

(Refer Slide Time: 21:09)

189
I am going to show you certain voltage regulators starting from the simple ones to more complex
ones. So, look at this circuit here, the input voltage is the voltage that you would get after the
grid power or whatever is the original source of your power it is reduced to low voltage levels
then rectified and filtered and it is applied here. The simplest regulator would use a zener diode,
you can get Zener diodes from as low a voltage of 2.7 volts to a higher voltage and in power
ratings of 400 milliwatts to 10’s of watts, maybe of 10 watts, and so it could be used to create a
power supply system.

This is not a very efficient system for various reasons, but you would also it uses several
components one you need a series limiting resistor you need the actual Zener diode and you need
two capacitors as I mentioned, one of the capacitors the C1 would be a ceramic capacitor and C2
would be an electrolytic capacitor typical numbers are for C1 would be a 0.1 micro farad ceramic
and C2 could be a 100 micro farad of suitable voltage rating of the type of electrolytic.

(Refer Slide Time: 22:59)

So, this is one simple now what is the problem with this power supply topology? Is that it
operates the zener in the reverse region, so, this is the voltage Vf, this is the reverse voltage Vr
and this is the point where your VZ the Zener principle kicks in. This is the minimum current,
Imin that must flow through the Zener diode for it to regulate the voltage and based on the power
dissipation characteristics of the diode this could be the Imax.

190
Now, you see this is a large range, but from the minimum to the maximum you get certain
variation in the input voltage. So, if you bias your zener at the center point if the input voltage
changes and reduces then it is going to go in this direction, it would have, the Zener diode will
conduct less current. If the input voltage increases, it would travel in this direction and it would
pass more current through the Zener diode. The Zener diode acts like a shock absorber against
the shock that is the variation in input voltage or variation in the load current.

If the load current changes because you have changed the amount of current being consumed in
the output, it has only one way to go which is through the zener diode. So, if the load reduced if
the input voltage is constant and the load current changes, if the load current reduces, the rest of
the current has to flow through the zener diode and it will move it in this direction.

If the load current increases, the operating point will shift in this direction leading to a variation
of output voltage of this nature. How much is this voltage, you have to refer to the datasheet of
the zener diode to estimate that.

(Refer Slide Time: 25:17)

Now, we would like to reduce this variation, which would lead to a bad specification, bad
voltage regulation feature of this power supply. And so, we use an alternative mechanism, we
use this zener diode together with a what we call as a series pass transistor in this case a emitter
follower. Now, because the transistor has a gain current gain of beta and the load is going to be

191
connected here, if we have the same amount of load as in the zener only power supply the zener
current would be reduced by a factor of beta.

(Refer Slide Time: 25:50)

Which means if I look at this, instead of this entire variation, the variation would be reduced by a
factor of beta which means it might be restricted to a smaller region if it is restricted to a smaller
region, the corresponding variation in the voltage gets reduced.

(Refer Slide Time: 26:08)

192
And so, if I use this topology, where apart from the zener voltage, I use a series pass transistor, it
would give me a better voltage regulation figure. However, the output voltage is no longer equal
to zener voltage it is equal to zener voltage minus the voltage drop across the VBE of the series
pass transistor, this can be easily compensated by adding a normal diode in forward bias.

(Refer Slide Time: 26:33)

So, that now the output voltage is equal to zener voltage. This power supply still has problems
for example, if I were to short this for some reason because of a fault or because of some user
adventure it would draw a huge amount of current through this transistor, this transistor will try
this supply that current, but eventually it will lead to a huge amount of power dissipation across
this transistor by this transistor, it would increase the temperature of the transistor and eventually
it will destroy the transmitter, there is no protection available in this power supply.

193
(Refer Slide Time: 27:18)

Now, let us look at another variation of the same instead of a simple transistor, I am going to use
a volt op amp. Now, the op amp because of the feedback, it applies. I am sure you are aware of
how op amp’s work, they operate on two principles, 1) the voltage between the on the V plus and
V minus terminals is near identical and 2) and this voltage is identical or near identical because
the gain of the operational amplifier is very large and 2) the current going into the positive
terminal or the negative terminal is very low and for ideal situations you can take that current to
be 0.

Similarly, the voltage difference between the plus and the minus in ideal situations can be taken
to be 0. In reality that is not the case. Anyway, we can use these two rules of thumbs to see how
this op amp circuit together with the transistor can work as a linear voltage regulator, I apply
zener voltage as in the previous case at the non inverting terminal, the principle of operational
amplifier is to ensure that when you have negative feedback, the two terminals input terminals
will have identical voltage therefore, if the positive terminal the non inverting terminal has a
voltage equal to Vz, the circuit will ensure that the inverting terminal of the power supply also is
equal to Vz.

Which means the output is equal to this zener voltage and the amount of current that you would
want to draw from the output terminal because after you connect the load it will draw some
current will be handled by the transistor. Why? Because if you try to draw too much current an

194
op amp is not designed to handle large amounts of currents typically, the maximum current that
you can draw out of an op amp is of the order of 20 milli amperes.

But if you want to design a power supply, which is capable of delivering hundred milli amperes
you must boost that current capability by using a transistor here T1 also operates as a voltage
follower, but it provides you a beta amount of current gain. So, if the beta is say 100 that means
20 milliampere into 100 this configuration can safely give you about 2 amperes of current. Thank
you very much. I will see you very soon.

195
Introduction to Embedded System Design
Professor Dhananjay V. Gadre (NSUT) & Badri Subudhi
Indian Institute of Technology, Jammu
Lecture 10
Power Supply for Embedded Systems Continued

Hello, welcome to a new session for this online course on Introduction to Embedded System
Design.

(Refer Slide Time: 0:45)

So, in this configuration, if we have the transistor, you want the transistor to handle more amount
of current, then you can use what is called as a Darlington pair, where you use two transistor to
multiply the beta and this is the typical configuration of a Darlington pair here. This becomes
your collector, this becomes your base and this becomes your emitter. Here is the Darlington pair
we used two transistors and the effective gain, the current gain of this transistor.

If this is the gain, beta1 is the gain of the first transistor and this is the current gain on the second
transistor. The effective gain becomes beta1 into beta2. And so this configuration can handle
much larger current. However, please note that now the base emitter voltage is no longer VBE it
is VBE1 for the first transistor, plus VBE2 for the second transistor, and therefore, if you are

196
going to use the Darlington pair in that power supply configuration, the Vout has to overcome
this.

And so the output voltage of the opamp will be such that it overcomes this requirement. And so
if I am going to use this power supply configuration and I want more current, which single
transistor may not provide me the required current gain and I could use this Darlington pair.

(Refer Slide Time: 2:38)

However, still, this power supply suffers from an inability to provide against any short circuiting
attempt at the output. And so we must build in some mechanism so that short at the output does
not end up destroying the power supply and the way it is achieved is through this circuit here,
through the introduction of this transistor T2, this ensures that the current is never going to
exceed a certain amount.

In this case, the maximum current that this power supply will provide is equal to the VBE of
transistor T2 divided by the value of R2. So, if this voltage is say 0.7 volts and if you choose R2
to be 1 ohm that means this power supply can provide 700 milli amperes of current. What
happens if you short it? If I short this power supply, yes, the current will try to exceed 700 milli
amperes, at which point it will enable T2 it will turn T2 on and it will provide an alternative path
for the current from the opamp instead of going into T1 and getting magnified by a factor of

197
beta, which would lead to the destruction of T1, it would divert the current instead of going into
T1, it would carry through this.

And since it would not be magnified by a factor of beta, it would protect the power supply. So,
this is a standard method of short circuit protection.

198
(Refer Slide Time: 4:08)

Three terminals, regulators of the type that we have been discussing, the 78xxx series I have
illustrated, two simple regulator configurations. One is a 7805, you see, these are the additional
components that you require apart from the regulator, a couple of capacitors are the input and
output and nothing else. Maybe an indicator to indicate that the power supply is on with the help
of this resistor here and LED this is a simple 5 volt linear regulator in case you want the output
voltage to be other than what fixed output voltage regulator, such as 7805 can provide, for
example.

In fact, this is a complete series you get 7805, then you also have 7806, 7809, 7812 and so on,
7815. And in fact, there is also a counterpart of for negative voltages, which is 79 series, if you
want an voltage for example, of 9.5 volts, then you can utilize this three terminal adjustable
voltage regulator where it uses this formula, Vout is equal to 1.25 volts which is the reference
voltage inside this and R3 by ratio of R3 by R4 here R3 and R4 and you can tell there R3 and R4
values to give you whatever arbitrary voltage within the range of output voltages that are
available with this adjustable 3 terminal voltage regulator.

This number is LM317, and this gives you an adjustable output voltage with the current of
maximum of 1 ampere.

199
This could be used, but as I mentioned, these are all of the past these days, people do not use
traditional 78 series of voltage regulators for the, for the problems that I mentioned, that they
require a large dropout voltage and they required a large percent current.

(Refer Slide Time: 6:22)

Instead, people are using low dropout voltage regulators. And I already mentioned the
characteristics that they offer. A low voltage of 0.1 volt dropout and about 10 to 100 micro
amperes of quiescent current. Here are some examples. If you want to power a 5 volt or a 3 volt
or a 2.7 volt circuit, you can use LP2950 this comes in various versions which provide 2.7 or 3 or
3.3 even 5 volt output another adjustable voltage regulator of the LDO variety is LP38500.

And this requires a 0.6 dropout voltage, which is still much lesser than the 3 volts that are 78
series requires. Now, linear regulators are great, they are simple to use. But one of the big
problems is that they are very wasteful. If your battery is say 12 volts lead acid battery and you
want to power your circuit at 5 volts, so the linear voltage would get a difference voltage about 7
volts. And if your system is consuming one ampere of power, let me illustrate this. This is the
important point here.

200
(Refer Slide Time: 7:26)

So, if I am using a 78 or linear regulator of whatever type, irrespective of whether it is a LDO or


a traditional 78 series, I have let us say this is a 5 volt regulator, 5 volt linear regulator. And let
us say I want my load here whatever the load is, is consuming 5 volt at a maximum of 1 empire
of current that it is expected to consume. And let us say my source is a battery which is a lead
acid 12 volt battery, even if I do not consider any quiescent current being consumed by the
power supply regulator.

Still, the difference of this and this is 7 volts. And it is going to provide the battery is going to be
you are going to take of a 1 ampere of current from the battery, therefore the power supply has to
dissipate 7 volt into 1 ampere, which is equal to 7 watt as heat because you only are going to
consume 5 volts at 1 ampere, and so a linear regulator is not a very preferred method of
powering portable applications which use a battery.

201
(Refer Slide Time: 8:59)

What are alternatives that instead of linear regulator, we use switching regulators, switching
regulators as against the linear regulators, where the active elements operate in the linear,
forward, active region. The elements which make up a switching regulator do not operate in the
linear region forward active region. They are either turned on or turned off, meaning they are
either saturated or cut off. And this leads to a high efficiency, typical efficiency figures that you
may expect is of the order of 90 percent.

The disadvantages that give you this efficiency and to operate in the switching mode, it requires
an external inductor. It requires a switching diode, which in some cases could be integrated on
the power supply chip. And it also requires a high current switch, which can turn itself on and
off. Other requirements are that it requires output capacitors to filter the noise that would come
because now your regulating elements are switching on and off.

You require a capacitor, but this has to be a special type of capacitor called low ESR, ESR stands
for equivalent series resistance. If the series resistance of a capacitor is large, it would prohibit
the capacitor from quickly stabilizing the voltage because the R and C time constant would slow
it down and so you need capacitor which are qualified as low ESR even after filtering the output
voltage, you still have relatively large output noise compared to a linear regulator and the type of
the switching regulator that use will depend on what is input voltage that is available and what
the output voltage that you expect.

202
(Refer Slide Time: 10:45)

They are of three primary types, one is called buck voltage regulator, where the word buck
means to bend, that is the output will do less than the input voltage. In some cases, you can use a
boost type of voltage regulator where you can if your input is say 1.5 volts alkaline battery, and
you want 3 volts output, you would use a boost regulator, this is a great advantage because the
linear regulator cannot perform this function. They cannot increase the output voltage more than
the input but switching regulator can, especially in which case you will have to use this boost
type of regulator in case your battery voltage could be more than the output required sometimes.

And sometimes it can fall below the required output, you would need a regulator of the type
called buck, boost. In bulk voltage the output voltage is less than the input, but the output current
can be is more than the input current. And the this is the topology of the circuit topology of a
buck regulator, the buck controller. You need one switch here and switching diode D1 is a
switching diode, this is the inductor. Unfortunately, you cannot integrate and inductor on a chip.

You can integrate this transistor, you can integrate this diode, but the inductor cannot be
integrated. So inductor and this output capacitor, which I mentioned, low ESR capacitor have to
be still outside. Here is an example of a commercially available, complete integrated switching
regulator LM 2575.

203
You still need this switching diode and an inductor and it will reduce the output voltage
compared to the input voltage and do it very efficiently.

(Refer Slide Time: 12:32)

In case you need the output voltage to be more than the input voltage, then use a boost type of
voltage regulator where the output voltage, as you see here, is more than the input voltage, but
then the output current is less than the input current because at the end of the day, power has to
be conserved.

If the input voltage is less than the output voltage, the input current will be more significantly
more so that the product of input current and input voltage is a little bit more than the product of
output voltage and output current. Here is an example this is the topology of switching regulator
boost type switching regulator. It still uses an inductor, it still uses the switching diode and it still
uses the high current switch, except the location of these three components has changed and this
is the low ESR capacitor.

Here is a available example in for TPS61070 is a switching boost type of switching regulator
available from Texas Instruments and using a 1.5 volt battery you can get, say 5volt or 3.3 volts
which is suitable to power your small embedded applications. Other example is you could use
linear technology LT1308 where the input can be in the range of 1 to 10 volts and can provide

204
output voltage up to 34 volts and the switching current can be up to 3 amperes. Switching current
means the current that it uses at the input, it is not the output current.

(Refer Slide Time: 14:14)

The third regulator type of switching regulator is the buck boost, as the name suggest it can
operate either as in the buck mode or the boost mode, depending upon what is expected at the
output and at that time what is the input voltage. For example, if the input output voltage
requirement is say 3.3 volt and the input voltage is 6 volts the regulator will switch in the buck
mode.

If the voltage falls below 3.3 volt the regulator will seamlessly switch into the boost mode so that
from 3 volts input, it can continue to provide 3.3 volt power supply. Typically, this is the
situation in your smartphones and mobile phones where the source of energy is a battery. The
nominal voltage of these batteries 3.6 volts when it is fully charged, it can be as high as 4.2 volts
and you can safely discharged this battery up to 3 volts. And the required output voltage could be
3.3 volts as one of the voltage requirements of a microcontroller.

So, if you are going to regulate this voltage, this battery voltage, you have to use a buck boost
regulator so that when the battery is fully charged, the regulator operates in the buck mode. As
the battery gets discharged and tries to fall below 3.3 volts, the regulator seamlessly switches
into the boost mode and continues to supply 3.3 volts.

205
Here is an example, and here is before that here is the topology of a buck boost controller. Now
it has merged the two components of buck and boost, so you have twice the number of high
current switches two switching diodes and only 1 inductor, and based on the requirement, it
would either switch Q1 and D1 or Q2 and D2, depending upon whether it is the buck mode or
the boost mode and maintain the output voltage to required values.

Here is a commercially available example of a buck boost regulator. This is LM3668, originally
from National Semiconductors but National Semiconductor is today part of the Texas
Instruments. And so this is being produced by Texas Instruments. It has input voltage range of
2.5 to 5.5 volts. The output is fixed, either you can choose the 2.8 output or 3.3. And the output
maximum output current you can draw out of buck boost regulator is 1 volt.

So, here we have considered the three common topologies for switching regulators, which could
be very common, which would be very commonly used in embedded applications.

(Refer Slide Time: 16:56)

Here is an example of a cell phone charger where you take the input voltage from the source,
which could be 100 to 240 volts, and you still provide 5 volt output, but with the output and
input are well isolated using this opto coupler. I am not going to go into the design of this, but
this ensures a very efficient power supply for a charging the batteries in such portable
applications.

206
(Refer Slide Time: 17:35)

Now, I have put together a list of various topologies, including the source and the regulator and
so on, so one option could be you use a line frequency transformer, when I use the word line
frequency means 50 or 60 hertz to stop drop down the voltage, followed by linear regulator,
which could be fixed or variable. You could have that but use a switching regulator buck or
boost. You could have a completely switching power supply. As I showed in the previous slide,
you could have a capacity attenuator meaning instead of using any transformer, at the input you
could use capacitance to attenuate and then have a Zener regulator.

You could use alkaline battery followed by a buck or boost topology based on your voltage
requirements.

207
(Refer Slide Time: 18:23)

You could use a lithium battery with a boost to give you 5 volts. You could use lithium battery
with buck boost to give you 3.3 volt, for 5 volt output. You only need boost because the battery
voltage is never going to exceed 5 volt so a boost type of switching regular is sufficient. If you
want a power supply, which is 5 volts plus 3.3 volts, you and the source of power is lithium, then
you would use boost for 5 and then using a buck or a LDO you could get 3.3 from either directly
from the lithium or from the boost you could use at the output of the boost regulator you could
use a LDO to give you 3.3 volts.

You could use radio frequency transmissions using an antenna and they are extremely low
power. But they are enough for many applications, as is illustrated of a in the RFID application,
you could use a Faraday based generator, you saw two examples of tube with the magnet and
coil, copper wire of coil to produce voltage, this would be rectified and then filtered and then you
would you would use appropriate regulator to get stabilise voltage.

You could also have a solar panel which would charge a battery followed by a regulator to
provide. Another method is using the resonance, vibration inherent in buildings which have air
conditioning because the air conditioning equipment, these buildings are vibrating at a certain
frequency. There are solutions where you have power converter which will stick to the wall of
these buildings.

208
They are tuned to the frequency at which the building is vibrating and they provide miniscule
amounts of power but often times this is sufficient for powering monitoring equipment. And then
you could use a thermoelectric based solution what is called a TEG which essentially is a
thermocouple or a regulator based on that to power your application.

(Refer Slide Time: 20:35)

Modern ICs are designed such that the chip is partitioned in several parts the periphery of the IC
often is operated at higher voltages and the inner parts are operated at higher frequency and
therefore lower voltages so has to maintain a uniform power dissipation across the chip so as to
maintain a uniform power dissipation.

Oftentimes, they may have a separate analog subsystem and I have already discussed that how to
power it. And this would require multiple power supply voltages required by such ICs.

209
(Refer Slide Time: 21:14)

In the next slide I have taken from the datasheet of a high end Texas Instruments
microcontroller. And as you see, it requires three power supply voltages 1.1 volts, 1.8 volts and
3.3 volts and you see the current expected out of these three power rails is such that the product
is more or less uniform, so that when I have if I have this, IC usually it will be split in three parts,
the periphery, the middle part and the core.

The core will be operated at the lowest voltage because it is going to operate at highest
frequency. The periphery will be operated at highest voltage because it can then provide large
noise margin but it will have to operate at lower frequencies and the middle one would be an
intermediate voltage. And each of these parts consume an amount of current such that the
product of current and voltage is pretty much uniform so that the entire chip dissipates uniform
amount of power so that there are no voltage differences which may lead to thermoelectric
effects or they may produce physical warping in the chip.

One solution is to use a linear type of regulator for all the three power sources where the input is
a lithium battery as can be seen. This is typically a lithium battery voltage and you see the first
power supply would be 30 percent efficient, the second will be almost 50 percent and the last one
where the output voltage very close to the battery voltage will give you about 90 percent of
efficiency. And this is not an acceptable solution because you are wasting so much power in
these two power supply voltages.

210
And the solution is not to replace all the power suppliers with switching regulators because this
power supply is already giving you about 90 percent efficiency. You will not gain much by
replacing a linear regulator with a switching regulator because it may give you better efficiency
of 2-3 percent, but at a much higher cost of additional components.

(Refer Slide Time: 23:31)

And so an ideal solution would be one in which the two, these two power supply’s regulators are
replaced with switching regulator and the third one is still maintain at of a linear type. This is the
expectation out of a designer when you are designing a complete embedded system, you have to
consider the power supply requirements of the microcontroller and other components in your
system and to design voltage regulators compatible with the requirements.

211
(Refer Slide Time: 24:00)

Microcontrollers, modern microcontrollers try to conserve available power based on the required
performance required at any given point of time by at least having three modes of operation. One
is the active mode where you are operating at full capacity, full performance, such as in a mobile
phone or a smartphone. If you are using it the microcontroller inside is operating at the highest
capability but when you are not using the mobile phone, it is lying down and you are not
receiving any phone call or any SMS, then it tries to save power by switching the display off and
so on.

And also maybe some internal circuit elements are switched off. The clocks signal to these
subsystem is turned off so as to conserve power. And the last mode of operation is power down
mode where the clock oscillator itself is switched off because clock oscillator is one of the
largest power consuming elements in a logic circuit. By turning it off, you can save power if you
are not going to use the system.

Let me tell you your mobile phone yours, whether it is smartphone or your regular non smart
mobile phone indeed offers these three modes of operation when you are using it it works in the
active mode, when you are not using it, but it is still on and you keep it on your table or
somewhere it is in tries to go into sleep mode. And when you so called switch it off, you think
you are switched off the mobile phone? Sorry, mobile phone is never switched off. It only enters
this power down mode.

212
And you actually you do not have on-off switch on a mobile phone, the so called on-off switch is
only a soft switch, which only is used to change the mode of operation from active mode to
power down mode. In power down mode your battery is still connected to the microcontroller,
the microcontroller is still getting supply voltage, except it is not doing anything. Why? Because
the main source of clock, which is responsible for all actions and activities on the
microcontroller, has been turned off.

And to get back into any of the other modes sleep or active mode, you have to press that
so-called on-off switch you to hold it, pressed for much longer duration, which ensures that the
oscillator starts oscillating, the oscillations are stabilized, and only then when the clock oscillator
starts working correctly, does it activate the rest of the circuitry on your microcontroller and then
it starts working.

So, these are the modes of operation, these are broadly the three modes of operation are typical
microcontroller may offer more varieties in the active mode. It may offer more variety in the
sleep mode and power down mode. In fact, as we will start discussing the MSP430
microcontroller, you will see that it offers many, many sub modes which would be classified as
sleep or power down modes, so that the you end user you the designer has more options to
choose from so as to conserve whatever battery power that is available.

(Refer Slide Time: 27:08)

213
Again, to backup the source you may need to use certain types of batteries. And these days
another alternative is to use super capacitors. Super capacitors are ordinary capacitors with huge
amounts of capacities. For example, in one of the projects that I showed you, it used a super
capacitor, which was a 1 Farad 2.5 volts capacitors and you know, the amount of energy that this
capacitor is capable of storing, it is equal to 2.5 coulombs, which is a huge traditionally the
capacitors that you used in your power supply filtering typically say 1000 micro farad at 25
volts.

This is just 25000 micro coulomb which is a much smaller fraction compared to the capacity of a
super capacitor. So, super capacitor could also be used a super capacitor is far better than
batteries because it has much longer life and it is not as hazardous for disposing compared to
battery.

(Refer Slide Time: 28:22)

These are the typical commonly available batteries these days that people are using, you need to
know the type of battery, the terminal voltage, what is the power versus weight ratio, what is the
efficiency and how many times can you charge and discharge this battery?

And this can be an important consideration depending upon the product that you are designing. If
you are making a cell phone kind of product, you could perhaps use lithium iron or lithium poly.
But if you are going to fly outer space probe where the lifetime is only a few years in the in these

214
kind of batteries, but your outer space probe may take several years to reach its destination.
Certainly these type of batteries are unsuitable to power the backup as a backup power in such a
space probe.

So, you have to find alternative other types of battery chemistries which have which may not be
as efficient as lithium iron or lithium poly, but they have much longer life cycles. With this we
come to the end of this lecture. I will pick up from here in the next lectures we are going to now
get on to understanding the MSP430 microcontroller and the architecture and other issues related
to this microcontroller. Thank you very much I will see you very soon.

215
Introduction to Embedded System Design
Professor Dhananjay V. Gadre (NSUT) & Badri Subudhi
Indian Institute of Technology, Jammu
Lecture 11
Introduction to MSP430

Hello, Welcome to a new lecture on this online course on Introduction to Embedded System
Design. I am your instructor, Dhananjay Gadre. Today, we are going to start our discussions on
the most important building block of out of our six box model, which is the embedded computer
block. And today we are starting real discussions on MSP430 microcontroller. MSP430 is a entry
level microcontroller from Texas Instruments. It is one of their oldest offerings as far as
microcontrollers are concerned.

(Refer Slide Time: 1:00)

So, here is the we are going to talk about the introduction to MSP430 and subsequently we will
cover the architecture.

216
(Refer Slide Time: 1:09)

MSP, as I mentioned MSP430, is a microcontroller from Texas Instruments, it is one of the


simple microcontroller families from TI. MSP stands for mixed signal processor. This is to
indicate that the microcontroller has a CPU and another digital building blocks. And apart from
that, it has support for analog circuits and that is the reason why it is called mixed signal. It is a
16 bit processor, so if we go back to our discussion on various classification methodologies that
we have that we have discussed.

From the point of view of bit handling capacity, it is a 16 bit processor, as you see here the 16 bit
data path which connects to the memory which is integrated on the chip. The amount of memory
and peripherals and various types of memory, in fact, can be accessed using a address bus, which
is for most cases 16 bit address bus which means it has 2 raise to power 16 address locations,
memory locations. And in some cases, when you want to have more memory than is possible
with 2 raise to power 16 combinations, it also uses a 20 bit address bus. The data bus is 16 bits.
This processor has been designed specifically for low power applications.

The intended application areas of general-purpose sensing and measurement, so you may create
instruments where you sense various physical parameters, measure them, process them and
provide an appropriate output. It has a concept called capacitive touch sensing you may correlate
with that very easily, because these days smartphones come with the touch and the kind of touch
that is used on smartphones these days is a capacitive touch.

217
And so almost all the pins are a lot of pins of MSP430 microcontroller have a capability to be
sensed using the capacitive touch sensing. It can also be used for ultrasonic sensing, ultrasonics
are frequencies about 20 kilohertz. So, it has special support for creating waveforms so that you
can operate in the ultrasonic range.

(Refer Slide Time: 3:41)

This series MSP430 was initially launched in 1993 and in 1997, it was released to the entire
world. Like we mentioned, typically a microcontroller family would have a lot of offerings so
that an end application could use an appropriate device, which is optimal for that application.
And so MSP430 has more than 500 different microcontrollers.

These include from the point of view of capabilities, what kind of hardware support a
microcontroller has, the amount of memory it has, and also the physical footprint, small chip and
big chips and so on. MSP430 series supports a low power operation. And to support that low
power operation, it has 5 low power modes.

You would recall an earlier discussion where we talked of operating modes of a microcontroller
and we are broadly used three terms active mode, sleep and power down. The sleep mode of
operation here refers to these five modes of low power operation and will see the details of these
operations.

218
(Refer Slide Time: 4:57)

Here is a snapshot which captures almost all the microcontrollers available in the MSP430
family, you have the capacitive sensing MCU here this one.

And it has the nomenclature uses these numbers, the maximum frequency operation of members
of this family is 16 megahertz and it has FRAM for the program memory and you can have up to
16 kilobytes of programmed memory. And SRAM for storing data, you can have up to four
kilobytes. And the number of input output general-purpose input output pins that are available in
this segment, you can have from 15 to 19 GPIO pins.

Then, we have what they call as value line microcontroller units, which means one can expect
them to be very inexpensive. They have two series for that, one is a FR2xx and the other one is
G2 series. The first series again can be operated up to 16 megahertz. It has FRAM up to 16
kilobytes and SRAM up to 4 kilobytes. And the number of GPIO pins as you see, is much larger
from 16 to 64 pins you can have so you can expect that the packaging for this line of
microcontrollers would be large and the G series and incidentally, we are going to use in our
experimentation we are going to use G series of microcontrollers.

They can also operate up to 16 megahertz. They do not have FRAMs, instead, they have flash
memory and you can have up to 56 kilobytes of flash memory and up to 4 kilobytes of SRAM.
And the number of input output pins available in this series you can have from 4 pins to 32 pins.

219
Then, we have what they call as performance sensing MCUs. And you have FR5 and F5x series.
The first one has a maximum frequency up to, again, 16 megahertz. It offers flash memory. It
offers FRAM for program memory up to 256 kilobytes.

And you see the moment this number is above 64k that means it would be using address bus,
which is the 20 bit address bus. It has SRAM up to 8 kilobytes and the number of IO pins is large
from 17 to 83 pins you can have. The second series the F5X/F6X operates up to 25 megahertz
and it has flash memory, not FRAM for the program memory. And you can have up to 512
kilobytes it has SRAM up to 67 kilobytes. So, it is a huge amount of ram that is available and the
number of input output pins is again large 29 to 90 pins you can have.

And then you have what is called as other MSP430 MCUs. They have two series F2 F4X and
F1X and the first one, both of them actually have a 16 megahertz clock, both of them offer flash
memory. And a number of IO pins is for the first one 14 to 80 and the other one is 10 to 48. And
the SRAM in the first case is 8 kilobytes and here you have slightly more at 10 kilobytes. So, this
single table in a way captures the kind of variety that is available in the MSP430 family of
microcontrollers.

220
(Refer Slide Time: 8:54)

221
Let us see some of the more features of this family. Before that, here is a nomenclature. Let me
see if I can zoom it. So, you would see these microcontrollers would be available starting with
this number MSP and then 430, because there is a 430 platform the next number or numeral used
is which indicates the kind of memory that is available. So, if it is F that means it is flash, if it is
G, then also it is flash. If it is F.R that means the microcontroller would have a FRAM memory
and so on. And then the other two next digit tells you what kind of frequency operation it offers
and so on.

At the bottom it also has a variety in terms of the temperature range for which these
microcontrollers are guaranteed to operate. And we have three temperature ranges. The standard
one is 0 to 50 degrees. Then you have industrial range, which is minus 40 to 85 degrees, and then
the extended range, which is minus 40 degrees to 100 plus 105 degrees centigrade. And of
course, the packaging, the overall packaging is in the form of small or large reels or you could
get these ICs in the tube form also.

And this is important information when you are doing mask manufacturing certain
manufacturing equipment requires the components to be housed in a reel certain other
manufacturing techniques, require them to be in a tube or even tray and so on. So, this sort of
gives you an idea of how to interpret the complete part number for this series of
microcontrollers. When you go to the Texas Instruments website, which is incidentally

222
www.ti.com, you could search for MSP430 microcontrollers and you would get to know more
details about this.

(Refer Slide Time: 10:58)

So, the important feature is that it is a 16 bit RISC architecture, it is a risk architecture. So, RISC
indicates that the instruction set architecture is of the RISC variety reduced instructions at
computer and from the memory interface point of view, it is a Von Neumann memory
architecture. Here, it what this indicates is that the program memory, the data memory and the
registers they are all mapped into a single memory map, as you see here.

223
(Refer Slide Time: 11:39)

This is the memory map, and in a single memory map, using a single set of address bus here and
a single set of data bus, you are able to access the ROM, which is the program memory, the
RAM and the registers and so on and so forth. So, this is to highlight the nature of MSP430
microcontroller family.

(Refer Slide Time: 12:06)

These are the features, the supply voltage unlike the microcontrollers of previous era, where they
would operate at standard 5 volts.

224
You may also remember that TTL ICs transistor transistor logic ICs operated at 5 volts but as the
frequency operation increased, continuing to use a higher supply voltage led to higher power
dissipation and one way to reduce power dissipation would be to reduce the supply voltage. And
so MSP430, since it is it calls itself a low power microcontroller family. Therefore, one way to
reduce the power dissipation is to reduce the power supply voltage. And here you can operate it
in a wide range of voltage between 1.8 volts to 3.6 volts.

This makes it very easy to operate from a battery of various types and we will see all kinds of
batteries we could use. The low power consumption numbers are mentioned here in the next part.
In the active mode, it only consumes 0.23 milli amperes 230 micro amperes of current. And that
happens when you operate it at one megahertz clock and the supply voltage is 2.2 volt if you
operate it in a what is called a standby mode, which is one of the low power modes that is
available, it consumes a mere 0.5 micro ampere of current.

And you can imagine that if you have a coin cell or a button cell, even on the single button cell
for how long this microcontroller can continue to operate, provided it has large periods of time
when it is in the standby mode. But once in a while it would wake up and do real work and then
go back to the standby mode. If you want to turn the internal operations off and just retain the
contents of the RAM, then the power consumption will go down to 100 nano amperes. That is
0.1 micro amperes that is a really low current.

It offers a variety of low power operating modes, five low power operating modes that can be
selected by the user through appropriate program, executing certain instructions. And you can go
from low power mode 0 to low power mode 4. While you are in one of these low power modes.
And if you want to go get back to the active mode, you do not want to waste time doing that
switching.

And in this case you can get back to active mode in less than one microsecond. So, these are very
important and salient features of MSP430 microcontroller family.

225
(Refer Slide Time: 14:51)

The you can, as you noticed in that earlier slide that the dominant frequency operation is 16
megahertz, so if you operated your microcontroller at 16 megahertz, the clock period will be 62.5
nanoseconds.

And in one clock cycle, you can execute instructions which would transfer data from a register to
register. Of course, other instructions would take more clock cycles and therefore they would be
taking more time. But this is the fastest instruction that you can execute on MSP430
microcontroller. The internal clock generator, which could take inputs from external pins, we
will see which are those pins or you could utilize internal RC oscillators offer a wide variety of
options.

One of them is you can have calibrated internal frequencies up to 16 megahertz, and you can
choose whether you want to operate at 1 megahertz or you can want to operate at 8 or 12 or 16
megahertz. It also has internal, very low frequency oscillator, up to 12 kilohertz. And this is a
very, very small frequency. And in case you do not have much computational activities to
perform, you could switch yourself into low frequency, which will reduce your power
dissipation.

You can use an external 32 kilohertz. 32 is exactly the 32768 hertz that I had mentioned. This
kind of RTC crystal could be used as an external clock source, or you can have externally

226
generated digital clock source. You can apply to MSP430 as a source of clock, which could be
internally utilised. And so and you can change the clock frequency. What we had mentioned, one
of the salient features of contemporary microcontrollers is the ability to scale the clock frequency
of operation. MSP430 has that feature.

(Refer Slide Time: 16:56)

Now for the input output it offers you two timers they are referred to as timer A and it has three
captured compare units. These are requirements of a timer that if you want to say how much time
has elapsed, how much time has elapsed, has no meaning. But the way it is interpreted, it is that
you when the clock clocks the counter, it starts incrementing and when that value is equal to
certain compare register value, then you say this much time has elapsed.

So, it has three compare capture registers with which you can do variety of things. The counter
these timers are 16 bit and therefore they can count from 0 to 65535. That is the dynamic range
of these timers and counters. It also have up to 24 pins, which have capacitive touch enabled
capabilities, and all the GPIO pins could be utilized for that, this is a very important feature of
MSP430 microcontrollers.

227
(Refer Slide Time: 18:07)

For serial communication, it offers a wide variety of communication protocols again, looking
from the point of view of one of the building blocks, one of the six building blocks that we
discussed, and there was this block regarding communication channels. And so this
microcontroller offers built in communication protocols and the communication interface is
called universal serial communication interface. It has these options you can have a UART,
which is the universal asynchronous receiver and transmitter.

You could also utilize it for infrared communication, bidirectional infrared communication IrDA.
It could be used for serial peripheral interface, what is called as SPI bus. And if you remember
from those discussions SPI and I square C that is inter IC communication were classified as intra
device communication that is within your gadget that you are building that embedded system that
you are building. If you want the microcontroller to communicate with an external IC which had
this or this protocol, you could use the built in protocol built in communication capability of
MSP430 to communicate with devices on within the system.

It also has a on-chip comparator that is an analog comparator , meaning something like this. This
and it is not just one single comparator , it has many, many inputs which could be routed to this
or the pin so that you can do a variety of comparisons, voltages. It also has a ADC and we will
see more detail about this ADC built in ADC.

228
(Refer Slide Time: 20:02)

The ADC is capable of 10 bits of resolution here and up to two hundred thousand samples per
second. That is the kind of maximum sampling rate that you can achieve out of this ADC.

ADC also require the reference voltage and you could choose an internal voltage reference of 1.5
or 2.5 volts. Of course, if you are if you are going to utilize an internal 2.5 volts of reference
voltage then your supply voltage has to be obviously higher than 2.5 volts. You could also have
an external reference voltage and we will see the pin out of this microcontroller, a sample
microcontroller, see that there are certain pins on which you can connect external reference
voltages.

Now, ADC requires that when the conversion is in progress, that the input voltage should not
change. This is a critical requirement of a ADC and MSP430 has an integrated sample and hold
units where the sampling frequency, which is up to 200 kilo samples per second. But you can
sample it at lower frequencies also. And it has a sample and hold for all these inputs. And you
can have up to 8, you can have up to 8 ADC inputs. That does not mean that it has 8 ADCs it
simply means that it has one ADC if I draw the ADC block diagram like this, it has 8 channels.

And with the multiplexer using a multi analog multiplexer and you can select at any given time,
one of the inputs will be connected to the actual ADC and a conversion will be performed. And

229
this is how the conversion would look like if you could sample it here, but in reality that value
will remain constant till the next conversion begins here and so on.

So, a wavefrom which the waveform which is shown in white will, once you discretise it will be
represented in the red signal that you see in this diagram, this is the result of ​discretization
performed through ADC.

(Refer Slide Time: 22:19)

Now, we will discuss more features that MSP430 has and I encourage you to map these features
with the salient features of modern microcontrollers that we had covered in a previous lecture.

And you can realize you would realize that MSP430 is a truly modern contemporary
microcontroller. It has reset source, one of the ways of resetting I had mentioned is a brownout
detector. Of course, it has use a reset. Also, we will see which pin is use for that you can program
you can download the program into the memory of the microcontroller if this is your MSP430.

You can download the code in a variety of ways, one of the methods is called serial onboard
programming, which means it uses two pins to download program. Apart from that, you can use
JTAG interface for downloading the program and you can also use and in-application
programming method using a pre-programmed boot loader, which is available in the flash
memory of the microcontroller, you could utilize it.

230
If you choose to use the in application programming that is programming with boot loader, then
it uses the UART which MSP430 has. And in fact our MSP430 evaluation kit, which is the
MSP430 lunchbox, uses this method. This allows you to program microcontrollers with very
little external support. And we will show you variety ways of actually making your own
evaluation kit. In case you do not have access to the lunchbox, we will show you how you can
create your own set up.

While programming in many microcontrollers, you require some external voltage. But in the
case of MSP430, no such voltage required. And so all you do is just connect some wires to your
microcontroller to your desktop or laptop, and you can quickly download the program. And once
the program is downloaded in the memory of the microcontroller, you can secure it by invoking
code protection, using security fuse. And this will ensure that the program, which is inside the
microcontroller, is secure from being copied and hacked by external you know elements. So, this
is a very important feature to protect the intellectual property of your product.

(Refer Slide Time: 24:54)

Let us see some more features it offers you on chip emulation, which means you can once your
download your program, you would like to evaluate how it is functioning and it uses spy-bi-wire
protocol, which is a SWD name that Texas Instrument gives to serial wire debugged, called
spy-bi-wire, and it is actually a serialized JTAG protocol.

231
(Refer Slide Time: 25:31)

Let me explain to you JTAG, because we have used this term several times a JTAG is JTAG
interface it stands for Joint Test Action Group. It is the name of the protocol. It is a 4 wire serial
protocol it has 4 pins TMS, a clock signal called TCK, a data output called TDO and a data input
called TDI and this was primarily used by a manufacturers of digital ICs for testing, and it uses a
concept called test access port over a period of time.

This protocol has been adopted and incorporated in microcontroller units and MSP430 has
embraced it. And so you would see some of the pins of MSP430 have JTAG functionality. But
because it uses 4 pins for such microcontrollers where the number of available pins is less, Texas
Instruments created a mechanism to use only two pins and out of those two pins to recreate the
JTAG interface of these 4 pins.

232
(Refer Slide Time: 26:59)

And that is the meaning of the spy-bi-wire protocol as you see, using two external pins here, it
connects to the internal spy-bi-wire logic, and from there it recreates the standard JTAG
interface, which allows it to connect to the core logic and memory which is utilized when you
want to debug your program, that after this instruction is executed, what is the result of that
instruction? What is the content of a given register? You can access that through the spy bi wire
interface.

(Refer Slide Time: 27:37)

233
And this spy-bi-wire interface actually uses 2 pins, one of them is the reset pin and other is a pin
called test and it has these pins are renamed SBW Clock and SBW data and using these to the
internal JTAG 4 wire 4 pins of J tag are created.

(Refer Slide Time: 28:05)

This is the available options, packaging options, you can have MSP430 in DIP form and we are
going to use a DIP dual in line package IC for our experimentation board. You can also have it in
SMD varieties of the type called TSOP. And then even small TSOP If you notice, it has pins on
two sides just like you have on DIP. But when you have a quad flat pack there you get pins on all
the four sides. So, this leads to even smaller size of package because then you are utilizing all the
sides of the IC.

So, your MSP microcontroller, MSP430 microcontroller is available with so much variety. Let us
go through the pinout or what we will do is we will consider the pinout in the next lecture
because we are just run out of time for this session. I will see you soon. Thank you.

234
Introduction to Embedded System Design
Professor. Dhananjay V. Gadre
Netaji Subhas University of Technology, New Delhi
Professor. Badri Subudhi
Indian Institute of Technology, Jammu
Lecture No. 12
MSP430 Architecture

Hello, welcome back to a new session. In the last session we had started discussion about the
MSP430 microcontroller family. We had discussed various features and one of the important
features that we discussed was the various low power modes of operation. We had also discussed
how very little current is required to power an MSP430 circuit.

I have a very interesting demonstration for you which consists of MSP430 circuit which is
powered with the help of a lemon battery. As you can see here I have created a battery made out
of lemons and two electrodes these electrodes are made out of copper and zinc and the power the
voltage produced by this battery. There are 4 batteries in series each battery is producing 0.9
volts. So, roughly the voltage is 3.6 volts, which is suitable for powering a MSP430 circuit.

(Refer Slide Time: 01:21)

Here, you can see that the LED is blinking. I will draw the circuit for you of what we have done
and you can try to create such a circuit at your at your end.

235
(Refer Slide Time: 01:39)

So, this circuit consists of a lemon battery which is made out of 4 lemons 4 lemon half’s. So, I
am going to represent each lemon half by this 1, 2, 3 and 4. This is powering a MSP430 circuit.
This is DVCC. This is DVSS and we also have connected a capacitor just so that it stabilizes and
filters the voltage produced by but this is made out of lemons. Lemons plus copper electrode plus
zinc.

On one of the output pins, we have connected a LED a red LED, as you saw. We also have on
the X1, Xin and Xout pins. We have connected a crystal. This crystal is 32 kilohertz crystal
32.768 hertz crystal and there are two 22pf capacitors as required by the circuit for its operation.
These are all 22pf ceramic capacitors. This is a 2.2 kilo ohm resistor and this is a red LED.

And what we have done is we have use this crystal operating at 32.768 kilohertz to clock the
internal circuit, but during the time the circuit is operating. The CPU is actually switched off. It
has initially programmed the one of the timer's to produce a PWM signal where you notice that
the LED was on for a short duration of time and it was off for a longer duration of time. We have
achieved that with the help of a PWM signal something like this, on for short duration, off for a
longer duration, again on for short duration, off for short duration and so on.

And this was applied to the LED. So, we the CPU has been shutoff. It is gone in a low-power
mode and the only part of the circuit which is operating is this timer and we have all these modes
under our control we can choose which part of the circuit would operate and this would be used

236
by a programmer to optimize the available power. So, this is a very interesting demonstration
that you just saw.

(Refer Slide Time: 04:43)

Let us resume our discussion which was to look at the pinout of MSP430 G-series
microcontrollers. Because we are going to use G-series microcontrollers throughout our
discussion. So, if you see here, it is a 28 pin G-series microcontroller, pin number 1 and 28 refer
to the power supply pins here and here. This is VCC and this is ground this is ground.

Then most of the pins have (multi) multiple functions each pin offers multiple functions and it
would depend on you the programmer the designer to write an appropriate program so as to
select the functionality that you would require that you would want in your application. For
example, if you look at pin number 2, it can act as port P bit number 0 or it can act as a clock for
timer A.

It can also act as analog input and it can also act as a comparator input because the MSP this
particular MSP430 microcontroller has one comparator as we discussed in the previous lecture.
If you notice here, let us go on the other side these two pins XIN and XOUT would be used to
connect an external crystal should you choose to have that option.

If you want you could use an internal RC oscillator. A calibrated RC oscillator to power the
microcontroller if you want in that way and if you wanted a more accurate source of timing, then

237
you could connect the connect a crystal here. If you choose not to have a crystal, then these two
pins, pin number 27 and 26 could also act as port pins as you see here P2.6 and P2.7.

This 28 pin IC has 2 ports as you see actually it has 3 ports P1, P2 and P3 and lot of functionality
that is available in this microcontroller is distributed across the pins of these 3 ports. Let me
show you another interesting pin. This is the reset pin and this one is the test pin the reset and
test pin also serve as the Spy-Bi- Wire interface to the microcontroller.

Also if you look at pin number 3 and 4, these are one of the functions that is available on these
two pins is dealing with the UART and you would use these UART pins, If you would want to
program this microcontroller using the the bootloader method as I mentioned repeatedly the
MSP430 Lunch Box kit uses the bootloader method of programming the this microcontroller. So,
they would use pin number 2 and 3.

Apart from that across the chip you would see several functions. If you look at pin number 6
here. It is also an input for a voltage reference. If you want to have an external voltage reference
for the on chip ADC. You could also use the internal reference voltages, but you can also
overwrite that by writing an appropriate program. So that pin number 6, whatever external
voltage that you apply would serve as the reference voltage for the on-chip ADC. Let us proceed
to the next slides and discover more about this microcontroller family.

(Refer Slide Time: 08:29)

238
Here is a same microcontroller G-series microcontroller in a different footprint. This is a TQFP
footprint because you see there are pins all around this IC.

(Refer Slide Time: 08:42)

This is the functional block diagram of the MSP430G2x53 family. For example, the one of the
numbers would be to MSP430G2553. MSP430G2553 is what we are using in our lunchbox.
Now, let us start from top left. Here these are the two XIN, XOUT pins, which you as a designer
could want to put a external crystal here, which would generate the system clock. It would also
generate two more clocks called A clock and SM clock. A clock and SM clock are used by the
peripherals which are available on the microcontroller. Whereas M clock is used to power the
CPU. The CPU if you let us go down the CPU has 16 general purpose registers, we will come to
that.

Let us go across and now you see this microcontroller series offers flash memory for the program
memory ranging from 2 kilobytes at the lowest value to 16 kilobytes. It has RAM and there are
two options either you get 256 bytes of RAM or you get 512 bytes. It has a ADC here and you
get 10 bit resolution ADC with 8 channels. There are 3 ports available. But depending upon the
physical footprint you may get 1 port or 2 ports or all the 3 ports, each of the ports has 8 pins
here.

And each of these pins have the capability to act as an interrupt input apart from that you can
 also choose to have pull up and pull down resistors. We have discussed the pull up and pull

239
down resistors in our discussion on physical interfacing and we will also discuss it in future all
the 3 ports P1 port 1, port 2, port 3 each having up to 8 pins has uniform capability that it has
interrupt in capability as well as pull up pull down, port 3 unfortunately does not have interrupt
inputs.

If we go down here, here we have the USCI that is universal serial communication interface. It
has two parts to this USCI A0 and USCI B0. The USCI A0 offers 4 modes of operation either it
can act as a UART universal asynchronous receiver transmitter or it can act as LIN Local
Interface Network or it can act as for a infrared communication or it can act as one of the SPI
ports.

The second channel of serial communication offers two options, either you can operate it as SPI
interface or you can operate it as I square C bus. So, if you look at the serial communication
options, you can use the USCI to give you two channels of SPI or you can have one SPI and one
I square C or you can have one UART and one SPI you can have one UART and one I square C
and so on.

All the combinations that you can make with these two channels of communication, to the left of
this we have timer which has 3 compare registers. We have another timer which also has 3
compare registers both these timers are 16 bit timers. Next to that is a Watchdog timer and as
you notice here this watchdog is a 15 bit watchdog, which means the maximum count that it can
it will count before it overflows and this would be used to reset the system is to 2 raise to power
15, which is 32768.

Next to that is a comparator with 8 inputs and you could select which input you would want to
connect to the inputs of the comparator. And we also have Brownout protection which means
this part of the circuit will provide brownout reset source. One of the reset resources that we
discussed in the past. This is one of them. Towards the left most under the CPU you have JTAG
interface.

240
(Refer Slide Time: 13:05)

And we saw in the pin diagram here. Let me show you here that this pin diagram has entire 4
pins of the JTAG that is TCK here TMS and then you have TDI and TCLK. If you want to have
a shorter or a smaller interface to the same JTAG, then you would use this Spy-Bi-Wire both of
them give access to the JTAG controller one in a explicit form one through the Spy-Bi-Wire.

(Refer Slide Time: 13:43)

So, that is what we have on the chip the JTAG interface and you could have access to the JTAG
interface through the Spy-Bi-Wire communication also. So this completes the block diagram
description of the MSP430 G-series of microcontrollers. Let us go further.

241
Now it is very important to be able to read a data sheet because data sheet is provides you wealth
of information more than what a course can teach you about the course can only sensitize you
that a data sheet is a wealth of information but you as the end user you as the engineer must
know where to look for relevant information inside a data sheet. So, I am going to open up a data
sheet and go through it so that you are able to understand.

(Refer Slide Time: 14:36)

The first page of the of any data sheet whether it is about the microcontroller or it is about
discrete component we will list out the salient features. So, if you see here it talks about the
features. Here where it says, the low power voltage range is 1.8 to 3.6 and so on and that it has
various modes of operation active mode, sleep mode, standby modes. It has serial
communication protocols.

It has on chip comparator all that we have discussed. But usually it will be available in the first
part of the first page of a data sheet. Then it might describe the details about it about the
microcontroller.

242
(Refer Slide Time: 15:15)

Then in this case it has available options in terms of the peripheral feature that this
microcontroller has.

(Refer Slide Time: 15:23)

Then if this micro if this data sheet reference to a certain family, it will talk about the pin outs
that are available. In this case, it says that it is available in TSSOP as well as PDIP on this page

243
(Refer Slide Time: 15:39)

And the next page shows QFN which is quad package, which has pins on all sides the same pins
distributed on for all sides.

(Refer Slide Time: 15:48)

Here is the functional block diagram the one we just discussed few moments ago.

244
(Refer Slide Time: 15:56)

It has what are the various terminals the pins of the microcontroller. What are the functions of
each of these pins? What alternate functions those pins serve, this is a list table of that.

(Refer Slide Time: 16:10)

Continued with that, here is a short form description of the CPU the various general purpose
register we are going to come to that shortly.

245
(Refer Slide Time: 16:21)

The instruction set and eventually it is going to talk about for example here are the interrupt
vector addresses these locations will be used to put pointers to the interrupt subroutines if you
want to use those interrupts in your in your system.

(Refer Slide Time: 16:35)

This is a description of all the special function registers. And so on.

246
(Refer Slide Time: 16:50)

And here are the electrical characteristics you would find these electrical characteristics in
almost every data sheet, whether it is for a microcontroller, whether it is for a logic IC, whether it
is for a for a semiconductor device any semiconductor device and it talks out absolute maximum
ratings, which means what are the maximum voltage you can apply to this IC in this case without
destroying it. It talks of maximum voltage it talks of maximum temperature that it can survive.

Then there are recommended operating condition meaning maximum ratings you are not going
to normally encounter in commonly, but recommended operating conditions are what you must
adhere to. So, it talks of the supply voltage the operating temperature and the frequency of
operation in this case of this microcontroller

247
(Refer Slide Time: 17:44)

Then it talks of the various current consumptions, the various in active mode and low power
modes, you can get you can use the information in this data sheet to verify when you are
designing a system and you find that it is not working the way you would expect. This is the
place to refer to to find out how much current should it consume versus how much current it is
actually consuming.

So, I recommend very strongly that you practice reading a data sheet and to ​interpret the
information given in this data sheet at the very fag end you will find this IC or the series of IC’s
in what bulk packaging form there available as I mentioned in the last lecture whether they are
available in a tube form or whether they are packaged in a role of which can be used in
production all that information is available in this data sheet.

Let us get back to our discussion on the features of this MSP430 G-series of microcontrollers.
So, the architecture of MSP430 CPU, is that as I mentioned it is a RISC architecture. You see
here. It is a RISC architecture and one of the ​Salient ​features of RISC architecture as a name
suggest reduced instruction set computer is that compared to a corresponding CISC architecture
the number of instructions would be limited. And in this case, there are only 27 basic type of
instructions.

248
(Refer Slide Time: 19:24)

It has 7 addressing which means each or many of these instructions would have variations how it
is going to fetch the operand. And for that it uses 7 addressing modes. The address bit usually
16-bits for G-series certainly it is 16-bits, but for other variants, it could be 20 bits. The data bus
is 16-bits because it is a 16-bit microcontroller.

Apart from the architecture and the bus interface unit, it has 16 16-bit registers. There are 16
registers each of the registers can hold a 16-bit value and we will see what all these registers
perform. The maximum clock frequency for a G-series is 16 megahertz and for the F-series it is
25 megahertz. The registers have a interesting feature that they can be used to get constant
values. And so there is a constant generator. I am going to come back to the constant generator
shortly.

It has direct memory to memory transfer. So, you want to move a chunk of memory or you want
to copy some part of memory into another section of the memory, you can do that without
bringing a register in the picture and the instructions have word and byte addressing which
means there are instructions which can fetch a word which means two bytes and there are
instructions which can fetch or deal with a single byte of instruction.

The memory architecture is Von-Neumann here, which means there is a unified memory map.
And in the same memory map you would have program memory you would have data memory.

249
And in this case it also has access to the special function registers. These registers control the
input output peripherals of MSP430 microcontroller.

(Refer Slide Time: 21:24)

The address bus allows you up to 64K memory locations as we seen. But in some cases it also
has 20 address lines and you can have 1048 1 million memory locations like this. The data bus is
16 bits wide so you can transfer either 16 bits in a in a single cycle, but you can choose to have
only a byte of data transfer as well. The way the words are stored, a word here means one word
is equal to 2 bytes, which is equal to 16 bits. So, inherently the microcontroller can store 16 bits,
but there is a restriction as to which memory addresses can it store these words.

250
(Refer Slide Time: 22:20)

It turns out that you can only store words starting from even memory locations. The memory is
addressed in byte addresses. And so you can only store words which start at a even byte address.
And since the instructions are all 16 bits, that means all the instructions are located at even byte
addresses. That is the meaning even addresses.

So, your first instruction will be at address 0 and so on and so forth. Now when I have 2 bytes to
store and my memory is arranged in byte form. The question is, in what sequence should I store
the 2 bytes? So, let me say the 2 bytes are, so this is my LSB lower significant byte and my
MSB.

251
(Refer Slide Time: 23:18)

And my address is are each address can hold a byte of memory. I have two options. I can store
LSB here and I can store MSB here in this location into sequential memory locations, or I could
reverse I could store MSB first and I can store LSB later and the way memory words are stored
is referred to as endianness of storage. Let me explain this.

(Refer Slide Time: 23:58)

So, lets say my memory has addresses which is starting from say address 0 then 1, then 2 and so
on and 3. And let us say I have a word which means I have 2 bytes. The right most is always
referred to as LSB and I have MSB. There are two options to store these two bytes in a byte wide

252
this memory is byte wide. This is very important to mention here byte wide memory. That is
each location can store one byte wide memory.

Given that each locations can store only 1 byte and I have to store 2 byte bites because this is 1
word I have as you can see I have two options. I can store LSB at some address and next address
I can store MSB. When I do the following that at a lower address I store the LSB and at the next
address which is a higher address I store MSB, this is called little endian.

On the other hand, if lets say at a subsequent address, maybe 10 and next address is 11. If I store
MSB first and then I store at the next address the LSB value of the word. This is called
Big-Endian. So, as a computer engineer as a electronics engineer who is into embedded system
design. It is very important to know the architecture that you are using. What kind of endianness
this is the term, I would call endianness it is not Indian.

We are Indians but we are talking of endianness how all the endings of the bytes being stored.
This is referred to as endianness. So, there are two methods one is the little endian the other is
the big endian. For MSP430 they have the designers have chosen to use little endian format of
data storage. Let us go back.

(Refer Slide Time: 26:24)

253
Now, If you see here, let me zoom this up for you. You see the low byte is stored at a lower
address. So, the way to remember is little endian means low byte, low address. High bite high
address. This is the safest way to remember, what is the meaning of low-endian and anything
else is the opposite of this is high endian. So in low address, this is the lower address. I am
storing the low byte and at the higher address I am storing the high byte and this refers to the
little endian format.

Within the within each location I can store 8 bits as you see here from 0 to 7. And since I have, if
I am storing words, the number of bits will be 16. So, it will go from 0 to 7 and then from 8 to 15
in the higher memory locations because of the little endian format that MSP430 microcontroller
follows.

This is the MSP430 G-series memory map, meaning the entire 64 kilobyte memory space. How
is it occupied? It is very important to know that and although there are 1 to 5 columns, which
means it is referring to 5 different microcontrollers. I am going to concentrate on this column
here, which is MSP430G2553 because that is the microcontroller that we are using in our course
here. Now, you see the address goes from 0 here if you can see this address.

254
(Refer Slide Time: 28:05)

This is address 0 and at the top it goes to FFFF in a 16-bit address range. This is the numbers you
are going to have. You are going to go from 0000 x to the maximum value is FFFFx and this is
equal to 65536 memory locations. So, the way these locations these addresses are utilized is that
the lower 16 locations. If you see here lower 16 locations are used to store 8-bit special function
registers. These special function registers deal with the input output ports.

The next again, next lot more locations from 10x that is 16 to FF that is 256. They are reserved
for storing 8-bit peripherals and thereafter from 100x to 1 FF. Let us see how the how much that
is this is further 256 locations are used to store 16-bit information about 16-bit peripherals. That
is such peripherals which require 16 bit of data. They are access in this range. The next memory
addresses are used to store the RAM which is the data memory. In this case the address starts
from 0200 to 03FF and this let me explain.

255
(Refer Slide Time:​ ​29:47)

This is if I go from 0100 to 01FF these are 256 memory locations. In our case, we are going from
0200 to 03FF and these are 512 bytes of 512 locations. That means in this range. We are we have
mapped the MSP430 microcontroller mapped RAM in this memory location. And so this is what
we have.

Thereafter there is some gap and you come at here, which is 01000 that is 1000 to 10FF and this
is called as information memory. Now information memory is also flash memory except this
information memory is used to store user data that you would not want to be lost if the power is
switched off.

256
So, this is basically a flash memory and in the G2553 microcontroller you have 256 bytes of
flash memory defined as information memory and at the top we have the main program memory.
In this case, we have 16 kilobytes and this is the address range actually of which there are the 16
kilobytes are utilized in two way. So, the starting address is C2 C3000 to four FFFF’s. Let me
mention what it is. So, our address are C000h to FFFF we have already seen that the lower two
digits refer to 256 bytes of memory.

And here we have FF minus C0, so it will go from C0 to CF, then D0 to DF, then E0 to EF and
F0 to FF and each of these pages is to like 16 locations. So, we have total of 256 bytes into C0 to
CF is 4 segments and like that we have total of into 4. So, this into this is 1 kilobyte and so this is
a total of from 00 to 40 and 40 here means 64 pages.

So, 64 into 256 bytes will give you 16 kilobytes of memory. So, the difference between these
two numbers is 16 kilobytes of memory and these 16 kilobytes of memory is what is available on
2553 microcontroller of this the top locations FFC0 to FFFF are stored to store vector locations
and these are 32 locations each having the storage of 2 bytes. That means a total of 64 locations
and I am able to store 32 interrupt vectors and the top of the address that is that is FFFE and
FFFF these are two memory locations. This is the Reset vector.

So, what happens when you reset this microcontroller or this microcontroller is reset in any
which way whether it is the user reset or whether it is a brownout reset or watchdog reset. It goes
to this memory location. At this memory location it reads the value and it jumps to that memory
location, which has to be in the in this code memory region and from there, it will fetch the first
instruction interpreted executed increment the program counter and get go to the next location
and so on and so forth.

So, this is the way the entire memory map of G2553 microcontroller 64 kilobyte memory map is
utilized for storing the peripherals the RAM the information memory and the main code memory
as well as storing the interrupt vectors. So, we stop our lecture here, and we will resume in the
next session and will continue this discussion about MSP430. Thank you.

257
Introduction to Embedded System Design
Professor. Dhananjay V. Gadre
Netaji Subash University of Technology
Professor. Badri Subudhi
Indian Institute of Technology, Jammu
Lecture 13
MSP430 Architecture- Continued And Introduction to Lunchbox

Hello and welcome back to a new session. In this session we are going to talk about the MSP430
microcontroller, continuing from our previous lecture. This is part of the online course on
Introduction to Embedded System Design and as usual I am your instructor Dhananjay Gadre at
Netaji Subash University of Technology. Now in the last lecture on MSP430, we looked at the
MSP430 series map of the memory map and specifically the G2553 microcontroller we were
looking at that here.

(Refer Slide Time: 01:02)

Let us continue further.

258
(Refer Slide Time: 01:06)

The flash memory which in this case is 16 Kilobytes of flash memory is partitioned into
segments. A segment is the smallest amount of memory that this microcontroller can erase and
the flash memory is partitioned in two parts, as we discussed, one is the memory where you store
the code and the other is what is called as the information memory.

The differences between the two segments here, the code segment and the information segment
is the size of the segment. The information segment is 64 bytes segments and the main memory
where you store code is 512 bytes.

259
(Refer Slide Time: 01:51)

In our case the amount of memory that is available you have, in 2553 we have 16 kilobytes of
memory. We have already discussed what all we can do with this and I will repeat here that the
flash memory can be used to store code as well as constants and you can modify some of these
constants also. The interrupt vectors are stored in the flash memory part of the code code
memory in the very upper the is the uppermost part of the flash memory.

This is the where you are storing the interrupts and various interrupt vectors as well as the reset
vectors. We have seen that the reset vectors is at address let me write it down here, is at address
FFFE and FFFF. You see it takes two bytes because the addresses are 16 bits that is why you
have to store these two locations.

260
(Refer Slide Time: 03:08)

Here is the table which describes all the interrupt vectors. G2553 supports 32 interrupts and each
of the interrupt requires interrupt sub routine. Interrupt sub routine is going to be a program in
the flash memory and in this vector table you store the address of that location in the flash
memory and so each address is 16 bits and so for 32 interrupts it requires 64 memory locations
and this is the this is the description of that.

(Refer Slide Time: 03:48)

261
As you can see at the top of the location is reset vector and you have the other interrupts
associated with various peripherals of G2553. We will go in this details when we are using these
peripherals. So, I am not going through each one of them but as you can see from this table that it
has interrupts for timers as well as comparators, watch dog timer, the universal serial
communication interfaces and the EDCs and as well as ports.

(Refer Slide Time: 04:28)

Now the information part information memory of the flash memory is in the case of G2553 you
have 256 bytes here and it is starting from this address to this address. This is 256 bytes and the
information these 256 bytes are splits in four segments of 64 bytes each as I mentioned earlier
and these are used to store various information. You can store constants as well as the first
segment is used to store factory calibration data for the digital controlled oscillator. The
oscillator that uses the RC oscillators.

You want them to be accurate so each one of them is calibrated so that they provide your 16
megahertz or 8 Megahertz clock frequency and so that information is stored there and this
segment called segment of the information memory is protected at reset. You cannot reset after
reset you can overwrite this information because this is very critical information.

The next part of the memory is what we call as the bootstrap loader. Now I have mentioned in
the past that MSP430 microcontroller can be programmed in several ways. One of them is to use
this spy-bi-wire protocol and the other is through the ​JTAG ​four ​JTAG ​pins that we have on the

262
micro controller like MSP430 and the third method is through the boot loader which
in-application programming method of uploading a code and in MSP430 jargon this is called
bootstrap loader.

(Refer Slide Time: 06:12)

And that bootstrap loader is located at this address as you see here. This is the location and in the
case of MSP430 microcontroller you do not have to write that program. The each and each every
MSP430 microcontroller specially the G series, they come with a preprogrammed bootstrap
loader.

All you have to do is in your microcontroller system provide an ecosystem which is compatible
with invoking the bootstrap loader mechanism and then you can upload any program from your
desktop computer into the memory of the microcontroller and later in this section we will discuss
about that but to mention here that about 1 kilobyte is flash memory is available and
preprogrammed with a Bootloader provided by Texas Instruments.

263
(Refer Slide Time: 07:14)

The RAM is used for storing variables as well as stacks and you have 512 bytes of SRAM
available on the G255 series. Here is the address. This is the starting address 0200 and the upper
limit of that address depends on exact chip number. In this case 512 bytes so from 0200 it will go
up to 512 locations.

(Refer Slide Time: 07:54)

Apart from the flash, the information flash and the RAM, you also have memory used by the
peripheral ​registers ​of the CPU and you can see them here. There are 3 types of ​registers​. Some

264
of the ​registers ​require 16 bit access so they are available here word access. Some of the
peripherals require 8 bit storage and so those ​registers ​are accessible through this and then there
are special function ​registers ​which we will come to shortly.

(Refer Slide Time: 08:38)

This is the various 16 bit word storage peripheral ​registers ​as you can see they deal with ADCs,
they deal with timer 1 and timer 0 as well as flash memory. You can control access to the flash
memory by writing into these ​registers ​and you can also write to the control the watchdog timer
at this location.

(Refer Slide Time: 09:05)

265
Then you have the peripheral modules for 8 Bit peripherals which is here and by reading and
writing 8 bit data into this information you can control such peripherals.

(Refer Slide Time: 09:21)

Here is a list as you can see there are much more than what you saw in the word accessible
peripherals. This is the USCI that is Universal Serial Communication Interface. The second
module you have some ADC devices, you have the comparator. The clock system can be
controlled various low power modes by writing into this and the ports P3 and P2 can be
accessed.

266
(Refer Slide Time: 09:48)

And similarly Port 1 and other special function ​registers ​related to the interrupt control are
accessible through this byte access special function ​registers​. Well I meant byte accessed
peripheral ​registers​.

(Refer Slide Time: 10:02)

Then we have special function ​registers ​, these deals with various enabling of interrupts and
allowing interrupts to function and flag ​registers ​related to them. The storage is 16 locations that
is 16 bytes. Now we have reached a stage where we are ready to talk about the CPU in MSP430.
This CPU of MSP430 is RISC architecture and as recommended by the RISC specifications

267
which were brought forward in early 80’s. RISC wanted all the CPU to have large number of
registers ​so that local variables could be stored within the CPU rather than having to go in the
external memory such as the RAM for fetching them which slows down the execution

268
(Refer Slide Time: 11:09)

And in keeping with that recommendation MSP430 has 16 general purpose registers. They have
labeled from R0 here to R15. Each of these registers can store 16 bit of data. These ​registers ​feed
16 bit ALU as you see here. The ALU can perform various mathematical and logical operations
like add, subtract and AND/OR operations and the result of these operations can be observed
through these flags but these flags are accessible though one of these general purpose registers
that we will see. So, we have in all 16 registers. Let us see the function of these registers.

(Refer Slide Time: 11:52)

269
There are 4 special function registers which means that out of this 16, 4 are taken off because
they have dedicated function. One of the registers is the program counter which means that the
content of this register will tell you which memory location in flash the microcontroller CPU is
fetching the current instruction from. The second register is for stack pointer which tells you that
where is the stack located in the RAM.

It is your responsibility to ensure that the stack pointer is pointing in the right memory of the
RAM and the third is the status register which indicates the various flags that we just saw
whether the result of a particular CPU operation of add whether the result is 0 or whether there is
a overflow. All those flags will be available in this status ​register ​and there is interesting concept
called the constant generator.

In many programs you require certain constants and this constant generator offers you that
flexibility without having to store them in your program and then apart from that you are left
with twelve general purpose registers which the CPU utilizes. Now since we are not going to
program MSP430 in our course in assembly language program, we do not really worry about
how this general purpose ​registers ​are going to be used.

It is depended on the C compiler or whichever compiler that we use to optimally use these
registers but to know that they exist is great consolation that our program is going to be compiled
efficiently.

(Refer Slide Time: 13:33)

270
So, let us see which special registers we have. We have a program counter and since the program
counter deals with reading the next instruction. The instruction are all 16 bits wide whereas our
memories are arranged in terms of bytes and therefore the least significant bit here is set to 0
because we want to store all our instructions at even byte addresses even addresses.

So, our first instruction if it is at 0 the next will be 2 and then next will be at 4 and this can be
ensured by ensuring the least significant bit is set to 0 and therefore out of potential 64 kilobyte
memory space we can actually store how many instructions? We can store half of them 32768
total instruction you can store.

Of course, the actual number of instruction that you store will depend on the available memory.
The flash memory that you have but this kind of limits the maximum number of instruction that
you can have. Instructions themselves can be one word which means 2 bytes or two words or
three words that is the depends on the exact instruction.

(Refer Slide Time: 14:55)

271
Then the second ​register ​we have is a stack pointer. A stack pointer is a special ​register ​which
points to the stack and stack is that memory area where you are going to store your return
address and you call a subroutine or where the CPU stores the return address in case an (instruct)
interrupt subroutine gets called.

So this is the location, this is the RAM location in which you store your return address. Again
just like the program counter, the insignificant bit is set to 0 so that it is able to write 16 bit
numbers which refer to the address of your program the return address and therefore this bit is 0
the rest of the bits are available to you and of course it your responsibility to initialize the stack
pointer appropriately.

(Refer Slide Time: 15:44)

272
The third register is a status register and the status register consists of various flags and we will
see the details of it. It also has access to the interrupt mask so that you can enable disable
interrupts and it has some special flags which allow you to turn the CPU off or turn the oscillator
off and so on and we will see these operations subsequently in our exercises.

(Refer Slide Time: 16:10)

We have overflow flag which is set to 1 when the result is an overflow as a result of
mathematical operations when you are dealing with signed bit numbers. We have these two
system clock generator bits where you can turn on and turn off the main clock or the other
clocks. We have the oscillator clocks and so on and here is the general purpose interruptible and

273
then these are the 3 flags apart from the overflow flag which is the negative flag which means
that when the result the most significant bit of your number that you are looking at if it is 1 this is
negative flag you have the 0 flag.

When you do any mathematical operation or logical operations it results in 0 in all the bits and a
carry flag when there is carry from the most significant bit into the outside that. So these are the
flags that are available.

(Refer Slide Time: 17:09)

The constant generator registers register is able to provide 6 commonly used commonly used
values using R2 and R3 and no special instruction is required to access those constant values and
we look at a program so that we illustrate this concept.

274
(Refer Slide Time: 17:31)

The rest of the general purpose registers can store 16 bit values and you have 12 registers to do
that as you see here from R4 to R15 and there is no dedicated function associated with these
registers. These will depend on if you are going to program in assembly language then it is your
responsibility to use them judiciously. If you are going to use a high level language compiler
then it is compiler responsibility to use these registers as it may deem fit.

Now, since we are not going to program MSP430 in assembly language programming but we
still want to have a feel of the kind of instructions that are available as I mentioned MSP430 is
RISC architecture which means the number of instructions expected is less compared to
corresponding CISC architecture.

It may have varieties of those basic instructions in the form of addressing modes so we will just
go through those names and we will see how much time some these instruction take and what is
the size of these instructions as I mentioned the instructions could be 1 word or 2 words or 3
words and then eventually we will see how we are going to be experimenting with MSP430
microcontroller in our course by looking at the design of the MSP430 lunchbox.

275
(Refer Slide Time: 18:53)

So, the instructions are they can have double operands here such that you want to add the value
of as an example R4 and R5. Here the sum of R4 and R5 which are general purpose register is
stored in register R5 here. This is the destination.

You can have a single operand instruction where apart from the instruction the opcode you have
a operand here you are saying call subroutine which is located at an address whose address is
located at a flash address whose the address which is stored in a register R8 and you could have
another instruction such as a jump instruction where it is unconditional jump with a relative
which means compare to current location you can jump forward or you can jump backward.

276
(Refer Slide Time: 19:46)

These are the 7 addressing modes which on the basic operation you can the addressing mode
specifies how do we get the operands and so we have a register mode in which 2 register or 1
register is used to specify the operand. You have indexed mode which means one the register is
used as an address to go into a memory location to fetch the operand. You have symbolic mode
which is referring to the labels that you would use in a program jump here or call that subroutine
at that location.

You have absolute mode where you are specifying the entire value. You have indirect register
mode which means you are going to use register in a indirect mode. You can do an auto
increment on those register values and you could use an immediate value such as you want to
initialize the register with some number. These are 7 addressing modes that operate on the basic
instructions and create variety for you.

277
(Refer Slide Time: 20:48)

And this is the addressing the source and destination bits that specify each of these modes as you
can see. We are not going to again go into the details of this because as an embedded system
designer we would worry about other issues.

(Refer Slide Time: 21:08)

Now we are we have reached a point where we are now ready to jump into experimenting with
MSP430 microcontroller and for that as you see as I have mentioned you mentioned here several
times we have designed microcontroller evaluation kit called as MSP430 lunchbox. Now let me
also briefly mention that this is not the only evaluation kit that you have. That Texas instruments

278
makes several, several wonderful evaluation kit and the most popular is called MSP430 launch
pad that is that is their official evaluation kit.

This kit is priced very, very competitively and if you get your hands on it you will realize that on
this kit there are actually two microcontrollers. One of the microcontroller is the one that you are
going to use which we call as the target microcontroller and there is a control microcontroller
which controls this target microcontroller and helps you download program into it or to emulate
it or to debug it and so it is a extremely competitive and extremely versatile piece of hardware.

Unfortunately it is slightly more expensive than what is possible to make with microcontroller by
itself and this where we come into picture and we have designed this lunch box. As you see here
is our target microcontroller which is going to be MSP430G2553 in the in the dip format. Now I
have been mentioning this several times in the past that there are several ways of programming
MSP430 microcontroller.

One is through these Spy-bi-wire methods which incidentally is the method that official Texas
instruments MSP430 launch pad uses. The other method is by accessing the JTAG interface pins
four of them. TDI TDU TMS and TCK. The third method is using what is called as the in
application programming what Texas instruments calls as a bootstrap loader and the advantage
of that is that you do not need any special mechanism to transfer program from your
development host which is the desktop or laptop computer into the memory of the
microcontroller.

All you need is knowledge of which signals to activate and a mechanism to connect the desktop
computer and microcontroller and today as you know one of the most common methods of
connecting anything to the desktop computer or laptop computer is through the USB.
Unfortunately the G2553 microcontroller does not have USB interface.

It has UART interface so you have to have a mechanism by which the USB signals from the
desktop or laptop computer could be translated and converted into UART and such a device
which converts from one protocol into another has a name and it is called a bridge. A bridge is
simply a mechanism to go from one side of the river to other side likewise I would say we need a
device which is USB to UART Bridge.

279
Now there are several mechanisms to achieve this bridge functionality and we have used IC
called CH340. This is commonly available bridge integrated circuit. On one side its talks to the
connects to the USB and on the other side it has the UART functions and apart from that it has to
control signals.

One is called request to send and Data DTR signals and these are used to connect to certain pins
of the MSP430G2553 series microcontroller. In this Spy-bi-wire mode only for control and then
because you are MSP430 microcontroller operates at 3.3 volts or up to 3.6 volts and not 5 volts,
we have taken the 5 volts available on the USB passed it through this low drop out voltage
regulator to provide 3.3 volts supply voltage not only to the micro controller the target
microcontroller but also to the bridge.

Apart from that you have 32.768 kilohertz crystal which is used to generate the bitrate what is
called as baud rate for UART communication. You have a user LED, you have one user switch,
you have a reset switch other than that rest of the available pins are accessible through header
pins as we will see in the next slide.

(Refer Slide Time: 26:15)

Here is the photograph of the MSP430 lunch box and let me show you this is the microcontroller
MSP430G2553. Here is the reset switch. Here is the user switch. We have the power on LED
here and a power on LED is very important component to have whether you are designing a
evaluation kit or your own instrument because that is the only way to convey to the user that the

280
power to the system is on if it was not there and if the system is not working the user would be
confused is it working because the power has not been applied or whether it is not working
because the system is faulty.

So, power on indicator is a good way for that. You also have this crystal which is required this
crystal is required by this CH340 USB to UART bridge. You also have 32 kilohertz crystal as
you saw in the previous slide. This is used by MSP430 for UART communication. The available
pins that MSP430 offers you are available on these header pins and you have this is the user LED
here. This is the User switch that you can that is connected to certain pins of the resident
microcontroller and here are some jumpers you have to engage in certain way as mentioned here.

If you want to put the MSP430 kit into programming mode which means you want to download
code then this jumpers have to be engaged. These are shorting jumper with which you can
connect two neighboring pins. You have to engage them in certain way and if you want to use
the same USB interface for serial communication in your program through your program during
runtime then you change the setting of these jumpers and this mentioned here and here. And this
is a transistor which is required for some level inversion.

(Refer Slide Time: 28:15)

This is the microcontroller that we are using. It has all these features which we have gone
through before.

281
(Refer Slide Time: 28:21)

This is the schematic I encourage you to go through this schematic it has been annotated nicely.
Here is the power supply. Here is the user peripherals which is switch and LED. Here is a USB
to UART Bridge. Here is your MSP430 and here you have extension headers.

(Refer Slide Time: 28:40)

This is the layout and as I mentioned repeatedly that this layout is available on my blog website
which we have shared on the GIT website. You can download this and you can print your own
printed circuit board and solder all the things yourself and you can make this evaluation kit
yourself.

282
(Refer Slide Time: 29:01)

If you do not have it you can even temporarily put together all the components on a bread board
or a zeroboard. You can have a in-house you can make you own PCB or you can get a
manufactured PCB from outside.

(Refer Slide Time: 29:16)

And so this is the evaluation the lunch box fabricated on a breadboard.

283
(Refer Slide Time: 29:22)

This is in-house that in my lab we used earlier.

(Refer Slide Time: 29:27)

And this is the manufactured lunch box. I hope that you have access to one of these three lunch
boxes to be able to continue having extensive hands on sessions in future. I will see you very
soon. Thank very much.

284
Introduction to Embedded System Design
Professor. Dhananjay V. Gadre
Netaji Subhas University of Technology
Professor. Badri Subudhi
Indian Institute of Technology, Jammu
Lecture No. 14
Programming Methods for MSP430

Hello, welcome to a new session for this online course on Introduction to Embedded System
Design. As usual, I am your instructor Dhananjay ​Gadre. Today, we are going to look at various
ways of programming the MSP430 microcontroller. In the previous lecture we have seen the
topology that we have that the hardware access that we have. Today we are going to see how we
write our programs and how to download them into the memory of the evaluation kit which is
the MSP430 lunchbox.

(Refer Slide Time: 00:58)

Now there are many to software tools, software development tools that are available for
MSP430. The most important of them is the Code Composer Studio IDE which means Integrated
Development Environment provided by Texas Instruments. We are in fact going to use this in
our course here.

Other options are that we can have an Energia, Integrated Development Environment,
environment and Energia gives you a look and feel as if you are programming MSP430

285
microcontroller like an Arduino and platform. You are free to use that if you like outside the, this
course.

But for this course we are not going to involve ourselves in Energia because it keep wrap
provides a wrapper layer, wrapper around the actual code which is running on the MSP430 and
distances you as a designer from the hardware feature of a microcontroller. And so it is good for
beginners. If you are in a school or beginning such activities in college Energia would be a good
environment.

But since we are training ourselves to be good embedded design engineers, we would try to work
as close to the hardware and the peripherals of the microcontroller as possible. And therefore we
choose to use programming languages such as C, or maybe assembly language if you are
interested in.

So, Energia I mentioned as one of the options that are available. If you develop applications in a
professional environment, perhaps you may use third party tools. And one of the very popular
third party development environments is the IAR compiler. And besides that, there are some
GCC GCC stands GNU C compiler. There are some open source packages also available which
can target the MSP430 microcontroller. These are the options that we have.

(Refer Slide Time: 03:01)

286
Now Code Composer Studio as it is called by Texas Instruments. This is a complete integrated
development environment when I say Integrated Development Environment means that you don't
have to invoke various software’s for writing your code and compiling them and debugging them
and all that you get a single window and through which you can do all the activities required for
the editing, debugging, compilation, simulating, downloading all those things you can do through
a single window and that is the meaning of this term integrated development environment.

So, Texas Instruments code composer studio offers you that opportunity. It has access to a
compiler. It offers your editor which means you can write your program, write in the single
window interface. You can build the project environment with various options that it offers.
Once you have compiled your program, you can debug it, you can test the code, you can simulate
it, you can connect it to various simulators.

This single window allows you to do all these things without having to switch windows and copy
paste or interface or import files from other software's. So this is a very good thing. In a
subsequent lecture, we will show how to download the code composer studio and get it to work
on your development platform which could be a desktop computer or laptop.

(Refer Slide Time: 04:41)

The Code Composer Studio is based on Eclipse software framework. Eclipse is a very popular
framework, which allows designers and embedded engineers which work on multiple platforms

287
they can use the eclipse framework for the development activities. It is supported on Mac
operating system. Or you could be using a Windows machine as well as Linux. And it is
supported from Texas Instruments on their support forum called E2E.

The website for this is e2e.ti.com. If you go to this website, you will see a lot of options that you
have and you can choose an appropriate forum to raise any questions or doubts if you recall, in
one of the previous lectures, I had mentioned, that choosing a microcontroller, you should
consider a possibility that the microcontroller that you choose has some sort of support
mechanism.

And so, here it is the right point to point out that Texas Instruments has fantastic support forum
through this e2e website, where various issues related to the development of your circuit or your
product or your software could be raised and the community which could be employees of Texas
Instruments but also educators and other freelance workers could be engaging themselves in that
discussion and their views and opinions could be off value in solving your problems.

(Refer Slide Time: 06:18)

This is the window of the code composer studio IDE that would appear on your laptop or
desktop once you install it. On the left you have the various ways of open you to open your
projects. The middle part is where you select as you can see, it offers you multiple platforms to
choose from and in our case we are going to use MSP430 which does not seem to be visible in

288
this but trust me that code composer studio supports MSP430. And on your right it allows you to
enter into various setup environments.

(Refer Slide Time: 06:58)

Apart from Code Composer Studio, you could also if you like, experiment with the Energia IDE.
This is an open source community driven, integrated development environment just like
Arduino. And you could think of this as, as Arduino for MSP430. And it is also supported on
like the Code Composer Studio. It is supported on Mac OS, Windows as well as Linux operating
system.

289
(Refer Slide Time: 07:27)

This is what Energia IDE looks like and perhaps this code examples here. You may if you have
experimented with before with Arduino, you can see that these are very similar to the coding
style and coding commands that you use during Arduino development.

(Refer Slide Time: 07:51)

Then apart from that you could engage with IAR and I am very sure that IAR offers you an
evaluation version where you can try it out, download it and try it out if you wish to wish to use
it in the context of this course.

290
(Refer Slide Time: 08:09)

This is what the IAR bench workbench looks like. And as you can see this has a look and feel
just like the Code Composer Studio.

(Refer Slide Time: 08:18)

Apart from all these options, you can also use GCC mechanisms which is using open source
packages, which is a free complete debugger and open source C, C++ compiler tool chains for
building and debugging entire applications from scratch to finish around the MSP430

291
microcontroller. Oftentimes, this works on a command line. And one of the advantages of using
the GCC tool chain is that it does not have any code size limitations.

Many of the up evaluation versions would put a limit on the maximum code size, maximum size
of code that you can experiment with. It just to give you a feel that, this is how my compiler is,
you if you like it then you can go ahead with the purchase or something like that, GCC does not
have those restrictions, and you can choose to use GCC for your applications.

Now, once we once you have chosen to use a particular environment for your application, then
we would in the subsequent lectures will show you how you start writing your code and how you
compile it and after you have compiled it, look at the, the messages that compiler such a
Integrated Development Environment generates to understand how it has compiled the code,
what is the size of the code?

If there are any warnings, how to interpret those warnings if there are any errors of course, you
cannot proceed so you must go back to your editing part and fix those errors. But once you have
done all that, with whichever approach you take, you would be ready to download that binary
code or the hex code into the memory of the microcontroller.

(Refer Slide Time: 10:18)

In this case, the MSP430 and we have 3 options. You could use the Spy Spy-Bi-Wire method,
which uses the test and reset pins on MSP430 microcontroller. Or you can, you could use a

292
JTAG Debugger. And you could use the poor man's alternative by using a UART USB based
Bootloaders.

Now, if you choose to have access to MSP430 launch pad which is an official evaluation kit
from MSP from Texas Instruments if you choose to do that, you would realize that on your
evaluation kit, there are actually two big microcontrollers. And one of them is the target
microcontroller that you are playing with the entry level MSP430 Launch pad does use MSP430
G2553 the same as we have on our on our kit.

But apart from that, you would see that there are a bunch of ICs and one of the ICs is actually the
one which connects to the PC through a USB interface. And that IC involves connecting to the
target microcontroller using this approach. It invokes the Spy-Bi-Wire protocol. And using these
two wires that is test and reset it is able to download code into the memory of the target
microcontroller.

And not only program it but you could debug your program by single stepping through the code,
which means execute one line of program, stop there to see what is the result of that program by
inspecting the registers or variables, and then going to the next instruction and so on and so forth.
If you choose to have an external debugger, it would require more pins to be connected, and
G2553 has access to those pins. But once you do that, you may not be able to use those pins for
connecting to your peripherals.

And as I mentioned, the third method is the USB UART based Bootloader, which we are going
to which I am going to explain in a little bit of more detail compared to what I discussed in what
I discussed in an earlier lecture here.

293
(Refer Slide Time: 12:46)

Now Spy-Bi-Wire is also called a 2 wire JTAG interface, because although it uses internally
inside the MSP430 it invokes the J tag, but the external connections are just through two pins and
therefore the advantages is that the interface is simple just involves two pins and there is no
overlap with GPIO pins.

In the case of JTAG if you choose to use the proper JTAG interface on MSP430 microcontroller,
that means that you would have to sacrifice 4 wires which are which share functions which share
functionality with other features of the MSP430 microcontroller. And these four pins will be
labeled TDI, TDO, TMS and TCK. But if you choose to use the Spy-Bi-Wire protocol, the
advantage is that it is not going to come at a cost of using any GPIO pins because it uses two
wires test and the reset.

And therefore, you are left with all your GPIO pins. The only disadvantage is because internally
these two wires are as if being received by shift register which receives the clock and data on
these two wires and make a full four wire protocol. So it will be slightly slower than the JTAG
interface. But that's a small price to pay for the advantages that you get using this approach
namely, just two wires and no GPIO pins sacrificed.

294
(Refer Slide Time: 14:20)

This is what the Spy-Bi-Wire protocol looks like that is you have to connect the supply voltage
here as you see two available voltages and usually they may be available from the JTAG
interface here. Then you have to use the reset and test pins of your microcontroller to the relevant
pins of the JTAG interface from the Spy-Bi-Wire capable output, and of course connect the
ground here.

And then using these two wires you can program and emulate the program inside the
microcontroller after you have downloaded it. So this is one option. And this is typically used on
the MSP430 launch pad, which is an official microcontroller platform.

295
(Refer Slide Time: 15:12)

The other option is that you have a JTAG interface and there are many JTAG interfaces
available. And then you would make connection with all the four wires that you see here, apart
from the reset pin so that you can put the microcontroller in reset and then invoke the JTAG
interface.

We do not recommend using it in this course of course in fact, we do not even recommend using
the Spy-Bi-Wire but I am mentioning it because this is if you have access to a launch pad you
this is how it works on a launch pad. We are going to use this boot Bootstrap Loader, which
Texas Instruments used to call Bootstrap Loader.

296
(Refer Slide Time: 15:50)

But now they just call it Boot Loader. It allows you any programmer to communicate with the
MSP430 microcontroller and it is very good for prototyping and with this you are able to
program the flash memory and also the RAM if you so wish.

(Refer Slide Time: 16:12)

These are the connections that are required for the USB and UART based Bootloader that you
need a mechanism you need a bridge as I mentioned earlier, a bridge which on one side connects
to the USB and then generates the TXD and RXD communication signals. But on MSP430 there

297
are two pins designated as TXD and RXD for the purpose of Bootloader programming you do
not connect to them you connect instead to these two pins.

And apart from that you also connect to the test and reset which the bridge invokes and asserts
before proceeding with downloading the code through this, these two wires. And of course you
have to connect to the ground and of course power the MSP430 microcontroller.

Now, we need to go through what is the program flow, how we are going to start with the editor,
the IDE write our program, compile it or add third party libraries and so on. So I am going to go
through that.

(Refer Slide Time: 17:24)

So you start with your C source file, you invoke the compiler options and the intermediate step in
the compile process that it will give you the assembler source at that time, you could use third
party libraries to integrate into this then this is assembled by the IDE and you get create object
files. These are linked and you create an executable file which is nothing but the binary code and
then you are ready to download it into the MSP430 target.

So, this is the flow of your code starting from what looks like as readable text which is nothing
but C C++ commands. And eventually it is all compiled in various steps to be able to download
into the MSP430 microcontroller.

298
(Refer Slide Time: 18:12)

Now you can write your program on MSP430 for MSP430 irrespective of the, the platform,
meaning the development environment, which could be CCS or GCC or it could be IAR and you
could choose to program in pure assembly language if you so wish. We do not recommend that
in this course because then your focus will shift from application development to assembly
language programming.

You could also use register level access using the GCC or the TI compilers and we are going to
take this approach. And the third option is you use APIs and third party libraries such as may be
available from open sources and we are going to stick to this approach.

299
(Refer Slide Time: 19:00)

Now in this course, we are going to use the Code Composer Studio for our development, we are
going to use the UART based Bootloader. And we are going to program using register level as
well as third party API libraries involving all of them together. One question would arise that
why do we concentrate on high level language programming, and that is because a high level
language programming allows you to conceptualize and recreate complex create complex data
structures, which you can easily manipulate in a high level language then it would be possible in
the assembly language program.

Assembly language program might be more efficient in terms of the actual memory usage. But
these days we are not short of program memory space and therefore, that is not really a big
concern. Our more concern is, as I mentioned in one of the earlier lectures that time to market
that we would like to start developing a project and quickly compile converge, do all the
hardware prototyping development and integrate the hardware and software aspects together.

So, time to market is an important consideration. And therefore, using a high level language to
target your application development is a preferred method these days and we are going to use
that. I hope this was beneficial to you. I will see you in a next lecture where we will deal with
other aspects. Thank you

300
Introduction to Embedded System Design
Professor. Dhananjay V. Gadre
Netaji Subhas University of Technology
Professor. Badri Subudhi
Indian Institute of Technology, Jammu
Lecture No. 15
Physical Interfacing - 1

Hello, welcome to this new session on the as part of the course on Introduction to embedded
system design. In this session we are going to look at the physical interfacing of the
microcontroller with various input and output devices. As you know, I am Dhananjay ​Gadre ​and
I am going to conduct this session.

Now, if we go back to the session where we had discussed the Six Block Model one of the
important blocks was the input block and input block consists of input devices through which a
user would interact with the embedded system. Similarly, the embedded system would know
about the environment through various sensors. In this part of this session, we are going to talk
about various ways in which a user can interact, user can provide input to the microcontroller
and therefore, to the embedded system.

(Refer Slide Time: 01:23)

So, what kind of Input devices we have? Well, we can use a Push Button. This one we also have
Toggle Switches, switches which have two states on and off. Push Buttons also have two states

301
except you have to keep that switch pressed to change the state of the switch. Whereas in a
toggle switch, you can leave it in that position and it will remain either open or close.

Similarly, we have varieties of Toggle switches like Single Pole, Single Throw, Single Pole
Double Throw, Double Pole Double Throw and we could generalize this to mean multiple pole
multiple throw just to illustrate this idea what is the meaning of.

(Refer Slide Time: 02:11)

So, when I have the when I use the word single pole single throw, that means, this is a single
pole, single throw. If I say single pole double throw, this is, this is SPST single pole single
throw, a single pole double throw would be this and there would be two switches which will
operate in parallel and to indicate that, that they are mechanically coupled, I will draw this
dashed line and this would be single pole, double throw.

And I could then extend it to single double pole double throw. Now, I would have two poles and
these are again mechanically coupled, which means if so, if this is A and B, I would call this A
bar, A dash and B dash. So, here I can see A, B and C here it will be A dash, B dash and C dash.
So, at if I look at SPDT if the switch is open, that means A and B are disconnected, then A bar
and A dash and B dash will also be disconnected.

The third switch is DP double pole double throw in this if A is connected to be in one pole. Then
on the second pole, A bar will be connected to B bar. If I move the switch, if I toggle the switch

302
and A is connected to C it will be disconnected from B at that time A dash will be connected to
C dash disconnecting itself from B dash. So, we have all these kinds of mechanical switches.
Let’s go back.

(Refer Slide Time: 04:13)

Similarly, we have a DIP switch, I will momentarily show you what is a DIP switch, we have
some pictures we may interact, humans may interact with the embedded systems through
Capacitive and Resistive touch. Through, a Joystick which is nothing but a combination of
switches. So that it gives you up, down, left, right and maybe center position which you can
engage.

There are Rotary Encoders, you may have seen especially in your oscilloscopes there are you
know Rotary Encoders with which you select the voltage setting or the time setting. Now, did
you realize that they seem to you can move them in any direction and there does not seem to be
any start or end. Similarly in audio systems, there is a dial for changing the volume or selecting a
song, they do not seem to have any start or end.

So, these are examples of Rotary Encoders and usually these are the cheapeR1s are what are
called as Incremental Rotary, Rotary Encoders although there is also an absolute variety of
Rotary Encoders and they are quite expensive. And then apart from these Human Inputs and

303
Environmental Inputs, such as for Sound, Light, Temperature, all the entire list that we have
seen, we will consider them later.

(Refer Slide Time: 05:42)

For now, let us see what are these Switches that we are talking of? So, here is a list of picture of
some Switches. This is a DIP Switch. Why is it called a DIP switch because this can be, because
the footprint of this switch is like a dual inline package, a common integrated circuit package,
you can insert this into a breadboard or into your circuit, solder it and then these switches are so
tiny that here in this case there are 8 switches.

You can turn them on and off using tip of a ballpoint pen because they may be too tiny for you to
engage and operate with your fingers. Then here in the second case is the Toggle Switch. This is
a Toggle Switch. The third one this is a Joystick, the fourth example here, this is a Rotary Switch
and as you can see, it has multiple poles and multiple throws so that you can probably move it
around and it would make connections with all these lugs that you see in the picture here, these
are the connections and so on.

And here the next picture is that of a Reed Switch. A Reed switch is cannot be operated just by
pressing it. This is enclosed in a glass tubing and to operate it you must bring a magnetic field
near it. So, you could probably hold a magnet in your hand and if you bring that magnet near the

304
switch, the contacts of the switch will close. If you remove the magnet the contact of the switch
will be opened.

And in the end here we have normal Push Button The most common input device that you would
be using and connecting to your embedded system. Now, let us see how do we connect these
various switches to our microcontroller, we have to realize that none of these switches provide
any voltage. These are passive devices, which means they do not have a concept of high or low
voltage.

They have a concept of the state of the switch, the switch would be either open or it would be
closed and it would require some external circuit connecting it to some voltage sources or maybe
to ground to convert the open and close state of the switch into logic 1 and logic 0. Let us see
how to do that.

(Refer Slide Time: 08:57)

Here is a picture of I have actually shown two ways to connect a push button these both these
switches Switch-1 and Switch-2 are Push Button.

305
(Refer Slide Time: 09:10)

Nor the normal state of the I would draw the switch like this. Now, if this switch is pressed, it
would short the contacts let us say A and B and if the switch is open the A and B connections
would be open. And so if we connect it, we can transform we can translate the two states of the
switch open and close into whatever configuration we want.

(Refer Slide Time: 09:40)

So on the left side, on the right side, you see for Switch-1 we have chosen that if the switch state
is on meaning if the switch is pressed, it would I want to get an output of logic 0 when the switch

306
is off, meaning I have not pressed the switch. I should get a logic 1, to translate to these two
states of the switch we have connected external resistor this R1 and the junction of the resistor
and the upper terminal of the switch is connected to input pin in this case of microcontroller.

This could be MSP430 we have considered we have started talking about MSP430 in previous
lectures. So, this could be one of the port pins, there is another way to connect the switch and
that is illustrated on the left side of this diagram. Now, we want to vary the output and have a
different relationship between the on and off state of the switch to logic 1 and logic 0.

And now we want that when the switch is pressed, I want a logic 1 and when the switch is
released, that is when the switch is not pressed, I want logic 0. Now, instead of connecting the
resistor to the positive supply voltage as you see here, I have connected it to ground and the
terminal the junction of the upper pin of the resistor and the lower pin of the switch are
connected and this is connected to port pin.

Now, what will happen when the switch is not pressed the port pin will see a logic 0 that is what
we wanted when the switch is not pressed when the switch is off we want logic 0 when the
switch is pressed, it connects the input pin to the VCC and you get logic 1. If you consider both
these options on the right side when the switch is not pressed, the resistor R1 pulls up the input
voltage to VCC and so you get 1 that is when the switch is off you get logic 1 here when the
switch is off you get logic 1.

When I press the switch that input terminal input pin is now connected to ground and so you get
this state. So, it will depend on you. Where you whether you want to connect the switch in the
Pull Down, using the Pull Down resistor configuration, or Pull Up resistor configuration.

In many microcontrollers, they have a facility to in where the resistor whether it is a pull up
resistor or pull down resistor, this is available on the port pin and we can engage whichever
resistor we want, we want a pull up resistor or pull down resistor so that you do not have to
connect external resistors like we have connected here. Although you may still connect external
resistor just to be on the safe side.

What is the value? What are these values of these resistors it is very important you cannot just
arbitrarily connect any value.

307
(Refer Slide Time: 12:46)

So here in this diagram, I am going to illustrate how to calculate the value of R1 or R2 in this
case, pull up or pull down resistors and both these values of resistance may not be same, and I
am going to take an example from the datasheet of MSP430 but we could consider other
examples also so that you are well equipped to choose the values of the pull, pull up and pull
down resistors whatever be the situation.

So, let us see the datasheet of MSP430 the relevant portions of the datasheet so that we can
estimate the value of the pull up and pull down resistors.

308
(Refer Slide Time: 13:31)

So, here is the here is a page from the datasheet. Now if you come to this part here, this talks
about the logic thresholds that an MSP430 recognizes and it has options for 3 volts and we are
going to use that. So if you see if the VCC is 3 volts like here, then the minimum voltage for
input to be considered as logic 1 is, you see here 1.35 volts and a minimum maximum voltage
when the input is to be treated as logic 0 for the same 3 volt is 0.75 volts.

So, we are going to utilize these numbers in our calculation. Similarly, when the input pin does
not have a pull up or pull down resistor because we are considering here how to estimate the
value we are going to program the MSB430 so, that neither the pull up resistor or the pull down
resistor is engaged but still that input pin will have a current which will flow out of the pin, if the
pin is grounded and if the pin is connected to VCC it will have a current going in.

And for that you see here the leakage current of a port pin is listed to be 50 nano amperes. So, we
have now let us go back here, let me add a sheet.

309
(Refer Slide Time: 15:08)

So we have ViH, the value is 1.35 volts 1.35 volts, ViL is 0.75 volts 0.75 volts and the current I
plus as well as I minus that is the current that goes into the pin or comes out to the pin is listed to
be 50 nano ampere. Let us go back to this diagram. Now, let us consider the first case of
Switch-1 where we have a pull up resistor. Now, here is my microcontroller. I have connected a
pull up resistor and here I have connected my switch and the switch is grounded.

I will connect it to VCC since we considered a VCC of 3 volts, let me write here that VCC is 3
volt, this device is also powered with a 3 volt source 3 volt. Now, we want to estimate the value
of R1 that is what is listed here. Now, when the switch is not pressed, because there is a pull up
resistor, positive current will go into the pin and this current from the datasheet we have
estimated to be 15 nano amperes.

And therefore, this current has to come from the supply it will lead to a voltage drop across R1
which is VR1 will be equal to the value of R1 into 50 nano ampere. Now, how much do we want
this voltage to be obviously, we want this voltage to be as small as possible, but that would mean
that the value of R1 has to Very small, if that value is very small, how is it going to impact the
overall design that when the switch is pressed, the small value of the resistor will allow a large
amount of current to go into the ground from the power supply.

310
And if it is battery driven, it will discharge the battery faster. So, we would like to keep the value
of R1 as high as possible, so as to minimize the current going into the ground terminal when the
switch is pressed, but it should not be so high that it leads to when the switch is not pressed. We
want the input to be treated as ViH. So, we want the voltage at the input to be more than 1.35
volts.

Let us say that we want the voltage to be 1.5 volts because 1.5 volts is certainly more than the
threshold. So, it allows me a margin of 1.5 volts on R1 and it will still leave at the input I will
still have 1.5 volts which will be recognized as logic 1 and therefore, we have estimated from
this that VR1 can be 1.5 volts therefore, 1.5 divided by 50 nano ampere is going to be the value
of R1.

So, if we see this it is 1.5 that nano comes up it becomes into 10 raise to power 9 divided by 50.
So, this will be 10 raise to power 7, 15 into 10 raise to power 7 divided by 5 and that is 3 and that
therefore, the value of the register is 30 can be 30 into 10 raise to power 6, which is 30 megohm
which is a very high value of resistor and in reality you can keep this value to be less than that
maybe a megohm or something like that, that would still give a lot of current allow for a lot of
current and it will lead to a slightly less voltage drop across R1 which is a good thing.

But, using these calculations we have estimated the upper limit the resistor value of r1 should
never be more than 30 megohm it can be much less and probably a megohm or half A megohm
500 kilo ohm could be a appropriate value of the resistor. Let us now consider what will be the
value of the pull down resistor if we want to use that.

311
(Refer Slide Time: 19:43)

So, our configuration is that we have the switch between VCC here is my switch and this is
connected through a resistor to ground. This is connected to VCC here which is 3 volts this is
your MSP430 just so that we are sure my resistor values now R2. Now, when the value when the
switch is not pressed I would want the input here to be a voltage which is ViL or less we have
estimated previously that ViL 0.75 volts.

So, we would want the voltage at this terminal to be much less than ViL that is 0.75. Let us say
we want the voltage at this junction let call it A. VA we want it to be say 0.5 volts and the
current now because of the resistor R2 being grounded, the input current from the pin is going to
flow out the amount of the value of this current is 50 nano amperes as estimated from the
datasheet, and therefore 50 into 10 raise to the power 9 into R2, this is the amount of I am sorry,
this is let me write this again.

VA is equal to the current I into R2, I is 50 into 10 raised to the power minus 9 amperes into R2
VA we have estimated to be 0.5 volts and therefore the value of R2 is equal .5 divided by 50 into
10 raise to power minus 9, which becomes 0.5 into 10 raise to power 9 divided by 50. This
cancels one of the 0s, this leads to 0.5 into 10 raise to power 8 divided by 5 and I cancel this. So,
it is 0.1 into 10 raise to power 8. So, that is 10 raised to the power 7 ohms and that can be, that
would be 10 megohm.

312
So, the value of resistor R2, R2 should be anything less than 10 megohm. So, I could again use a
4 1 megohm or 470 kilo ohm resistor, just because I am going to use that value for the pull up
resistor. So, I could use an identical value it would lead to a voltage drop which is much smaller
which will be lesser than 0.5 volts and therefore, I would be able to provide I would have
translated the two states of the inputs that is on and off state of the input switch into logic 0 and
logic 1.

Well above the high threshold or low threshold as the case may be. And so, this is the way to
calculate. In reality, if you are going to use MSP430 you can engage the internal pull up or pull
down resistors and you may not use R1 and R2 at all, but as a electrical engineer, somebody who
is designing embedded systems, one should know how to calculate the values of pull up and pull
down resistors and this exercise I hope you have learned that.

(Refer Slide Time: 23:47)

Let us go to the next aspect. Now, the problem with Mechanical Switch such as such as this
meaning this is that when you press the switch, it does not change the state instantly. In fact it
bounces between the two states for a short duration of time meaning it is not completely on or off
it is on off on off before settling to on state if you have pressed it and when you release again, it
oscillates between these two states before settling to the off state.

313
(Refer Slide Time: 24:18)

And this feature of a Mechanical Switch is called Switch Bounce. We are illustrated here that if
we use a pull up resistor with a switch, then the voltage of the, at the output of that configuration
would be high. This is what you are seeing here. But the moment the switch is pressed it is
expected to go low. Let us say this will be the 0 volts but it does not settle to 0 instantaneously.
In fact, it oscillates for some time.

Here is the time that it is actually bouncing. And then you would have pressed the switch for a
certain duration of time when you release again, you have released at this point, but it oscillates
for some time bounces between logic 1 and logic 0 before settling to the high state. Now,
obviously, we must know, what is the duration of this bounce?

Because if this bounce the duration of this bounce is comparable to the execution rate of the
microcontroller, then it each switch press will be treated as multiple switch presses and that is
certainly not very desirable.

314
(Refer Slide Time: 25:25)

And so, here is a physical capture of a logic digital storage oscilloscope with the same pulled up
resistor and you see hundred microseconds we see roughly 1, 2, 3 we have roughly if you see this
as you see this, this is roughly I would say about 300 microsecond duration and certainly a
microcontroller would be executing will be able to execute several instructions in these 300
microseconds

And therefore, this is not a good way to connect a switch directly to the to the microcontroller
pin it would be considered when you press one switch it would be treated as the switch has been
pressed multiple times even if you have pressed it once and therefore, this bounce has to be
removed this activity of removing the bounce of a switch is called Switch Bounce.

315
(Refer Slide Time: 26:21)

And we must is called debounce and we must consider we must have some mechanism to
debounce the switch. There are two options, one is Hardware debounce and the other is a
Software debounce.

(Refer Slide Time: 26:37)

Hardware debounce would, because the these oscillations are high frequency in nature, you
could apply a low pass filter and you can filter out this can be treated as noise and so, a high
frequency noise and you can filter it out using a low pass filter such that, such as this you could

316
probably this is a low pass filter this input from here and here is the output this, this filter
configuration will remove this noise.

But the objective in the embedded system design is to minimize external components. So, I
would not like to you would not like to engage more components because that will take a PCB
space it will take up external components which will increase the cost.

(Refer Slide Time: 27:19)

So, are there other methods of Debouncing the switch? Yes, there is a method called Software
debounce and what do you do in a Software debounce that when the switch, you press and you
expect the switch to bounce the moment the first time you notice that the switch has been
pressed, you can execute a delay sub routine and that delay sub routine can be little more than
the expected debounce.

So, if we have estimated in the previous DSO capture that the bounce happened for about 300
microseconds I could easily write a delay sub routine of one millisecond that is 1000
microseconds and I will execute this delay when I come back, it would bring me somewhere here
and so, this would be very nice. And now again when the, I would wait for the switch to be
pressed again.

When the switch is pressed at that point of time, you would the, the output would again bounce
before settling to logic 1. And the moment the first time I detect the switch has been released, I

317
would again call this one millisecond sub routine and when I come back I would be somewhere
here, which would have where the, the bounce phenomena would have finished and I would have
physically I would have debounce the switch using software without any external components,
which will keep the cost down.

Of course, with a little more overhead software overhead, but this is what we normally do. And
let us see. Now once you have connected the switch, single switch, if you have if you want if
your system requires a few switches, you can engage few pins, but as the if your requirement is
of large number of switches say 10 or 20 switches, it may not be feasible to have spare 20 pins to
connect 20 switches.

What do you do in that case well, we use a Switch matrix and in the next session we are going to
look at how to connect a matrix of switches to a microcontroller so as to minimize the number of
pins and yet be able to read every single pin every single switch even in the matrix of switches it
will provide you, it will illustrate, it will show bounce and it will have to be debounced in
software. So, we will consider these ideas in the next session. Thank you.

318
Introduction to Embedded System Design
Professor. Dhananjay V. Gadre
Netaji Subash University of Technology
Professor. Badri Subudhi
Indian Institute of Technology, Jammu
Lecture No. 16
Physical Interfacing - 2

Hello, and welcome back to this session. In the previous session we had seen how we can
connect a single switch to a microcontroller pin and just to reiterate and also talk about the
debounce activity using software.

(Refer Slide Time: 00:41)

If the switches as you see in this slide, I will read it drawn, if the switch is not pressed, then it
will give a logic 1. When the switch is pressed it will give logic 0, but when you press the
switch, the switch will bounce and how to handle that in software is what I am going to just write
here again.

So, you are going to wait till so that we call SW switch is equal to 1. So, if you wait while switch
is still the switch is 1, that means you are waiting for the switch to be pressed the moment
switches become 0, you are going to get logic 0 you are going to call a delay for we had
mentioned say about 1 millisecond then after you come back from the delay the switch will give

319
you a logic 0 because the duration of time for which you would a human being would presses
which would be significantly more than this.

So, you are going to wait for the switch to be released. So, wait till switch is equal to logic 0.
And once you find that the switch has been released, you will get a logic 1 again but it will
bounce. So, you are going to delay for again 1 millisecond when you come back from the delay
hopefully this switch will have logic 1 and now you can go back with the with the understanding
switch has been pressed and released, pressed and released and therefore, thereafter you can do
whatever you wanted to do in response to this switch being pressed.

So, all this will become part of your software as a debounce activity. Now, we have seen how
one switch can be handled by the microcontroller. Let us now see if you have multiple switches,
and you do not have individual pins to connect to each of these switch. How are you going to
handle large number of switches, and that is handled by connecting these switches in a matrix
form.

(Refer Slide Time: 02:58)

One, the argument behind the matrix is as follows that you would create row and column let us
say, I create a row and column of 3 rows and three columns. And I connect 3 registers, which are
pull down resistors and these are going to come to columns are going to come from output pins
of microcontroller.

320
And these rows are going to go to 3 pins which will have to be programmed as input and at the
junction of each of the row and column you would connect a switch. So, what you have seen is
that using 6 pins 3 configured as output and the rest 3 configured as input, you are able to
connect how many switches 9.

And this scheme can be extended to cover or connect large number of switches to a
microcontroller system. Let me show you a better drawn diagram so that we can discuss this
technique further.

(Refer Slide Time: 04:08)

This is the matrix of Matrix of Keys. Here we see the microcontroller we have is a MSP430 let
us say it MSP430 and 3 of these pins P1, P2, P3 will be programmed as output. The other 3 pins
here P4, P5 and P6 will be programmed as input. And we see that P3 is connected to these 3
switches S1, S4 and S7 to one end of these 3 switches, P2 is connected to S2, S5 and S8 here and
P1 is connected to S3 S6 and S9.

Similarly, P4 is connected to the other end of S1, S2 and S3 and there is also a pull down
resistor. P5 is connected to S4, S5 and S6 and there is a pull down resistor R2 and P6 is
connected to S7, S8 and S9 with a pull down resistor. Now, you need a bigger software sub
routine to handle this activity.

321
(Refer Slide Time: 05:17)

So, this Read keyboard function let me describe it here with call this subroutine as Read KBD,
short for Read keyboard. This function will be called by the microcontroller and it will perform
the task of identifying if any switch has been pressed and if a switch has been pressed, what is
the code of that switch?

Now, I have brought this diagram here for easy reference. We know that port pins P1 P2 P3 have
been declared as output pins. Port pins P4, P5 P6 are input pins and there are 3 pull down
resistors R1, R2 and R3. So at the beginning of the subroutine, the subroutine will set P1 equal to
P2 equal to P3 to logic 1 and then it is going to read the value of port pins P4, P5 and P6. So, it
will perform a read operation for Read P4, Read P4, P5 and P6.

Now in the situation that no switch amongst these 9 switches is pressed, the logic that will be
returned on port pins P4, P5 and P6 will be a logic 0. Why? Because we have these pull down
resistors. Now imagine that switch S1 is pressed by the user. So, the moment switch S1 is
pressed, because the sub routine is reading P4, P5, P6 not only will it read it once it will keep on
reading for some time and the moment switch S1 is pressed because P3 is also set to 1.

P1 and P2 are also said to 1. It will return a value on P4 equal to logic 1 all right. So, P4 if S1 is
pressed by the user P4 is going to return a logic 1. However, if you notice P4 is not only
connected to one end of S3, it is also connected to one end of a S2 as well as S1. Now, it was S1

322
which was pressed which made P4 equal to logic 1, but the microcontroller has no means of
knowing whether it was because of S1 being pressed or S2 being pressed or S3 being pressed.

And so, it must do something to identify that what is the reason for P4 getting a value of logic 1?
So, what it will do is it will go through a sequence of operations, the first operation will be 1, it
will set P1 equal to 1, P2 equal to 0 and P3 equal to 0. Now, as you see the moment P3 is set to
0, if S1 was pressed, it will make P4 equal to 0 but P1 is 1 but because S3 is not pressed P4 is not
going to be 1 P2 is 1, but because S2 is not pressed P4 is not going to be 1, to be 1.

And therefore, it would get P4. So, in this situation P1 equal to 1, P2 equal to 0, P3 is equal to 0,
the value of P4 will return a logic 0 again. Then it will go to the next step of identification, it will
do P1 equal to 0, it will reset P1 to 0, it will set P2 equal to 1 now, and it will remain retain P3
equal to 0 and then read P4 again and because only S1 was pressed, the value of P4 will still
return a logic 0.

Then it will go to the third step because there are only 3 combinations for P1 P2 P3. It is going to
be may retain P1 is equal to 0, it is going to make P2 now equal to 0 and it will now set P3 equal
to 1, the moment it sets P3 equal to 1 again, because S1 is pressed the value of S1 will the value
of P3 equal to 1 will come to P4 as 1. So, now P4 will get a value of 1, the microcontroller will
read that P4 is 1 and from here it will conclude that S1 was pressed.

Now, you see the human operation of pressing a switch versus the microcontrollers operation of
performing these tasks, there is a huge difference of time, a human will press a switch and that
switch press will last for several milliseconds or several 100 milliseconds whereas the
microcontroller can perform these tasks quite fast. And so, even when the switch is just pressed
the microcontroller would have concluded that S1 has been pressed.

However, it must wait for this switch to be released. So, what it is going to do is it is going to
wait but before that when you press a switch as we have mentioned there is a bouncing on the
switch. So it has to debounce that switch so it is going to delay called sub routine or delay sub
routine for 1 millisecond. After that, it is going to wait for wait for S1 to be released.

323
And it may take any amount of time because people would they have different habits somebody
may press it momentarily some way somebody may press that switch for a longer duration of
time, the microcontroller has to wait till such time that this switch is released.

(Refer Slide Time: 12:02)

Then what it will do it is going to again, when the switch is released again the switch debounces,
switch bounces and so it must debounce it so it is going to again called a delay sub routine of 1
millisecond.

And after that it will check the value of P4, while P3 is still 1, P3 is 1, P2 is 0, P1 is 0. If the
switch S1 is released now P4 will return a value of 0. And so now it will conclude that yes, S1
was pressed and it has now been released. Now it has to send the value of a code so that the main
program can be informed that it was switch S1 that was pressed.

324
(Refer Slide Time: 12:52)

Now how will you go, how will you indicate to the calling program. you will have to encode
these 9 switches using a 4 bit switch code. And one of the values will be for S1 and so on. So, 9
values will be taken using a 4 bit code, you can have 16 combinations, 16 combinations and out
of these 9will be used, the rest are not to be utilized and so, the main program will get the
information that which of the 16 which has was pressed if any switch was pressed.

(Refer Slide Time: 13:32)

Now, when you create a sub routine like this, this sub routine can be written in two form

325
(Refer Slide Time: 13:36)

And now I am therefore, talking about the software aspects. Any sub routine such as this which
is going to be used by the microcontroller to read external inputs can be written in two forms and
they are called Blocking Subroutine or the same Subroutine can be written as a Non Blocking
subroutine. What is the difference?

In a blocking sub routine here, when the subroutine is called the subroutine will not return till a
activity is detected, which means if I call read keyboard sub routine if I design it to be of the
blocking nature till a user presses a switch, it is not going to return to the main program. What
will be the return value of such a blocking subroutine? Only a switch the code number which
would indicate which switch was pressed.

But why is it called blocking because it blocks the performance or blocks the operation of the
main program. Sometimes this may be a desirable method of writing a subroutine, but in the case
of keyboard, this may not be a very good way and instead we program we write the subroutine in
a non blocking format.

Now, a non blocking subroutine would have two return values. First value will be one of the
values will be the switch code and the let me not say that let me say that the first value will be a
True or False and the second value will be Switch Code, switch code, what is the interpretation?
So, when the non blocking will wait for default amount of time for the user to press a switch.

326
If during that time the user does not press a switch, it will return to the main program with the
one of these values set to false to indicate that knows which was pressed and in fact, there is a
timeout and the value of switch code will be ignored by the main program. On the other hand, if
during the default time that is the time for which the subroutine is going to wait for the switches.

If during that time, which we call as a timeout period within the timeout period if a user presses a
switch, then after it has detected which switch was pressed, the subroutine will return the true
and false value equal to True plus the Switch Code.

So, the main program when it calls a read keyboard sub routine, which is written in a non
blocking format, when the subroutine returns, it is going to first check the value of this true or
false return value if it is set to true then it will understand it will know that a switch was pressed
and it will find out which switch was pressed by looking at the switch code.

And this is the most common method of writing a subroutine for a Switch Matrix. Imagine if the
switch matrix such a switch matrix was used in an ATM machine. If it was written in the
blocking subroutine method, it is going to block that resource completely. Because suppose you
insert your ATM card into the machine and you refuse to enter, enter your passcode the machine
is going to wait till you enter it so this is not a very advisable method.

And you would have, you would notice that when you use ATM machine when you insert your
ATM card, it asks you to enter your PIN number. If you do not enter your PIN number for a
specified period of time, the ATM machine returns your card and says timeout. This is why this
is the reason this is to indicate that the subroutine for the keypad on ATM machine was written
in the non blocking fashion.

And so we will see in our subsequent lectures, we will show you how to write this non blocking
sub routine for a switch matrix if you would like to interface. Let us go to the next aspect. Now,
we have seen that using switch matrix you can connect several switches to your microcontroller
system. There is one more interesting method of connecting multiple switches and in fact using
even lesser number of pins.

In the first configuration, you saw that you could connect one switch per pin. In the second
configuration creating a switch matrix you could connect multiple number of pin switches to a

327
few number of pins. But here is an alternative method which uses a single pin however, that pin
should have the capability of reading analog voltages.

(Refer Slide Time: 18:43)

So modern microcontrollers, as we know have if this is MSP430 or and similar microcontrollers


if this is MSP430 which as you know has several ADC inputs. using one of the ADC inputs, you
can connect as I have shown here, you can connect 4 switches, but there are some additional
hardware required as in this case, we need 4 additional resistors and let us say we decide the
values of these 4 resistors to be equal values and let us say the values are R1 equal to R2 equal to
R3 equal to R4 is equal to 10 kilo ohm each.

Now, how is this system going to work you are going to write a subroutine where you are going
to continuously sample the ADC value. Now, when no switch is pressed, what will be the ADC
voltage? Will be because of the pull up resistor it will read almost VCC which means the ADC
will have a maximum count if it is a 10 bit ADC, which MSP430 has, then you can expect that
the count on the ADC will be about 1023 or near about that value or 1024.

Now, if S1 is pressed because the other side of S1 is connected to ground, it will give a 0 volts
on the ADC. So, you would know if the ADC input is 0 volts if the ADC input is more than
thousand that means no switch is being pressed. If the ADC input is near 0 volts, that is count
near 00 a few numbers that means S1 was pressed.

328
On the other hand, if S2 is pressed the voltage at this junction, the ADC input will be half of
VCC because all these registers are equal. So, you can expect VCC being 3 volts, VCC, VCC is
3 volts so you will get about 1.5 volts at the ADC input. So, the corresponding count
corresponding to 1.5 volts you can expect. So, when you get 1.5 volts, you can conclude that S2
pressed.

If on the other hand S3 is pressed, that means this part of the resistor R3 is grounded, that will
give a volts voltage at the ADC input which is 2 by 3 of VCC. That means you are going to get
roughly 2 volts that means S3 pressed. Similarly, if I press S4 it is going to put an ADC value
equal to 3 by 4 of VCC which is about 2.25 volts. And so if you read the ADC count
corresponding to 2.25 volts, then you conclude that S4 is pressed.

And of course, here also you will have to debounce and perhaps you could connect a capacitor
from here to this, so that it will filter the ADC input and it may also be used for debouncing the
voltages because of the switches being pressed.

But you can still add a delay and then wait for the ADC values to stabilize to conclude whether
S1 is pressed or S2 is pressed or S3 is pressed or S4 is pressed and you can extend this technique,
but you should not you may not be able to connect many, many too many switches because the,
the entire range of the ADC, in this case 10 volt the 3 volt range has a count from 0 to 1023. As
you add more and more switches you would get a smaller range of numbers.

And in fact using equal value resistors of 10 or whatever kilo ohms each is also giving you a
nonlinear counts meaning when switch S1 is pressed compared to when nothing is pressed you
get an entire variation from 3 volts to 0 volts. Whereas, when S2 is pressed you go to half as you
see the difference between the voltages here, this is less, and even less and so on. And so, one
method could be to appropriately select the values of R1, R2, R3, R4 to be non equal values.

So that you get a voltage range which is equal parts from VCC to 0. And yet, one does not
recommend this technique to connect more than four and five or maybe seven, eight, ten
switches at max. So, this is an interesting method to connect multiple switches on a single ADC
pin of a microcontroller.

329
Let us see what all we can do. Now the next input device is a Rotary Encoder, what is a Rotary
Encoder? Usually it is a knob and this is how it looks physically,

(Refer Slide Time: 24:17)

But electrically it has 4 pins. One of the pins is VCC that means you have to connect it to VCC.
Another is ground and there are usually two outputs labeled A and B. What it does is let us say
this is the reference point of this Rotary Encoder, as you move it either clockwise or anti
clockwise, it would give you pulses on A and B outputs. And the rate of the pulses that you are
getting will indicate that you are moving the Rotary Encoder fast.

If the rate is low, that means you are moving it slowly for so let us say, suppose this is the 360
degrees that is one entire rotation is suppose this is a 4 bit encoder that means, you have 16 parts,
which means for every how much is that roughly, roughly 20 degrees 25 degrees of rotation it
will give you 1 pulse.

So, if you move this 25 degrees from the reference it will give you 1 pulse, but you would not
know have you moved it in the clockwise direction or anti clockwise direction and for that, that
is the reason why these two outputs are provided these two outputs are called Quadrature Phase
Outputs. Which means the pulses on output A and B are 90 degrees apart, let us see how these
pulses look like.

330
(Refer Slide Time: 26:06)

So, I have drawn the two sets of pulses, these are the output on A and B in one case this could
be, this could be clockwise motion of the encoder may give you this relationship between A and
B as you see, if you consider the reference to be B, that means during the time that B is high, A
is going from 0 to 1.

So, by measuring the relative phase of A and B you can know that the Rotary Encoder is being
moved in a clockwise direction. How many times? What angle it has moved each pulse? So, each
of this pulse each of this edge indicates that it has moved about 20 degrees, 25 degrees as the
case in this case of 4 bit encoder, however, if now the Rotary Encoder is moved in the
counterclockwise direction.

Now, you see for the same reference of B, the signal on A is a falling edge. So, you had to see
whether during the time that B signal is high, does the A signal have a transition from 0 to 1 that
means it goes in the clockwise direction. If it is going from 1 to 0 that means, it is going in the
counterclockwise direction, the angle will be measured by how much, by how much angle the
encoders moved will be measured by counting these pulses.

So, in the software in the microcontroller will have to keep a count and it can increment or
decrement that count based on whether the encoder is moved in the clockwise or counter
clockwise direction and the number of pulses will decide whether the count goes up or goes

331
down depending upon whether it is moved in the clockwise or counter clockwise. This is the anti
clockwise direction. So, this is one of the popular inputs with which users can interact with the
microcontroller system.

(Refer Slide Time: 28:18)

Now, let us see how we can connect some output devices to our microcontroller system and
these would form from the, the output box and we see the ways multiple ways in which
microcontroller can interact with the outside world would be through LEDs of various types. As
we had listed in that block you have LEDs, normal LEDs, you have RGB LEDs. You can also
addressable RGB LEDs, you have 7 segment displays.

You have dot matrix displays LCD and through sound output. Other outputs could be to control
relay and motors you would like to control heaters or a Peltier module with which you can heat
or cool you may want to control the speed and direction of SP DC motor as well as a Stepper
motor. And so in this session we are going to in this part of the lecture we are going to consider
how to control LED is to begin with.

And then we will see how we can control Relays, how we can control Peltier modules and DC
motors and so on. We will resume this lecture, this discussion in the next lecture. Thank you very
much.

332
Introduction to Embedded System Design
Professor Dhananjay V. Gadre
Netaji Subhas University of Technology, New Delhi
Lecture 17
Physical Interfacing - 3
Hello, welcome back. We are going to continue our discussion on how to connect LEDs in
various ways. LEDs and RGB LEDs and even 7 segment displays. So, let us begin.

(Refer Slide Time: 00:37)

Now here if you look at this diagram that I have drawn. Here, my microcontroller is MSP430, for
example, and I have shown that I have collected 4 LEDs in 4 different ways. This is to ensure
that you understand that LEDs are can be seen as binary devices. Binary output devices which
means either the LED is on or off. There is another way to control LEDs where I would like to
change the intensity of an LED, which will consider in a latter part but here, let us see how we
can. So, if you see this is wrong, this is output OP1.

In the output 1, I have connected the LED with a resistor R1. At the output pin number 2, I have
connected the resistor first and another LED. On output 3, I have now used a different
configuration. I collected the LED first and then the resistor R3 and for output 4, I have
connected the resistor 4 first to the pin of the microcontroller and then the LED. Now, the
question is how different. Are they all same or are they very different? Well, the answer is that
LED1 and LED2 are identical.

333
These are LED1 and LED1 and 2 are identical in connection and LED3 and 4 are identical too
and they are different from LED1 and 2. How? LED1 and 2 would light up when the output OP1
or OP2 is high. That is logic 1. On the other hand, LED3 and 4 would light up when the output of
these pins that is OP3 and 4 is logic 0 and so these 2 LEDs will be called as active high meaning
they are lighting up when the output is logic 1 and these 2 LEDs will be called active low
outputs.

They are lighting when the output is 0. Also, we are controlling the high side of the voltage for
LED1 & 2. That is why we have written high side control and for LED3, we are controlling the
lower potential of these LEDs. So, we call it low side control and now let us see what should be
the value of resistor R1 and R2 because R1 and R2 will be same value because the 2
configurations are same whereas R3 and R4 are also same but they might be different from R1
and R2.

How should you select the value of these resistors? That is an important point. So, first of all for
that we have to consider what is the voltage drop across the LED. Now, most of the time when I
asked this question to beginner students, they say the voltage drop across LED is 0.7 volts. For
some reason, they think that the LED is also a normal silicon diode but that is not the case.

(Refer Slide Time: 04:04)

In fact, the voltage drop across LED, voltage drop across and here I mean in the forward region
across LED depends on colour of the LED and we have the entire range of LEDs available which

334
emit different colours and they might be VIBGYOR. Your you might have red coloured LED,
you may have orange, yellow, green, blue, indigo and violet. So, it turns out that if you have a
red LED, which has the smallest energy. This has the smallest voltage drop across it whereas the
violet or blue in this range as you go to these colours, the voltage drop across the LED increases
because the bandgap required to emit these colours is more and therefore the voltage drop is
more.

Typically, a red LED has a, red LED requires about 1.6 volts and as you go towards blue, the
voltage goes from 1.6 to maybe 2.2 for orange and yellow maybe for green about 2.5 volts and
for blue roughly 3 volts and so you must consider this when you are designing a system to
control these LEDs. Let us go back.

(Refer Slide Time: 05:52)

Now, here we see we have the VCC here. Now, if the VCC itself is 3 volts then it may be
difficult to control a blue LED but MSP430 can, the supply voltage can go up to 3.6 volts. So,
we can power this with say 3.6 volts and we will be able to connect blue LEDs also. However, in
the calculations we must use a forward voltage drop across an LED appropriately so that we can
estimate the value of the resistors.

335
(Refer Slide Time: 06:26)

So, what all we need to know? We need to know what is the voltage drop across the LED.
Secondly, to control these LEDs we need how much what should be the value of the resistors and
now the question is how to calculate. Now the 2 calculations for the 2 setups are different and let
us go through those calculations.

(Refer Slide Time: 06:49)

In the case of a high side control meaning I have the LED set up so that they will light up when
the output voltage is high here in this case. So, let us say this is R1 and let us say this is some
LED. Let us say this is R red LED and I do not have to use exact values. I will use symbolic

336
values here. So, when I turn the pin to logic 1, the voltage of this will be V OH. The voltage
across the LED will be V LED. You can find out from the data sheet that what is the voltage
drop across a red LED. This difference is the voltage across R1 and therefore the current through
this will be I is equal to Voh minus V LED divided by R1.

Now, suppose you want 5 milli amperes of current. Let us take some numbers. Let us say V oh is
3 volt. If your VCC is say 3.6 volts, this is equal to VCC and let us say V oh is V oh is equal to 3
volt. The exact value you should find out from the data sheet. Let us also assume that V LED for
a red LED is say 1.6 volts and let us say we want the current to be equal to 5 milli ampere and
therefore this becomes 3 minus 1.6 upon 5 into 10 to the power minus 3 amperes. This is 1.4
divided by 5 kilo ohm.

So, this is 1400 divided by 5 ohm and this is roughly R1 will be equal to roughly 300 ohm and
you can safely use a standard value of 270 ohms in this case to allow about 5 milli amperes of
current through the LED.

(Refer Slide Time: 09:10)

On the other hand, if you want to control the LED in the low side control method, then your
configuration will change and it will be here is my microcontroller MSP430. My VCC is set to
3.6 volts. Here is my ground and here is my output pin say output 1 and I have connected the
LED in the low side control. Here is my VCC and this is now say R2 and this is still red LED.

337
As I mentioned earlier the LED will be turned on when the output 1 is set to logic 0 but when the
output is set to logic 0 the output voltage is not 0 volts. In fact, the maximum value of voltage
that you will get will be VOL and we can go to the data sheet to find out the value but let us
assume that VOL, this is 0.4 volts. We will still assume that V LED for this red LED is equal to
1.6 volts. My VCC is here 3.6 volts. The V LED 1.6 volts. The VCC is 3.6 volts and we want to
estimate the value of R2 from the current that we desire through the LED.

Let us say the current we want through the LED is also 5 milli ampere. Now, the calculation will
be 3.6 volts minus V LED, which is 1.6 volt minus the V OL output which in this case is 0.4
volts divided by 5 milli ampere. Therefore, the resistor R2 is equal to 1.6 volt because this is 2
minus 0.4 1.6 divided by 5 milliampere and now this is about 1600 ohm divided by 5.

So, this would be roughly 320 ohm and so you can R2 is 320, ohms and you can use a standard
value of 330 ohms for allowing about 5 milli amperes of current through this configuration.
Now, what if you wanted to increase the current through the LED through either of these
configurations whether low side or high side. Let us see that but before that let us see other than
the LEDs, individual LEDs what all can be controlled.

(Refer Slide Time: 12:11)

And in this case, here is an example of a 7-segment display. A 7-segment display is actually a
misnomer because there are 8 segments as you see here. You have a b c d e f g and a decimal

338
point. So, really there are 8 LEDs in a 7-segment display. Now, these 7 segments displays come
in 2 varieties.

(Refer Slide Time: 12:38)

One is called common anode which means this display internally will have 8 LEDs and the
anodes will be connected together. So, you would have 8 LEDs. This is the so this terminal will
be called common anode and you would have a b so on and so forth up to the dp and the other so
this is common anode.

The other type of LEDs, 7 segment displays are called common cathode where what do you have
is that the cathodes of the LEDs are all connected together like this and this terminal will be
called CC that is Common Cathode and here are the actual inputs. So, this is your a, this is your
b and so on and this is your dp that is decimal point. Now, how can we connect these 7 segments
displays to microcontrollers. Let us look at this game.

339
(Refer Slide Time: 13:57)

So, I have shown here that a microcontroller in this case, let us say we are talking of MSP430
that we have 2 ports. This is port 1 and this is port 2. Each port has 8 outputs and we have used
common cathode LED here and we have used 8 resistors and how to calculate the value of the
resistors here because here common cathode, the common point is grounded. That means what
sort of control will you be exercising. This will be high side control that is when an individual
port pin here is set to 1, it will turn that led on. If you want to turn a LED off, a segment off, that
port pins will have to be set to 0. The value of the resistor will be calculated in the same way as
this calculation.

340
(Refer Slide Time: 14:55)

This calculation why because the cathodes are of each of these LEDs are grounded. So, I do not
have to repeat that discussion here. Another method to connect these LEDs instead of common
cathode LEDs you can have well here is another variation to that. Now, you may wonder that
instead of connecting using 8 resistors can you connect use a single resistor like this.

(Refer Slide Time: 15:25)

And this way you can save 7 resistors. Well, this may seem like a good deal but this will give
you unequal intensity of the LEDs. Now, imagine that you want to turn only 1 LED out of these.
Maybe you want to just display a bar. So, this particular LED you want to turn on. So, the

341
corresponding pin will be set to 1. The rest of the pins output pins will be 0 which means this
resistor, the current that can flow through this configuration is going to all that current is going to
flow through 1 LED.

So, it will grow bright. Now, imagine that you want to display 1 which means you want to turn
this and this led on. Now, this same current will be shared by 2 LEDs. So, the LED intensity will
become half. Similarly, if you display dash, you will get certain intensity. When you display 1,
you will find that the intensity has become half. If you display 2 which will look like this. How
many LEDs have you turned on? 1 2 3 4 5 LEDs.

That means the current through each LED becomes 0.2 times the maximum current so each LED
will be roughly lighting up with one fifth the intensity and so although this appears to be
economical method because it uses only one resistor. What you will end up having is that as you
change the display numbers the intensity of that display would vary and therefore it is not very
recommended to use this configuration and so one should use a resistor on all the pins as
mentioned yet.

Also, important to know is you have to know which segment is connected to which pin of the
port because in the software this will be used so that you can display numbers or any other
symbols on this display and we will cover that when we do an exercise to control 7 segment
displays using MSP430. Right now, we are only looking at the electrical aspects, the circuit
aspects of controlling 7 segment displays.

342
(Refer Slide Time: 17:37)

The second method would be to use common anode LEDs. Now, here the anodes are common.
Therefore, it is connected to VCC and the cathodes are the segments which is a b up to dp. They
are connected to port pins. This is your MSP430 microcontroller and here the calculations will be
same as we saw. This is low side control and so the calculations would be what we did is equal
to the resistor value will be to VCC minus VLED minus VOL divided by the current that you
require.

This is the value of the resistor and you would have all these 8 resistors equal to this value as we
estimated in the last calculations for 5 milli amperes of current and read display 7 segment,
display the value of resistor. Each one of these will be, I think we got a value of let me go back
and check. This was 330 ohms.

So, in this case, you can connect all these 330 ohm resistors, 8 of them like this and here I have
shown that we have connected 2 digits so we can have we can just use this to display numbers
from 00 to 99 or if you want to display hexadecimal numbers, you will be able to display from
00 all the way up to FF which means you can display a total of 256 values on these 2 sets of
displays.

343
(Refer Slide Time: 19:16)

Let us see how what else we can do. Now, imagine that we want to increase the current through
each of the these LEDs that is you want to turn these you want to drive these LEDs more
brightly. Then you would require a transistor here as I have shown and we are going to take this
discussion forward in the next few slides.

(Refer Slide Time: 19:37)

Now, here is what I meant when I mentioned that what if you wanted to increase the intensity of
the LED. Now, each of the port pins of the microcontroller has only a limited amount of
capability. As we have seen for MSP430, the maximum current that each of the pins can provide

344
you is about 6 milli ampere and so what if you wanted to drive the LED with say 20 milli
amperes of current. There are 2 ways. This is the first method. If you have multiple pins
available, spare pins, then you can connect 4 resistors to drive a single LED and if you want 20
milli amperes, you can share it each of these to be 5 milli amperes and so together you can drive
20 milli amperes through LED1.

Of course, it requires 4 resistors and the value of the resistor will be calculated assuming that you
want 5 milli ampere and so I think this is if we go back here we can see the calculation here.
Well no, this the configuration is this one and so here we have 330 ohm. So, if you want the low
side control of the LEDs and more current through the LED of say 20 milli amperes, you allow 5
milli amperes each and the resistors. All resistor will be 330 ohm. Now, with this you can turn
the LED on by making all these bits set to 0 and you want to turn the LED off then all these bits
will be set to 1.

Now, this configuration also has an interesting side effect that instead of all the output pins
turned to logic 1 or logic 0 will turn the LED completely on or completely off. What if you
turned only D0 equal to 0 and D1 and D 2 and D 3 are set to logic 1, you will see that the
intensity of LED will go from minimum to maximum and you can actually control the intensity
also not just in a binary way 0 and 1, LED on or LED off. You can have various levels of
intensity in the LED. The other method of increasing the current through the LED is list shown
in the right side of this diagram. Here we have used the npn transistor. Here to control the current
through the LED why because since the microcontroller pin cannot provide say 20 milli amperes
of current we will choose an external transistor and we have to select the transistor appropriately.

345
(Refer Slide Time: 22:27)

So, let us continue with this firm example. Our requirement is that the LED current ILED is to be
20 milli amperes. Our microcontroller cannot provide 20 milli amperes of current. So, we have to
connect an external circuit which we saw in the previous slide. Let me redraw it here for easy
reference. Here is our microcontroller. Here is the output pin. Let us call it OP1. It is connected
to a resistor which we label as R1. Here is the npn transistor. We have to choose a low side
switch and so we choose a transistor as we discussed earlier. The supply voltage is 3.6 volts.
Here is our red LED.

The choice of LED is important because knowing what led we are going to drive will allow us to
know what is the voltage drop across the LED and here is our current limiting resistor through
the LED. We call it R2 and this transistor is T1. Now, we can choose any transistor npn
transistor that will offer maximum collector current which is much more than the load current.
The load current in this case is the current through the LED which we have decided to be 20
milli amperes. So, as long as the transistor is able to handle much more than 20 milli amperes,
any transistor should be fine.

Now, how much is much more? Let us say we use commonly available transistor, which we use
in our undergraduate electronics laboratories BC 547. Then we know from the data sheet, of
course that the maximum collector current IC max for a BC 547 is 100 milli amperes and so such
a transistor would be quite suitable.

346
You could of course choose another transistor which has collector current more than this. Apart
from the maximum collector current that the transistor offers, we also have to look at the data
sheet of the transistor to find out what is the saturation voltage the collector emitter saturation
voltage VCEsat because that is going to come in this loop in the calculations for calculating the
value of R2 and subsequently for the calculation of value of R1.

For BC 547, the saturation voltage is typically in the range of 0.1 volts to 0.2 volts. So, now we
have to calculate the value of R2. So, R2 into the collector current that is ILED that is this volts
plus VLED, the voltage drop across the LED plus VCE SAT as we see here. Here is the VCE
SAT, VCE saturation. All the sum of these 3 elements will be equal to the supply voltage, which
is 3.6 volts. Now, what is the voltage drop across LED? That of course depends on the colour of
the LED and if we choose red LED, typically the voltage is 1.6 volts.

So, we are going to use that as a reference of course for particular LED that you use you must
find out the value of the forward voltage drop across the LED for the given current. What is that
voltage, you must plug it into this equation. So, let us solve this equation for the value of R2. So,
R2 is equal to 3.6 volts minus 1.6 volts for the voltage drop across the LED minus VCE SAT and
let us choose this 0.2 volts as the saturation voltage for BC 547 divided by 20 milli amperes
because that is our load current and so this becomes 1.8 volts divided by 20 milli ampere and this
returns a value of R2 to be equal to 90 ohms.

Of course, 90 ohms may not be a standard resistor value. So, you must choose the nearest resistor
value to 90 and I can tell you that the nearest value is 91 ohms, which is very close to what we
actually need and so R2, the value of resistor R2 turns out to be 91 ohms. Now, having a value of
resistor is important but also selecting an appropriate resistor which can dissipate the power is
also important. In this case, we must find out what is the power dissipated by R2 so that we can
choose resistor which can dissipate more power than that so that it operates in a safe region.

Now, here we can use the PR2 that is the power dissipated by R2. We can calculate using I
square into R which in this case is 20 into 10 raised to power minus 3 milli amperes into 20 into
10 raised to power minus 3 into for sake of ease of calculation, let us plug the value of R2 to be
100 ohms and so this gives me a value of 40 milli watt. If you go through this calculation, this is
what you would get, 40 milli watts of power and a typical 5 percent quarter watt resistor. Quarter
watt resistor means 250 milli watts. That would be quite suitable to be used in this configuration.

347
So, we have seen that what equation to use to be able to calculate the value of the current
limiting resistor with the LED. Now, if you want to change the value of the current from 20 milli
amperes to say 100 milli amperes, you would still use the same approach but find out a suitable
transistor to replace BC 547 which will be able to give you what you need. Which will be able to
handle 100 milli amperes.

So, if you want to conduct 100 milli amperes through the LED, you must choose a transistor
which is say, 200 or 500 milli amperes of maximum collector current and you can repeat go
through these equations again, plug the values appropriately and estimate the value of R2. Now,
that we have the value of R2, we must also estimate the value of the base resistor. What is the
value of the base register here labelled as R1.

(Refer Slide Time: 29: 41)

Let me take you through that equation and for ease of reference, let me redraw the circuit here.
We have value of R1, our transistor T1 which in our case we have decided to be BC547. We
have the supply voltage of 3.6 volts. Here is our red LED, which is going to be driven with 20
milli amperes and our value of R2, which we have estimated to be 91 ohm. Now, we are left to
calculate the value of R1. Here is our microcontroller. Now, a microcontroller will turn the LED
on when the output is logic 1. So OP1, when OP1 is 1, it will turn the LED on. Now when the
output of a micro controller is set to 1, it means it necessarily is logic 1, but it does not mean that
it will have the same voltage as 3.6 volt.

348
If it is also driven with a supply voltage of 3.6 volts, it is not necessary. So, what we have to find
out from the data sheet of the microcontroller that what is VOH that is the output voltage. When
the output is high, what is the VOH for that given microcontroller and in this case from the
datasheet, let us assume that it is 3 volts. 3.0 volts for VCC equal to 3.6 volts. Now, we have to
our collector current is 20 milli amperes. We must saturate the transistor in nominal base current
that will be required to maintain 20 milli amperes of current. The value will be IB is equal to IC
by beta that is the current gain of this transistor.

BC547 is available in many varieties and the simplest value that the simplest version of this
transistor has a beta of about 100 and so our base current that we require will be 20 milli ampere
divided by 100 which turns out to be 0.2 milli ampere. Now, to ensure that the transistor is
driven strongly into the saturation region, we must provide base current which is much more than
this value.

Now, how much is it how much more is much more? Well value of 2 or 3 times or even 5 times
more than this current would be suitable. So, let us first estimate the value of the resistor R1 for
current of 0.2 milli amperes and then we will reduce it by a factor say factor of 2 or 5 so that we
are sure that transistor T1 is driven deep into the saturation.

So, for this VOH, that is the output high voltage is equal to the voltage drop across R1 which is
IB into R1 plus VBE saturation because we are driving the transistor in saturation. For typically,
the turn on voltage for a npn transistor, the base emitter voltage is 0.6 0.7 volts, but when you
drive the transistor in saturation, this voltage is slightly higher and let us we can refer to the data
sheet and it will tell you that the saturation base emitter saturation voltage is 0.9 volts.

So, we have to find out the value of R1. Therefore, R1 is equal to VOH which we have estimated
to be 3 volts 3 minus 0.9 volts divided by base current which in this case is 0.2 milli ampere. So,
the value of resistor, this calculation shows 2.1 volt divided by 0.2 milli ampere here and
therefore the value of resistor turns out to be approximately 10 kilo ohm.

Now, this is the minimum current that you would require for the base current but to ensure that
the transistor is driven strongly into saturation, we must provide a base current which is 2 or 3
times or even 5 times more than this base current and so it will reduce the value of this resistor
by that much factor.

349
So, let us say that we want 5 times more base current so it will reduce the value of R1 by a factor
of 5 and so R1 should actually be 10 kilo ohms divided by 5 2 kilo ohms. So, now we have the
values of all the components that are required. R1 is 2 kilo ohm, R2 we have already estimated to
be 91 ohms. Our transistor is BC 547 and we have chosen the red LED and, in this configuration,
the micro controller will be able to drive 20 milli amperes of current through the LED and this is
the process. This is the steps. These are the steps that you must take to be able to design all the
components to arrive at the values of the components for a low side switch as we have
illustrated. We will resume this discussion in the next lecture. Thank you.

350
Introduction to Embedded System Design
Professor Dhananjay V. Gadre
Netaji Subhas University of Technology, New Delhi
Lecture 18
Physical Interfacing - 4
Hello and welcome back to a new session. In the last session we looked at various ways of
controlling the LEDs through what we call as the low side switching. In that we looked at
various options to increase the current through the LED and we came up with this configuration
of driving LED with the help of a npn transistor operated in a switch mode.

(Refer Slide Time: 00:50)

So, to operate the transistor in the switch mode, it has 2 options. Either the transistor is saturated
or the transistor is cut off. When the transistor is cut off, there is no current through the collector.
Therefore, in our case the LED will be turned off. To saturate the transistor, we must drive a
certain amount of base current which is much more than the base current you would require that
you would get by merely this relationship that base current is equal to the collector current
divided by beta.

If you get a certain amount of base current, if you want to operate the transistor in a switch mode
and you want to saturate the transistor, the required base current should be much more than you
get by this equation and which is what we saw in this example that the nominal value of base
current from this equation is a certain amount which leads to a value of resistor R1 to be 10 kilo
ohm, but to ensure that the transistor is driven deep into saturation, we reduce the amount of the

351
resistor by a factor of 5. As you see here, we have gotten it down to 2 kilo ohm, which will
ensure 5 times more base current than you would get this equation and driving large amount of
base current ensures that the transistor is nicely saturated.

Now, this is all fine when you are driving an LED where the supply voltage is constant, but
imagine a situation where the supply voltage is being derived out of a battery. As you use the
battery the battery voltage will go down and, in this situation, the reduced battery would lead to a
current through the LED which will keep on reducing why because your VCC is going down.

Now, how do we ensure that the LED current remains constant even though the battery voltage is
going down. So, let me show you a configuration where we can drive the LED with a constant
current source or current sink in this case so that for the entire lifetime of the battery, usable
lifetime of the battery, it still provides a constant current.

(Refer Slide Time: 03:18)

Here is the configuration. So, this is a constant current low side driver, which means this is a
constant current sink because the current is sinking into the switch. Look at the configuration.
Here is our output from the microcontroller. Our microcontroller is MSP430. Instead of regular
VCC from a regulated output maybe this is a battery as would be the case let us say in a TV
remote. The battery voltage will drop over a period of time but we do not want the current
through the LED to vary and so what we see is the output voltage is high and I have used 2
diodes, silicon diodes.

352
One of the silicon diodes is to ensure that it compensates for this VBE across the transistor. Mind
you that this transistor npn transistor is not operated as a switch. Here, the transistor is being
operated in a forward active region and the configuration is actually emitter follower that is
common collector. The voltage here would be 0.7 or VB voltage drop above the voltage at the
emitter.

(Refer Slide Time: 04:46)

And therefore the voltage across the resistor R2 would be equal to VR 2 is equal to VB that is the
voltage at the base minus VBE and because we have used 2 diodes, VR2 is equal to the voltage
drop across the second diode, which would be equal to VBE because the second diode is also a
silicon diode and therefore the current through R2, IR2 is equal to VBE which in this case is
actually V diode divided by the value of R2 and now you see the current is independent of the
supply voltage and so for the entire duration of the lifetime of the battery, the resistor would
ensure that a constant current equal to VBE divided by R2 would keep on flowing through the
emitter of the transistor.

If the beta of the transistor in this case is large enough then IC will be approximately equal to IE
and this IR2 is actually equal to IE, the emitter current and therefore this would ensure that the
collector current which is the LED current remains constant equal to this equation determined by
this equation. So, this is a method to drive the LED with the constant current source equal to
value of VBE, which is 0.7 divided by R1. So, let us say, if I want 5 milli ampere current

353
constant current through the LED, VBE is 0.7 volts divided by 5 milli ampere. This is the value
of R2 is equal to 700 milli volt divided by 5 milli ampere.

This and this goes away, the V divided by ampere leads to this and this is roughly 12 and 120.
So, the value of R 2 is 120 ohm, which incidentally is a standard value. It is not actually 120
ohm, it is 140 ohms so the value of R2 is R2 is equal to 140 ohms. The nearest standard value is
150 ohms. So, you could use a 150 ohm resistor then you would get a little less than 5 milli
amperes of current but the current would remain constant throughout the lifetime of the battery.
This is what is normally used in the LED driver part of a TV remote or other such applications
where you want the current through the LED to remain constant, even if the supply voltage
fluctuates.

(Refer Slide Time: 08:05)

Now, apart from the so we have seen till now various ways of driving the LED or similar loads
using a low side switch. Let us look at other ways of driving the LED, in this case the high side
driving which means the control of the current is towards the higher side of the voltage which
means connected to the VCC. Now, we have configured LED1 here and we have grounded the
cathode of the LED. The anode of the LED is connected to the same four resistors R1 R2 R3 R4
and we can use this configuration to increase the current through LED1.

If we turn the voltage, the LED will be turned on whenever any of the inputs here is logic 1 and
it would flow a current through the LED equal to the equation that we have previously seen that

354
is VOH minus VLED divided by the value of R. In this case, say R1 will be the current through
the LED and since we have 4 resistors and if these values, if these 4 resistors are equal, we
would have a sum of all these 4 currents flowing through the LED and we can drive the LED
with a higher amount of current than is possible with a single LED, single microcontroller pin.

This is one configuration and the other configuration if you want high side switch, high side
control of the current we can use a PNP transistor as a switch. Here we have used a PNP
transistor, a similar transistor to BC547 corresponding PNP transistor is BC 557. It can handle IC
max of about 100 milli ampere and using this configuration, we can apply VCC to this part
minus of course the VC SAT of this transistor and using the same arguments, we would be able
to drive LED2 with larger current and let us go through the equation here again.

(Refer Slide Time: 10:31)

When the transistor is saturated, the Collector voltage VC is equal to VCC minus VCE SAT and
we can assume the same voltage is here, VCC is say 3.6 volts and VCE SAT is say 0.2 volts. So,
the collector voltage will be equal to 3.4 volts which is equal to VLED that is the voltage drop
across the LED plus the voltage drop across the resistor. In this case, it is VR2 and so we can
find out the value of the resistance based on the current that we need. Let us say we want 20 milli
amperes so IR2 is equal to 20 milli ampere which in this case will be 3.4 volts minus V LED
which in this case is say 1.6 volts divided by R2.

355
So, to estimate the value of R2, we have R2 is equal to 2.2 volts. Sorry. Since the voltage drop
across the LED is 1.6, it will lead to 1.8 volts. 1.8 volts divided by the current which we want to
be 20 milli amperes which will lead to 1800 by 20 ohms and so this will lead to about 90 ohms
and we can use therefore R2 is a standard 91 ohm resistor we can use and using the high side
switch control, we can allow more current through the LED than is possible with a single pin of
the microcontroller and the same equations can be applied if you want even more current than 20
milli amperes.

If you want to have 500 milli amperes through the LED, we have to find a different PNP
transistor, which has a higher current capacity. If we want to control, if you want to allow 500
milli amperes to pass through the transistor, we must select a transistor which is capable of
handling at least 1 ampere and then similar equations could be used and you could use to
estimate the value of the R2.

(Refer Slide Time: 13:04)

Apart from that, you also need to like in this equation, we need to estimate the value of R1 and
similar arguments can be presented. How? Let us see.

356
(Refer Slide Time: 13:14)

So, the output voltage in this case of the microcontroller to turn the LED on now has to be low.
Then only the LED will be the transistor will be turned on which will enable the LED to have
that current. So, VOL is the output voltage. So, let me draw this schematic. Here is my resistor,
here is my PNP transistor, it is my resistor and my LED and we want to estimate the value of this
resistance, which is R1 this voltage here from the microcontroller is VOL. This voltage is VC,
the voltage drop here is VBE SAT and therefore the voltage across resistance, VR1 is equal to
VCC minus VBE SAT minus VOL. So, let us take similar numbers. Let us say VOL is 0.4 volts,
VBE SAT is 0.9 volts and let us say VCC is 3.6 volts.

Therefore, the current that will flow in this case is equal to the difference of this voltage IB will
be equal to 3.6 volts minus 1.3 volts. The sum of these 2 voltages divided by R1 and how much
base current we want. We want the base current to be many times over the actual base current
where IC that was 20 milli ampere is divided by beta that is the base current in a linear region but
since we want to saturate, we will allow much more current. So, this is 20 milli ampere.

We can assume the beta to be 100. Therefore, this is 20, 200 micro amperes. This is actually 20
into 10 raise to power minus 5 amperes and so this is also 200 micro amperes. So, the base
current is 200 micro amperes and so we will allow let us say 5 times more current into 5 is 1
milliampere. So, we will use this 1 milliampere in this equation and so what does this lead to.

357
(Refer Slide Time: 16:08)

That R1 value is equal to 3.6 volt minus VBE which is 0.9 volt minus VOL which is 0.4 volts.
So, this divided by 1 milli ampere and therefore it is 3.6 volt minus 1.3 volts divided by 1 milli
ampere and so this becomes 2.3 kilo ohm. So, the resistor value at the base has to be 2.3 kilo
ohm to allow about 20 milli amperes of current through the LED. This is the way to control a
high side switch.

(Refer Slide Time: 17:06)

358
This is the high side switch and this is the way to calculate the value of the base resistor. We
already seen the value, the way to calculate the value of the series resistance. Let us see what
other configurations we have.

(Refer Slide Time: 17:21)

Now, in case the supply voltage that we want to connect to the LED is much more than the
supply voltage of the microcontroller. Let us take an example that the microcontroller MSP430
has a supply voltage of 3.6 volts but VCC which is required to drive the LED is say 12 volts and
then it will never be able to turn the LED of in the normal configuration.

(Refer Slide Time: 17:55)

359
Why because if my microcontroller has a supply voltage of 3.6 volts and I have this resistor, here
is my PNP transistor in the supply voltage, here is 12 volts and here is my resistor and the LED. I
will never be able to turn this transistor off for whatever the state of the output pin whether it is 1
at which time the voltage will be VOH and if it is 0 it will be VOL. I will never be able to turn
this transistor off if the output voltage is VOH because VOH as we have seen is can be
maximum 3.6 volts, but usually it will be less than 3.6 volts. Let us say it can be 3 volts.

Even with 3 volts here, this transistor is always going to be forward biased and so this switch
will always be on and therefore it is not possible to control this LED that we cannot turn it off if
the voltage is high. It will be turned on if the voltage is low as we have seen but outputting logic
1 on this pin will never turn this led off. Therefore, we have to find an alternative way to control
this high side switch.

(Refer Slide Time: 19:19)

360
And this is the configuration that we require that instead of apart from the transistor T2 now,
which is the PNP transistor, we also need another transistor T1, which will isolate the voltage
that appears at the output pin and ensure that transistor T2 can be turned on or off. Let us
understand the voltages that are available here.

361
(Refer Slide Time: 19:46)

Now, we have a PNP transistor where the VCC is 12 volts. Here is our load through the resistor
and LED and we have now registered driving a npn transistor and at the base of the resistor, we
have created a voltage divider. This is connected to 12 volts. This has a supply voltage of 3.6
volts. Now, when I output logic 1, this transistor will be saturated and therefore the voltage here
will be close to, this will be VCE SAT, which is a very low value say 0.2 volts.

Therefore, this voltage is at 0.2 and therefore out of 12 volts, I will create a voltage divider out of
this. I can choose these resistors like that. The voltage here is close to 12 volts so as to if I have
1, I can make this ground and I can saturate this transistor and so it will turn the LED on. Now,
instead of 1 if I apply logic 0, this will cut off and therefore it is as good as this resistor is this
collector is disconnected.

This lower resistor is floating and therefore the voltage at the base is the same as the supply
voltage which means this transistor is not forward biased and this will turn off the LED and
therefore whenever you have a situation where the dry voltage of your load is higher than the
supply voltage of your driver circuit, microcontroller circuit, the only way to control the high
side switch is by incorporating an additional transistor, an npn transistor in this case so that you
can turn the LED on and off.

362
(Refer Slide Time: 21:38)

Similarly, if you want to control the high-power high side switch to provide a constant current
source through the LED, we have a similar configuration. Now, we see from the previous
configuration, we have moved the currently determining resistor to towards the emitter side.
Now, the voltage across this R2 will be equal to one of the LEDs. The other LED will be used to
compensate for the VBE drop across the VB of transistor T1 and therefore the current that will
flow through R2 IR2 is equal to the voltage drop across diode 1, which is VBE say 0.7 volts
divided by R2 that becomes the emitter current of this transistor.

If the beta of this transistor T1 is large enough, the same amount of current will flow through the
collector and will be a constant current irrespective of the voltage here. As long as this voltage is
above the voltage of some of this plus some of this plus a little bit voltage to keep transistor T1
in active region you will continue to power LED1 using a constant current source. In this case, it
is a source why because the current is flowing from the positive supply into the load.

So, this is the way to drive a constant current driver load using constant current source using a
high side switch. In fact, this is not a high side switch. It is a high side driver because transistor
T1 is not being operated as a switch. It is in the active region.

363
(Refer Slide Time: 23:23)

Now, we have to consider the situation like we considered for the switch case that when you
want to connect a few number of switches, you can 1 switch each to each pin. As the number of
switches increase, you have to optimize the number of pins by creating a matrix and if you have
N pins output and N pins input that is total number of 2 N pins, you are able to control n square
switches. In the same configuration, how about if we want to control large number of LEDs.

We may not have large number of pins to control the LEDs and therefore 1 configuration is that
if we have N pins we can control N LEDs. What if N is very large and is more than the number
of output pins that a microcontroller has? Then one way is to use a multiplexing technique.

364
(Refer Slide Time: 24:20)

Let us see what it looks like. Here I have a configuration where we have 4 7 segment displays as
I showed here. As we have seen earlier a 7-segment display requires 8 pins. So, if we want to
control 4 7 segment displays, it would require that the microcontroller has 32 pins, but what if
we do not have 32 pins. Can we control these 4 7 segments displays with less number of pins? It
turns out yes using this configuration.

This is a multiplex time multiplexed circuit. Here the number of pins that are required to drive
the individual segments is 8 and you need 4 pins to control the common pin of each of the
displays and in this case since we have 4 digits we will require 4 pins. So, using 4 plus 8, 12 pins
you are able to control 32 LEDs in spread across these 4 7 segment displays.

How does it work? Here at any given time only 1 digit is on but if only 1 digit is on but you want
to display all the 4 digits, the way to beat the human eye we have to use a concept called
persistence of vision. That is if I display a value here for some time then I turn it off and I display
the second digit, then the third digit going to the 4 digit and then I come back to the first digit. If
this is repeated at a fast in a frequency, then the I will assume, the I will actually see all the 4
digits simultaneously on and this is what allows multiplexing techniques to use less number of
pins and control large number of LEDs.

365
(Refer Slide Time: 26:25)

What is the rate? What is the limitation that persistence of vision happens whenever you turn
anything on and off beyond about 16 hertz. In fact, at 16 hertz you may see some flicker. So
typically, you go at a much higher frequency say 100 Hertz. So, if I turn each LED each display
7 segment display at a rate greater than 100 Hertz, then my eye will not be able to see individual
display on. It will actually see all the displays on at the same time.

(Refer Slide Time: 26:51)

So, this is a very effective method of controlling large number of displays using less number of
pins, but at the cost of additional circuitry. In this case what we call as anode driver circuit, and

366
we have a cathode driver circuit. We will see what kind of electronic components are used for
creating the anode driver circuit and creating the cathode driver circuit. Now if the way this led
7-segment displays on can you guess what sort of 7 segment displays being used here.

This one is a common anode 7 segment display which means to enable a display to display a
value this voltage must be close to VCC and the individual segments here must be at a lower
potential and therefore we need a anode driver circuit, which is a nothing but a high side switch
and the cathode driver circuit will be a low side switch and by now, you know that a high side
switch is made using PNP transistors and the cathode driver circuit could be used using in
configured would be implemented using a low side switch using NPN transistors.

So, by using 4 PNP transistors here and 8 NPN transistors here and 4 PNP transistors here, you
would be able to create a high driver circuit and low driver circuit to control 4 7 segment
displays and this can be scaled. You can go from 4 to 8 or maybe 10 but not too much and we
will see what is the limitation here but let me show you the circuit diagram.

(Refer Slide Time: 28:43)

For such a configuration here, I have created a schematic for you which shows 4 7 segment
displays common anode type and as you see here, we have 4 PNP transistors and instead of
individual 8 NPN transistor we have used a IC which consists of 8 NPN transistors that IC is a
low side driver.

367
(Refer Slide Time: 29:04)

This is the IC. In the electronic components that we expect you to have, you may recall that we
have an IC called ULN2003. It is exactly like 2803 except ULN2803 has 8 control pins, but
ULN2003 has 7 pins that is you can control 7 switches.

(Refer Slide Time: 29:34)

Similarly, for P and B, either you can use individual PNP transistors or you could also use this
driver IC called UDN2981.

368
(Refer Slide Time: 29:44)

In this in this circuit. I have actually used individual PNP transistors and on this side, I have used
a ULN2803. In the next lecture, I will go through how this circuit operates, what are the
limitations, how to calculate the values of these current limiting resistors, how to calculate the
values of these base resistors for the PNP transistors and since we are using an integrated circuit
for the low sides, which we do not really need to register to control these switches. They can be
directly driven from the logic output of a microcontroller. We will consider all these questions in
our next lecture. Thank you very much. I will see you soon.

369
Introduction to Embedded System Design
Professor Dhananjay V Gadre
Netaji Subhash University of Technology New Delhi
Professor Badri Subudhi
Indian Institute of Technology Jammu
Lecture 19
Physical Interfacing 5

Hello. Welcome to a new session on this online course on Introduction to Embedded System
Design. In the previous lecture, we had seen at various ways of driving LEDs in 2 modes
called Low Side Driving and High Side Driving. And the purpose was how to control the
LEDs or similar loads in a way that the switch was either connected to the VCC or switch
was connected to the ground side. And we are going to continue that discussion forward. And
I want to actually take this opportunity to actually calculate values of components for various
options.

(Refer Slide: 01:09)

The last slide that we looked at in that previous lecture was talking about using a
microcontroller to connect to a multiplex display. In this case, 4-digit Seven Segment Display
using PNP transistors as high sides switches here, and NPN transistors available as IC
ULN2803 and current limiting resistors for the seven segment displays, 8 of them here.

370
(Refer Slide Time: 01:40)

Now, I want to go back and review some of the concepts that we discussed for low side and
high side driving. I am going to take first the low side part. And the options we had was that
we have a microcontroller and we are going to control the low side part of this circuit, which
means we have our LED and resistor combination, and we connect it to the output of a port,
let us say P1 and this is supply voltage, in this case I have mentioned here that let us say this
is a MSP430 microcontroller, it is having a supply voltage of 3.6. We also have the supply
voltage of LED also 3.6 and this would be a low side driver.

Now, in case we want to increase the current through this configuration, we suggested the use
of an external switch, an external transistor which is capable of handling much more current
than would be possible with the maximum current capability of MSP430, as we have seen in
the lectures related to MSP430 that the current is limited to a few milliamperes, and if we
want more than that, then we have no other option but to use an external switch.

So, I am going, I have, I am going to use external transistors and take this discussion forward,
how to calculate the values of various components that we use. So, let us take an example
that we want to drive 20 milli ampere of current through the LED, 20 milliampere through
our LED and we want to control the LED with the low side switch which we are discussing
here.

371
(Refer Slide Time: 03:31)

I have chosen to use a BC547 transistor here and I have copied the relevant portions of the
BC547 transistor datasheet here. This one is the collector base voltage; this is the collector
emitter voltage and this is the emitter base voltage. And this mentions that the maximum
amount of current that you can collector current that BC547 can handle is 100 milliampere.
So, this is very safe to drive 20 milliamperes of current through the LED, it also talks of how
much power dissipation this transistor can handle.

(Refer Slide Time: 04:10)

In the next slide here, here it talks of the DC current gain and there is a number minimum
current gain that you can have is 110, we are going to use a number of hundred. The VCE sat
when the transistor is being saturated for various options, and we are going to use this that if

372
the collector current is 100 milliamperes then what is the kind of VCE sat voltage you get, so
you get 200 millivolts, so we are going to use this number 0.2 volts.

At the time that the transistor is being saturated, the base emitter voltage for this we are going
to consider 0.9 volts and we do not need anything else. The transistor itself is available in 3
formats called BC547 A, B and C. So, we are going to think that we are going to assume that
we use a BC547A transistor, and all our calculations are going to be based on that.

(Refer Slide Time: 05:06)

So, let me write down the information here that for our BC547A, our numbers are that beta is
100 VCE sat is 0.2 volts VBE sat the saturated voltage of base emitter junction is 0.9 volts,
the current we want, IC that is through the LED is 20 milliampere, our transistor is capable of
IC max the maximum current that the collector of this transistor is capable of handling is 100
milli ampere.

And using these numbers, we are going to design a circuit which can achieve, what we are
planning to do, which is with our MSP430 microcontroller powered with VCC of, this is
MSP430, this is one of the ports which is equal to 3.6 volts, we have a base resistance, this is
our transistor which is BC547A, this is grounded here and we have a resistor and the LED,
red LED, we are going to use, so I am going to write here that VLED is equal to 1.6 volts for
these 20 milliamperes of current.

You should of course, verify it for the LED that you are using, what is the forward voltage
drop across the LED when you want to repeat this calculation with different settings, so here

373
supply voltage is also 3.6 volts. And now here, now what do, what do we have to estimate?
What is the value of this current, this resistor, and what is the value of the base resistor? So,
since we are assuming that when the transistor is saturated, it should handle 20 milliamperes
of current, at that time the voltage at the collector will be 0.2 volts, and this information we
get from here.

The current flowing through, we want it to be 20 milliamperes, the voltage drop across the
LED will be 1.6 volts. So, the voltage across the resistor VR, let me write here VR is equal to
3.6 minus 1.6 minus 0.2 volt which is equal to 1.8 volts. And so, since the current I expect is
20 milliamperes therefore, R is equal to 1.8 volts divided by 20 milliampere and therefore, R
comes to be about 90 ohm. So, this is as far as the current limiting resistor in series with the
LED is concerned. Now, the second calculation is to calculate the value of the base resistor.

(Refer Slide Time: 08:14)

And for that we are going to have, so let me repeat this diagram here, this is 3.6 volt, this is
the circuit here, this is BC547A. We have already estimated now, that for 3.6 supply volt, my
resistor will be 90 ohm. I will have a LED in series, a red LED and the current going here is
20 milliampere, the beta is 100 therefore, the base current will be IB required out of this, IB
is equal to IC by beta therefore, it is 20 milli ampere upon 100.

In my previous presentation, I had made a little mistake in these calculations, so this lecture is
to correct that and so this becomes 0.2 milli ampere, the base current required is 0.2 milli
ampere, but when we want to drive a transistor in saturation, we always choose a base current
which is much more than the one determined by this relationship.

374
So, in this case it is base current should be 0.2 milliampere but since we want to drive it hard
into saturation, we choose a certain amount of current more than that, and so let us say that I
want to go 5 times that base current, so therefore actual base current that I want to drive,
actual IB is equal to 5 times, 5x therefore this becomes 1 milliampere.

Also, the voltage at the output here, when the logic is 1, I will assume that it is for a 3.6
supply volt, VOH for this transistor is 3 volt and therefore, this voltage VBE sat is 0.9 volts
as we saw from the datasheet therefore, VRB, that is the voltage across RB is equal to 3 volts
at the output, the base at the input of the resistor minus 0.9 volts, 0.9 volts. So, it is 2.1 volts
and therefore, RB is equal to this voltage which is 2.1 volt divided by 1 milli ampere and
therefore, this becomes 2.1 kilo ohm.

So, now I have my circuit ready, I need a 90 ohm collector resistor, I need a red coloured
LED and I have 1 (2.), base resistor of 2.1 kilo ohm. If you configured your circuit like this, it
will work exactly as you expect. Now, one of the nice things about low side control using
NPN transistors is that there is no requirement that the supply voltage which is connected to
the load, in this case the load happens to be a red LED that the supply voltage should be 3.6
volts equal to the supply voltage of the microcontroller, there is no such necessity.

In fact, this value of the voltage can be any higher value and we can repeat this exercise, what
if we wanted to control a LED or a bunch of LEDs in series, where the supply voltage is more
than the supply voltage of the microcontroller. We can repeat that this exercise for such a
configuration.

(Refer Slide Time: 11:55)

375
So, I am going to take my microcontroller MSP430 still powered with 3.6 volts. I still have
that transistor BC547, but now I am going to pump up the current through the LED that is the
load to a slightly higher voltage, higher current and I am saying that my supply voltage is
now plus 12 volts. I will still need a current limiting resistor, I have a LED and now I want
the current to be say, 50 milli ampere.

So, now I have to estimate the value of this R and RB for a different setup where the supply
voltage is 12 volts. I am going to repeat the same VCE sat is going to be 0.2 volt is equal to
VCE sat, the VBE sat, VBE sat will still be 0.9 volts as maximum as we saw through that
datasheet but because the currents have increased the collector current will be more, so
therefore, VR, the voltage across this resistor is equal to 12 volts minus the voltage drop
across the LED, of course at 50 milli ampere, the voltage drop across the LED will also
increase.

So, let us say that it will climb up to 2 volts, so I am going to do 2 volts minus 0.2 volts of the
VCE sat, this is the voltage and therefore, this is equal to 18 minus 0.2, so this is 17.8, oops,
12 minus 2, 10, 10 minus 0.2, this is 9.8 volts. So, the voltage across the resistor is, has
increased to a much larger value of 9.8, the current is expected to be 50 milliamperes
therefore, R is equal to 9.8 volts divided by 50 milli ampere.

So, this becomes 19.6 divided by 100 kilo ohm, so 19600 upon 100, so this cancel out, so this
becomes 196 ohms. So, you can take a resistor value of 200, nearest is 200 ohms, R is equal
to 200, so this is what we have. Now, our collector current is IC is equal to 50 milliampere
therefore, IB will be equal to 50 divided by 100 that is the minimum base current, we must
have, so this is equal 0.5 milliampere but as I mentioned, we should pump in much more base
current to ensure that the transistor is driven hard into saturation.

Let us say I want IB to be equal to 5 times, so this leads to a 2.5 milliampere of base current
and therefore, VOH is equal to 3 volt from this microcontroller, therefore VRB is equal to 3
volt on one side minus 0.9 volts, this leads me to 2.1 volts and therefore RB is equal to 2.1
volts divided by the current, base current I am pushing is 2.5 milliampere. And so, this will
be roughly 800, 800 ohms or something like that.

So, it is 2100 divided by 2.5, these many ohms, roughly 800 ohms. Now, you see compared
to the earlier calculation where this resistor was 2.1 kilo ohm, it has dropped down to 800
ohms. So, if you now, you take here 800 ohm, this resistor, we have estimated to be 200 ohm,

376
if you do this, it is going to be able to drive (two hun) 50 milliamperes of current through
this.

Now, what is, what we have learned out of this configuration is that the supply voltage need
not be the same value as the supply voltage for the, supply voltage for the load need not be
equal to the supply voltage of the microcontroller. And this is often a requirement when
where your load requires higher voltage for, for right now we have taken a simple example
where the load is LED, but we could easily change this to say, okay we have a bunch of
LEDs in series, and that would change the values of resistors and so on and so forth. So, this
was one of the topologies, we saw. The other topology was that now we want to, let me go
back and let us, let me show you all the topologies that we looked at.

(Refer Slide Time: 17:46)

So, we looked at this topology right now, we have made calculations for the base resistor and
the collector resistor. This is for the low side driver.

377
(Refer Slide Time: 18:02)

And then we saw that if you want to do high side driving, now, we have to use a PNP
transistor, let us repeat this exercise for a high side driver using one example of say, 50
milliamperes.

(Refer Slide Time: 18:20)

So, we are going to do this, that we have High Side Driver, our I LED, the current through
the LED that we want is 50 milli ampere, our transistor will be now a PNP transistor, so the
corresponding transistor to BC547, which is a similar transistor with similar parameters is
BC557, and we are going to assume the same numbers for it. Of course, you should refer to
the datasheet of BC557 to ensure that what are the numbers and if they are different to use
them in these calculations.

378
We will say, VCE sat is 0.2 volts, VBE sat will be 0.9 volts. And so now what we have is we
want a microcontroller, which is operating at VCC equal to 3.6 volts, which is our good old
MSP430. Now, it is exercising a high side control over the LED and now so we have the
configuration where the transistor becomes now PNP, this is your VCC. We are going to
show the same VCC of 3.6 volts and we will see what changes when the supply voltage
becomes higher.

And now, we have the resistor here on the collector and the LED connected to ground. And
we want to calculate the value of this R and this RB. And the current through this
configuration, we have chosen to be 50 milliampere. Alright, now, when the (transist) when
will the transistor be saturated? When it is forward biased, heavily forward biased and that
will happen when the output is VOL, VOL is the output voltage here, then this transistor will
be saturated.

Of course, whether it is saturated or not will depend on the value of RB, so we will ensure
that the value of RB is low enough for the transistor to saturate. At that time, the voltage drop
across the VCE will be 0.2 volts, so in this case, we will get 3.6 minus the drop across the
LED, we will assume it to be 1.6 volts minus the VCE sat, the 0.2 volts is equal to the voltage
across the resistor, and that is equal to, again 1.8 volts. And so, R is equal to 1.8 volts divided
by 50 milliampere and that will give me a value of 1800 divided by 51 ohm.

So, I will get a value of R is equal to 36 ohms, and I can either use a standard value of 33
ohm or 39 ohms. Let me say that I can arrange a 36 ohm resistor. So, this is what I am going
to use for this resistor. Now, we have to calculate the value of the base. Here again, I am
going to assume that for 50 milliamperes, the beta load, the collector current, the beta of this
transistor is 100, and so IB is equal to IC which is 50 milliampere divided by 100, and so this
becomes IB, required minimum IB is 0.5 milliampere, and because I want to drive it hard into
saturation, so I choose a 5x, IB is 5x, and therefore this becomes IB is equal to 2.5
milliampere.

379
(Refer Slide Time: 22:36)

Now, let us take a new page. Now, we have the, here voltage is VOL, and so I am going to
assume a VOL of 0.2 volts. Here is my resistor, the transistor, the transistor here, this supply
voltage is 3.6 volts and on the load I have this resistor, which we already calculated, the LED,
this was 36 ohms, this is red LED and this voltage will be 0.9 volts for this VBE sat and
therefore, what I have is V, if this is RB, the voltage across RB is equal to 3.6 volts from here
minus 0.9 volts minus 0.2 volts, 0.2 volts, the VOL saturation and that leads me to 3.6 minus
1.1 and that gives me 1.1, that gives me 2.5 volts, that is the voltage across the base resistor
and therefore, I, RB is equal to 2.5 volt divided by 2.5 milli ampere.

The amount of current as you saw here, we want through the base so as to saturate the
transistor hard and so the value becomes RB is equal to 1 kilo ohm. This is what we have.

380
Now, let us take another example, because this is a tricky example, when you are doing a
high side switching where the supply voltage, this is still 3.6 volts, but in the situation where
the load voltage is more than the supply voltage of the microcontroller, which drives, the
things complicate and we already seen the configuration.

(Refer Slide Time: 24:37)

The configuration is that we have to use a mechanism, so this supply voltage is 3.6 volt.
Now, if we were to, let us go back here, if this supply voltage here, 3.6 volt changes to 12
volts, suppose, then this 12 volts will never be the output voltage here will never be able to
turn this transistor off because when it is logic 1 you are going to get about 3 volts that will
still make the transistor saturate and when it is logic 0 even then it will saturate the transistor.

381
So, we actually lose control over this PNP transistor in this configuration. And so, we had to
find another method so, that we can (satu) where we can cut this transistor off when we want
and we should be able to saturate. And so, we had seen the configuration, so, I am going to
choose a supply voltage of 12 volts. Here is my PNP transistor and my load is this resistor
and this LED, and to be able to drive this, I have shown you the configuration is in this
fashion. This is the method to turn this transistor on, which is a BC557.

I will need another NPN transistor and I can choose this transistor to be BC547. I need
additional resistor, so this is my current limiting resistor with the LED, I have let us say, R1
and R2 and I have RB. Now basically, the introduction of an additional transistor basically
becomes an inverter, and so now, the LED will be on. So, if I see the earlier case, LED state
and rather the microcontroller output as a function of LED state, what do we have? That if the
microcontroller output is 1, this transistor cuts off, so LED is off and when the
microcontroller output is logic 0, the LED becomes on.

Now, when we introduce this NPN transistor, let us do the same mapping, microcontroller,
microcontroller output versus LED state. Now, if microcontroller is 1, this will saturate
transistor, NPN transistor, which will pull the base to ground, which will saturate the PNP
transistor, and will turn the LED on.

So, when this is 1, LED is on, when this is 0, this transfer cuts off, this floats the base. So,
base is now being pulled up to the same supply voltage of 12 volts, the PNP transistor is not
going to saturate, and so the output is off, so this is off. So, it has become different from the
earlier time where 1 was off and 0 was on, here, 1 is on and 0 is off. So, that is the case, we
will see how to calculate the value of R1 and R2 and RB, so that we can put it in the
configuration like this.

So, let us see how in this configuration or how to calculate the value of R1, R2 and the base
resistor, we can easily, there is no need to recalculate the value of this current limiting
resistor. If our configuration is that ILED is going to be 50 milli ampere, our VCE sat is
going to be 0.2 volts, our VBE sat is going to be 0.9 volts, the voltage across this, we are
going to assume to be 1.6 volts. Then the value of resistor will be the same as last time and
the value of resistor was 36 ohms.

So, we are going to get the same value here R is equal to 36 ohms. Now, the issue is in this
case, the current is going to flow here, when the transistor is saturated and no base current

382
will flow when the transistor is cut off. Now, we already seen that the current, the collector
current is IC when the transistor saturated is going to be 50 milliampere, and so IB for beta of
100 will be 0. 5 milli ampere.

And so, for hard saturation, that is I want to allow 2.5 times current. So, IB for the, just to
make differentiation IB for the NP, PNP transistor here will be 5x and so it is 2.5 milliampere
when the transistor is saturated that 2.5 milliampere current is going to flow here, it is going
to flow in this path, but some current will also come from R1. Now, how much current will
flow through R1 will depend on the value of R1 and the voltage dropped across R1 and that
volts when the transistor, the PNP transistor is saturated, we have already estimated to be 0.9
volts.

(Refer Slide Time: 30:31)

And therefore, the collector current of NPN transistor, so, the collector let me redraw the
circuit here for easy reference, here is my NPN transistor, here I have R1, here I have R2,
here is my base of the second transistor, here is my resistor and my load and this supply
voltage is 12 volts whereas the supply voltage of microcontroller is 3.6 volts, and this is R1
are R2 and is RB.

This current we have estimated to be, so IB of PNP, we have estimated to be 2.5 milli
ampere. IC of NPN, this transistor here will be equal to 2.5, the base current coming from
here, 2.5 milli ampere plus the current generated because of, because of R1. The voltage
dropped across R1 will be point 0.9 volts plus VR1 divided by the value of R1. And it is up

383
to us, how much current we want to flow and so let us say that we want to flow 0.1
milliamperes of current.

So the total collector current becomes, so this value we want to be 0.1 milliampere and, so the
total collector current through the NPN transistor becomes 2.6 milliampere. At that time, if
the current through this resistor is 0.1 milli ampere and the voltage dropped across is, across
it is 0.9 volts by virtue of the saturation voltage VBE sat therefore, R1 value becomes 0.9 volt
divided by 0.1 milliampere, so this becomes 9 kilo ohm.

All right, whereas, or also what will, when this transistor is saturated, the voltage dropped
across this will be 0.2 volts therefore, VR2 is equal to 12 volts minus the voltage drop across
R1, which have estimated to be 0.9 volts minus the saturation voltage across the NPN
transistor, which we take to be 0.2 volts and therefore, this becomes 12 minus 1.1 which is
equal to 10.9 volts.

So, the voltage across the resistor R2 is 10.9 volts and therefore, R2 is equal to 10.9 volts
divided by the current which is 2.6 milliampere, and that way you estimate the value
whatever it is. Similarly, the current now flowing in the collector is 2.6 milli ampere, the base
current again will be, will have to be determined and from that the value of RB of this will
have to be determined.

Therefore, IB of the NPN transistor is equal to 2.6 milliampere divided by 100 which is equal
to, which will give me a value of, oops, this is the collector current, and so I get 26
microamperes. This is the value of the base current that has to be, that has to flow through the
NPN transistor and I, again make it 5 times therefore, the actual IB, I want to push through
the NPN transistor will be 5 times this. So, let, let me approximate this to be about 100 micro
ampere. So, it is closer to 4 times than 5 times just for ease of calculations.

384
(Refer Slide Time: 35:20)

So, my IB through the NPN transistor is equal to 100 micro ampere. The VBE sat for the
NPN transistor is again 0.9 volts, the VOH, now I have to consider, VOH for this will be, it
becomes 3 volts as we assumed earlier for a supply voltage of 3.6. And therefore, VRB, the
voltage across the base resistor of the NPN transistor is equal to 3 volts minus 0.9 volt which
is equal to 2.1 volt divided by 100.

So, this is the value of RB equal to 2.1 volt micro ampere. And so, this is 0.021, the micro
goes up, becomes mega ohm, so 1 2 3, 21 kilo ohm. So, what is, what does our final circuit
look like? It look like, it looks like here is my MSP, it has a NPN transistor which is BC547,
this is grounded, the supply voltage is 3.6 volts. I have a resistor R1, which was R1 is 9 kilo
ohm. So this is 9 kiloohm. I have another resistor here, which is R2, I have a PNP transistor,

385
the base is going here, the collector driving a red LED, and this was 36 ohm, and this supply
voltage is plus 12 volts.

And the value of R2 was this 10.9 by 2.6 milliamperes. So, it is R2 is equal to 10.9 kilo ohm
divided by 2.6. If we take this to be 3, 3 and 3 9, so a little more than, a little more than 3 say,
3.3 kilo ohm. So, R2 value is 3.3 kiloohm. I have R1 of 9 kilo ohm. The base resistor here is
21 kilo ohm. And what I have achieved is high side control over load using a supply voltage
of supply, 12 volts driving the load, but the supply voltage of the microcontroller to be a
much smaller value of 3.6 volts.

(Refer Slide Time: 38:36)

Now, often times we would require in a single configuration, both high side and low side
control, and where are we going to need those? We are going to need those when we are
driving load like such a DC motor. Okay? So, I am going to show this DC motor as this, and
a DC, so I am going to write here DC motor.

So, the DC motor has two parameters, one, speed of DC motor is proportional to the supply
voltage across the DC motor and the direction of the DC motor is determined by, by the
polarity of the supply voltage, which means if by applying plus here and minus here, it is
going to rotate in this direction, then to reverse the direction I must apply plus here and minus
here and then it will rotate in this direction.

So now, I want a mechanism. If my requirement in an embedded application is to be able to


control the speed and the direction of motion, I need control over both these parameters. And

386
what we will do is in the next lecture, we will see how with an interesting combination of
high side and low side switches, implemented either through NPN transistors or MOSFETs,
we can exercise that control. See you soon.

387
Introduction to Embedded System Design
Professor Dhananjay V Gadre
Netaji Subhash University of Technology New Delhi
Professor Badri Subudhi
Indian Institute of Technology Jammu
Lecture 20
Physical Interfacing 6

Hello and welcome back to a new session. In the last session, we were talking about
exercising control over a DC motor with the idea of controlling the speed and the direction.

(Refer Slide Time: 00:37)

Now, as I mentioned the speed of a DC motor is proportional to the voltage that you apply
across the terminals of a DC motor, and the direction is determined by the polarity. Now,
how am I able to change the DC voltage across a motor, where my control is in the hand of a
microcontroller which is a primarily logic circuit? And so, one concept that we use here is the
use of Pulse Width Modulation.

388
(Refer Slide Time: 01:05)

Here is the representation. A pulse width modulation is a rectangular voltage waveform,


where the time period of the waveform as we see here is constant, here we see, the time
period is constant whether, whether it is for this waveform or for this or for this, but what
varies is the duty cycle. This amplitude of the rectangular waveform is also constant. So, we
have two constants in this generation of waveform, the time period and the peak amplitude.
And what is variable is a duty cycle. Now, let us see how we are able to change the DC
voltage in such a situation.

(Refer Slide Time: 2:02)

Now, if the time period is constant, if the, that is the frequency of the waveform is constant
then if I draw some reference grid here, and if my amplitude of the waveform is this much

389
then I try to generate a similar, here and here. Now, this voltage is let us say, V and this is the
area under the curve, this is the time period. The on time is constant in these four waveforms,
let us say, this on time is t on and the total time period is T, the average, V average, the
average voltage of such a waveform is equal to t on divided by the total time period which is
T into the peak voltage which is V.

Now this ratio, we call as the duty cycle, D into V, where D is equal to duty cycle. And what
is the range of the, this value? D will always be greater than equal to 0, because when t on is
equal to T, you get a value of 1. When t on is 0, 0 by T is 0, so the value of duty cycle is less
than, greater than 0, greater than equal to 0 and less than equal to 1. And so, by changing the
duty cycle to any arbitrary number between 0 and 1, I can have average voltage, which can be
varied from, so, V average can, in this case can vary from 0 to V.

It all depends on my ability to generate this pulse width modulation wave. This waveform is
called pulse width modulation, the ability to generate this pulse width modulation waveform,
where the duty cycle of that pulse width modulation waveform is in my control, will give me
an opportunity, will give me a mechanism to modify the output voltage, the average voltage
which can lie in any arbitrary which can be any arbitrary value between 0 and V volts.

Now, the question is, if I am generating a rectangular waveform, how do I get a DC voltage
out of this? Well, if you want to measure such a DC voltage using a multimeter, what do you
can do is, if any device is capable of generating PWM signal, we know the frequency of this
PWM signal is F is equal to 1 by T. The frequency is not changing, we can pass it through a
low pass filter such as R and C and this voltage will be equal to VDC, V average.

This will be exactly this provided the cut-off frequency of this low pass filter is much, much
lower. So, F low pass filter should have, should be much, much lower than F. So, if this is
FPWM, just so that we are able to, if we can ensure this relationship then you will get DC
voltage which is determined by this equation to lie in this range. And in fact, in one of the
exercises that we are going to have, we will actually show the setup.

Now, I could also utilize such a waveform to drive a DC, DC motor. So, the DC motor
behaviour is like a low pass filter. So, as long as I can have the frequency of the pulse width
modulated signal to be much higher than the bandwidth of the DC motor then I do not need to
put this external filter at all and I can simply apply such a waveform to the to the DC motor
which will allow me to change the speed of the DC motor, but I still need to change the.

390
(Refer Slide Time: 06:30)

So which means if I were to extend this and I, if I, if my requirement is just to change the
speed and not the direction, then I can do very much like this, here is my microcontroller
which is a powered at 3.6 volts. I need a mechanism to generate a PWM signal, so I will say
PWM out, and we will see how PWM signal can be generated out of MSP430. I will take
NPN transistor in the similar way that we used earlier. And I will put a DC motor here and
this is VCC which can be any value, 3 6, 3.6 volts or even higher.

And I, this is my motor, and by changing the PWM duty cycle here, I can change the average
voltage that appears across this motor and it can change the speed. Now, my question is I
have to be able to change the direction also at will. Now what do I do? I have an interesting
topology, and we will see what is the name of this topology. Imagine that I have 4 switches.
Right now, I am showing these switches to be mechanical in nature.

And now, here is my supply voltage VCC. This is the same as this. And I apply my motor in
the centre here. Now, so, let me name this, this is S1, S2, S3 and S4. Now, let us look at the
condition state of S1 and S4 is equal to closed that is the switch I had turned on and S2 and
S3 is equal to open. So, if I close this and I close this, this applies plus voltage here and this
becomes grounded. It perhaps moves in this direction. Right?

Now, I open this switch S1, and instead I close this and this, it applies a voltage here in this
polarity. So, the polarity of the voltage has been changed to the opposite of the earlier one
and because of this, this motor is going to go in this direction. So, by using 4 switches and
closing 2 of them at any given time, yes, you have to ensure that S1 and S3 are never turned

391
on at the, are never closed at the same time. Similarly, S2 and S4 should never be engaged
together, if that happens, basically, you are going to short the supply voltage.

So, as long as you can ensure that by engaging S1 and S4 or S2 and S3, I am able to change
the polarity of the voltage applied across the motor and therefore I can change the direction of
rotation. Now, how do I control the speed? Now, do you recognize, do you recognize that this
switch S1 and S2, if these were implemented using electronic components such as BJTs and
MOSFETs, then S1 and S2 become high side switches. Why? Because they are connected to
the high side of the circuit, high side switches.

And S3 and S4, S3 and S4 are connected towards the ground side. So, these are low side
switches. And we have already seen that when you need a high side switch, what do you use?
You use a PNP transistor. When you need a low side switch, what do you use? You use a
NPN transistor. And this configuration of using 4 switches implemented through electronic
components such as BJTs or MOSFETs for that matter has a name and this is called
H-Bridge.

And you do not have to build such a H-Bridge using discrete transistors, H-Bridge integrated
circuits are available where the high side and low side switches are implemented in a
common package and you get 4 controls, a control, so S3 will be implemented, this part will
be collector, this part will be the emitter and you will get a base. Similarly, for S1 and S2,
you will get a PNP transistor, where this side will be the emitter, this side will be the collector
and you will get a base control.

So, you get base controls for the switches and internally the emitters and collectors are
appropriately connected, so that all you do is apply, control waveforms. Now, what would be
the control waveform? Instead of not keeping the switch on or off, if I apply a PWM signal
appropriately, so if I apply, if I want to have the motor move in the direction of this one
where it had to have a plus here and minus here, I will keep S1 and S4 open and maybe keep
S2 closed, but I will apply a PWM signal on S3, it will give a proportional voltage across the
motor equal to the supply voltage into the duty cycle of the waveform applied to S3 and it
will allow me a speed control.

By varying the duty cycle I can increase or decrease the speed of the DC motor. If I want to
reverse the direction, I am going to open S, S2 and S3, close S1 and apply a PWM signal on

392
S4. This will reverse the direction and the speed will be determined by the duty cycle of the
PWM waveform connected to S4. And so, such packages are called H-Bridge driver ICS.

And they come in different ratings that is the amount of current that they can handle, the 4
switches can handle and the maximum voltage that they can handle and using such a driver
IC, you can easily control a device like a DC motor. While we are on the topic of controlling
such external loads with microcontrollers, it is impertinent to note here that suppose you
wanted to control relay, a relay is a electromechanical device.

(Refer Slide Time: 13:12)

Let me draw the symbol of a relay, a relay has a coil and it is electromagnetically controlling
3 contacts and they have, this is called normally open, this is common and another contact
which is called normally closed, which means this contact normally closed is normally
connected to the common pin when the coil is not energized. When it is energized, the
common, the normally closed pin gets disconnected from the common pin and the common
pin goes and connects itself to the normally open pin.

And with you, since this is electrically isolated from the coil, you can use a higher voltage or
AC voltage, you can use this with 220 volts means 220 volts AC means to control external
load, such as what we discussed if you remember, in the very first lecture of controlling air
conditioners and motors for washing machine or a bulb, you could connect on this side. And
on this side, you can exercise the, you can control this relay with the help of our low voltage
DC, which can be controlled by a microcontroller.

393
So, imagine that we want to control a 220 volts load, say a bulb or a higher power device.
And we want our microcontroller to do it. So, I am going to take a microcontroller. This is
my MSP430. These relays come in various ratings, the primary coil ratings, say 5 volts or 9
volts or 12 volts and obviously since my microcontroller cannot drive 5 volt supply voltage
load, I am going to connect my VCC, say, VCC equal to 5 volt, and I will have to use a NPN
transistor as an external switch, using the same calculations that we saw earlier.

The only problem here is now because this is a coil, when the coil is energized there is no
problem, when the, when this, when the input here, the output of the microcontroller is VOH,
it will saturate the transistor which will bring the voltage to the collector to VCE sat which
will apply almost all the supply voltage of 5 volts across the coil, the coil will, the relay will
energize and will connect the common pin to normally open pin.

When you make the microcontroller output equal to VOL, it will cut off this transistor and
the relay will de-energize and the common pin will come back to the normally closed
position. However, when that happens this terminal, the collector terminal of the relay of the
coil since you want to suddenly stop current flowing through that coil, it reacts in a very
violent way and it produces a very high voltage here, and this high voltage is capable of
killing this transistor. Why?

Because that voltage will often exceed the VCE max that we saw earlier easily, and so this
transistor will be destroyed the first time you turn this relay off, and therefore, there are there
is a good method that you apply a diode like this. So, this diode is called freewheeling diode
that is when this voltage, collector voltage tries to exceed the supply voltage of 5 volts, this
diode is turned on and it recirculates the energy through that coil and it protects the transistor.

So, one must take care of using such diodes, so that the transit, the driver circuits are not
destroyed. So, this is one way of controlling external loads such as a relay. We have already
seen that instead of relay if you want to control LEDs, we have seen that configuration. If you
want to exercise a high side control, this is the low side control over the relay. If you want to
exercise the high side control over the, this relay for some reason, then you know what
topology to use.

If the supply voltage is more than the supply voltage of the microcontroller, you will have to
use 2 transistors, so as to isolate the higher supply voltage of the load from the low supply
voltage of the microcontroller. So, with this we have seen how you can control external loads,

394
which may require higher current and higher voltage to be handled and controlled through a
microcontroller. We have seen various topologies. One point we were at last time was when
we were looking at various methods of controlling large number of LEDs through a
microcontroller.

(Refer Slide Time: 18:03)

And we have seen that there are, these are the options we have that we could have, if we want
to control n LEDs, we could dedicate n pins. If you do not have n pins, then you go to a
Charlie technique called multiplexing.

(Refer Slide Time: 18:13)

395
And this was in fact a normal multiplexing technique. There is an interesting extension of that
technique. And it has a interesting name it is called Charlieplexing. And I would like to
illustrate the concept of Charlieplexing to you through this lecture. And here is a topology of
a Charlieplexed LED display.

(Refer Slide Time: 18:37)

Now, you see here is a microcontroller, it could be MSP430. In fact, we will rig up an
experiment to show you how you can have Charlieplexed LED displays. Here, we have only
three pins as you see here P1, P2 and P3. In the normal configuration, you would, you could
have only connected 3 LEDs to the 3 pins, but now with this configuration, we are able to
control 6 LEDs. And the normal rule of thumb is that for n pins, you can control n into n
minus one LEDS.

396
However, this formula should not tempt you into believing that, let us say I can have n equal
to 10. It is easy, easily possible to have 10 control pins on a microcontroller, 10 output pins
on the microcontroller. And using this technique, you can control 90 LCDs. Well, in principle
you can, but those 90 LEDs will not grow, glow as brightly as you would like them to grow,
glow for the reasons that I am going to explain. But first, let us see how these LEDs are going
to work, how you are able to turn them on and off using this technique.

And so, if you notice I have 6 LEDs and between any 2 pins, I have 2 LEDs in reverse
direction. LED 1, if you see is connected with anode on the P1 and cathode on P2 and LED 2
is reversed. So, we have two LEDs between any 2 pins and therefore because there are 3 pins,
the total number of combination is 6, we have total number of 6 LEDs. Now when you want
to turn LED 1 on, what should be the, what should be the, the state of the 3 pins. I am going
to redraw it and show, show, discuss it here.

(Refer Slide Time: 20:31)

So, we have my microcontroller. Here is my resistor. So, this is all these 6 LEDs. This is
LED number 1 2 3 4 5 and 6. This is P1, P2 and P3. When I want to control LED 1 on, LED
1 then P1 should be equal to 1, P2 should be equal to 0, but what about P3? If P3 is 1, it will
turn LED number 4 on, which may, we may not want. If we make P3 equal to 0, then it will
turn LED 5 on, and so, again this is not what we wanted. And so, this is to bring out the fact
that microcontroller pins, modern microcontroller pins can have not just 2 states, it can have
3 states, a 1 or a 0 as well as you can convert the pin into an input pin and it becomes a high,
high impedance state

397
So, the third pin P3, I will program it to be Z. This will ensure that only LED 1 is turned on.
When you want to control LED 2, the state of P1 becomes 0, P2 becomes 1 and P3 is still Z.
When I want to turn LED 3 on, then P1 becomes Z. P2 becomes 1 and P3 becomes 0, and so
on as you can see. Now at any given time, in this configuration, only 1 LED is turned on.
And so, if there are 6 LEDs, they are going to start with 1 2 3 4 5 6, back to 1 2 3 4 5 6.

If you want any number of LEDs to be on, the turn on and turn off of these LEDs is done at a
much higher rate, higher than the persistence of vision of a human eye, which is roughly 16
hertz. So, if you go much more than that, let us say we turn on and off each LED at 100 hertz
and since these are 6 LEDS, if I have a mechanism to turn on and off things from a
microcontroller point of view at 600 times a second then each LED can be turned on and off
100 times a second, it will give me a comfortable display.

Now what is happening is at any given time, since only one LED is on therefore, you have 1
2 3 4 5 6. So, this is time slot 1 2 3 4 5 6 and the time slot 7 8 and so on. Now, in time slot 1,
I can turn LED 1 on and then it will have to be off for the next 1 2 3 4 5 and it can only be on
here. Similarly, LED 2 can be turned on in second time slot and it will have to be off for the
next and then it can have an opportunity to be turned on here and so on.

Each of the LEDs has 1 slot out of 6 slots. Now, if this waveform represents the current
through that LED that means this is 0 current, this is some current I, which will be
determined by both these resistor at any given time, 2 resistors come in the path of the LED.
Therefore, the current will be determined by some of these two resistors in series with the
LED. Let us say that current is I, so you have either a current I flowing for 1 time minute and
for 5 time minutes no current is flowing. Therefore, the average current, if this I, the I
average through the LED becomes I by 6.

Now, if the current becomes one sixth, the intensity of the LED in the Charlieplex
configuration in this case become one sixth. And there is not much you can do by trying to
increase the current through the LED’s because the microcontroller pins are limited in the
maximum current they can allow. MSP430, as we saw is the limited to 6 milliamperes, other
microcontrollers can go up to 30 40 milliamperes and yet the average current will start falling
rapidly, if I, instead of 3 if I go to 4 pins, I will be able to control 12 LEDs.

So, my I average current will become I by 12. So, it becomes, quickly, it starts reducing, and
therefore, using a Charlieplexing technique, this is what I meant that this is not a very

398
scalable opportunity, this is not a very scalable technique, that if you try to increase the
number of LEDs by using slightly more number of pins, it does not work very well because
the intensity of the LEDs goes by this.

(Refer Slide Time: 25:46)

So, I, the average current through the LED in a Charlieplexed fashion I average is become,
will be equal to the maximum current that you can allow divided by n into n minus 1 that is
the for n pins that you have, you can control n into n minus 1 LEDs. You see, this factor
grows up by a factor of a, by square. And so, the average currently is quickly going to drop.
And may, we will make this topology quite useless for value of n more than 4 or 5.

But still, it is a very interesting mechanism, it allows you to control relatively large number of
LEDs using few pins, if you are stuck in an application where the number of pins is very less,
and you want to control a few LEDs, few 4 5, maybe 10. This is a good technique because
this allows you to control relatively large number of LEDs for using less number of pins
without involving additional hardware expansion technique.

For example, you could use a shift register, you do not have to involve any extra, extra
hardware and yet you are able to control these LEDs, so this is very good for such a
configuration. And so, in this lecture we have seen how you can control external LEDS in
multiplex fashion, using Charlieplex fashion, how you can control large amount of currents
through these loads such as the LEDs or the relays using low side switch or a high side
switch, how you can also have a combination of high side switching and low side switching
using the topology called H- Bridge which is used to control DC motor and such loads.

399
We complete our discussion here. We still have to talk about creating digital to analogue
converters and controlling LCD displays and so on and so forth which we will take up at
appropriate opportunity. I thank you for listening to me. I will see you in the next lecture very
soon. Bye-bye.

400
Introduction to Embedded System Design
Professor Dhananjay V. Gadre
Netaji Subhas University of Technology, New Delhi
Lecture 21
GIT, CCS Installation and Embedded C
Hello and welcome to a new session for this online course on Introduction to Embedded System
design. I am your instructor, Dhananjay Gadre. This is a very important session in which we are
going to go through certain steps. So, that appropriate software is installed on your desktop or
laptop computer, whatever you maybe using. So, we are going to deal with two installations, one
is a software called GIT, and the other is the code composer studio, which is the C compiler from
Texas Instruments for MSP430.

In fact it supports many other macro controllers, but we are going to… restrict ourselves to
discussion about the MSP430 micro controller. After the installation of these two packages, we
are going to discuss a little about Embedded C programming. Of course, we assume that you
have some experience, you have good experience in general C programming. So, we are not
going to consider those aspects. We are going to consider specific aspects to the Embedded C
part. Alright. Now GIT is a version control system.

Now, before I explain, what a version control system is, I would like to take this opportunity and
discuss a few issues with you as a beginner student or as a student who has not yet entered the
professional domain. I as an educator with some experience, I would like to share my experience
with you. For example, suppose I. when I teach a class and I tell them, please send me a report
about today’s exercises that I covered in the class, most of the time unless I tell them to begin
with, I would get 20, 30, 40 emails with a document enclosed, and often times the document is
labeled or named report dot doc.

401
(Refer Slide Time: 2:18)

Now, as far as the student who has sent this is concerned, he is happy he has created a document
and he has emailed it to me. But you please step into my shoes and consider that I have received
50 emails and all the 50 emails have pretty much 50 files. All of them are named report dot doc.
If I download and save them, what is going to happen? It will make me crazy. It will be
impossible for me to relate a given document with a person. And therefore, I always ensure that
when I ask my students to send me reports for a given topic on email, I ask them to follow a
certain protocol.

In a classroom, in a as a student you would have a roll number, and therefore often times my
protocol is, you include this information in the file name. You say roll number, whatever your
roll number is. The year in which we are doing, or the subject we are doing. Suppose we are
doing EC301 and maybe if this is your first report, or if this is the first report that I have asked
this class to send me, it could be report 1 dot doc or any other file format if it is a PDF fine.

This way, the moment I get this, now roll number has to be replaced with your actual roll
number, whatever it maybe. You do not want to receive 50 emails with the same roll number as a
literal word. Here the roll number will be replaced by whatever the student’s roll number is.
Likewise, if tomorrow, now this is fine, this scheme works as long as you are part of a ecosystem
where the roll numbers can be used to distinguish person A from B and C and so on and so forth.

402
Now, let me put you in a different perspective. Suppose tomorrow you are going to enter the job
field, job market and you are going to send your resume to somebody. And that somebody has
asked 20 other people to send their resumes. Now my question to you is, what would you send
you, what would be the name of the file that you send to that person containing your resume.
Well, if it is going to be resume dot PDF, well, you have recreated the situation which I
explained earlier.

And therefore, what I normally do when I, when I go on speaking assignments to various


colleges for giving a lecture, I have followed a format and I recommend to you that you follow a
similar format if not the same. I always keep track of my changing activities and reflect them in
my resume as I would say DVG, my initials, but that is because these are very uncommon
initials. If you have names which end up having very common initials, please modify it. And
then I say resume or cv. And then I also have a 4 digit number, for example, it could be 0320.

And here 0320 s going to tell me that I created it in third month of the year 2020. And this way, I
am able to know, what is the latest resume that I have kept on my files. And the person who
receives it can make an idea that this is a resume for a person whose initials seem to be DVG.
You can follow a similar or a different format. But the important point is, there should be enough
variety, enough information in the file name itself for somebody who is collecting tens of
resumes to call one resume file apart from the other one.

Now, this is not the topic of our discussion here, but it is very closely related. Now imagine, so
before that I hope you will give some heed to this idea that I have thrown at you. Now, coming
back to the whole idea of version control system, imagine that you have a PC and that you are
creating a, you are creating a report like your teacher might have asked you to create. Then you
write a few pages of a Word document and then are happy with it, you save it, you go to sleep,
next day you wake up and say, no no no, I think I can improve this report a little bit.

And so you open that file and you start editing it and you spend another few hours and suppose
that report was xyz to reflect your initials, report dot doc. Alright. And then next day, you have
modified it. You have edited large parts of it and you have replaced it with some new text. And
few hours later you realized, oh god, the first version that you wrote last night was much better

403
than this one, now what to do. You have deleted parts of it and you have replaced it with new
text, and you do not like that text.

How would you solve this? Well, if you are going to do manage this manually, you could say I,
the night that you sleep happy with the report that you have created, the next day when you want
to edit it, you open that file, but now first save it into a new file name. Well, at least some,
keeping some part of the filename common, but an identifier which tells you that this is new
version. So, what I could do is, I could say xyz underscore report. The next day, I will say
underscore v2 dot doc.

And now, I have my file xyz report dot doc on my folder. I have created a copy of that and I
renamed it as xyz report underscore v2 and I can edit it. And if I am happy with v2, I can retain
v2. If not, I can always go back to the original xyz underscore report. And this way you can keep
on creating newer and newer versions of your report.

Keeping the newer versions, if you are happy with it and reverting back to the older versions if
you are not happy. And so, these stages while you start from the beginning if your file to some
conclusion, conclusion of this whole exercise, you have created perhaps multiple versions of that
file.

And this allows you to at least keep track of the changes that you have made. Now, of course, if
you did it manually, it will be a nightmare to have so many files on your system. This is where
an automatic version control system or creating documents under the supervision of a software
which keeps track of these changes, comes into picture. Now, till now what we discussed was in
the context of one person, you as an individual creating documents and you could extend this
analogy to not just creating documents but also to create software or files.

You write a piece of code, you are happy with it and you want to make changes, you make
changes which ends up making it worse than what it was earlier. So, when I say documents, it
could be Word documents, or it could be Text documents, it could be code files, it could be
anything else. This whole discussion applies to all of it. So, imagine that you were working on a
project in which there were three or four files and it was being worked on by a few people, who
were not geographically present at the same location.

404
That is they were distributed across the town or across the city, or maybe across the world, which
is quite common these days. Now, imagine that all of you wanted to access files, make changes
to those files and it is possible that the changes that you made, made the whole new version
worse than what it was earlier. And so, you not only need to create, you not only need to take
care of these files, the changes that you are making, through a automatic piece of software, but
you also need a single source or single repository, single location where these files will be
accessible to all the people who are working on it.

And in fact, the whole Cloud based storage of files maybe a Google doc is an example of that,
but in this context we are going to use specific software created to facilitate keeping making
newer and newer versions of the project that you are working on, whether that project is writing
a book, writing a report, creating a schematic file, creating code software, no matter what, this
version control system can take care of all of it.

Now, there are of course a lot of version control systems. Some of them are paid, many of them
are paid, but there are some which are open source and free for you to use. And we have selected
one such, which is quite popular and quite common, and that is called GIT. Now, what we want
you to do is, we want you to become familiar with GIT and you can become familiar with GIT
by beginning to use it. If you already know GIT, well you can skip this initial part of my, of this
session, and head on straight to the part where we start discussing the code composer studio.

But if you are not, this is a right place to start. And GIT is a very complex software. It is, it offers
you lot of facilities. It offers you facilities as a creator. It offers you facilities as a end user. And
right now, the best way to start using it if you have not used it before is to start using it as a end
user. And you as a participant, we assume that many of you or most of you have not heard of
GIT, or version control softwares. And so, we are going to show you the use of GIT from the
perspective of a beginner.

As you start using it, there are lot of resources which will teach you about various features of
GIT, specially the features of GIT, when you want to use it as a creator and the material that you
have created, you want it to share with others, or share with other members of the team, or share
with common public, you could use the advance features. But right now, we hope that you are a
beginner and so, you would like to, we would like you to install GIT, and using this, we would

405
like you to download all the code files and in fact schematic files and other things that we have
shared on a repository that we will soon talk about, and it will allow you to download all of it on
to the computer that you are using.

(Refer Slide Time: 13:16)

Alright. So, to begin with, open a browser of your choice that you are using and type this link
which is https double slash GIT dash scm dot com slash downloads. Once the software is
download, downloaded, you can double click on it and follow the normal installation process.
Once the software is installed, you open a terminal on your Windows PC. By the way all this

406
discussion is a Windows PC centric. That is the most common operating system for people to be
using. And so we are going to discuss all of that in the context of Windows.

So, open a terminal and in that terminal, find a suitable, create a suitable folder into which you
would want to show, save all the files related to this course. So, I leave it to you to create that
folder. And using the terminal go to that folder, and then type this, type GIT config double dash
global username and then username. So, for example, if I were to do this, I would on my
command prompt on the terminal window, I would say GIT, I would type this, config space
double dash global user dot name space, and then I will write the name that I want.

Suppose I want to do it as my name, so I could say DVGADRE, I close those and I press enter.
After that, so this registers me with GIT with this username. And then I say on the command
prompt again, I say GIT config, basically repeat most of it, double dash global user dot email
double quotes, whatever is my email address.

So, if it could, if it was DVG at the rate Gmail dot com, I should type that, or if it is something
else, I should type that. By the way, this is not my email address. So, you once you do this, it will
basically register this software with this username and assign this email address to this user. Now
what do you do?

(Refer Slide Time: 15:53)

407
Now again, in that folder that you have created, you could do one of two things. You could
execute this command on the prompt. But this would you would do if you are somebody who is
creating a repository, you are creating a set of files that you want to eventually share with the rest
of the world.

Since you are not that, you are going to execute this second line. And what do you do, you type
GIT clone, GIT clone and a URL address. So, which means basically you are going to write GIT
clone followed by this entire address. Following the letters and characters exactly. If something
is in capital, you must do that in capitals. And when you enter this, basically it is going to pull
from a, a repository on the web internet called GIT hub. We have created this repository, it will
create a local version of the files that are stored on that repository on to your local computer.

So, that you could access them even if the internet connection is not on. I will talk about more
about this. Then if you are going to make changes to the files and you would want to share the
changes with us, of course we need to agree to those changes and we need to agree to that, then
you could follow these things. But we are not going to right now do that. We will talk about this
in next slide.

(Refer Slide Time: 17:18)

Now, when you create a, a repository or you create a file, basically GIT looks at those at that file
in various ways. When you create a file, it is still not attached to that software which is, which

408
you just installed on your PC, that is GIT. Now, you can from that and that such a file is called
untracked file. This is the untracked file. Now, and you obviously created in that folder, that I
mentioned. And then, you can add that file into this next stage which is called the staging area.
And from there, you commit it and, and now all this initial these three parts here, these are when
you are doing it as an experienced user who is creating a repository, first of all that repository
has to be created.

This is the repository on your local computer. And then you upload it to the internet global
repository. So, when I say install GIT, that GIT is a local repository. Now, this local repository
could be cloned as the word they use, could be replicated on a platform that is globally
accessible.

Because your computer is not accessible to other users. If you as a creator wanted to share your
work with others, you could move your, or you could copy your repository from your local
computer into, onto a global GIT, or a global version control software website. And one of the
website is GIT hub. There are other websites also. But we are going to use GIT on our local
computer and GIT hub for the internet access. So, you can push all those files on to the internet
repository on the internet, which in this case is GIT hub.

(Refer Slide Time: 19:10)

409
If you notice here, you install GIT, but you downloaded the repository that we have created on
the GIT hub website. Likewise, when you, when you did this, when you cloned that repository
that we have created on GIT hub, after that, you are set. All the files that are there on our
repository will be replicated on your, on your computer, in the folder at which you did all this.
And at this point you are ready to use them.

Now, imagine the following, that let us say you created this clone on your local computer and
you are happy with it and then you went to sleep, maybe you stopped doing work for a week.
And a week later, you wanted to resume. Well, you need not worry, you could open those files in
the way that we will talk about soon.

But what if we here make changes to those files. If we make changes to those files, you would
not know them, you would not get the changed version of the files, unless you did something.
And what do you need to do, you need to go to that command prompt in the area that you, in the
folder that you created and you need to pull those files again. Now, in case those files have not
changed, nothing will change. In case we have made changes to those files, they would be
reflected, you would get a newer version and the local repository on your computer will be
updated with the changes that we may have made, we might have made.

(Refer Slide Time: 20:53)

410
And therefore, you need to learn to use two commands for that, usually you would run this
command. You would say GIT, exactly like this, on the command prompt, you just type GIT pull
origin master. The GIT software on your PC knows what you are talking about, what is the
remote host, from where to get it and update which files. In case you do not want to and that will
bring into the, the so called staging area, at which point you can use them in the way that you
want.

You could also, of course when you do this, the local repository is also updated. Or you could
use GIT fetch origin master, you can type this in the command prompt. It will only bring it into
local repository. It is not yet available, these newer changed files may not be visible, will not be
visible to you in the work area. And then you need to execute another command called GIT
checkout master, for the changed versions which have now come to your local repository, but not
yet available or visible into the designated folders.

So, we suggest that each time you are working on these files, you just open your computer, make
sure that the internet is working and then go to the folder, go to the, open the terminal in the
folder that you have stored all this and just run one command which is get GIT pull origin
master. When you type it, any changes that may have happened would be reflected on the local
repository and into the work place where these files are stored.

411
(Refer Slide Time: 22:27)

And so you say GIT fetch. It allows you to fetch these files and you can do, but we recommend
that you do GIT pull, which will not only fetch it, but also store and make the files visible in
those folders where the original files were stored. So, this is the way to ensure that any changes
that have happened on the GIT global repository, those changes are reflected in your local
repository. So, let me revise some of these terms. GIT is a version control system. There is a
local version of it running on your computer when you install GIT.

There is a global repository and there are many such global repositories and GIT can talk to any
such global repositories, but we have chosen to connect GIT to a global repository called GIT
hub. GIT hub is where we upload the files that we are creating for you. And if you want to
synchronize the files that you have already downloaded on your local repository, you need to
execute this command. So, on your terminal you just type GIT pull with this word GIT pull
original master, it will bring the latest version of the file from the global repository, that is GIT
hub, in from that file, that link that we shared.

You do not have to provide that link, it knows. It will simply pull those files from that repository
and update your local repository and then you are free to use them in any which way you want.
You can make changes to it also, does not matter. Of course, those changes will not go and
change the files on the global repository.

412
(Refer Slide Time: 24:14)

For that you need to learn more about how to use GIT and essentially that part is covered here.
So, you could use this as a reference, learn more about GIT. There are lot of sources of learning
material related to GIT on the internet. We recommend that you read that if you want to be a
contributor, or later on if you want to create your own repositories and share it with the world, or
create it, or have a team in which multiple people need to work on such shared files. So, once
you are done this, you are ready to go to the next step, which is to install code composer studio.

(Refer Slide Time: 24:50)

413
And just to recap, you have created a clone using this command. If you just want to download
the files once and for all, without the possibility of synchronizing with the changes, you could
download just the files using this command, type this into your browser and you get the zip file
which has all the folders and the sub-folders and the files inside those and so on.

Of course I hope that you are going to be worried about the synchronization and all that, so you
would use this command. Well, now you are ready, your GIT is installed on your computer, you
have downloaded the global repository and you are now ready to jump into the next part of this,
which is to install the code composer studio.

(Refer Slide Time: 25:37)

414
For that, you go to this website, or you just search code composer studio, TI code composer
studio, you would get the link. Go to this or type this into your browser and when you see, you
will see this. There is lot of options, but the top version which is released 9.3.0 is what we want
you to download. And we want you to download the Windows 64 bit version. There are no other
versions available anyway, so you click on it and follow the normal software download and
installation process.

(Refer Slide Time: 26:05)

415
When you click on the downloaded part, it allows you to setup, it offers you two options. Either
you can go with the custom installation or you can go with the full installation. As I mentioned
code composer studio is C compiler, C, C plus compiler from Texas Instruments for a lot of their
micro controllers and processors. But since in this course we are only going to be talking about
MSP430, there is no need to for full installation. If you did a, if you chose the full installation, it
will install compilation ideas for all the processor that TI offers. We are only dealing with the
custom part that is one part out of so many processors. So, we recommend that you use the
custom installation.

(Refer Slide Time: 26:50)

416
Then you go next, and in the next, it offers you all these options which you can check out. And
since as I mentioned, we only want to deal with MSP430, check out the first option which is
MSP430 Ultra low power MCUs. And then select next.

(Refer Slide Time: 27:08)

417
And now you are ready, your software is going to be installed shortly. And once it is installed,
we want you to be able to write code files and compile them and download them and so on so
forth. Of course we do not want you to write code files from scratch. In the beginning we would
want you to use the files that you have just downloaded. Remember in the previous segment of
this lecture we talked about creating downloading a repository of code files and of course many
other things on to your local computer. So, all you need to tell CCS that I want to edit existing
files, you want to point where those files are located and so you need to import those files.

So, to import existing files, you go to file import and in the tab it will show general and then you
say that you want existing projects into workspace and you need to point it to the right directory
which would be in that folder that you created. And once you do that, you refresh select all
finish. Now, you are good to go. You have all the your code composer studio would know all the
code folders that we have created for you, they are already installed on your computer, but now
code computer studio knows where they are and that you want to work on them.

In case, you want to create a new project, meaning apart from all the code files in various folders
that we have shared with you, in case you wanted to create your own new project, you are of
course welcome to do it.

(Refer Slide Time: 28:45)

418
And for that, you use in your CCS go to file, select new and you say you want to do a new CCS
project. There you need to mention that your target is this. This is the MSP430 G2553 and that
the compiler version is this. And then when you say finish, it will create, it will automatically
install some information for you into specified areas.

And one of the important things it will store is that it you have chosen MSP430 G2553. So, in
the predefined symbols, it is going to use this file. And in the header file, it is going to use this
version. This is just to illustrate what is happening, You, do not need to be worried about it. Once

419
you have selected this option while installation, all the files that you create, all the code that you
write in these files will compile for the MSP430 G2553 micro controller.

Now, once you have created a file, or you have opened a existing file, you would want to
compile it. Now, of course compilation will convert the C file into assembly and from the
assembly into a machine code file. But what do you do with that machine code file. Your idea is,
your intent is that this machine code, that is the object code, the binary code should be
transferred into the memory of the MSP430 micro controller. And for that, as you know, you
would connect your MSP430 lunch box.

But just the compilation process is not going to transfer the code file into the MSP430 target. I
am using the word MSP430 target because it could be MSP430 lunchbox, or you could use any
other MSP430 evaluation kit. Right? And so we need to still tell MS, our CCS compiler that
once the code compilation is completed, what is to be done with the object code.

What we want to tell it is that we want to invoke the boot strap and we can do that in the CCS.
So, that I do not need to open ten windows and in each window I have to tell one part and the
second window I tell the second part, the third part. The code composer studio is IDE, Integrated
Development Environment, which means it allows me to edit, it allows me to make changes, it
allows me to save files, it allows me to open files, it allows me to compile them, it allows me to
look at the compiled versions and then eventually it allows me to download the software right
into the target micro controller.

And so for that, we have to tell what is our way for transferring the object code from the
compiled, from the CCS compiler into which way into the micro controller memory. And since
we are going to use the boot strap loader, we need to instruct the, the CCS that this is our
preferred method.

(Refer Slide Time: 31:39)

420
421
And for that, you go to project properties, there you would see a tab build. In that you select
MSP430 hex utilities and you say enable MSP430 hex utility. Then you press apply and close.
And then you do the second step, where you again go to project properties, you say build
MSP430 hex utility. You are specifying the output format options and you select, here as you
see, output TI dash TXE hex format.

There are many ways in which the hex file can be saved. This is the preferred version which is
compatible with the boot strap loader, so we want you to select this. Once you are done, then you
go to step 3. And you, it basically shows you that once the build is completed that is when I say
the word build, here it means the entire process of compilation and so on and so forth. What to
do with it? It is going to create a filename like this. and remember, this part is very critical.

This is basically telling the computer and the code composer studio that the compiled file has to
be downloaded, has to be sent through the USB port which is seen as by the computer, which is
seen as com 9 in this case. Right? But of course, in your comp, on your computer the USB port
which you connect the lunchbox may appear to be a different number. So, what you need to do
is, go into the device properties and find out that the port, when you connect your lunchbox, it is
reflected as what com number.

And the way to do that is, if you have already connected the lunchbox, disconnect it. Connect it
again and you see a number pop up into the device manager. And that is the number. And you

422
should change that, that, you should write that number here. And this is when you are going to be
installing a new file. If you are going to open the files that we have created and which are
available to you on the repository, you might find this number and this number may be different
from the one reported by your device manager.

So, you need to go back into this BSL step 3 and edit this part to reflect that com port number
that you see now. And one idea is that if you have chosen a particular USB port to connect your
lunchbox. If you continue to use that port over the period of this course, you may not have to
worry about having to changes this over and over. Five days later also if you open your computer
and connect it to the same port, the port number would not change.

But just in case, your code does not seem to work on the lunch box, one of the reasons could be
that this port number has changed. So, it is not a bad idea to check with the device manager to
find out, is this port number has changed, since the time that you set this in this BSL settings. If
it has changed, please make appropriate changes here. So, it is very important that you find out
the port address to which you are going to connect your lunchbox and if it has and that address
must reflect into the BSL setting in this step 3. Once you are done, you are good to go.

423
(Refer Slide Time: 35:12)

Now, let us talk about the MSP430 compiler. It is a compiler which accepts C, C plus plus
commands. And it is good for 2014 version of the C plus plus language.

(Refer Slide Time: 35:27)

Now, we are not going go in this, C of course has keywords which you cannot use in as names of
your subroutines and things like that. And here is a list of those keywords. Please avoid these.
Please, please understand these, please familiarize yourself with these keywords to ensure that
you do not use them when you are writing a program.

424
(Refer Slide Time: 35:50)

Now, what does a C program have? At the very minimum it has a main loop. That main loop
indicates the entry point into the micro controller or the micro processor, it is compulsory. And it
will do a bunch of things as, as reflected by the code that you write. But once all those
commands, all those instructions are executed, where, where does the main loop take you? Well,
actually it does not go anywhere. The micro, as long as the micro controller is powered, it has
clock, and it has memory, it will continue to execute some program.

You may think that the instructions that you have written are over, the micro processor is now
sleeping, it is not doing anything. But that is not the case. It actually has infinite loop where it is
jumping to itself. So, it could be something like this, let us say the label is ABC. And it could say
jump ABC. So, it is like, the equivalent assembly command would be jump to itself. So, it will
be waiting, it is doing something. For you it may not be doing anything, that is visible, but it is
actually doing something.

And so you can explicitly have a infinite while loop, after your code instructions are as you
understand is over. Or if you do not, the C compiler will actually be executing some instructions.
Now, what is inside a main, the main loop. Well, what we do in the context of MSP430 is that
we will cover this, this is a watch dog timer. It is a very important feature of any micro
controller. And you need to configure it. So, you can choose to have it operational or you can
choose to disable it, but you must deal with it.

425
Then a micro controller and specially MSP430 has lots of options of the various clock signals.
So, you need to set that up, if you choose to. If you do not set it up, the MSP430 works with
some default clock, which is usually born out of the DCO and the frequency is 1 point 1 mega
hertz and I am talking in the context of MSP430G2553 micro controller. Then you need to do
something to configure the ports and peripherals that is you may have output ports and you want
to say, you have ports and you say I want these ports to be output, or some bits of those ports you
want to be input.

Or some timer you want to work at certain frequency or some ADC you want to work at certain
rate, you do these initializations. After this, in case your code requires interrupts, you enable
them. And then comes the actual meet of the program which is basically you are doing
something repeatedly.

(Refer Slide Time: 38:42)

As an example, let me show you a structure of a Embedded C program. As you see, initially we
have all these input files which have the prototypes of the function that you are going to invoke
and many other things. And here is the main loop. Now, why we are doing this is, not only we
want to compare it with the description of the various elements in the main loop, but also
something interesting.

426
So here this part, we have disabled watch dog timer and you would understand what we are
doing here once we cover the watch dog timer later on. Then we have called a function, which is
initialized serial print on the lunchbox. Now why we, why we are talking about it is, you see,
when you learn C programming on a compiler, on your PC, you had a great mechanism to see
the result of your program, and that was the display.

Unfortunately, on the micro controller, there is no dedicated display. There is a display very
rudimentary display, but that display can show only binary information and I am talking about of
an LED, that LED is on, it has done something, if the LED is off, maybe it has done something
else. But there is no way to print verbose information, or it, it appears to be like that. Well, if you
have used the PC or laptop desktop to download code into your micro controller, you could
actually in principle, use the display of your development post, that is your laptop or desktop to
display information.

For that of course you need, the micro controller needs to do a lot of things, it should be capable
of doing serial communication and connect to the PC. But it does, that is how you are able to
download the program from the C compiler into the memory of the micro controller. And so you
could use the same channel through you which you programmed the code from the desktop into
the memory of the micro controller. You could use the same channel and use it after the code is
working to print some information on your desktop computer.

Of course, this would be useful only when you are building the code, when you are developing
the code, this may, this info, this mechanism may not be available to you when the code is fully
working and is installed in some application. But while you are developing the application, this
is a great resource. And for that, all you need to do is include this file into any program that you
write and then you could, as if you have the printer function when you did your first C program,
you did Hello world right, and used this printer function.

It is like being able to use the printer function except it is not going to print it on the micro
controller display, because your micro controller display does not have, your micro controller
does not have a display like that. It is going to use the display of the PC and display information,
and in this case, what it is going to do here in this case when you compile this code and

427
download it into the memory of the micro controller, it will print Hello world and followed by a
number, and that number is going to continuously increment going from 1, 2, 3, 4 and so on.

And this part of the loop is simply just delaying it, so that you see that line for sometime and
then that line is updated, it is pushed up and a new line prints. It says Hello world 2, Hello world
3 and so on so forth. And so this is to illustrate that we have some mechanism to debug the
program, or use the display of the PC as a means of displaying verbose information, or more
critical information, maybe values of some variables or some count that you want to display. It
this would be, this part of the code function you would have to replicate in the code that you
want to, that wants to use this facility. And so we are going to show you how to use it very soon.

(Refer Slide Time: 42:50)

Now the, what are the elements of Embedded C programming. Well, I mentioned earlier, it has a
library definition, it has a main function, of course only very simple programs would have only
one main function and you can have only one main function. As you become experienced
programmers, you would relegate many of the programming tasks to subroutines.

And so your program may have one or more subroutines. And if you are an Embedded
programmer, that is what would distinguish you from conventional programmers is that you are
going to include something called interrupt service routines. They are also subroutines except
they will be invoked once when some event happens.

428
That event could be, you press a button, or the event could be you receive a value from the serial
port, or the event could be that a internal timer reaches some value and so on so forth, which we
are going to cover subsequent, in subsequent lectures when we talk about these peripheral
features. But you are going to be adding interrupt service subroutines into the, the C program.

Now, what how you manipulate data in a program is very important. Because at the end of the
day, the program is doing nothing but processing information which is data, you manipulate that
data and you store that data back in the memory or you send that data into an output port and so
on so forth. So, we need to worry about understand what are the various types of variables that
are available to you.

(Refer Slide Time: 44:24)

Broadly it is an integer variable, character variable. It is also, you can also look at it as unsigned
integer of a size 8. Integer is usually 16, but you can over write that by saying no, I want to use
an unsigned integer with, with 8 bits. You can have bullion type or you can have a numerated
type of variables. Then you can modify the size by using, you know, before these variable you
say short int, or you could say a long int that would modify the size of the int. And you could
also use these variables which could be defined as unsigned or signed, it basically reduces the
available numbers but allows you to have plus and minus numbers also.

429
(Refer Slide Time: 45:12)

Apart from that, the CQ words that are required to manipulate memory locations are auto in
which variable is allocated in this stack memory, or you could have static in which the
information will remain in a memory location. You can use an external definition in which you
want to access certain memory locations which are outside the scope of the current program. Or
you could use internal registers for storing information.

(Refer Slide Time: 45:41)

430
Also, the variables that you have defined, you could also qualify the way the operate, the way
they are managed by the compiler by saying that the information is constant of course, then it is
not a variable, but you are saying here is a number that I do not want to change. Or here is a
number which is stored in some memory location. The micro controller often keeps a, could keep
a copy of that memory location into a register. And so, whenever it is needed, instead of bringing
it from the memory location or a port, it could actually give you a local copy.

And sometimes you do not want that local copy. You want the compiler to fetch it from the
source, from right from the horse’s mouth. And you have to tell the micro controller the C
compiler that please bring the value of that variable right at the source. And one way to do that is
to add this key word in front of the character or integer variable that you are declaring. For
example, I could say int my underscore value. This would be a normal variable.

But if I said volatile int my value underscore. Well, you would still create a variable called my
value. But you are saying that, you know, the information to be fetched from this variable has to
be brought from that location where it is created. A copy if it is being maintained should not be
used to provide you whenever you need it. And so usually we use this keyword when we are
looking at exchanging information from a interrupt subroutine with the main program or from
the main program into the interrupt subroutine. And of course you would get to know it when
you see code examples that we discuss.

431
(Refer Slide Time: 47:35)

The here are the data types that are available in C. I do not need to repeat this is very similar to
what you may have already studied when you learnt C programming.

(Refer Slide Time: 47:43)

Of course we can, there are many ways as I mentioned, usually it would suffice to have int and
char and maybe a float type of variable, but often times you can use uint or uint 16 so you are
defining that it is a integer but it is of 8 bit size or it is an integer of a 16 bit size. Of course you
need to know where this header files which define the, these kind of data as available. So, if you

432
are going to use this, you have to include int types to attach into the C program that you wrote,
write.

(Refer Slide Time: 48:17)

433
Well, now coming back to the whole point of using a serial debugger or serial print, here is the
micro controller lunchbox that you would have received. Now, if you see here, there are, we are
going to use we are underneath here. Here is the u, USB port. And the USB port there is a chip
underneath here which is a USB to uart convertor, which connects to appropriate uart pins on the
micro controller.

Now, it turns out that there are two uart codes so to say, one is a conventional uart code, that is a
serial communication code. And the other is the code to be used when you want to use the USB

434
to download the program through the boot strap loader from the PC into the memory of the, this
micro controller.

And so you have to select some jumpers and that is being shown here. When you want to
program, when you want to download the program, the jumper should be on this side. And when
you want to use this micro controller and you want to use the USB to transfer information from
the micro controller into back to your PC, then you must change the jumpers to these locations.
So, that is what is the meaning as they are set here.

So right now, if you try to connect this lunchbox to your PC, and compile the code and download
it, it will not download. Why? Because it has not made the connection to the appropriate pins.
So, be very careful and sure that when you are downloading code, the jumper should be placed
here. Let me show it again here.

When you are downloading code, the jumper should be placed here. And when you, in case you
want to use the serial port to the micro controller needs to use the serial port to communicate to
the PC while it is running, while your program is running, then you need to pull the jumpers
from here and engage in the these two holes.

So, there are three holes here, 1, 2, 3 and 3 holes here, 1, 2, 3. 1, 2, 3. So, you would short these
and this when you want to do programming. And if you are going to be using the serial port, then
you are going to, you have three pins here again, three here. You are going to short this and this
and this and this. And then it would connect the uart pins to the USB, to uart convertor and it will
allow the PC to receive values from the micro controller.

Now, once you have the code in the C compiler, you have to go and build the project. And you
say build all, and you do that rebuild, then it will not only compile, it will also download. Why?
Because you have already instructed that once the code is compiled what is to be done with that
code. That it has to be downloaded through the USB using the boot strap loader facility into the
micro controller that is connected.

435
(Refer Slide Time: 51:15)

And so, when you do that, if you were to compile this program that we were discussing earlier,
here we have compiled this and downloaded it. After you have downloaded it, you change the
jumper setting to connect to the uart. This is, you would start seeing the values on your PC. But I
missed a point, that for the PC to show the values that are coming from the micro controller, you
need to have a programming running.

(Refer Slide Time: 51:46)

436
And that program is called PuTTY. It is a serial terminal emulator. You can download it from
this link. Now in this also, because there are many USB ports, you could be communicating
through any USB port. You need to tell the PuTTY configuration screen which code you are
going to use.

So, here in this case for example it says, COM60, of course not. You find out from the device
manager which comport your lunchbox is connected to and you write that number. And then the
serial communication speed has to be set to 9600, because our micro controller is going to be
sending values at this rate. What this rate is and what does it mean, we are going to cover when
we do serial communication in one of those lectures. And then you do only on clean exit and
then you open this, alright?

437
(Refer Slide Time: 52:41)

And then, when you do it, and your program is running. You have already downloaded the
program and when it is running on your micro controller, this PuTTY window will open and here
is what you see. Hello world 1, 2, 3 and you will see every second or so, this value is being
updated. So, this is the way serial debugging could be implemented with the micro controller.
Now, once you are happy with the way it is working, you can use this feature later on and maybe
in one of those lectures we will, one of the subsequent lectures, we will show, how to use this
serial monitor facility to print intermediate information on your PC for debugging purposes or
for any data, you know, monitoring purposes.

Right now, let us come back to using the C programming language for issues related to
Embedded C programming. And one of the things that it needs to do is to manipulate bits
because it is going to get information from the PC, from the various ports or value stored in the
memory and then it needs to decide whether the number is 0 or whether a particular bit in this
number is 1 or shift that bit certain bits to the left or to right, so you need to know instructions
which allow you to manipulate these bits.

438
(Refer Slide Time: 54:08)

And so instructions which allow you to play with these bits is, are called bit manipulation
instructions. And so we say, for example, you want to set a particular bit in a variable, so let us
say the variable, although this is not really a variable, this is a port that we are going to talk about
once we talk about the digital input and output ports of micro controller. But imagine that this
port, this could be as well this p1dir could as well be a another variable. And if that is initialized
with the value 8, now 8 in decimal is also 00001000.

And so, we want to set certain bit, what do you want to do? We want to set the, so this is 0, 1 and
2. We want to set the second bit. So, the way to do that is we want to set the second bit without
affecting the other bits. And so what we do is, we, we did that variable or with the variable which
is shifted, in which 1 is shifted two places to the left. And so once you or it, this 8 is going to be
or with the 00000100. And so the result will be 00001100. This would be, this you would get at
this point.

Now, you want to take the bit 7 plus bit 6 that means you want to set this and this bit and you
want to or it with the original value. And so, when you execute all these three instructions, initial
value loaded into that variable was 8. But after these two additional instructions that is this and
this, you would end up with this result. So, please go through this code and satisfy yourself that
that is what it is going to happen. So, this is a mechanism to set arbitrary bits in a, in a variable.

439
In this case, this variable happens to be a port address or a port location. Then you can clear
certain bits, that is you can turn certain bits off, and for that you use And function and you And it
with the invert of that, so that particular bit becomes 0. So, you have taken 1 and you have
shifted it three digits to the left. And then you invert that so that particular bit becomes 0, rest all
become 1. And so when you and it, the other bits remain unaffected. The bit 3, that is bit 0, 1, 2,
3, bit 3 is made 0. It was 1 it will become 0. It was 0 it will remain 0.

Then you can flip bits using this these set of instructions. A particular bit that is bit number 5 and
when I say 5 it means 0, 1, 2, 3, 4, 5, that bit needs to be flipped. That is if it was 1, it becomes 0.
If it is 0, it becomes 1. And so, as you see, the number is 8. In this, this bit is 0, 1, 2, 3, 4, 5. This
bit is 0. When you execute it, this bit becomes 1. This is the operation to flip bits. And here you
can get a bit, that is you want to know a particular bit is the value 1 or 0, if it was 1, you would
do something, if it was 0, you do something else.

This set of instructions will allow you to do it. How? You have initialized it with some value,
now you want to know if that a particular bit is 1, it will do something, if it is 0, it will do
something else. You And the original value with 1 shifted 3 bits to the left. And if the ending
operation is 0, you do something. If it is non zero, that is it is greater than 0, then you do
something else here. And so these are the mechanisms to play with various bits.

(Refer Slide Time: 57:53)

440
You, you could you know, look at this code which is available in the repository. Here it does lot
of operations, you could modify them and since we have included the serial print on the
lunchbox, you would be able to see the result on the serial monitor and then you can see what it
is doing, you could vary numbers here, change numbers here and rerun the program, re compile,
rebuild and download and you will see, you can check your understanding of these instructions
by predicting what number should come and see whether that number is coming.

(Refer Slide Time: 58:27)

Now, a lot of things that you would do on the micro controller would deal with ports, read the
ports, manipulate the value that you get from the ports and output into some other ports, alright.
And so here is an example, which if you would run, right now, you would see a bit connected on
the LED connected on the lunchbox would blink at certain rate. For that, we have to tell the
micro controller that such a bit, such a LED is connected to such a port which has a certain
name.

And as we have, as we will see when we deal with the MSP430 architecture that these ports on
MSP430G2553 micro controllers, there are two ports, one is called p1, the other is called p2.
And in our case, we have bit 7 of port 1, we have connected a LED. And so, we are dealing with
those ports using a name, these names are defined in this header file. And so, we do not have to
remember the addresses of those ports, we simply refer to them with these names.

441
So, it is like somebody has already declared a variable whose name is this and you can deal with
these names, manipulate information in these locations. But it is possible to access those
locations as memory addresses also, because you see, MSP430 is a von neuman architecture,
which means the micro controller or the processor inside has a unified memory map, and in the
same memory map, you are going to store the program, some other parts of that same memory
map are going to be used to store variables, because you have RAM there. And some other
locations are port addresses.

So, you could look at a port 1 as a name available through this header file, or you can find out,
what is the address of port 1 and directly access that memory location. So, the same program I
would show that you can get rid of this, you can remove this hash include, but then you would
not, the C compiler would not recognize this P1 dir if you used it, or p1 out if you used it, it
would not know. So, you need to replace it with addresses of these two ports.

(Refer Slide Time: 60:38)

And the second example here identical it just replaces with the memory address. In this case it is
22. And in this particular case it is 21. And the same program, we are just, you know commented
out the names of those ports and replace them with the addresses. And, and as you see here, we
have also commented out the header file. So, we are not using the information in the header file,
we are directly writing into those memory locations. Even then the same program works. So, the
whole point of this exercise was to illustrate that when you are compiling code, essentially all

442
these instructions, at the end of the day for a von neuman architecture, modify certain memory
locations.

Whether they are registers or whether they are variables, or they are constants, they are all in the
same memory map. If it was Harvard architecture, then of course there will be data memory for
which you would need to deal with those data memory in a different way and you would have
programmed memory and you would need to deal with that in a different way. In fact here,
MSP430 not only it is von neuman architecture, but also that the ports are, you can see ports in
two ways, one is called actual ports and the other is called memory map ports.

In MSP430, these ports are mapped into the memory map, that is the port addresses are like
memory locations, which means any port can be seen as a memory location, any memory
location can be seen as a memory location. And in fact this the point of this exercise was to show
that a port is also a memory location and we can manipulate the information in the case of
MSP430. Why? Because it has a concept of memory mapped ports.

Ports which are seen as memory locations. And if they are seen as memory locations, their values
can be manipulated by reading and writing to those memory locations. All you need to know is
the address of that memory. And this second exercise is actually to illustrate that. Once you
know specific and exact address locations, you do not need any names to access those ports or
those memory locations. You can directly read and write. And when you read and write in this
case, you are actually changing the way the LED toggles.

And so, with this, we cover three important elements of our journey, which is to understand what
is version control system, version control mechanism software for doing that. And in this case,
we have used GIT. With that execution of that line you have pulled the repository from the GIT
hub website and you have created a local repository on your computer and then we install the
code composer studio. Then you saw how the code composer studio could be made to point at
those folders which contain these code examples.

You could import them and you could build them, or you could modify them. And once you
rebuild them, you would be able to download the code into the memory of the micro controller.
And then a little bit about elements of Embedded C programming. With this we finish this topic

443
and I will come back with a new lecture and deal with various aspects of MSP430, architecture
and programming, and I will see you very soon. Thank you.

444
Introduction to Embedded System Design
Professor. Dhananjay V. Gadre
Netaji Subhas University of Technology, New Delhi
Lecture 22
MSP430 Digital I/O
Hello, and welcome back to a new session. And in this session, we are going to actually
connect a piece of hardware, that is our MSP430 lunch box to a laptop, as you can see my
setup here has changed apart from the iPad that I used to write and present this lecture. I
also have a laptop, on which I have connected the MSP430 lunch box. And I am going to
go through the first aspect that you would do when you connect a microcontroller to your
system that you would like to run the first program.

And when you learn C programming, the first program that you wrote was ‘Hello World’
in which you wrote a program, compiled it, and when you executed it on the screen of the
laptop or desktop computer it printed ‘Hello World’.

Now in our world of embedded systems, our world is dictated by the LED. And so the
first program will be ‘Hello LED’ and I will show you, once I explain how to write a
program to manipulate the bits and the pins that we have on our MSP430 microcontroller,
how do we write our first program so that we can convey the information on a LED
connected to our kit, that we, that is the objective of this lecture. So, let us begin.

Now, the problem is that in a microcontroller you have so many pins and you have many
more functions and the way to address this disparity is that allocate many, many
functions on a single pin and leave it to you the programmer, the embedded system
designer to write an appropriate program, to select an appropriate function to be routed to
that pin. But the basic function of each pin is to serve as either an input pin or an output
pin and even that is a big question that, how do you make a pin programmable?

You may recall that in one of the previous lectures I had mentioned, that one of the great
features of modern microcontrollers is the ability to decide by writing an appropriate
program that of the given number of input output pins how many will be input and how
many will be output. And so in this lecture, we are going to first of all solve that
conundrum and then we are going to address the issue as to how multiple functions are

445
routed to these pins, if you choose not to have those pins functions that in, function as
input output pins, how do you route additional functions on those pins?

So, we have a slightly complex task at hand and in the beginning it may appear very
daunting to you but please you know stay with me and I am sure, I would be able to help
you understand this whole complex arrangement of logic which allows a microcontroller
to funnel so many functionalities on one side onto a single pin. So since, we are dealing
with a MSP430G2553 microcontroller, which itself is available in two footprints,
meaning physical devices.

(Refer Slide Time: 03:37)

The fact is that the first version of the microcontroller, if you choose dip package you
will get two ports and those two ports are labeled P1 and P2, and our MSP430 lunch box
as a dip IC. In case you choose to implement your system using the SMD version, then
you will get 3 ports because that SMD version has 28 pins and those 3 ports are labeled
P1, P2 and P3.

Each of these ports has eight input output pins, meaning you can choose whether these
eight pins can be input or output or any combination thereof. As I mentioned, each of
these input output pins can be input or output and you can read or write to these pins.

446
You can also, apart from being input and output or output pins you can also configure
these input pins to become a source of interrupts on P1 and P2.

Apart from this functionality if you choose these pins to become input pins, then I had
mentioned that when you connect external devices which do not provide any logic
voltage then you had to transform the state of those signals as open and closed into 1 and
0, and so you need external resistors, you need pull-up or pull down resistors.

Well, on the microcontroller such as MSP430 you do not have to connect external
resistors, you can program the chip so that internal resistors can be pressed into service
and you can choose either a pull up resistor or pull-down resistor.

So, you can configure a pull up or pull down resistor and these ports, all these
functionalities are programmed through the 8-bit peripheral register interface that I had
discussed earlier, in the memory map of the microcontroller there were some registers
which were 8-bit access, some which were 16-bit so for the digital input output these are
all 8-bit registers. So, this is what we talked about here.

(Refer Slide Time: 05:42)

447
Now here is a schematic of one of the pin, you see this is such a complex circuit, it is
very much possible that you as a beginner will get, you know confused with such a
circuit but you do not have to worry, I am here to simplify things for you.

(Refer Slide Time: 06:04)

So, let me draw a simple diagram to illustrate this idea. The idea is that, I have a physical
pin, this is my pin, let me label it a pin, this is a pin of the microcontroller and you want a
mechanism, you want some circuit which will convert this pin as an output pin, which
means here is my microprocessor CPU bus, data bus and I would like to make this pin
output when I want to.

But when I reprogram the hardware related to this pin, I should be able to convert this pin
into a input pin. Of course, MSP430 offers you even more options but let us first see how
very basic digital circuit components can be pressed into service to provide that
functionality of being able to change the pin as input pin or as output pin. And one of the
biggest beauties of digital electronics is this, tri-state buffer.

So imagine, that I have a tri-state buffer, here is my flip-flop, a D type flip-flop, I call it
D-FF, into which I can write any value and here is a clock so that at the clock edge that I
decide a particular bit is stored in this flip-flop, the output of this flip-flop feeds the input

448
of this tri-state buffer, now it becomes a tri-state buffer. If the tri-state buffer control
signal is 1, then this output gets the value as input.

If on the other hand it is 0, then this tri-state buffer is disconnected from the pin and this
is how a typical microcontroller, a modern microcontroller such as MSP430 uses this
kind of hardware to select the functionality and give the control of that functionality to
you, the system designer or the programmer so that you can choose.

Do you want this pin to be an output, yes, if you want to this pin to be an output you will
write through appropriate registers, a logic one here that will enable this tri-state buffer
after that whatever you write into this flip-flop that value will appear here and
subsequently it will appear on the pin.

And so when I want to make a pin an output pin, I, my micro controller would have
suitable circuitry especially with the tri-state buffer which will be enabled through
writing bits into appropriate control registers and this tri-state buffer will be enabled,
thereafter I can keep on writing any bit sequence into this flip-flop and that value will
appear on this pin.

Now suppose, you want to convert this pin into an input pin. Obviously, you expect an
external voltage to be applied to this pin, this voltage could come from a external device
or it could be a switch, then you do not want this tri-state buffer to be enabled. Because
otherwise, this logic will come from here, and some logic will come from here, and if
these two logic values do not agree with each other it will lead to what we call as bus
contention.

And the simplest way to avoid it is to write, is to write a logic 0 here, if I write a 0 on this
control pin, then it as if disconnects this part. So, I am just left with a hanging pin from
the microcontroller side, and now I can use an external device to apply voltage.

And of course, this goes through a buffer and goes into the data bus, so that now, and
again this also needs a tri-state buffer so that on demand when the microcontroller
program reads, makes this bit a logic 1, here it will read the pin value and put it on the
data bus and eventually it will go into your register so, that you can process that

449
information. So, this is the basic idea behind any pin with the functionality that it can be
made input pin or output pin. And this is actually what is happening on this pin.

450
(Refer Slide Time: 10:19)

Here is my pin, if you see here, here is the pin. And you see, this is the tri-state buffer that
I was talking about, this tri-state buffer is controlled by this gate which is getting
information from some of these registers here and I am going to simplify that information
for you.

If this is enabled, this information is coming from this multiplexer and one of the
multiplexer inputs is this register called PxOUT. And you writing information here can
be routed into this and it can appear at this pin, if you want to make this pin as output, if

451
you want to make this pin as input then obviously, you will have to ensure that this
tri-state buffer here becomes 0, and then you can apply external voltage it will go through
this buffer, tri-state buffer and go into here and then can be read by the microcontroller.

So, as you see here, there are several, you know value is written here, some of them here
are related to the port, some of them are talking about timer, there is something here
about comparator, and ADC, and so on and so forth. So, this is to just indicate that
MSP430 microcontroller pin is multifunctional and it is up to you as the programmer to
decide which function this particular pin should behave and so we are going to look at
that.

(Refer Slide Time: 11:52)

452
Now, you see we are going to look at one example, let us see that, let us say that our pin
is P1.0. Now P1.0 pin whatever physical pin it maps on to has several functionalities, one
of the functionality is that it will act as a port pin 1.0, the other is that it can act as input to
one of the timers here TA 0 clock.

The other could be that it can be used to route an external information, in this case the
auxiliary clock value can be outputted on this pin. The fourth function that this can serve
is it can become the ADC input for with bit 0, the third is that it is a CA 0 input that is the

453
input for a comparator, and the last function that it can serve is that it can be used for
capacitive sensing.

So, as you can see each of these port pins has1, 2, 3, 4, 5, 6 functions and how do you
select which function will be used to make this pin work in, these are all the registers we
have. So we have one register called P1DIR, that DIR stands for direction, then we have
two registers called P1SEL and P1SEL2 so these are select registers.

So let us simplify it, say select register and select two register associated with each port,
which means P1 would have a select register, P1 would also have select two register, P1
would have direction register, P1 would also have registers associated with the ADC, and
P1 would have register associated with the capacitive sense functionality.

So, let us see, if we want to use the pin as an input output pin then what should be the
value of the register called direction register, what should be the value of the two
registers called select, and select two registers and the rest of the registers. Now you see
here, I can write a 0 or a 1 into the direction register, this will decide whether it becomes
input or output. But, to select it as input output, whether it is input or output will be
determined by the direction register.

But for it to become an input output pin you have to write a 0 and into the select register
and another 0 into the select two registers in the appropriate bit, remember each port has
eight pins, each pin is associated with the port bit. So, if I am talking about bit 0, that
means I am saying P1DIR 0, I am talking of P1SEL 0, I am talking of P1SEL2.0, and so
on.

So, this is very important that you have this functionality associated with each and every
pin. Now let us say, that no, you do not want to use this pin as a input output pin, you in
fact wanted to become a clock for the timer. That means, the value of P1DIR register for
bit 0, let us talk about 0, should be 0 and the select and select two pins, select and select
two bits should be 1 and 0 and ADC and the capacitive register can have 0, 0.

If it has to be used to route the internal auxiliary clock signal on to this pin, now you see
the direction becomes that it becomes an output. And that is why, you have written the 1

454
you have to write a 1 into the direction register. And select value is 1 and 0, select two 0
and ADC is 0, CAPD 0. If you want it to become ADC input, then it does not matter what
is the direction value, it does not matter what is the select bit value, select two bit value,
X means do not care, you overwrite that function by writing a bit 1 into this register
ADC10AE and since you do not want it to be the capacitive sense you write a 0.

On the other hand, if you want it to become a comparator input again this is X , X, X, this
is 0 and CAPD becomes 1. And if you want it to become capacitive sense then, the value
here is X but SEL1 value has to be 0 and 1 and these two are again 0, 0 this will select
this particular pin to become capacitive input.

And this as you see, this kind of functionality is repeated for rest of the pins, the actual
functionality will change from pin to pin but the selection process is the same. So, let us
see, how many resistors are we going to deal with when we are going to connect, decide
to use these pins as input or output.

(Refer Slide Time: 17:15)

455
So, for using the input output pins as I/O registers we have at least 1 the direction
register. X here refers to which port are we talking of, for example, if you are talking
about port 1 this will become P1DIR, if we are talking of port 2 it will become P2DIR,
and so on. So, I will not repeat this. So, we have PxDIR means the export, the direction
register, then we have the information register called PxIN, this is the register that you
will read if you want to make this pin or this port as input, if you want to make this pin of
this port as output you will write to the PxOUT register.

Now, if you choose to make this pin of this register as of this port as input you will of
course read this, but you may choose that you want a pull-up resistor or pull down
resistor, for that you have to enable the resistors and you do that by writing into this.
Whether it will be pull-up or pull down will depend on what you write into the PxOUT
register.

And then, is this pin going to function as input output pin or is it going to take the
alternative functions associated with this pin will be determined by writing appropriate
bits into SEL and SEL2 bits. So, this is the sequence of operation that we have to perform
and let us see how we do that.

456
(Refer Slide Time: 18:48)

So, we already gone through that, here X refers to the particular port, P refers to the port.
So, if I say, P1DIR that means, I am talking of the direction register associated with port
1. And if we choose the 28 pin package you will have port 1, port 2, port 3 it is a 8 bit
register. A value if you write in a particular bit, so you have 8 bits in a port, so let me
show that 8 bits to you, this is how I make 8 bits, this is bit 0 and going up to here bit 7.

Now, in this if I write a 0, so this is my P1DIR register. If in this I write 0 at bit 0 that
means the pin connected to bit 0 of port 1 will be configured as an input, that is the
meaning. If next pin if I write 1, that means bit 1 of port 1whichever pin it is connected to
will become an output pin and I will write appropriate values in this register to decide the
basic functionality of the port, whether I want them as input or output. I hope it is clear.

Now, if I choose by writing in the P1 direction register to be a 0 to make it as input,


where do I read the input from? This is just going to determine the direction input or
output. Now, you have to read different registers if you have made this pin as input or
you have made this pin as output.

457
(Refer Slide Time: 20:33)

If you want to make this pin as input, you have to read a register called PxIN, so here for
P1 it will become P1IN. Now of course, you may choose that for the 8 bits some of them
are inputs some of them are output, how do you read the value, you will read the entire
register, you will read P1IN and then isolate those bits which you have configured as
input and identify their values, a 1 means the pin is 1 is held at logic 1, if it this register
reads a 0 in a particular bit location, that means that pin was externally set to 0 that is the
meaning of this entire slide here and you can go through it to verify what I mentioned.

On the other hand, if you have decided that for a particular bit you want it to be output
you are going to write a 1 in that bit location.

458
(Refer Slide Time: 21:37)

How do you actually write the value, how do you actually send the value to the port pin,
you are going to do that by writing into the register called PxOUT, in this case that value
becomes P1OUT. So you will write values in this register, those bits of port 1 which are
configured as output they will take value that you write into P1OUT and will decide
whether that pin becomes 1 or 0, you will of course write it into the entire register but
only those ones will be affected which you have made as output, please understand this.

You, when you write to a register you are writing all the 8 bits but maybe you have only
one bit we have configured as output so the other seven bits will not affect the
functionality on those pins because they are not output, only the one which was
configured as output will get the value. And if you want to output a 0, you write a 0 into
the PxOUT register, if you want to output a 1 you are going to write a bit 1 into that bit.

459
(Refer Slide Time: 22:37)

And then as I mentioned, if you want to configure a port as input, you had to decide do
you want internal pull-up resistors, if you do, then you control and program this register
called PxREN, which means for port 1 this will become P1REN, port 1 resistor enable
and this enables either the pull-up or pull down.

Now, if you write a 0 in the PxREN register at an appropriate bit location it will disable
the function of pull-up pull down, if you write a 1 it will enable it, if you write a 1,
question is will it become pull-up or pull down? The answer is provided by writing an
appropriate value into the corresponding bit of the P1OUT register, by writing 1 into
P1OUT at that bit location it will make a pull-up function, if you write a 0 it will become
pull down function that is the meaning of this.

460
(Refer Slide Time: 23:48)

Now, we also had to deal with the select bits, there are two registers; one is called P1SEL
and P1SEL2, so this will become P1SEL for port 1, and this will become P1SEL2. And
what are the options we have? If the value is 0, 0 written into these two registers at any
bit location that enables that pin to function as input output, if it is 0, 1 it is the primary
peripheral module if it is 1, 0 it is reserved you are not supposed to use this combination
and if you write a 1, 1 into corresponding bit locations of these two registers a secondary
peripheral function is selected.

And we have already gone through the various combinations of PSEL and PSEL2, how
the other functions are selected. So now, we know that we have so many registers to deal,
with we have a direction register, we have a input register, we have a output register, we
have a pull-up enable register, and we have select and select two registers these many
registers you have to write.

Now thankfully, many of the resistors have friendly default values, that is values which
are at reset are helping you that these are configured as port and they are usually
configured as input, so you do not have to worry.

So, the only thing you have to do is, you have to decide whether you want the port to
become input or output by writing into the direction register and if you have chosen them

461
to become output to write values into the output register and that is it. Only when you
want to invoke the additional functionality, the secondary functionality you have to worry
about writing into the PSEL and PSEL2 registers.

Now since, in this first exercise we are going to deal with writing values, converting
these pins as output and writing values of ones and zeros we are, our program is going to
be very simple. But we still need to go through how we manipulate bits, so that I can
make a 1 or 0.

(Refer Slide Time: 26:17)

So as we know, we involve bitwise operations and we can invoke or function, that is or


two bits in corresponding locations and two bits for this we use a symbol this, for or we
use, this XOR we use this here, for shift right we use this, for left we use this, and for
inverting we use this tilde. Let us see some examples to deal with this.

462
(Refer Slide Time: 26:40)

Now, since the input output pins are independently configurable, it is very important that
we understand what information are we writing into any direction register, then
outputting into the output register, reading from the input register, selecting appropriate
pull-up values by enabling or disabling the REN register, and so on. So here let us say,
that we execute an instruction P1OUT is equal to P1OUT or BIT3. Now what is this
BIT3, BIT3 are value stored in the header file associated with this, we will show that with
an example.

And this allows us, these are mask bits, now if I say BIT3, now let me show where is
BIT3. In 8-bit register this is bit 0, 1, 2 and this is bit 3. Now we are saying, P1OUT is
equal to P1OUT or with bit 3, so bit 3 is 0 0 0 0 1 0 0 0. Essentially, this is nothing but if
you see this this becomes these are four bits become 0, these 4 becomes 8, so this is 0 8 in
hexadecimal.

So, these 3 are doing the same thing, here we are explicitly saying that P1OUT is equal to
P1OUT original value ored with BIT3 which is 8. In the second statement we are saying
it in a different, way we are saying P1OUT is equal to, repeat this operation P1OUT with
odd with BIT3. And in this one we are explicitly saying, that or P1OUT with this
information which is 0x08. So, this is the way you can manipulate the bits using the or

463
operator. Now we have seen, how to make a bit 1 or 0 on any of the port pins. Let us look
at how do we turn that LED on.

(Refer Slide Time: 28:53)

Now you see here, the basic assumption is that on our port in this case P1.3 our LED is
connected like this, which means if the bit is 1 the LED will glow, if the P1.3 bit is 0 it
will become, it will turn off. Now we want to turn off the LED, we do not know what is
the previous value, we do not know whether the LED was on or off, how do you ensure
that we turn off that LED? Now there is no way to directly address this LED, why,
because this pin is part of eight pins and so if you write to this register it is likely to
change the information on the other bits.

So what we must do is, we must isolate this bit and only make it 0 and so this is what it
does, that P1OUT is equal to the original value of P1OUT which means the value that
exists right now on this port, I want to and it with the invert of BIT3, I already mentioned
what is BIT3, BIT3 is 08hex, which means 0 0 0 0 1 0 0 0.

Now what is the invert of that, it becomes 1 1 1 1 0 1 1 1 which is equal to F7. So in this,
without explicitly mentioning F7x, I have inverted that bit and involved in that operation
it is going to take the original value of port 1 out register and it with this F7 which will
make the BIT3 equal to 0 and I am going to send that information to that port, what will it

464
do, it will retain the information on the rest of the seven pins and only make port 1 BIT3
equal to 0.

Another way of doing that is this. And the third way is to explicitly mention, that you
want to and P1OUT with F7 which of course, you got using inversion of BIT3 also. So,
this is the way to turn a particular pin of the previous one showed how to turn it on.

(Refer Slide Time: 31:06)

Now in case you want to make a particular port pin as input, then you must read the value
on the register called P1IN. And here we have taken an example, that suppose we have a
switch connected to P1.5, port1 bit 5 then you must and the BIT5, now what is BIT5?
Here, this is 0 1 2 3 4 and this is 5 6 and 7, so you want to know what is this value so you
will read it, isolate this bit and if, if the anding operation is equal to 0 that means this bit
is 0 you can choose to do something, if else you can do something else, that is the
meaning of this structure of the program.

So, you can read entire register P1IN, isolate a particular bit that you are interested in
using bit operations and the result will be 1 or 0, which will allow you to do one or the
other thing that you want to do.

465
So we have now seen how to manipulate the registers to program the MSP430
appropriately, so that we can control the pins whether they are input or output, right now
we are going to deal with the port pins as output and so we are ready to write our first
program and to write it, compile it, and then download it into our MSP430 to control the
LED which is connected on the appropriate pin of the MSP430 lunch box, which I will
mention in the next part of this where I am going to switch over to the laptop.

So, what I have here is my laptop and I have opened the ‘Hello LED’ program you would
have downloaded it from the git repository and you would see a program called ‘Hello
LED’ I will go through that.

(Refer Slide Time: 33:09)

466
467
468
469
470
So, the first part of the program is talking about including MSP430H, this is a header file
which has useful information, such as the bit mask and so on. Then you have the main
code, this main code is like an infinite loop where you are doing something. And the
reset, when you reset a MSP430 micro controller you remember when we were talking
about reset it turns on the watchdog timer, and if the watchdog timer is turned on it is
going to reset you very frequently.

So, we do not want the watchdog timer to interrupt what we are doing or to stop what we
are doing and therefore, the first instruction is to stop the watchdog timer from generating
reset information. Then we come to dealing with the deciding the direction of our port,
here we have LED connected to bit seven. And so what we do is, we make P1DIR which
is the direction register for port 1 we make it 1 and we do it without affecting the
functionality on the other pins.

So we have an instruction called P1DIR is equal to P1DIR ored with 0x80, so that means
the most significant bit being equal to 1 the rest being 0 is anded, is ored with the rest of
the, with the original value of direction register and that is sent again to the direction
register, this configures P1.7 pin to become an output pin. Now, in the current form we
have, we are writing a 1 into that by saying P1OUT is equal to the original value of
P1OUT ored with 0x80, so we are turning it on and I am going to do this.

471
So, I select the ‘Hello LED’ program and on that I press the rebuild project and you see
what it does, it is going to compile the program and eventually it will download the code
into the microcontroller bit and lo and behold the user LED has turned on. Now let me,
modify this program, so as to turn it off. I will comment this part of the code here, I am
going to comment this and uncomment this part where I want to make it 0 and so I
remove it.

And now I will recompile this, rebuild this, again it is going to, you know compile it and
then download it and you see the LED has been turned off. So, this is the first part of the
exercise of writing a program and downloading it into the microcontroller kit.

What have we seen in this, that our first part of the instruction is to disable the watchdog
timer, then select, write into the direction register so as to select the direction of the bit
that we are dealing with, in this case it is P1.7, and then since we want it as an output we
write appropriate values on the output register that is P1OUT on bit seven because we do
not want to affect the output pins of other bits, so we only isolate P1.7 and write whether
we want to write a 0 will turn the LED off, if we write a 1 will turn the LED on, and that
is the first part of this exercise.

Now this may look very trivial, but to be able to come to this point gives you great
confidence for many things, one that your compile process is working, that you have the
ability to download code into your working board and that the board is also working.
Now let us go to the second part of this program, which is to basically blink the same
LED so instead of just turning it on or off we are going to add a certain more code into
that initial this program and make it blink.

(Refer Slide Time: 37:52)

472
473
474
475
So, this we call as the ‘Hello Blink’ you would again, by downloading it from the git you
would have access to this. Here again we have the include instruction and then we have
the main code loop which is an infinite loop in that we, on line number seven or whatever
line you have on your version you would find that we have disabled the watchdog timer.
And then we write the direction, we make the direction of pin 1.7 port 1 bit seven, we
make it output by writing a 1 into it and then we go into an infinite loop.

See in the earlier case we just wanted to write 1 or 0, now we want to continuously write
1 with some delay we write a 0, then with some delay we write 1 again and so on so

476
forth, so that the LED can blink. Now it will appear to be blinking only when the delay
between, delay between the turn on and turn off is sufficient to be observed by human
eye and so we have written a delay, small delay function which delays, it ensures that the
state of the LED is held to a value of 0 or 1 long enough for it to be observable by human
eye.

And so, what we have here is mechanism to do that, in the first part we are turning the
LED on by writing a 1 into that register, then we have a line where we say for i equal to
0, i less than ten-thousand essentially this is a delay. We can also replace with some
built-in delay functions which we will look at later on. But right now, this is like a delay
created using a loop which runs for certain amount of time, once you get out of that loop
you again you toggle the value.

Now here we have done and the value of the original value with the inverted value of 80,
that is what we have done here. And this toggles, this makes the LED 0 and then again
we delay, so we have another same repeat of delay function and then this is the complete
while loops, so it is going to go through that writing 1, delay, writing 0, delay, and it is
going to do this infinitely.

Now when you do compile this, when you build this code, so I have choose rebuild
project, now you see it is going to compile, and download and lo and behold that LED is
now blinking at a comfortable rate which is observable by the human eye. I hope you are
able to get a similar experience with your kit that you are able to turn the LED on and off
and then you are also able to blink it, if you have reached this stage I must extend my
congratulations to you because that means that the entire ecosystem is working as good to
you with you as it is to us.

And we are ready to jump into the next part of our programming exercises, where we will
show how to read inputs from the pins, how to output values based on the inputs that we
read and many other things including interrupts, and so on and so forth. So, I hope you
are with us in this activity, I thank you and I will see you very soon. Bye.

477
Introduction to Embedded System Design
Professor Dhananjay V. Gadre
Netaji Subhas University of Technology, New Delhi
Lecture - 23
MSP430 Digital I/O: Switch Interfacing
Hello and welcome to a new session. I am your instructor, Dhananjay Gadre, and I am
conducting the session for the online course on Introduction to Embedded System Design. In the
previous lecture, we connected the MSP430 microcontroller using the MSP430 lunchbox to
LEDs, and we saw how we could toggle the LEDs or we could turn the LEDs on and off; we
called those program HelloLED or HelloToggle. Now in this session, we are going to consider
input devices and the most common input device is a switch. So let us see how we can interface
an MSP430 to switches.

A switch is a mechanical device it consists of two metal plates with the shorting cover over it,
which when the user presses the plastic button, the cover, metal cover inside shorts the two
contacts of the switch; when the user releases it, the cover retracts and the connection is broken.
So using this arrangement, the contacts of the switch toggle between or move between two
states, switch is open or switch is closed. To ensure that the switch retracts there is usually a
spring connection, spring arrangement.

(Refer Slide Time: 01:54)

Now because of this, the switch will often bounce as we have discussed, but before that, the
switch has two states; open and close. And these states we have to translate into logic 1, if we

478
choose logic 1 for open, then the close must translate to 0 or we can have another possibility that
we can have open translate to logic 0 and then the close will translate to logic 1. And this is
achieved by using a pull-up resistor configuration or pull-down resistor configuration. Let us see
how these configurations look like.

(Refer Slide Time: 02:33)

Here is the pull-down configuration. As you see here, we have, this is the mechanical switch, this
is the pull-down resistor, and in the second configuration we have the switch here and the pull-up
resistor and the connection between the resistor and the switch in both the cases is going to a
microcontroller pin, in this case, some MSP430 pin which can be configured as input.

479
(Refer Slide Time: 03:05)

Now let us look at what resistors to engage, what resistor to program so that we can connect a
switch on a input-output pin, configure the pin as input and without having to use external
resistors, invoke the internal facility, internal feature to either use a pull-up function or use a
pull-down function. And for that, we have four resistors that is PxDIR, which means if we are
talking about port 1, it will become P1DIR then we need to, so we need to configure P1DIR,
appropriate bit of P1DIR, where we want to connect a switch as input.

Then we need to be able to read P1IN because this will give us information that what is the state
of our switch, whether it is 1 or 0. If we want to engage internal pull-up or pull-down resistors,
then we have to enable that using this function, using this resistor and whether we want to have a
pull-up or pull-down will be exercised by writing appropriate value of 0 or 1 in the appropriate
bit in the P1OUT resistor, P1OUT and this is P1REN.

So this is the resistors that we need to deal about. There are other resistors that is P1SEL and
P1SEL2 but these are only utilized when we want to invoke alternative functions on a given pin,
and since we have decided that we want to use this pin as input, we are not going to be bothered
by these two resistors, we will not use them in our program. Now to read a switch we will not
read a single bit, we have connected the switch to one of the pins, which means to one of the bits,
but when we read the port we will get all the 8 bits and we will have to then isolate that bit so

480
that we can take a decision is the bit sending a 0 or is the bit sending a 1, and we can choose to
implement a particular function if the bit is 0, what to do; if the bit is 1, what to do.

(Refer Slide Time: 05:53)

Now in our case we have, on our lunchbox, we have a switch available on the lunchbox and it
has been connected to P1.3 and an external resistor has been used in the pull-up state and
therefore, we should ensure that in our program it takes cognizance of this feature that a switch is
connected to P1.3 pull-up resistor has been used and so the program must appropriately
recognize this configuration.

So to be able to identify whether the switch is pressed, when the switch is not pressed it will give
a logic 1 because there is a pull-up resistor, here is how it is. Here is the switch connected to
ground, here is the pull-up resistor, and the junction is going to P1.3. So when the switch is not
pressed, it will give you logic 1; when the switch is pressed, it will give you logic 0. So I am, by
reading P1IN and then ANDing it with bit 3, bit 3 nothing but a mechanism to identify and
isolate bit 3, its value is 00001000 why this is bit 0, bit 1, bit 2, and bit 3.

So on bit 3, there is a 1, this is a mask, mask value, and by ANDing whatever has been read from
port 1 IN, by ANDing it with this you will get binary result, either the result is 0, but because this
bit 1, the third bit is 1, if the result is 0, the ANDing operation, bit-wise ANDing operation leads
to 0 that means the bit 3 which is read from the pin has reported a 0. If it is 1, the ANDing will
become 1, so if this is equal to 0, then do something whatever you want to do if the switch has

481
been pressed, else if it is not pressed, it will return a 1 and then you can do something else. This
is the basic logic by which we detect that a switch is pressed or not pressed and we can choose to
do one or the other activities in this program.

(Refer Slide Time: 08:06)

Now, because mechanical switches will exhibit bouncing and here is the recap of what happens,
when the switch is not pressed you will get a logic 1, when the switch is pressed you might
observe a phenomenon like this. This has been captured on a digital storage oscilloscope, you
could try recording such a event at your own end. However, it does not mean that every switch
press will leads to so many ups and downs. In your case they may be more, in it is also possible
that you will get even less bounce, it is also possible you do not get bounce, any bounce at all.

So do not get alarmed this is an extreme situation and we have taken several recordings on our
oscilloscope just to identify a situation where it shows several bounces and the idea is to convey
that switch, switches do bounce and this an extreme situation, it is possible that you do not get
any bounce. And as mentioned here, the bouncing is because of the mechanical nature of the
switch, spring, and it would have fluctuations and that is why you get bounce.

482
(Refer Slide Time: 09:31)

Now the question is we cannot have a bounce in our program, because the bouncing would lead
to being interpreted that the, even though the switch was pressed once if you see here, even
though the switch was pressed only once but if the program does not remove this bouncing, it
will conclude that it was pressed once, twice, thrice, four, five times and it might do five things
but we know that it was pressed only once, so we have to find a mechanism to remove these
fluctuations.

483
(Refer Slide Time: 09:56)

And one method is to use a hardware debounce technique and a simple capacitor here of a
suitable value, which must take into account the value of the resistor, the pull-up resistor so that
R and C makes a low-pass filter. And so if we know that our switch bounces say, in this case as
you see the couple of 100 microseconds. So if you have the low-pass filter frequency to be much
lower than 1 by, in these case, 1 by 300 microseconds whatever is the resultant frequency, if you
choose the, if you select the value of the R and C such that the resultant frequency is much lesser
than that, then this will be able to debounce the switch in hardware.

484
However, I do not recommend this solution. Why? Because in real application, such a capacitor
would add to the cost. If you have 10 switches, it would mean having to use 10 capacitors. And
the reason is that these capacitors can be easily avoided by using an alternative method, which is
called software debouncing. But here the capture on a DSO shows that now the transition is
much smoother, there is no bounce on it, and because the capacitor you see this charging sort of
feature on the transition of the voltage from 0 to 1.

So let us see what is the software debouncing. In the case of software debouncing, we simply,
once we detect that there is a transition of the input of the pin that at which the switch is
connected, we simply stop looking at that pin for a certain period of time.

(Refer Slide Time: 11:32)

And for example, we could use 20 milliseconds delay, but you can alter this to be of different
values. For example, if you know your switch only bounces for about 200 microseconds, then
you could decide to use a 1 millisecond debounce delay period and you can play with this to get
an optimum value.

In our examples that we will show subsequently just after this, we have used a 20 milliseconds
delay and let us now move over to our hardware configuration, where we have this laptop, we
have also connected the MSP430 lunchbox. There is switch on the lunchbox already connected
to P1.3, but we want to illustrate that how we could utilize the internal pull-up and pull-down
resistor configurations.

485
(Refer Slide Time: 12:36)

We have a breadboard here, on this breadboard there are two switches which have been
configured in the pull-up and pull-down configurations, meaning we have a switch in one case
where the switch is connected. Two terminal of the switch are available here. If we want to use
in the pull-down mode, we ground it. So now these two connections are available, we will
connect it to an appropriate pin, pin of MSP430 and this will be connected to ground.

We have another switch in which case the switch, now for this configuration we have to invoke
the pull-up feature, we have another switch here where the switch is connected to VCC, here,
and the other pin is available here and this will go to VCC of the MSP430, this will go to another
pin of MSP430, and this configuration allows us to test the pull-down feature. So we have, we
will in, test several versions of the program, one with no debouncing either in hardware and
software, and then you can observe what happens with the result of that switch, switch press.

In other case we will involve a hardware debounce, then we will add a software debounce, using
the onboard switch on the lunchbox. Then we will have two versions of the program where we
use this breadboard, we will use jumper wires to connect to one switch and then the other switch,
one which is pull-up feature, and the other which uses the pull-down feature.

So make sure that your hardware is ready and you follow the program examples to test these
experiments. Here we are going to connect switches in various configurations and I am going to
show you five versions of the program, I have four versions of the program.

486
(Refer Slide Time: 14:49)

The first version is, I am going to use the onboard switch, as you know this switch is connected
to the bit P1.3, and if you look at the code which you can, which I am sure you have
downloaded, you will see that the switch is connected to bit 3, the LED onboard of MSP430
lunchbox is already connected on bit 7, in a previous exercise we had seen, experimented with
this LED and we had turned it on and we had toggled it. So it is the same LED configuration.

Then, now we come to the main code part of the program, here the first instruction talks about
stopping the watchdog timer. We talked about it yesterday also that the default state after reset is,
one, the watchdog timer is turned on; two, the master clock frequency is 1.1 megahertz. So our
program is running at 1.1 megahertz, we are not changing anything else, 1.1 megahertz is okay
for our experiments, so we will continue with that.

Now in this, we have, so as I mentioned we have to first determine the direction of our pin, our
pin, in this case, is connected to the switch is connected to P1.3, our LED is connected to P1.7.
So we have to determine and dictate the direction of these two pins that is bit 3 and bit 7. The
first instruction after turning off the watchdog timer turns the P1 direction on bit 7 so that it is 1,
and by making that pin 1, it becomes an output pin.

And the second instruction talks about, so the first instruction is P1 direction resistor is equal to
whatever value of P1 direction resistor is ORed with a constant here which is actually a masking
value of LED, LED is bit 7, that means the most significant bit is 1, the rest are all 0, when we

487
OR it, in P1DIR bit 7, you get a 1. And when you send it out to P1DIR resistor that bit becomes
1 that means the, that particular bit becomes output.

In the second instruction here P1DIR, you are saying P1DIR is equal to P1DIR ANDed with the
inverted value of the mask constant called SW. SW is on bit 3 and therefore, essentially it will
make the P1.3 bit in P1DIR resistor is equal to 0. This will make the pin as input. Now once
these two instructions are executed, we are ready, we have decided, we have converted P1.7 as
output and P1.3 as input. And these are all on board that is on the lunchbox, switch is connected
on P1.3, and LED, user LED is connected on P1.7.

Then the next instruction is a infinite loop which says, while 1. While 1 means you enter the
program and then you are not going to exit from this program. In this program, we are waiting
for the switch to be pressed, meaning if the switch on pin 1.3 is not pressed, it is not going to
enter the second loop and it is going to wait there, but the moment you find that the switch is
pressed, you will get a logic 0. Why? Because in this configuration we have used an external
pull-up resistor.

So when the switch is not pressed, you will get a 1, the moment the switch is pressed the logic
inside the if-statement here will become 0, invert of that will become 1. So if this condition is
true, that condition is true, when the switch is pressed you are going to enter the if-loop. In that
you are again waiting for the switch to be released because you press it, usually, human
interaction means you are going to press the switch for much longer duration and so this will
hold the state of that pin to 0, you are waiting for that to be released. That is the second
instruction.

When you release the switch, the switch, the P1.3 bit will become 1, and then at that time it will
come out of that while-loop, the inside while-loop and it will toggle the LED. P1OUT is equal to
the value to the LED invert of that, ANDed with the invert of that. So it is going to toggle the
LED value and now once you compile this program, you rebuild the project. This will be
compiled and then downloaded. Yes, now it is ready.

Now when I press this and release you will see that most of the time it toggles, correct, but
sometimes it misses. That is even if I press and release, the LED state does not toggle from 0 to 1
or 1 to 0, sometimes it remains. So I recommend that you play with it to realize that this problem

488
exist because you have allowed the switch bounce to propagate through the program and
therefore sometimes it would miss, sometimes it will not be able to toggle in a way that you
expect it.

Now you can re-run this program, you can continue experimenting this program by connecting a
capacitor between the switch and the ground and we recommend a value of about 0.1 microfarad
of ceramic capacitor between P1.3 pin and ground and repeat this, and you would find that the
performance as far as toggling the LED is concerned, might improve, would improve. So I am
not doing it here but I am recommend you try that, the same program by connecting a capacitor.
This will do hardware debouncing.

But as I mentioned, in embedded applications our aim is the cost and cost means less
components, which means we should avoid using an external component as much as possible, try
to utilize it through that functionality, try to gain that functionality by using software. So we are
going to avoid using a capacitor and instead we are going to involve in software debouncing.

(Refer Slide Time: 21:35)

So the second program that I want to show you here is a variation of this program but with a
small modification that once the switch is detected to be pressed, I will call a delay subroutine of
appropriate duration, once the switch is released, again I will call a delay subroutine and then I
will toggle the LED. So the rest of the instructions are the same, you still have the while 1 loop,

489
you are waiting for the switch to be pressed, when a switch is pressed you will get a logic 0 in
that operation, invert of that you will get a 1.

So if-condition becomes true, the moment you get inside there is a software delay of 20
milliseconds. This is a built-in function, you are saying delay for 20000 instructions that leads to
about 20 milliseconds delay and then you wait for the switch to be released. This has debounced
the part where you have pressed the switch, now you are waiting for the switch to be released,
that is the first while-loop inside that if-loop. When you release the switch, again it delays, same
20 milliseconds debounce, and once you finish, once you complete that 20 milliseconds delay,
you toggle the LED. And you are going to be in this if-loop which is inside a infinite while-loop.

Now let me go back to the first program that we tested in the previous lecture, where we showed
that our code has a main-loop and we just either turn the LED on or we toggle the LED. Now I
mentioned that that is an infinite loop, although there was no while 1 kind of a loop.

Now you see the reason why I mentioned it is, even though main program has only one
instruction, the question you have to ask is what does the microcontroller do when that
instruction in that main loop is over? You see the microcontroller have all the features, all the
necessity, necessary ecosystem which supports continued execution of program, even though
you have not provided an another instruction to execute, does the microcontroller stop or does it
continue to execute a program? The answer is it continues to execute a program where it keeps
on waiting, it keeps, goes in a infinite loop doing nothing, which means the microcontroller is
still working, except that it is not doing any useful stuff.

So a main program is still an infinite loop, in this case, it is explicit, in the case of our switch
experiments it is explicit because we have a, within the main loop we have a while 1 infinite
loop. But even if it was not there, when the program is compiled, it will still continue to work
like that.

490
(Refer Slide Time: 24:33)

Let us now go to the second, third version of our program, where we are not going to use an
onboard switch. Instead, we are going to use external switch, we have a switch where we are
going to enable the internal pull-up resistor or internal pull-down resistor connected to a different
pin.

Now if you see this program this is called HelloSwitch with the option of pull-up resistor. And
now the switch definition has changed, instead of the switch being on bit 3, it is on bit 4. The
LED is still on bit 7, which means we are going to use the onboard LED which is on the MSP430
lunchbox. Our first instruction after we enter the main loop is still to stop the watchdog timer and
now we have created an instruction where we have turned the bit on port 1, which is connected
to the LED as output.

We have turned the switch which, the pin which is connected to the switch, in this case, P1.4 as
input. But besides that, we have two more instructions, one says P1REN is equal to P1REN
ORed with the value of switch.

So we have enabled the internal pull-up feature with this instruction and the next instruction is
P1OUT is equal to P1OUT ORed with the switch mask. What are we doing? We are making that
P1OUT on port bit 1.4 equal to 1. What does this do? This enables the pull-up resistor. So I have
connected the, I will connect the appropriate switch in which it is connected to the pull-up
function and we will re-compile this program, here this wire, there are two wires, one is to

491
ground and VCC and the third wire is to an appropriate switch. In this case, the switch is such
that it is a pull-up configuration. So we are going to use the internal pull-up feature.

I am going to, here the program is compiled and it has been downloaded. Now let me press this
switch and you see the switch is toggling nicely, no external resistors has been used. Why?
Because an internal pull-up resistor was used with debouncing, it also has the same debounce
logic.

So we have, we have the same program compared to the earlier version of debouncing, we have
just added a feature that we have switched the switch, moved the switch from P1.3 to P1.4 by
connecting an external switch, the switch is configured in the pull-up configuration and we have
used an internal pull-up resistor, nothing else changes. So now when I have compiled and
downloaded the program, what I find is that the switch toggles nicely, the LED toggles nicely
each time I press this switch, which is an external switch with the internal pull-up resistor
connected, each time I press and release the switch, the LED on the board toggles nicely.

(Refer Slide Time: 28:19)

Now let us look at the fourth version of the program, which will use the same switch except now
the switch is in the pull-down, it will use a pull-down resistor. And the initial programs are all,
initial instructions are all same, except when we come to the point of enabling the pull-down
value of the resistor. Here you see P1OUT is equal to P1OUT and invert of SW, so now that
P1OUT on which pin? P1.4 is set to 0, this will enable the pull-down resistor. So I am now going

492
to change the input from this switch, which was configured for pull-up to another switch, which
is configured for pull-down.

I am going to compile this program and download it by rebuilding this project. As you see on my
laptop the program compiles and now it has downloaded, build is finished, the program is
downloaded. Now I am going to press the other switch and now you see here also the switch is
debounced internally because of the software.

If you see the, inside the while 1 loop, we have 20 milliseconds delays, we are waiting for the
switch to be pressed and released. The only difference is now we are waiting because we have a
pull-down resistor, the value is 0 when the switch is not pressed. So it is waiting for the switch to
be pressed so it becomes 1, till it is 0 it is going to wait there. And then when it is released, again
delay and then it will toggle the LED.

So I recommend that you play with all these four versions of the program. In the first version,
there is no debouncing and you should be able to see that there is false toggling. It can improve
when you connect an external capacitors of 0.1 microfarad and then the rest of the programs are
all going to debounce the switch. The second version of the program uses the onboard switch,
and the third and fourth version of the program uses external switch with internal pull-up or
pull-down resistor as the case is both these versions.

So I hope this clarifies you the enormous capabilities of MSP430 microcontroller of offering
internal pull-up and pull-down resistors, which you can invoke when you are connecting external
mechanical devices such as a switch and this would we would use in subsequent programs and
experiments of creating interrupts and things like that. So I will meet you in a new lecture very
soon. Thank you very much, buh-bye.

493
Introduction to Embedded System Design
Professor Dhananjay V. Gadre
Netaji Subhas University of Technology, New Delhi
Lecture - 24
MSP430 Clock System and Reset
Hello and welcome to a new session for this online course on Introduction to Embedded System
Design. I am your instructor Dhananjay Gadre. In this lecture, we are going to look at one of the
most important aspect which forms an important part of the ecosystem for a microcontroller to
function effectively, namely clock and reset sources. We have seen in a previous lecture that a
microcontroller require four very important elements clock, reset, power supply, and an ability to
download code into the memory of the microcontroller.

In this lecture, we are going to deal with the first two issues, namely clock and reset. Now, why
does a microcontroller require a clock? The reason is a microcontroller is an example of a
synchronous digital circuit. And because I have used the word synchronous that means it is going
to use a clock signal, and therefore I must provide a, such a signal. Also, the value that is the
frequency of this clock signal will determine lot of things.

The frequency, higher the frequency, higher the performance because your microcontroller will
be able to execute more instructions per second if the frequency is high, but it will come with a
price. And the price is that as the frequency is gets higher and higher, the power dissipation will
proportionately increase because the power dissipation of a CMOS circuit is directly proportional
to the frequency of operation.

And so we must decide what is an optimum frequency for the operation of the microcontroller at
any given point of time. Fortunately, and it was one of the salient features which I had mentioned
in the salient features of microcontrollers, MSP430 offers the ability to be able to dynamically
change the clock frequency using a software.

Using the user program, the user can decide at any given point of time do they want a higher
frequency for operation because the performance requires so or if there is no work to be done,
there is no point in clocking the microcontroller at a high frequency and instead, a lower
frequency operation could be selected so as to conserve available power. So let us look at the
clocking options of MSP430.

494
(Refer Slide Time: 02:49)

This is the block diagram of the clock module, which is there inside MSP430. On the left, you
have the sources of clock and on the right of this diagram, you see signals which are derived
from these three sources. There are three sources. This is one of them. An internal VLO clock
that is called, an external crystal-based oscillator and an internal digital, digitally controlled
oscillator. These are the sources and using a particular combination of these three sources, the
MSP430 clock module offers three signals, clock signals.

It is called A clock that is auxiliary clock, the main system clock, and a subsystem clock. Let us
see what these clock signals do, what part of the microcontroller do they serve, and how their
frequency can be changed.

495
(Refer Slide Time: 03:54)

This is a simplified block diagram of the clock module as applicable in MSP430G series. You
have a very low-frequency internal oscillator, it operates at about 60 kilohertz, we will come to
the details. You have a low-frequency crystal oscillator; the oscillator is inside the
microcontroller. The crystal has to be connected to external signals, external pins, and apart from
that, you also have a digitally controlled oscillator.

There are three multiplexers, multiplexer number 1, number 2, and number 3, and each
multiplexer has two inputs broadly. And you can write software to select one or the other source
of clock. Once you decide the clock source, it can be further divided with a clock divider using
an option of divide by 1, 2, 4, or 8, to derive three clock signals. And these three clock signals
are auxiliary clock, master clock, and subsystem master clock. Let us see what these clock
signals are used for.

496
(Refer Slide Time: 05:09)

So, as I mentioned, the there are three sources, digitally controlled oscillator, low-frequency
crystal oscillator, and very low-frequency oscillator inside the MSP430.

(Refer Slide Time: 05:23)

The digitally controlled oscillator is based on a RC, internal RC oscillator, and let me give you a
very simple circuit that may illustrate how a RC circuit can be made using logic gate such as an
inverter here. This will oscillate at a certain frequency as determined by the value of this R and
this C. This is not to suggest that the DCO uses this. This is just an example.

497
Anyway, the digital controlled oscillator allows you to change the frequency operation in this
range from 60 kilohertz to 16 megahertz for a certain supply voltage. If the supply voltage is
changed, these numbers, these upper and lower limits would change. It is a RC, controlled RC
oscillator, as I have mentioned, and because it is a very quick-start oscillator, it can start working
in less than a microsecond, it can be used to get out of low-power modes of operation, we are
going to consider low-power modes of operation of MSP430 in a subsequent lecture, but this
digital controlled oscillator allows you to switch from low-power modes into active modes of
operation.

The DCO frequency, digitally controlled oscillator frequency can be adjusted by software. By
writing appropriate values in various registers in the program, you can change the frequency. The
default frequency after reset is 1.1 megahertz. So if you do not do anything and you just reset
your microcontroller, you do not have to make any selections, the value of the DCO frequency
will be 1.1 megahertz.

(Refer Slide Time: 07:28)

And this is the source of the clock, as you see this part in the block diagram here, lower side is
highlighting the DCO clock and all these names that you see here, these refer to various bits in
various registers that we will see very soon, which allow you to change the frequency of the
DCO oscillator, digitally controlled oscillator.

498
Further, you have a multiplexer here, as we had seen in the simplified block diagram, which
allows you to select the SM clock here as well as, as you see here, this signal goes and feeds to
the master clock also. We come to that shortly but so this is the part about the source of clock,
clock source that is the DCO.

(Refer Slide Time: 08:14)

Then, apart from the DCO, we also have the low-frequency crystal oscillator. You can use a low
or a higher frequency crystal, but for the G255 series, you are restricted to a low-frequency
oscillator and that is recommended at 32 kilohertz. And in fact, the exact frequency is 32768
hertz. This is a crystal used in real-time clocks and so is very commonly available, and this is
low-frequency, which is used with for the low-frequency crystal oscillator, which is inside, the
oscillator is inside the microcontroller, this crystal has to be connected to external pins X, as we
have seen.

If you had a different microcontroller, apart from other than this, you could use a higher
frequency crystal also.

499
(Refer Slide Time: 09:13)

Here is the part highlighting the low-frequency crystal oscillator. These are the XIN and XOUT
pins onto which you, between which you connect a crystal, this is the crystal. And in the case of
our current microcontroller MSP430G2553, this crystal can be only 32768 hertz. It can be other
frequencies also. But it just so happens that you will have to get such a crystal custom made.
This is the most common commercially available crystal.

(Refer Slide Time: 09:47)

500
The third source of clock is very low-frequency oscillator. It is also internal RC based oscillator,
and the typical frequency operation is just a mere 12 kilohertz, and you can imagine that from 16
megahertz for the DCO, down to 12 kilohertz here, you can really change the frequency
operation and therefore change the way the microcontroller performs, functions and the amount
of power that it consumes.

(Refer Slide Time: 10:22)

Here is the source, clock source, and as you see it feeds a multiplexer here.

(Refer Slide Time: 10:36)

501
Now the question is, we have seen here that we need auxiliary clock, we need a main system
clock, and we need a subsystem clock.

(Refer Slide Time: 10:47)

What is the purpose of having multiple clock signals on a microcontroller MSP430? And the
reason is low-frequency operation is best for energy conservation, it is also good for
timekeeping. The high clock frequency will allow you to react to external events in a short time
and therefore that is beneficial when you want to respond quickly. And if you want a stable
clock, then having a crystal-based oscillator is the best option and MSP430 allows you all the
three options.

It offers you very-low-frequency RC based oscillator, it allows you 32.768-kilohertz


crystal-based oscillator, and it allows you another RC based oscillator which whose frequency
can be digitally altered to go from 60 kilohertz on one end to 16 megahertz on the other side, and
so you could select that if you would like to have fast response time. And that is the reason why
multiple sources have been provided and the clock signals can be derived from these clock
sources.

502
(Refer Slide Time: 12:01)

What are the signals that we need? As we mentioned, one of them is master clock. It is used by
CPU. CPU has only one clock signal and that is master clock. Master clock signal can also be fed
to other peripherals. As I mentioned, after reset the default master clock is derived from the DCO
with a frequency of 1.1 megahertz, but you can select the master clock signal to come from
low-frequency crystal oscillator, to come from VLO or the DCO and XT2, that is high-frequency
crystal 2, but this option is not available on our microcontroller, this particular microcontroller
part.

(Refer Slide Time: 12:47)

503
This is the part where you are selecting the master system clock here, and as you see, you have a
divider which allows you to further divide the frequency, you have a multiplexer which allows
you to select which source, clock source can be used. A master clock can come from here and
this itself allows you to select either the VLO or the low-frequency crystal and the other part of
this multiplexer is being fed by the DCO. So master clock can be derived out of VLO or
low-frequency crystal or DCO.

(Refer Slide Time: 13:28)

504
Then the other signal that we need is the subsystem master clock. It is distributed only to
peripherals, this is not fed to the CPU. Oftentimes it is the same as master clock and if at reset,
the value is from the DCO and the frequency is 1.1 megahertz and again, it can be selected from
low-frequency, it can be sourced from the low-frequency crystal oscillator or the VLO oscillator
or of course, the DCO clock.

505
(Refer Slide Time: 14:04)

Here is the part about subsystem master clock.

(Refer Slide Time: 14:08)

And the third is the auxiliary clock. This is again, only distributed to peripherals and the source
of auxiliary clock can only be the low-frequency crystal or the internal low-frequency oscillator.
If, now both these oscillators are slow oscillators meaning when you turn, apply power to them,
they do not start oscillating quickly. They take some time to build up and for the oscillations to

506
stabilize. And because of this, if any peripheral is being fed from the auxiliary clock, you must
make sure that the oscillators have stabilized.

If the oscillator has not stabilized, the microcontroller will not connect the clock source to the
clock signal and therefore to the peripheral, and this we will see later how we can detect whether
the oscillator is stable or not, and if it is not stable, we can wait. And why we can wait? Because
the CPU which decides which clock is to be fed to which peripheral, the CPU is being fed by
master clock and we can choose the master clock to be from the DCO so it can continue to
perform, the microcontroller can continue to run the program, but in that program, you can wait
for these oscillators to stabilize before you apply to any peripherals.

(Refer Slide Time: 15:39)

Here is the selection for the auxiliary clock. Again, it has a divider, as you see you can divide the
source, which is either this or this by 1, 2, 4, or 8.

507
(Refer Slide Time: 15:51)

Now, in the DCO, apart from the ability to vary the frequencies, it also has four calibrated
frequencies and those are 1 megahertz, 8, 12, and 16. And you can write values into appropriate
registers to select whatever frequency you want. This is a sample code that two registers, one of
them is called BCS control, the other is called DCO control, by writing appropriate values, these
are basically bitmasks, by writing this into these two registers will result in a DCO frequency of
1 megahertz calibrated frequency. Not 1.1 megahertz, but quite accurate 1 megahertz frequency.

Now, sometimes and often times when you want to measure time accurately, you may not want
to use the DCO, you may want to use the low-frequency crystal because a crystal is a very stable
and accurate source of frequency, in which case you have the option of selecting the
low-frequency crystal oscillator. Traditionally, oscillators, crystal oscillators offer you large
range from 32 kilohertz up to few tens of megahertz.

508
(Refer Slide Time: 17:18)

In our MSP430G255 series, we are restricted to 32-kilohertz crystal and it is designed to give
you the printed frequency at 25 degree centigrades. In the case of MSP430, it has to be
connected between these two pins that is XIN and XOUT.

(Refer Slide Time: 17:28)

Where do you use crystals? When you want to measure time or when you want to measure
frequencies of events then you should consider using a crystal. A crystal oscillator also requires
capacitors. Some capacitance is already on the microcontroller but you, depending upon the

509
recommendations of the datasheet of the crystal that you use, if it requires more capacitance,
then it can be connected to the X, these two pin XIN and XOUT pins. Extra capacitance on these
pins as the requirement may be for a particular crystal that you choose.

(Refer Slide Time: 18:12)

Okay. Now that we have seen the sources of clock and the clock signals that we need, here are
the registers which allow us to select various sources, decide their frequencies, and route these
clock sources to appropriate auxiliary clock or master clock or subsystem master clock.

(Refer Slide Time: 18:38)

510
The most important register is the DCO control register, and it has two sets of bits. One is called
the DCO bit and these are three bits here, and the, you have five bits here, which are the mod
bits. The DCO bit selects a frequency, broad frequencies which are dictated by another set of
bits, which is which are these bits which we will see in the other register that we will briefly see.

These RSEL bits allow you to go from 16 kilohertz to 16 mega, 60 kilohertz to 16 megahertz,
and within that, these bits will tell you what particular frequency you can operate at. If you want
to have a frequency selection even finer than you can get with DCO, DCOx, then you have to
play with the MODx bits. For introductory applications, for simple applications, you do not have
to worry about this.

(Refer Slide Time: 19:40)

Now, this is the second important register, Basic Clock Control Register. Here, I want to make a
point. Do you notice that some of these bits here, it says, when it says rw means these bits can be
written to as well as read from? And then it says, rw, here it says rw-0 and here it says rw-0
within a bracket.

These two refer to different values of zero depending upon the source of reset and we will
consider this when we consider the reset case, reset facilities in MSP430 but I just wanted to
bring that to your notice. In this register, basic clock control register, we do not have this option
because as I mentioned, it does not offer you high-frequency crystal, you can select this, only

511
this option is available, and using this you can decide whether you want to which divider you
want to use for the auxiliary clock. And these are the RSEL bits, these four bits, which decide
broad frequency ranges that run the DCO oscillator.

(Refer Slide Time: 20:59)

Then you have the Basic Clock Control Register 2. Here this decides whether what is the source
of the master clock, meaning these bits, these two bits will decide will select the multiplexer,
which is feeding the master clock source. This will, these two bits will decide what sort of
divider do you want to use for the master clock source.

This will decide whether do you want, how do you select the sub-master clock and you only have
this option here because this is not available on our MSP430G2553. And then these two bits will
allow you to choose the divider for SM clock. And then this bit allows you whether you want to
have an external resistor. This is not available on our G2553 series.

512
(Refer Slide Time: 22:08)

This is the third register, Basic Control Register, Clock Control Register 3, and here you have
several bits. But the most important bit is these, which allow you to choose what sort of
frequency crystal you want to use and whether you want to use internal capacitance, what will be
the value of these capacitance.

(Refer Slide Time: 22:32)

513
Now, to set the frequency of the DCO, you have to write into the DCO register as well as the
second register, that is Basic Clock Control Register 1 and I suggest that you go through this
slide to understand all the options.

(Refer Slide Time: 22:52)

Based on the bits that you write into these registers, you see, this is part of the datasheet that
allows you to change the frequency from 60 kilohertz to 16 megahertz. Now we want to illustrate
the great flexibility that MSP430 offers by dynamically changing the clock frequency and what
are we illustrating here? Let me show our plan.

514
(Refer Slide Time: 23:26)

515
What we are doing is we are going to take a MSP430. As you know that there are three sources
VLO, crystal low-frequency crystal oscillator, and DCO. We are going to use, select the very
low-frequency oscillator for the master clock, which means the processor will operate at 12
kilohertz but the 12-kilohertz basic frequency can be divided by 1 or 2 or 4 or 12, which means
by selecting an appropriate divider, we can reduce the frequency operation for the CPU. Because
we are, I am saying we will select the master clock from master clock signal will come from
VLO.

What we want to show is as follows, we want to have a LED like this, and in fact, we are going
to use the existing LED on the lunchbox, but we want to connect three external switches with
pull-up resistors, one more, here VCC. And where are these connected? Where are these three
switches connected? They are connected to P1.3, 1.4, and 1.5. So let me write here, P1.3 pin,
P1.4, and P1.5. And we, as we know, the LED is connected to P1.7.

What we will, what do we hope to achieve? That we will start the oscillator, we will select the
VLO to go through the multiplexer and provide the signal for the master clock, and then we will
have a program which will continuously poll these three switches and if one switch is, if this
switch is pressed, for example, it will divide the VLO frequency by 1. If the second switch is
pressed, it will divide it by 4, and if the third switch is pressed, it will divide it by 8.

And thereby you will get these three resultant frequencies. You see? If you divide by 1, the
source is 12 kilohertz, therefore the frequency will be 12 kilohertz. The CPU frequency that is

516
master clock frequency will be 12 kilohertz. If you divide it by, if you choose the divide by 4
option, you will get 3 kilohertz, and if you choose the 8, you will get 1.5 kilohertz.

And you can, how would you know that the oscillator, that the CPU is working at different
frequencies? Well, what we will do is we are going to blink this LED, we are blinking this LED
at a certain rate which is derived out of the clock frequency. Basically what we are saying is turn
the LED on for some clock cycles and turn the LED off for some clock cycles.

Now, if the frequency of operation reduces you will see that the duration of the on and off
increases, that is frequency goes down. And so by operating it at, let us see, P1.3 is, here you get
a 1.5-kilohertz clock. Here you get 3-kilohertz clock and here you get 12-kilohertz clock. Of
course, we are further used delays so that the LED will be blinking in visible range, you can
make, you can observe that the LED is turning on and off.

It is not that it is turning on and off at such a high rate that it is beyond the persistence of vision.
No. We have written the code in the manner that it is, you can see that it is turning on and off,
but the rate of blinking will be perceptibly different when you choose these clock frequencies.

So let us go through the code to understand how it works. At the beginning we see, as usual, we
have included the header file, then we have defined that we are going to put the LED on bit 7,
but bit 7 is not telling the actual port pin, bit 7 is simply a mask bit as we have seen. Then we are
putting one switch at bit 3, bit 4, and bit 5, and these are all P1.X. So here it is P1.7, 1.7, 1.3, 1.5.

Then we have a function which we call as switch input, I will come to that later. We have
another function called register settings for GPIO, I will come to that also. And we have third
function, which is called register settings for the VLO.

517
(Refer Slide Time: 29:00)

And then we have the main program, so the main program is really very simple. What is it
doing? The, when you reset the system, the first instruction that is executed is to stop the
watchdog timer. We do not want to be bothered by watchdog timer overflowing and resetting us,
which we will see in the next part of this lecture.

Then we are calling this subroutine, which is basically selecting the VLO, and based on the
switches, it is going to select a particular frequency operation, and then we are calling another
subroutine where we are deciding the direction of the pins of the microcontroller. The P1.7 pin
has to be output pin and the other three pins have to be input pin that will be done in this second
function.

And then we have a infinite loop, while 1, and we are saying read the switch. So I am going to go
execute this function in which I am reading, waiting whether switch one is pressed or two is
pressed or three is pressed. If a particular switch is pressed, it will go and change the frequency
operation of the VLO oscillator and will come back here, and then it is going to, so this part of
the code is simply toggling the LED.

So you toggle it once, go back, wait for the switch to be pressed if it is not pressed, you come
back, again toggle the LED. So you keep on doing it, which means most of the time you are
toggling. But after every toggle, you are going and checking whether the any switch has been

518
pressed. If any switch has been pressed, you wait for it to be released and then based on which
switch was pressed you are changing the VLO frequency.

And so after that when it comes here, you will see that the LED toggle rate changes. Why?
Because the CPU clock itself has changed and this is therefore a great example to illustrate how
MSP430 offers you dynamic clock stability. Let us go through the code again, switch input.

(Refer Slide Time: 31:12)

Here we are waiting whether switch one is pressed, if it is pressed, this is to debounce and then
you are selecting that the VLO divider should be by 8, therefore you will get a frequency of 1.5

519
kilohertz. If switch two is pressed, then you debounce it again and select this divider so that your
resultant clock frequency CPU frequency is 3 kilohertz, and the third option is, if the third switch
is pressed, your VLO will not be divided, it will be the same as the VLO frequency. Therefore,
the CPU clock will be 12 kilohertz.

Then this is very simple, it simply turns the pin which is driving the LED as output and the other
three pins P1.3, 4, and 5 as inputs. It does not do anything else and then this second function,
which allows you to select various, select VLO as the source. As we saw earlier, you have to
play in the Basic Clock Source Register 3 to select the VLO oscillator.

Now, as I mentioned, this is a slow oscillator, and therefore after power on it may not quickly
turn on, and if you go through the datasheet of MSP430, it will tell you to wait for a certain
amount of time before you can expect this clock to work.

And the way to check is to reset a particular flag in this register we, which we will see in the
reset part, and you turn this bit to zero and wait for some time, and if this bit remains zero that
means the oscillator is stable. If the oscillator is not working properly, the microcontroller will
set OFIFG bit again. And so you are going to wait in this loop till this bit is reset to 0. If this bit
remains reset to 0, that means the oscillator is stable.

Now, you can make this setting will allow you to route the VLO oscillator as the master clock.
So you are doing those two things. One, you are selecting VLO to come out of the first
multiplexer, and then you are using the clock signal multiplexer to select master clock from
VLO.

520
(Refer Slide Time: 34:01)

And so here is the implementation we have collected, as you see these are the three switches one,
two, and three, these are the pull-up resistors, and this LED, the user LED on P1.7 will blink. So
I suggest that you have downloaded this code, rebuild it and upload it into the lunchbox and see
how this the blinking rate of this LED changes as you press this or this or the other one. The rate
is quite perceptibly different and this is the proof that by, the program can decide what can be the
frequency operation for the CPU, also, what can be the frequency operation of other peripherals.

(Refer Slide Time: 34:49)

521
So this is as far as the clock frequency operation, the clock sources, and clock signals of MSP430
microcontroller are concerned, we have covered that. Now we are going to look at the reset part.
Now, why does a microcontroller require reset? It is because a microcontroller is a logic circuit
and logic circuit uses flip-flops and the flip-flops may have arbitrary values when power is first
applied to them. And this may lead to non-uniform operation. And therefore it is very important
that all the internal registers are initialized to a known value when the system is powered on for
the first time. And that is the function of reset.

There are broadly two types of resets, one is called power-on reset, and the other is called power
up reset. There is a fine difference between the two. Power-on reset happens, as the name
suggests, when the power is applied for the first time. But power up clear can happen from other
sources also.

(Refer Slide Time: 35:50)

Now, power-on reset is generated whenever you turn power for the first time. It can also be
generated because there is a brownout. Brownout means that the supply voltage to the
microcontroller is not stable. If it dips below a certain value, it will reset the, it will generate a
power-on reset for the microcontroller as well as if you press the reset NMI pin that will also
generate a power-on reset signal.

522
Now, what reset the system? Is it possible to find out what was the source of reset? Was it
brownout, was it a power-on reset that is turning the power off and on, or was it the user pressing
the switch on the RST/NMI pin? Is it possible to find out? Yes, MSP430 microcontroller has
registers, which capture the source of that reset. And in fact, in this segment, we are going to
write up code which will show which sources of reset was the reason the system was reset.

(Refer Slide Time: 37:04)

Power up clear on the other hand, is generated because of software conditions. So the primary
difference between power-on reset and power up clear is that power-on reset is because of

523
external conditions. Why? You are powering the device up, so it generates a power-on reset or
the supply voltage is not stable, so it generates a reset or a user presses a switch on the RST/NMI
pin, these are all external events.

But power up clear is generated because internally something has happened and one of the
reasons could be the watchdog timer. Of course, whenever a power-on reset signal happens, that
also generates a power up signal, but additional to that, a watchdog timer or a security flash
memory access violation or a CPU trying to fetch something from the peripheral address range,
each of these four events could lead to a power up clear signal being generated.

(Refer Slide Time: 38:06)

What happens in them? Whether it is power-on or power up, the system is going to restart
fetching the first instruction as pointed to by the reset vector. The after power-on reset, the
RST/NMI pin is in the reset mode that is it works as RST pin, not NMI pin. The I/O pins are all
switched to input mode and other peripheral modules and registers are initialized to a known
value, which you should refer to the datasheet and the user guide for exact information.

Now, this is what I had mentioned earlier, each of the registers, when it is reset or when it is
cleared, meaning when it is POR or PUC, will be indicated under that register. If it is written like
this, that means, one, rw means it can be read and written and 0 means that the, after PUC the
value will be 0. But if it is this, that means only on power-on reset the value will be 0, only on

524
power-on reset, which means if the power up clear condition has been generated because of some
internal event, the state of that bit, maybe 1 if prior to that event, this bit was 1, that is the
difference.

So this is because of POR and this is because of PUC, this nomenclature that is rw-0 indicates a
PUC condition, and rw-(0) means this is only achieved on a power-on reset condition, not power
up clear condition.

(Refer Slide Time: 40:18)

After system reset, which means whether it is because of power-on reset or power up clear, the
status register is set to 0 that means if you have been operating on, in low-power mode, you will
come out of it. The watchdog timer becomes active in the watchdog mode, and the program
counter is loaded with the reset vector location which is this and as we have mentioned, two
locations are required for the address of the memory where our program is located. And these
two addresses are FFFE and FFFF.

525
(Refer Slide Time: 41:02)

After the system reset, you must, if you wish, you must initialize the watchdog timer and usually
you turn it off and you must configure the peripheral modules that is the responsibility of the
program.

(Refer Slide Time: 41:20)

This indicates brownout reset if the voltage falls below a certain level here and here, the system
is reset. Only when the voltage exceeds this can the system start working.

526
(Refer Slide Time: 41:36)

Please go through this slide to understand how brownout reset works.

(Refer Slide Time: 41:43)

Watchdog timer is a very important peripheral, it is actually part of a general-purpose timer


which can function either as a timer or it can function as a watchdog timer and we can choose
which mode of operation do we want that timer to operate at. The primary function would be to
as a watchdog timer because there are other timers which are available which you want, which

527
you could use for measuring time. This particular timer is often dedicated for use as a watchdog
timer.

Now, what does a watchdog timer do? That if you allow the watchdog timer to function,
depending upon the source of clock to the watchdog timer, it will count, it will count up and if
you do not reset it, eventually it will overflow and the overflow signal will reset, will generate a
power up clear signal, which means you are going to reinitialize the system. You are going to
start executing the program, using the vector at the reset vector.

Now, if you enable the watchdog timer, how do you ensure that the watchdog timer does not
create a power up condition is to frequently reset the watchdog timer, because when you reset the
watchdog timer, it will start from 0 again, it will count up and before it expires, meaning before
it overflows it is your responsibility to reset it. In case you forget to do that it will create a power
up condition. And we will see later in a code here. We will see how watchdog timer can create a
power up clear condition.

(Refer Slide Time: 43:20)

The watchdog timer can count up to these many bits that is, it is a 15 bit, although the timer itself
is 16 bits, for watchdog purposes it has a 15-bit limit. You can also choose lesser values, which
means the watchdog timer can be made to count lesser number of clock signals, and then it can
generate a power up clear signal.

528
(Refer Slide Time: 43:45)

In the interval mode, it can work as a conventional timer and we will see this when we are
talking about the timer operations.

(Refer Slide Time: 43:57)

Now to control the watchdog timer there are three registers to worry about. One is the watchdog
timer control register. The other is a interrupt enable register. This is a special function register
and the other is the interrupt flag register.

529
(Refer Slide Time: 44:16)

In the watchdog timer control register, it is a 16-bit number, a 16-bit register, and it is password
protected. It is a read-write register, which means if you want to write, you must also supply the
password and we will see what is the password. This is the password. And if you read it, you will
in one part of the register, you will get this value.

(Refer Slide Time: 44:46)

This is these are the bits, as you see this is a 16-bit register, this is for password, read or write
and these are the effective 8 bits. Let us go through them, the important ones. This is used to hold

530
the timer, meaning with this bit, you can stop the timer. With this bit, you can decide whether
you want the RST/NMI pin to act as RST pin or NMI pin, as you see here if you write a 1, it will
function as NMI pin and if you see go back here, you see this indicates that at power up, it will
retain the previous value. But on power-on reset, it will be 0. This bit allows you to select the
watchdog timer as watchdog or a timer.

And this is, this bit allows you to reset the watchdog timer from so that you can restart from 0.
And this bit allows you to select a source of clock for the watchdog timer. You can select either
the SM clock or the auxiliary clock and this allows you to decide what is the number of counts
that it will count before it overflows and generates the power up clear signal and you can go from
64, a count of 64 to 32768. This will give you the maximum amount of time before the watchdog
timer kicks in. So this interrupt enable register, we will see which bits are useful for our
operation.

(Refer Slide Time: 46:42)

If you set this to 1 that means you want to use this for as a timer function. If the, this bit is
inactive in the watchdog mode, the other is if the oscillator fault, if there is a fault in the
oscillator, this will be set to one.

This is when the NMI interrupt happens and the last one is when whenever you try to access
regions of flash memory which are not accessible to you, this interrupt will be enabled, meaning

531
if you enable this, an interrupt will be generated when you try to access flash memory, which
you should not, and so on. So as the important point to note here is that this bit is not, is only
applicable for the watchdog timer in a timer mode, not in the watchdog mode.

(Refer Slide Time: 47:39)

And then we have the SFR interrupt flag register. Now, this is very important because this is
telling me lots of flags related to various sources of resets, and we are going to use this in our
code. If this bit is 1 that means the source of reset was a watchdog timer. So as we see, set on
watchdog timer overflow, meaning if you have enabled the watchdog timer and this the
watchdog timer overflows for whatever setting of the clock and whatever bits to count, if this bit
becomes 1, that means the source, it would reset the, it will generate the power up there and this
bit will be 1.

On the other hand, if the let me look at this reset parts. If the power-on reset was generated, this
bit will be 1. If the external reset, meaning the pin was pressed, this bit will be set and if the NMI
pin was used, then this will be set to 1. And what is this? This is the oscillator fault, meaning
whenever the VLO or the low-frequency crystal oscillator is unable to start, this bit will be set to
1 and the user has to keep writing 0. And if the oscillator is not starting to function, the
microcontroller will set it set to 1.

532
So you write a 0 and wait for some time and then check. Is it still 0? If it is still 0 that means
your oscillator is working, and so this is very the part I was referring to earlier. Let us see what
we do now.

(Refer Slide Time: 49:33)

To stop the watchdog timer, you simply write these two values into the watchdog timer control
register, these are basically this part of the instruction, this part of the register is supplying the
password and this is telling that please reset the, please stop the watchdog timer and we will you
will see how it is used in our program example.

(Refer Slide Time: 50:00)

533
So now what we have done is we have set up a experiment which this is the code for it, and we
want you to download this code. Now instead of testing the code on the lunchbox, we want you
to just download the code into the lunchbox and then remove the IC and insert it on a breadboard
and connect few switches, well, no switches, a few LEDs to indicate what was the source of
reset.

We also want you to connect one switch but that switch will be connected to the RST pin and
with this setup, we will be able to identify was the source of reset the watchdog timer overflow
or was it power being applied for the first time or was it because the reset pin was pressed. This
program allows you to do that.

Now for that, we have used five LEDs, whenever, whatever be the source of reset, the program
will start executing. As we have mentioned, the master clock which supplies to the CPU is
derived from the DCO at 1.1 megahertz. And so immediately upon whatever be the reason for
reset, the microcontroller will start working and this LED will be turned on. This LED is
connected to P1.0.

Then when the program actually runs in a loop, this LED which is P1.1 will toggle, will blink.
Besides this, the program will try to identify what was the source of reset, if the source of reset
was power-on reset that is you had turned the power off and you turned it on again, LED on bit
P1.2 will turn on. If on the other hand, the watchdog timer overflow happened, it will turn the

534
LED on P1.3, and the third option is if you press the reset switch, the LED on P1.4 will turn on.
And so I recommend that you go through the code. Let us go through this.

535
(Refer Slide Time: 52:20)

536
Here we have first stopped the watchdog, this is the main code, we are going to go back to the
part of the code which is, which has some functions. This is first we have turned the watchdog
timer off, then we have selected the auxiliary clock to operate at this, using the crystal divide by
8, so that we are operating at 4 kilohertz.

What is it going to do? It is going to feed to the watchdog timer. Why do we want such a
low-frequency operation for the watchdog timer? So that you can get some time after, let us say,
power-on reset or the user reset.

If the watchdog timer is fed with this low-frequency clock, it will give you time before the
watchdog overflows and you can see that initially the source of reset was say power-on reset or
the user reset, and then when the watchdog timer kicks in, you will see that the system resets
again. But now the LED corresponding to the watchdog timer will turn on. And that is why we
wanted to give time. And so we have chosen a very low-frequency crystal oscillator.

Here is a code which allows you to set the bits appropriately, we want those port 1 bits to be
outputs and now you are waiting for that oscillator to stabilize, and then you check the reset
source. Now, also in this we will go and see the code in this, the moment you, the first program
that runs is you, of course, turn the watchdog timer off, then you enable the auxiliary clock and
then you run off to execute this register settings for GPIO part of the code. Let us see what it
does.

537
Here it simply makes these bits as output, PDIR, and then it simply turn LED1 on and it turns all
the other LEDs off. So LED1 is on, the moment you see LED1 on meaning your system is
working. Now, what will happen is you go back to the main part of the code. Now you are
waiting for the oscillator to stabilize and this may take some time. After that, you go and check
the source of reset. Let us see that code here. So in the reset, how do you check the source of
reset, you have to look at this register here.

This register, by identifying various bits, you will know whether the source was watchdog reset
or whether it was power-on reset or whether it was user reset button. This code basically looks
for that turns appropriate LED on and goes back to the main program and in the main program,
once you have checked the source of reset, it simply goes in a infinite loop of toggling LED2.

(Refer Slide Time: 55:24)

So here is the how the circuit has been connected. Although I am using a lunchbox and it appears
to have a microcontroller here, I am not using this microcontroller. I am using the lunchbox only
to drive, derive the power supply from here. This is the MSP430 which you could have taken
away out from your MSP430 lunchbox inserted here, as you see here, here is the crystal. So you
need to connect a 32 kilowatts crystal for that oscillator that I mentioned and the rest of the
connections.

538
And then here is the, this is LED1, this is LED2 which is going to blink, this will turn on the
moment power is applied. And these are the three LEDs which indicate the source of reset
whether it is power-on reset, whether it is the user reset, this is the user reset pin switch and the
third source could be the watchdog timer.

So I recommend that once you have programmed your microcontroller in the lunchbox with this
code, take it out gently, insert it into the breadboard, using the crystal oscillator and other stuff,
connect these LEDs and see how the microcontroller is able to find out the source of reset.

So this is what we have for you in this lecture on sources of clock as well as various ways of
various ways in which MSP30 microcontroller can be reset. I will see you very soon with a new
lecture. Thank you.

539
Introduction to Embedded System Design
Professor Dhananjay V. Gadre
Netaji Subhas University of Technology, New Delhi
Lecture - 25
Interrupts in MSP430
Hello and welcome to a new session for this online course on Introduction to Embedded System
Design. As usual, I am your instructor Dhananjay Gadre. In this lecture, we are going to talk
about Interrupts. Interrupts are very important paradigm, is an important paradigm, is a
mechanism which gives a feeling of multitasking or being able to do multiple things at the same
time. Of course, this is not true, because at the end of the day your microcontroller, whether it is
MSP430 or any other small microcontroller has only one CPU and a single CPU can only
perform one operation at a time.

But because it is able to perform those operations at a very fast rate compared to the human
interaction levels or speeds of human interaction, it is possible to give a perception that the
microcontroller or your microcontroller in the embedded system is actually doing multiple things
at the same time. And so we are going to introduce you to this concept of interrupts.

Now, why do we need interrupts? It is an important idea because a microcontroller or an


embedded system would like to perform several functions at the same time. For example, let us
say that in a system you have many, many switches or you have few switches, few selector
knobs, and an external user such as a human being may press either the switch or a knob or some
other switch and you would want the microcontroller to respond to this external event.

Now if a microcontroller is trying to read one switch, then it will have to wait for that switch to
be pressed, if it is waiting for that switch to be pressed, what if the user presses another switch?
How does one, how does one deal with such a situation? So (micro) the way to resolve this is to
bring in this concept of interrupts.

540
(Refer Slide Time: 02:29)

So, interrupts allows you to perform multiple tasks instead of polling. Now what is polling? For
example, I give this idea that there are several switches, maybe there are several knobs, and one
way to deal with an external user pressing any of the switches or turning any of the knobs would
be to go to a switch, wait for it to be pressed for some time, then go to another switch wait for it
to be pressed, if it is not pressed go to the third switch so on and so forth, and it can keep on
polling. Polling means waiting for a action, waiting for an event to happen and if there is no
event it can go and look at another event, possibility of another event.

Now, this polling is fine but when the number of such external inputs increases or let me
continue with this example, let us say there are several switches and the user presses one switch,
but the moment a user presses a switch, the microcontroller will detect that that switch has been
pressed. What if during that time another switch is pressed?

But because the microcontroller is waiting for this switch to be pressed and it has now detected
that this switch has been pressed, it will wait for it to be released, during that time if somebody
else or the human being presses another switch and releases it, it is possible that the
microcontroller will miss it, and therefore the way to handle such external events would be to
give time slots and perform an action. If there is no action go to another task or another input,
wait for it to be performed, if not you can keep on going from one to the second to the third to
the fourth and so on.

541
So, polling external events using a method which is often called round-robin is a good idea and I
can give you an analogy. Let us say I am giving a class, I am delivering a lecture in a classroom,
a physical classroom where there are few students and these students want to ask me questions
based on what I have taught. Now one way to deal with that is, set a rule that I will after I teach a
particular module, let us say I teach a concept and at the end of the concept I will, starting from
let us say left of the classroom, I will ask every student, have you understood it? Do you have
any doubt? Have you understood it? Do you have any doubt? Have you understood it? Do you
have any doubt? I can go from left to right and cover the entire class.

Now, if I do this method, if I use this method of trying to find if somebody has a question and
would they like resolution of that question, this method of providing a resolution is called polling
and this works well if the number of people in this exercise are limited and they are small. Now
imagine the number of participants, number of students in the class increases. If that is the case,
let us say I start polling this class from the left and there is a student on the right, extreme right
and he has a doubt, he has a question, but till I come to that student, he will have to wait.

Whereas after I ask him what if the just the previous student had another question and he would
have to wait till I come back after completing all the students again to that second last student,
and so polling is problematic when the number of inputs, number of participants increases and
this is where the idea of interrupt comes in. How does it work?

Imagine I change the rule of participation in the class, that instead of me after having taught a
concept that I will individually ask each and every student if they have a doubt. Let us say I
change the rule that whenever I teach a concept after that anybody who has a doubt can raise
their hand. So, this act of raising hand is equivalent to generating an interrupt, of course when I
am teaching and if somebody raises a hand, I will have the option of ignoring it because I might
be facing the blackboard and after I have taught that concept I will turn around and I will see
how many hands are raised.

If there are no hands raised, what does it mean? That they, students have received my, that
particular topic well and I can continue to the next topic. But if some students have a doubt they
would raise hand and again, I would scan from left to the right and the one raised hand that I find
in this scanning process from left to right, the first one I find, first hand that I find raised I will

542
ask them what is the question and I will answer that and then I will go to the next raised hand
and so on so forth.

Now imagine in this situation the first person raises a hand on the left, I ask what that question is,
I answer that question, in the meantime another person towards the right had also raised the
hand, but because I can only answer one question at a time. I choose to prioritize the person on
the left and by the time I finish that question and I started scanning towards the right, I found that
the second person has put his hand or her hand down.

For me, my job is done. If I find no other hand raised till the end of the room, I would imagine
that the second person probably waited long enough did not get an opportunity or it is also
possible that the first question that was raised was also the same question that the second person
had to ask and therefore he or she found it unnecessary to continue to raise the hand.

So, this idea of raising a hand is very, very similar to this concept of interrupt. So, an interrupt is
a mechanism by which a microcontroller system or a digital system can look at external events
whenever they happen, they can respond to those events. Now before we come to that aspect, I
want to show you how much time does MSP430 take to execute any given instruction.

(Refer Slide Time: 08:59)

So, I have listed here the various types of instructions and in this especially, look at this third
column where it says, second column where it says how many cycles are required to execute a
given instruction. And there are several such sheets.

543
(Refer Slide Time: 09:11)

Here now you see, here, they are taking three cycles and the cycles here refer to the clock cycles.

544
(Refer Slide Time: 09:21)

Similarly, so you have one, you have a range from 1 clock cycle for executing an instruction,
going up to 6 clock cycles. So, this is the longest instruction. Now, let us also consider how
much time, what is the frequency, what is the time period of this clock cycle?

545
(Refer Slide Time: 09:43)

So, if we, we know that MSP430 works at a maximum clock frequency of 16 megahertz. So, 16
megahertz is your clock frequency, this leads to a clock period of 62.5 nanoseconds, which
means the fastest instruction will execute in 62.5 nanoseconds and the longest will be 6 and so it
will be about 400, 380 nanosecond or so. Now, of course, we need not argue here exactly which
instruction is taking how much time, let us take an average.

Let us say that all the instructions in my program are on an average taking 4 clock cycles, which
means roughly we are talking of 62 into 4, roughly 260, let us you know round it off to 250
nanoseconds. 250 nanosecond is the average time any given instruction takes in a given program,
which means if one instruction takes 250 nanoseconds that means in 1 microsecond I am going
to execute 4 instructions. In 1 second, I will execute 4 million instructions.

And this, in fact, refers to the capability or the speed of the processor, it is often expressed like
this that for a sample program, for a reference program where we are assume, where we have
assumed that each instruction will take 4 clock cycles, this MSP430 microcontroller can perform
4 MIPS, at the rate of 4 MIPS that is it can execute a program at the rate of 4 million instructions
per second. Now that is a large number.

Human interaction, on the other hand, the act of pressing a switch and releasing it is a much
slower process, which means if a human is going to press few switches, at this rate the
microcontroller will be able to scan and poll many, many, many switches in 1 second. Even so,

546
you would be deprived of executing the actual program while the microcontroller is waiting for a
switch to be pressed, and therefore this idea of interrupt is brought into picture.

Now interrupt involves, the microcontroller is executing a program and let us say an external
event wants attention, an external event here, for example, could be a user presses a switch. And
so instead of the microcontroller continuing to execute the program that it was executing, it
suspends it for some time, goes off to execute a subroutine which deals with this external event,
in this case, a user has press a switch and then it returns back after it has found out which switch
was pressed, it can come back to the main program and continue the execution of that program.

So, an interrupt refers to the transfer of control of the microcontroller from the existing program
to execute a special subroutine, perform it and then come back quickly to resume the ongoing
program that it was executing.

(Refer Slide Time: 13:14)

Now, this event could be because of an external event, meaning somebody has pressed a switch
or because of an internally generated request or event, for example, maybe the microcontroller
has a ADC, Analog to Digital Converter. Analog to Digital Converter takes a long time to
complete a conversion and after the conversion is over the ADC peripheral could generate an
interrupt telling the microcontroller that whatever conversion was to be performed, it is over,
kindly look at the result and do whatever you have to do. So, interrupts could be generated from
external sources as well as internal peripherals.

547
(Refer Slide Time: 13:53)

Now, where are interrupts used? Well, typically when you have an urgent task, you are
performing a main program and some urgent task comes, you would like to deal with it by
suspending your existing program dealing with this urgent tasks and coming back to continue to
execute the ongoing program.

Infrequent tasks, which happen once in a while, you would like to deal with them using an
interrupt and as I mentioned, human inputs are very slow, they may be infrequent compared to
the rate at which a microcontroller can execute a program, human interaction is much, much
infrequent and so you would, you could handle the external events generated by inputs by
humans through interrupts.

Also, in the case of MSP430, and this is very important and specific to MSP430 because it has a
lot of power-saving modes. Once a microcontroller enters a power-saving mode, it is going to
suspend operation of a program and if you want to resume program execution, it is very
important that you exit these low power modes. As we have discussed, there are several
low-power modes, it has four or five low-power modes and the way to exit the low-power mode
and continue, start, begin executing the program requires an interrupt.

And so in MSP430, when you are, when you have entered a low-power mode, the only way to
get out of it is by way of an interrupt, whatever may be the source of that interrupt. We will

548
discuss this when we discuss low-power modes and how interrupts are used to exit these
low-power modes.

Now, how do you handle interrupts? As I mentioned, your main program that you were running
would be suspended and you would execute a subroutine, and therefore it may appear that an
interrupt is performing a response to an interrupt is like executing a subroutine, indeed it is.

(Refer Slide Time: 16:00)

But it is different from a conventional function or subroutine, it is definitely a little different for
various reasons. In a normal function or subroutine, you call that function. But in an interrupt,
you do not call that interrupt subroutine, the interrupt subroutine gets called. Why? Because it is
often the result of a asynchronous operation like a user pressing a switch.

In a normal subroutine, you, of course, suspend your current execution and you go off to execute
that subroutine. But after the subroutine is finished, you want to come back to where you were
earlier, and therefore the way to do that would be to save the program counter value onto the
stack.

Now in the case of interrupt subroutine, you do not know when you get called and therefore you
need to not only store the address of the instruction which you are executing or would have
executed on to the stack, but also the state of the microcontroller and the state of the
microcontroller here refers to various flags like zero, carry and so on. So even those need to be
saved on the stack.

549
Also, you need to know that for a given interrupt, where is the subroutine. Because there may be
several sources of interrupts and you cannot go to a single address to find out who created, who
generated that interrupt, and therefore let me execute this particular program in response to that
input. The way it is handled is that for all the various inputs and all the various sources of
interrupts, you associate a unique address, where you locate your, where you put your subroutine
in which would be executed when such a interrupt happens.

So, that is this aspect the address of the interrupt subroutine is determined by the hardware. The
address of a normal subroutine is determined by the software. Depending upon how big your
code is, the assembler or compiler will put that subroutine at someplace, but and that place can
change. But the subroutine for interrupt is decided by the microcontroller, meaning it is decided
by the hardware and when we see the details, you will realize what I mean.

(Refer Slide Time: 18:26)

So, interrupts require that a subroutine be executed to in response to this event, and that
subroutine is often called, very popularly called Interrupt Subroutine or Interrupt Handler.
Interrupts can be generated by most peripherals in MSP430, they can be generated by
general-purpose input-output pins here. As we know that on the MSP430 that we are using on
our lunchbox, there are two ports P1 and P2. Any input pin on P1 and P2 can generate an
interrupt. Each interrupt has a flag and when that flag is raised, the condition for interrupt is
satisfied and the microcontroller will do something in response to that condition.

550
Also broadly on the MSP430, there are three types of interrupts. One is the system reset that is,
we have discussed the reset part. Each time you press, generate a reset for whatever, whatever
may be the source of that reset, it is treated like an interrupt.

Also, the reset pin is shared with the non-maskable interrupt, you may recall that that pin is
actually called RST/NMI, which means the same pin can be used as a reset input as well as a
non-maskable interrupt. NMI stands for non-maskable interrupt. And apart from these two
sources, you also have many, many peripherals which provide or generate what are called as
maskable interrupts. We are going to discuss, what is the meaning of non-maskable versus
maskable very shortly.

Now, what is the meaning of maskable interrupt and non-maskable interrupt, and let me take you
to usual normal life to illustrate that idea? Like, let us go back to that classroom example.
Somebody has raised a hand, but because I was doing something important on the blackboard, I
can choose to ignore the raised hand, that would mean that I have masked that source of
interrupt.

On the other hand, let us say that this classroom has a fire alarm, and anytime the fire alarm
rings, would I wait for whatever I am doing on the blackboard to finish it? No, I would run for
my life. So the source of this particular interrupt, as illustrated by a fire alarm, is an example of a
non-maskable interrupt. I do not have the freedom or the liberty to ignore such an event, such an
interrupt and such interrupts are called non-maskable interrupt.

So, broadly the classification of interrupts is maskable interrupts, such interrupts, such events,
which can be ignored or suspended for some time, meaning suspended as in you need not
respond to them by executing that interrupt subroutine, you can let them wait, and some
interrupts which are non-maskable. MSP430 offers both of them.

In the case of MSP430, will see in the next slide that even the non-maskable interrupt can be
disabled. In general, in general microcontrollers, non-maskable interrupt cannot be disabled,
cannot be suspended at all. But here there is a little flexibility that there is a mechanism to even
ignore that or disable them.

551
(Refer Slide Time: 22:00)

So, this diagram here is an important illustration of how interrupts are generated, detected, and
then responded to. So as I mentioned, the source of the interrupt could be input-output pins here.
The source of an interrupt could be the timer counting time. It could be the, a non-maskable
interrupts. Now the first important consideration that a interrupt will be serviced would be that it
must generate a request, it must generate an event. And when a event is generated, it is captured
in a register called interrupt flag, interrupt flag register.

So, if the flag is 1, that means there is an external event. However, it is up to you do you want to
respond to that event or do you want to ignore it and the second part of this block diagram shows
you that. Now you see this GPIO could generate an interrupt, but you could ignore it if this
switch is open. So, you have a register called interrupt enable register if you have disabled those
interrupts, this request for an interrupt will not proceed forward to the CPU.

On the other hand, you see this non-maskable interrupt can only be stopped by this switch
thereafter there is nothing to stop it. Once if this switch is turned on, it can go all the way
through. On the other hand, the rest of these interrupts, these are all maskable interrupts you need
a individual interrupt enable bit, but there is also a global sort of a switch, if this switch is turned
off, then no matter whether an external event happens, no matter whether it has been individually
enabled, the CPU will not respond to such interrupts.

552
But for non-maskable interrupt, there is nothing, there is no roadblock apart from this switch
here, there is no roadblock, if this which has been enabled, the moment an external non-maskable
interrupt happens, the CPU will have to respond to it. And so we will see how these switches,
how do you control them and how do you manipulate them so that external events could lead to
an interrupt in response to which the microcontroller will execute a interrupt subroutine.

So, there are three aspects interrupt flag register, interrupt individual interrupt enable bits and a
global interrupt enable. For most, for all the, for all the maskable interrupts, you have to deal
with all these three parts. For the non-maskable interrupt, you do not have to deal with this
global interrupt enable, you only have to deal with the fact that the non-maskable interrupt
should generate an event and then it should be enabled, then it would reach from here to the
CPU. So now non-maskable interrupts can be generated from several sources.

(Refer Slide Time: 25:14)

It can be generated because one of the oscillators, and you know that there are three oscillator
sources in your MSP430 microcontroller if any of the oscillator is not working the way it should
it can generate non-maskable interrupt.

Also, you have program memories; RAM, if you are trying to read or write from locations which
are not available on your microcontroller, it would lead to memory access violation that also will
generate a non-maskable interrupt. And the third is the non-maskable interrupt pin, which as we
have mentioned earlier is actually shared with the RST pin, RST/NMI. If you provide a signal on

553
this, then it could be construed as a non-maskable interrupt. This can also be used to generate a
non-maskable interrupt. So these are the three non-maskable interrupt sources.

(Refer Slide Time: 25:59)

Here is details of, here are the details of the RST/NMI pin. At power-on, when you power up,
when you turn the power on, the RST/NMI pin is configured as reset pin, and the function of the
RST/NMI pin is selected in the watchdog control register.

Then if the RST/NMI pin is selected as a reset function, the moment you press this switch that is
you hold the logic on this pin to 0, it will reset the processor and it will keep it in reset state as
long as you hold this pin 0, and when you release it, it will let the microcontroller execute the
program for which it will go to the reset vector. As we have discussed, the reset vector is at this
address and it will, from this address, it will find the address of the first instruction in the flash
program memory and it will execute it. It will also set up this RSTIFG flag so that you know,
what is the source of that reset.

If on the other hand, this pin has been configured through software as a NMI, then a single edge
selected by this register generates a NMI, non-maskable interrupt, and it will go to the vector for
non-maskable interrupt and execute a program in response to it.

554
Introduction to Embedded System Design
Dhananjay V. Gadre (NSUT, New Delhi)
&
Badri Subudhi (IIT, Jammu)
Indian Institute of Technology, Delhi
Module 8
Lecture 26
Interrupts in MSP430 - Continued

(Refer Slide Time: 00:38)

Let us resume our discussion on the interrupts that we have been having, in this session today.
Now, let me also mention a little bit more about these interrupts. As we have seen, interrupts can
be classified like - maskable interrupts or non-maskable. We have seen that on our MSP430, we
have both varieties.

There is one more way to classify interrupts and that deals with vectored and non-vectored. What
is the meaning? When I use the term vectored interrupts, that means whenever a interrupt
happens, I know exactly where to go looking for the subroutine to deal with that interrupt. I can
also have non-vectored interrupts which means well, an interrupt has happened but I exactly do
not know where to go and therefore the system must provide me some information to help me
locate the subroutine to handle this non-vectored interrupt.

Well, MSP430, most of the interrupts are vectored interrupts, all the interrupts are vectored
interrupts. The source of the interrupt also supplies the address. In fact, this address is available

555
in the memory map of MSP430. The top, that is the highest memory locations are reserved for
storing vectors for each of the interrupt sources. Also, now imagine that at a given time, when
the microcontroller is ready to, you know, branch off for executing a interrupt subroutine, what if
two interrupts happened at the same time? Of course, microcontroller cannot go to satisfy the
needs of both the interrupt sources at the same time, so it must prioritise.

(Refer Slide Time: 02:44)

And this is called, what is the interrupt priority - which means the one with, if two events
happen, the one with higher priority will be serviced first. After the completion of that interrupt,
you can go and execute a subroutine for the second interrupt.

The reset vector, and we see how this is prioritized in MSP430. The higher vector address means
a higher priority. And so reset vector has higher priority, why? Because it is located at this
address and just to repeat, the address is a two addresses that is your instruction is at FFFE and
FFFF, alright? So you are going, so the vector at this address will have the highest priority. The
one after that will be FFFC and FFFD would be the lower priority interrupt compared to this and
so on.

556
(Refer Slide Time: 03:45)

Here is the clipping from the MSP430 data sheet which lists all the interrupts - what are their
names, the source and what is the flag referring to the interrupt flag that we mentioned and what
is the address of the vector for that interrupt and what is the priority. Of course, as I mentioned
'31, highest' priority is for reset and as you go down, the priority decreases which means it two
interrupts happened, the one with the highest priority will be serviced first.

And as you see, we, the sources of interrupt are - Power up condition, external reset - that is a
user pressing the reset button or non-maskable interrupt or a timer here - comparators, watchdog
timers. Another timer - the serial communication protocols, the ADC and last but not the least,
the two ports that we have on MSP430 G 2553.

In fact, you would remember that MSP430 G2553 is actually available in several physical
footprints. The one which we have on our lunch box is in a dip format; it has two ports. But if the
MSP430 is chosen to be of the SMD version, it has three ports. Port 1, Port 2 and Port 3. But,
Port 3 does not have any interrupt capability. The only interrupt capability you have for this
microcontroller number is for port 1 and port 2. And as you see, port 1 has the lowest priority in
this and also here you see these are all maskable interrupts and only the NMI interrupt is
non-maskable. So let us proceed further.

557
Now, as I mentioned, an interrupt flag is an important element in the whole process of an
interrupt being generated, being recognized and being serviced. And the interrupt flag, once it is
generated, it will automatically vector to a address location and usually it will have a single
source. But there are peripherals where a single vector is going to help you generate sources
from several pins.

(Refer Slide Time: 06:19)

For example port 1 or port 2 - each of these ports as you know has 8 pins and each of the 8 pins
can generate an interrupt. But if the pin refers to port 1, all the 8 pins will have a single vector.
So it will take you to the same location and it will have to execute the same subroutine at that
location. In that subroutine you will have to identify which was, of all the 8 pins, which caused
the interrupt, right? So we will deal with this.

So when you are when you are ready incorporate interrupts in your system, in your
programming, in your embedded system, there are a few things that you have to keep in mind.
You must keep the interrupt subroutine very short. And one of the ways to ensure that is to not
use any delay subroutine in your interrupt function, in your interrupt subroutine - why?

When you take too long in that interrupt subroutine, what are you doing is - you are constraining
the rest of the execution of the main program or you are starving other sources of interrupts. You
want to give all the sources of interrupts a fair chance, a fair participation, therefore you must

558
keep the interrupt service routine very short. Now, what if you want to actually execute a bigger
program? The way to deal with that is to interact, deal with the requirement in the main program,
not in the interrupt subroutine.

When you are executing a interrupt subroutine, by default all the other maskable interrupts are
disabled- that is the meaning. Therefore, you must keep the execution of the current interrupt
subroutine to a shortest possible program length so that you can quickly finish it. When you go
back, it will enable the interrupts, so that other interrupt sources could get a chance.

Now, for interrupt to be accepted, there are several conditions that have to be satisfied. The first
is that because interrupts are often generated from external sources, which means they are
asynchronous to the execution of the current, the program on the microcontroller, it does not
mean the moment an interrupt is generated, the microcontroller would suspend whatever it is
doing and will rush off to execute the subroutine for that interrupt.

(Refer Slide Time: 08:53)

The very, at the very least, it will complete the current program, current instruction, if it has
started fetching that inspection it will complete it. And as you know, the length of these
instructions take one clock cycle or it could take 6 clock cycles. So if in the first clock cycle, an
interrupt event it happens, it will have to wait in the 6 clock cycles associated with the current
instruction are completed.

559
Also, once the interrupt is recognized, if there was no interrupt, the microcontroller would have
gone to the next location to fetch the next instruction and execute it. But now because interrupt
has happened, it must store the value of the program counter somewhere and this somewhere is,
location is a memory location in the RAM and we call this memory location, special region in
that RAM, we call it 'stack'.

And so the microcontroller saves the value of the program counter on the stack. Then apart from
the program counter, the state of the microcontroller is reflected in the status register. Even this
is saved on the stack. So that when you resume your interrupted program, you can resume with
the state which you had before the interrupt happened.

Now, if multiple interrupts have happened, it would prioritise and it would give the highest
priority to the highest priority, higher priority interrupt and execute an instruction - subroutines
related to that interrupt. The interrupt flag resets automatically on single source flags, meaning if
there a source of interrupt which is not shared with other resources, the moment the interrupt is
recognized, it will reset this flag, so that next time another event happens on that resource, it can
be captured.

It also clears the status register within the interrupt subroutine. So when you enter the interrupt
subroutine, the status register reflected, reflecting from the main program is saved on the stack
and within the interrupt subroutine, you get a clean status register all the bits are reset to 0 and
this will allow you to actually exit low power modes. The GI, that is the Global Interrupt bit
which is like the global switch is also cleared and further interrupts are disabled - which means
when you are in a interrupt subroutine, if any other interrupt happens, it is going to have to wait.

Once these conditions are all met, then before you go into the subroutine the interrupt vector is
loaded on the program counter and from there, the microcontroller start fetching and executing
the instructions of that subroutine.

560
(Refer Slide Time: 11:53)

To help come back to the main program, so this is your, this is a reflection of what will be the
state of the RAM. So let us say, before the interrupt happened, the micro, the stack pointer was
pointing to this address and whenever the interrupt happens, it has to store two contents, two
words one is the program counter and the other is status register. So now TOS stands for top of
the stack. So what was top of the stack here is now at this location four memory locations are
used to store the, these to register; the program counter and the status register.

561
(Refer Slide Time: 12:42)

Now, once you are inside the interrupt subroutine and you have executed the program, you
would do the same things that you did while getting into the interrupt subroutine in the reverse
order. The status register of the previous setting will be popped from the stack which means
when you had, when you had interrupted, when you had been interrupted in the main program,
the status register was saved on the stack it will be recovered.

And the program counter is also recovered from the stack, that value, put in the program register
so that you can resume executing the program which got interrupted, which got suspended - that
we call as the main program, so this is shown here. Now, for handling interrupts, for the purpose
of illustration here, we are going to use the input output pins. And so we are going to look at all
the registers which help manipulate, which help control or which help, you know, handle all the
interrupts associated with the GPIO; general purpose input output pins. And we have three
register which help us manage the interrupts associated with the input output pins.

562
(Refer Slide Time: 14:06)

All these registers are 8 bit width. We have an interrupt enable register call PXIE; X here are
referred to which port we are talking of. For example, if you are talking of port 1, that register
will be P1IE. We have a interrupt edge selection register, why? Because you could generate an
interrupt on the rising edge of a signal on a port pin, you could also generate an interrupt on the
falling edge.

So you have to tell the microcontroller, do you want to be interrupted when the signal goes like
this or do you want to be interrupted when the signal goes like this. So that is indicated to the
microcontroller by writing appropriate values into this register called interrupt edge selection
register. And the third, the most important register is the interrupt flag register and for reference,
I have a replicated that previous block diagram of interrupts, so that we can assign or we can
locate these registers in this block diagram.

So program interrupt enable register is this part, here, here. So if you want that a particular
interrupt should be enabled, you must enable it in this register. So it affects this red part. The
edge selection and the flag register together are here and so you must get a 1 in this blue bit, if
that is 1, and it this switch which is represented by that red circle, if that switch is closed, then
only it would generate an interrupt, how provided this master switch, let me color it in a third
color master switch here, is also turned on.

563
And that is by a flag called global interrupt enable flag and it can be enabled in various ways, it
can also be disabled and we will see two methods of controlling this flag in a program
subsequently. So to reiterate we have three registers that we must manipulate so as to handle
interrupts on the input output pins of MSP430 microcontroller. Let us proceed forward.

(Refer Slide Time: 16:42)

Now, P1IE. that is, port 1, if I want to talk about port 1, interrupt enable. This is a 8 bit register
corresponding to the 8 pins that you have for port 1. If you want to enable interrupt on any of the
pins, you must write 0, you must write 1 in that bit. So let me say, draw the 8 bits here. So this
would be your P1IE, this is bit 0, this is bit 7. If I write a 1 here, that means I want interrupt
associated with P1.0 port 1 bit 0, to be enabled.

Of course, a signal has to be applied to port 1 bit 0 for interrupt to actually happen, but this you
are enabling it. And if you want to disable it, you write a 0. So if I write 0 in the rest, that means
I do not want to be interrupted by any signal on any of the pins of port 1 except bit 0. This is the
interpretation of port 1 interrupt enable register.

564
(Refer Slide Time: 18:00)

Second in the line is the interrupt edge selection register. Like I mentioned, you can generate an
interrupt on the rising edge and you can generate an interrupt on the falling edge. You have to
tell the micro controller which edge would you like to generate an interrupt and again here, there
are 8 bits. And here I am going to write the name of the register this one is P1 IES, interrupt edge
selection.

If I write a 1 here, that means it will generate an interrupt when there is a transition from high to
low; so 1 means high to low. So a falling edge will generate an interrupt if you have written a 1
in that corresponding event. If you write 0, that means you want an interrupt in the rising edge.
So depending upon your requirement, depending upon the state of the logic on that particular
pin, you can write a 1 or a 0. Corresponding bit in the previous register interrupt enable register
has to be 1, otherwise writing a 1 or 0 here makes no sense whatsoever.

565
(Refer Slide Time: 19:20)

And the third is interrupt flag register. This flag register when, if it becomes 1, that it will
become 1 upon which condition? That you have enabled the register and an external signal
which is qualified by the edge selection register has been received, then and then only, a
particular bit in this register will be set to 1. And if that bit is set to 1, subject to other conditions
being met, it will lead to an interrupt.

So let me again show it here. So it which is P1IFG, if this bit is 1, that means an interrupt on port
1 bit 0 has been recognized and if the global interrupt enable bit is enabled, this will fly; it will
interrupt the CPU and the CPU will go to the interrupt vector associated with port 1 and from
there it will execute the subroutine and you can do whatever you want within that subroutine.
That is the meaning of this. Of course these bits can also be set or reset in, by software, by
writing a 1 or 0 and this will generate a software controlled interrupt that is the meaning.
Normally, you do not want to do that, but that is also possible.

So let us see what is the flow of the program when we are dealing with interrupts, this is very
important. Now in C, how do you tell the program, when you are writing a program in C
language, how do you to tell the compiler that this subroutine that you are writing is to, for the
purpose of handling a particular interrupt.

566
(Refer Slide Time: 21:12)

And you do that by using a # declaration called #pragma. This is a keyword vector. You are
telling that you are going to deal with timer 0, a 0 vector and what program to be executed in
response to this vector? This is the name of the program. So you, this is by the way, double this,
interrupt void these are all necessary, you cannot change these. This, is your choice, this name is
your choice; you can put your own name.

So you have to have a #pragma, name given. Then this is a keyword here and the name itself the
name of the subroutine is your choice, you can put whatever you want, of course it should not be
a reserved keyword or anything else this is required. Once you to write this in your C program,
you must therefore, there after write this subroutine associated with this label. Now void here
means you are not passing any parameter to the subroutine nor is it causing any result back to
you. Then how does a interrupt program help you? Through way off shared memory locations,
alright? Variables. So we will see how that is handled.

Now I have put together this list from the MSP430 header file so that you know what are the
names for each of the vectors; like for timer 0, what is the vector and so on.

567
(Refer Slide Time: 22:55)

So here is the, as you can see, this is the vector for trap, that is the non-maskable interrupt. No,
this is not the non-maskable interrupt, it should come here somewhere. So this is a trap vector.
Then you have port 1 vector, that is the vector you would go to you when there is an interrupt on
port 1. Here it is for port 2 and so on. So in your C program, you must use these exact names in
capitals for, to enable you to link your interrupt subroutine for that particular peripheral. We will
illustrate it with an example.

568
(Refer Slide Time: 23:41)

Now what do you do, what happens in an interrupt subroutine? Well the moment the main
program is interrupted, you must save the context, and what do I mean by the context? Context is
reflected by two things the status register plus the program counter. So both these registers have
to be saved so that you can resume using the values here whatever program was interrupted.

So this must be saved and this is done automatically by the microcontroller, how? It saves these
two registers on the stack. Now once you enter a interrupt subroutine, the global interrupt enable
bit it is turned off, which means no interrupts can happen during the execution of this program.
But you as a programmer and a designer are free to enable the interrupts which is what we are
saying here. It is possible to enable interrupts within the interrupt subroutine and I would request
you, I would advise you to exercise great caution in trying to re-enable interrupts within the
interrupt subroutine.

Of course, what after that would come is the actual program that you would execute in the
subroutine. Now, if the source of an interrupt at multiple sources, it is your responsibility that it
is a responsibility of the program to reset the flag, so that subsequent setting of the flag will
generate another interrupt and once that is done you can restore the system context and return
meaning when you return, automatically the system will recover the stacks register, the status
register and the program counter from the stack and put it into the respective registers, that is, the
status register and the program counter which means you will go back to the main program

569
which had been interrupted and you will resume your execution from that point onwards. So this
is the way things happen in an interrupt subroutine.

(Refer Slide Time: 25:40)

Now, as I mentioned how does an interrupt handle variables? How does it communicate with the
main program? It is not that an interrupt happens, you go into interrupt subroutine, you do
something there and you come back, no. Often times, you would want to convey to the main
program that an interrupt happened and this is the input provided. And that is done by using
variables, but these variables are not normal variables, they have to be declared as volatile, and
volatile is a keyword, so you have to append this name 'volatile' in front of any variable.

What it does is often times the C compiler will keep a copy of variables in registers because
reading anything from a register happens quickly but if the main variable is in the memory, you
may not get its exact value. But by using this keyword, you are telling the compiler please do not
use a copy of that value, go into the memory which is being reserved for that variable, fetch the
value from there and then pass it.

And as a rule of thumb, all the variables associated with ports and interrupts should be declared
as volatile. And we will see that example either in this or subsequent lectures.

570
(Refer Slide Time: 27:03)

So here is a checklist of things that you must perform in the main program so that interrupts can
happen, if they happen, and if they happen they can be serviced. You must have enabled
interrupts both in the module and the global interrupt enable bit. You must have interrupt
subroutine for each of the enabled interrupts, you must acknowledge that interrupt meaning you
must disable the flag within the interrupt subroutine.

And if you are using any variables, you have to ensure that they are declared as volatile. Now
what we are going to do is, we are going to illustrate how you can experiment with interrupts on
your MSP430 lunch box. So in the first exercise, we are going to connect the lunch box to our
laptop and we will discuss this code, we will download this code on the lunchbox and using the
peripheral on the lunch box itself, we will see how interrupts can be generated and how they can
be serviced, that is how a interrupt subroutine can be executed in response to an interrupt be
generated on the lunch box.

So take out your lunch box and connect it to your laptop and let us go to through the code, so that
you understand how the code works and how you can modify it. So in the first exercise we are
going to use the switch on the lunchbox as well as the LED on the lunch box to illustrate this
interrupt being generated by the switch.

571
(Refer Slide Time: 28:45)

So as you know, on the lunchbox, there is a switch connected to bit 3, that is P 1.3 you know that
that is the a switch connected to this. You also know that this switch is connected in the pull up
mode, meaning there is a resistor and a switch like this the switch is grounded on the other side.
This side of the pull up resistor is connected to VCC and this junction here is connected to P 1.3
that is the meaning of pull up register.

And you also know that we have a LED connected on P 1.7. So we are going to use the available
resources on the lunch box itself to illustrate this idea of an interrupt and how an event on the
interrupt or interrupt been generated by this switch can be handled with a interrupt subroutine.

So we have to include, as you know, this header file in our C program. We have already defined
that we have a switch which is on bit 3. Now, you see bit 3 is a mask, which means, what it
actually is, is that is why I have 8 bits like this this is bit 0, 1 to 7, so this is 0, 1, 2, 3, so it means
1 0 0 0 0 0 0 0 that is the meaning of bit 3.

And we will use this to mask this particular bit or to do bit operations on this bit as and when
required. Similarly red is a defined as a masked bit 7, that means, so bit 3 actually becomes 0 8
this value is 0 8 in X and bit 7 being 1 means it is 8 0 X, that is the meaning of bit 7. That is bit 7
is 1, rest bits are 0 - that is the meaning of these masks.

572
Now in our main program, as we always do, we are we have disabled the watchdog timer. And
we have to now tell the microcontroller that we want to use red, we want to use LED on pin 1.7,
therefore that pin must be declared as output. And we want to use is a switch on pin P 1.3 and
that must be declared as input. And so this instruction, you are deciding the direction of the P 1.7
bit as output.

The P 1.3 pin is being declared as input. You are also enabling and internal pull-up resistor by
using this REN register. And then you are writing a 1 into P1 out corresponding bit so that you
are enabling the internal pull up resistor also. But beware, that there is also an external pull up
resistor so, this instruction is superfluous but it does not hurt.

And then, you are saying that you want to you have to decide where do you, how do you want to
generate the interrupt- do you want to generate the interrupt on falling edge for rising edge. Since
I am in the interrupt enable register, I am, edge selection register, I am writing 0 that means I
have, I have chosen to generate an interrupt on the rising edge. And then, on the interrupt enable
register I make that corresponding bit that is bit 3 equal to 1, that means I have enabled the
interrupt to happen on this pin. And then this instruction is used to turn the global interrupt
enable bit to 1, now I am ready.

(Refer Slide Time: 32:56)

573
If I go back to that block diagram, basically what I have done is, here using that instruction I
have turned this on and the earlier instruction I have enabled the particular bit. Now we are ready
to do something in the main program.

(Refer Slide Time: 33:15)

But in the main program in this particular case, there is nothing to do and so we will simply, as
you see here, we are going to wait here in a infinite loop while one. So it's, your main program is
doing nothing, waiting for something to happen and in this case that something is an external
interrupt which will be generated because you press the switch on pin 1.3 port 1.3.

When that happens, before that, see you have declared that you are done #pragma and then
vector you have said relates to this vector, port 1 vector and you have named for subroutine
port_1. And this is the interrupt subroutine. So and this is the entire interrupt subroutine for
interrupt been generated on port 1.

What happens the moment you press the switch and when you press a switch, because there is a,
the switch is already pulled up, when you press a switch, you get a high to low transition. And as
you see here, you have selected an interrupt for the rising edge. So what is going to happen is
when you press the switch it is going to go low, this is not going to generate an interrupt. But
after a while when you release the switch, this act of releasing the switch will generate an
interrupt.

574
(Refer Slide Time: 34:36)

Now, please note here that we are calling this program a bad ISR, meaning this is not a very
good style of writing a interrupt subroutine, why? As I mentioned the interrupt subroutine must
be kept short, and as you see here, there is we have written a delay program. As you see here, we
have written a small delay program. This is not a good way of writing an interrupt but I will
explain why this is needed.

(Refer Slide Time: 35:07)

575
Now when the switch is pressed, it is going to go low but as we know, when a switch is pressed
often times it may bounce. So the act of pressing a switch may generate this. So you see multiple
rising edge can happen and then it is going to be held low for as long as you keep the switch
pressed and when you released again multiple events are likely to happen, multiple rising edge
can happen.

And the duration of these bounces is such that the microcontroller will treat each of these bounce
as an individual interrupt, even though you press which only once, it may interpret it that you
have pressed the switch several times. And therefore to remove that ambiguity, at this point you
have waited for these bounces to die of.

But what about the bouncing that may happen when you press the switch? Unfortunately, in our
program we have not dealt with it and so it is possible, anyway let us see what the program does,
when it this checks if really the interrupt happened because you pressed the switch.

(Refer Slide Time: 36:19)

So P1 IFG, is it 1? Isolate that bit using this & operation. This is superfluous because since you
have disabled the rest of the interrupts, this interrupt would have happened only because you
pressed the switch but it is a good idea. When that happens, and when will this happen? When
you press the switch and release it or if while pressing there is a switch bounce and that also
generates a rising edge signal you immediately toggle the LED on port 1 bit 7, then you delay

576
waiting for the bounces to die down and then you reset that flag so that, next time when the user
presses a switch it can generate t0, it can generate an interrupt and it can execute this program.
And why do we call this example of interrupt subroutine as not a good example? It is because we
have used a delay subroutine; we do not recommend using delay subroutine in the interrupt
program.

Now, how do we deal with this? Well, make sure that you don't have to de-bounce your switch.
Now, if this which is read using polling, this is a good method. But reading a switch or
de-bouncing the switch using delay in an interrupt is a complete no-no. So what we do is, we
look at another example.

(Refer Slide Time: 37:51)

In this example, we are going to use an external switch and this is the wiring that you should do
connect an external switch and de-bounce using hardware. As we have discussed in the past, one
way to de-bounce in hardware is by putting a capacitor across the switch. This capacitor acts as a
low pass filter and kills any switch bounce.

577
(Refer Slide Time: 38:17)

So the way this would look like is, here you have a pull-up resistor, here you are you have a
switch and across this which we have put a capacitor, and then this signal goes to a pin which I
will briefly mention what it is. In this case it is P 1.4. So you need to wire a switch in this
configuration and connect it to Port 1 bit 4, here 1 bit 4.

578
(Refer Slide Time: 38:41)

You are dedicated, you are dedicating for a new switch which you connect on the breadboard.
We will continue to use the onboard LED on 1.7. Now you see, we have all the same, we want a
rising edge interrupt, which means if I press the switch it is going to go low, that is not going to
generate an interrupt. When I release the switch, eventually it will generate an interrupt. And in
this particular case, I have ensured by using external hardware mechanism to de-bounce, that I
am going to get a clean switch transition from high to low, remaining low for as long as you hold
the switch down and when you release it you get something like this.

579
(Refer Slide Time: 39:35)

And so when you download this program, what you let me go back to the first program. When
you compile, rebuild this program and download, what you will see is when you press the switch
if there is no bounce you will not see that toggle off the LED. But when you release it, you
should notice that the LED toggles.

In case when you press the switch the LED toggles, and when you release also it toggles, maybe
it's toggle multiple times, you may think that the program is not working the way it should and
the explanation of that would be that in your kit it so happens that the switch press and release is
generating switch bounce which we are not able to deal with, at least at the time when you press
the switch. For the release, we have taken care of by including a delay. And so while releasing
there will not be multiple toggling but while pressing it is possible that it toggles when it should
not.

On the other hand, when you wire this external switch there is not going to be any bouncing,
why? Because we have killed that bouncing with the help of a capacitor.

580
(Refer Slide Time: 40:35)

Here the example is very similar, but there is no delay subroutine here. And rest of the code is
very similar you are enabling the interrupts, you are choosing that the interrupt should happen on
the falling edge, on the rising edge, which means when you press the switch and you release it. at
the time the LED will toggle.

So please compile this program, download it in the kit, connect an external switch appropriately
and what you should observe is when you press the switch nothing happens when you release the
switch the LED will toggle, meaning if it was on earlier, after the switch is pressed and released,
it will turn off. When you, after it is of you press the switch and release it will turn on that is the
meaning of this.

So the interrupt subroutine is a very simple piece of code which just toggles the LED, no delay
instructions included in the interrupt subroutine and this instruction will reset that inter flag so
that next time the switch is pressed it will be entertained.

581
(Refer Slide Time: 41:43)

If you want to convert this program - that you want to toggle the LED when the switch is pressed
instead of toggling when you release the switch you just simply modify this part here that you
want the interrupt to be generated on the falling edge, which means when you press the switch
like this and release, at this point it will toggle the LED.

Rest of the instructions as you see are the same. Here you are enabling the global interrupts and
you are waiting in this infinite while loop and the only way to get out of this will be when the
interrupt is generated, you will execute this subroutine, you will perform the task of toggling the
LED and you will go back to waiting in that while (1) loop indefinitely.

Now we have a small exercise and this would, this exercise will actually help you understand
that when the interrupt source is common, how do you handle that?

582
(Refer Slide Time: 42:43)

So we have an exercise where we would want you to connect two external switches and two
external LEDs on the breadboard in the following way. Connect switch 1 to port 1 bit 0, switch 2
to port 1 bit 1. Corresponding to switch 1, we wanted to connect a LED on port 1 bit 4 and
another LED for switch 2 for this.

And what do you want you to do? That when switch 1 is pressed and released, it should toggle
the LED 1. When switch 2 is pressed, it should toggle LED 2. You can decide whether you want
the toggling to happen when the switch is pressed or when it is released. But if switch 1 is
pressed, it should not toggle LED 2, it should only toggle LED 1. If switch 2 is pressed, it should
not toggle any other LED, but LED 2.

And the way to handle that would be that in the interrupt subroutine, you will have to find out
what caused the interrupt. Both these interrupts are going to be routed through the port 1
interrupt. But the source is different. One, in one case, it is switch 1, in the other case it is switch
2. So in your interrupt subroutine, you have to identify which caused the interrupt and based on
that, take necessary action. If switch 1 was pressed, you should toggle LED 1. If switch 2 was
pressed, you should toggle LED 2. And then correspondingly, clear that flag so that, that switch
can again generate an interrupt.

583
So we would like you to write a program and test it, and satisfy yourself that this is how interrupt
subroutines are written and handled. Of course, we will have more examples where we illustrate
how interrupts work using other peripherals of MSP430 lunch box. So I will see you very soon in
a new video. Thank you.

584
Introduction to Embedded System Design
Professor Dhananjay V. Gadre
Netaji Subhas University of Technology, New Delhi
Lecture 27
Interfacing Seven Segment Displays with MSP430; Low Power Modes in MSP430
Hello, and welcome to a new session, for the online course on introduction to Embedded
System Design. In this session, we are going to look at two aspects, one is to increase our
capability of the microcontroller to interact with the outside world through interactions,
including displaying numbers. Till now, we have seen how we can use the micro controller to
turn LEDs on and off, but an LED can only give you binary information, something is on,
something is off. But if you would like the microcontroller to show you numbers or other
information, we would have to use a display device, such as a 7 segment display.

Of course, we can also use a liquid crystal display and other graphics displays which we will
come to, in a later lecture. But in this lecture, we are going to see how we can connect a
single 7 segment display. For the reason that it is easy to connect a single 7 segment display
or a couple of 7 segment displays to a microcontroller. But as the number of 7 segment
displays increases, it would not be possible to connect to large number of 7 segment displays
or large number of LEDs to a microcontroller without increasing the complexity from the
software side.

Right now, we are going to look at how we can connect a single 7 segment digit display.
Now, as you know, in our electronic component inventory, which we had shared with you
earlier, and I hope you are able to get your hands on a four-digit 7 segment display. We are
you going to use the same four-digit 7 segment display in our experiment but we are only
going to enable only one of the digits. In a subsequent lecture, we will show how we can
control a four digit or for that matter, a larger digit, larger number of digits display. But let us
begin with our interactions here today, on how to display information on a single 7 segment
LED display.

585
(Refer Slide Time: 02:34)

We call this experiment, we call this exercise, HelloSSD because we are talking to a 7
segment display. As we have seen in the past, 7 segment displays are of two types; one can be
called as common cathode or, so common cathode will be, here we have the display LEDs,
this will be common cathode. And then you would have the 8 segment pins, a, b upto dp and
this is a, b, c, d, e, f, g and here you have dp. Similarly, you can also have a common anode.
So now, the common part is the common anode and you have the same display with a
decimal point and you have a to dp.

You can choose either of these displays, in our case we have a common cathode 7 segment
display. Now, let us see how we can interface it to our MSP430 microcontroller, using our
MSP430 lunchbox. The connection to a 7 segment display is not very different from
connecting a microcontroller to a LED, it is just that a 7 segment display consists of 8 LEDs.
So, it is just a matter of connecting 8 pins to a single 7 segment display and turning
appropriate segments on and off, so that you can display the number that you wish.

In our exercise, we what we are doing is we are connecting one switch to one of the port pins
and we are connecting 8 pins of the microcontroller to the 8 pins of the 7 segment display.
And each time we press and release a button, each time we press and release that switch it
will count the value, from count going from 0, 1, 2, upto the maximum value.

586
(Refer Slide Time: 05:06)

We are showing the count in a hexadecimal fashion, which means we can display numbers
from 0 to F, 0 to 9, and then A, B upto F. So, this is what we are going to do in this exercise.
So, let me draw a sort of block diagram here is my MSP430 microcontroller, here is my
switch connected to a pin which happens to be P2.3 in a pull-up mode and the port one pins
P1 pins all 8 of them are being used to connect to the 7 segment display with appropriate
current limiting resistors and because this is a common cathode display, we are going to
ground the common cathode pin of the 7 segment display. Of course, in this exercise, we do
not have a single digits, we have four digits.

(Refer Slide Time: 06:08)

587
This is the Fritzing diagram for the arrangement. Here we see our lunch box, here we see our
breadboard and onto our breadboard we have four digit display, but as you see only one digit
is being used. This 7 segment display as you see here, it has digit 1, digit 2, digit 3
somewhere, and digit 4, here digit 3 and digit 4. These are the common pins of each of these
displays and then you have a, b, c, d, e, f, g and dp. We are going to connect all the 8
segments a through dp, and then we are going to only use one of the digit common pins as we
see in here.

It does not matter which one you use; you can use first digit or the second digit. All you have
to do is, you have to ground that digit common part, common signal. Of course, we have also
connected to capacitors here, this is to you know reduce noise in this case. And then we have
this switch here, with the pull-up resistor. And we also have connected a capacitor here, so as
to debounce that although we are doing debounce in the software also. So, let us see what the
code looks like.

588
(Refer Slide Time: 07:50)

Now, here as we always seen that we include MSP30.h header file. Then, we have defined
our switch to be on BIT3 and we actually connected to port 2, BIT3. And here we have our
segments of the 7 segment display, A through DP, they are connected to port 1.0 to port 1.7
pins. We have used limiting resistors, and if you choose 1 kilo ohm or value of resistor
around that, that should be, that should work fine.

So, what we are doing is, we are defining that the segment A of our display, which is like
this, a, b, c, d, e, f, g and dp that we have connected segment A to BIT0 that means P1.0,
segment B to P1.1, and so on. Now, on this display, what would you like to display, we
would like to display numbers.

(Refer Slide Time: 09:03)

589
Now, displaying numbers on a 7 segment display, one has to be very careful. For example, if
you want to display 1, then or let us start with 0, so display 0 will look like this. That means
all the digits except g and dp are off. This is a, b, c, d, e, and f when you want to display 1
then B and C are on, when you want to display 2 then you have a, b, d, e, g are on, and so on.
So, you had to create a map that for a given digit to display which of the segments need to be
turned on.

(Refer Slide Time: 09:47)

And that we have listed in this sort of a hash define, where we are saying when we want to
display 0, this D0 means when we want to display 0. Which of the segments should be on, so
we are saying segment A, B, C, D, E, and F nothing else. When we want to display 1 it is
segment B and C, as I mentioned and so on. And for this is mentioned for all the 16 digits,
from 0 to 9 and then a, b, c, d, e, and f.

Of course, some of the alphanumeric characters will appear in capitals and some will appear
in small letters and one can see what they will look like by simulating these numbers on a
graph paper. So, this part of the code tells you that, when you want to display a number
which of the digits should be, which of the segment should be turned on.

590
(Refer Slide Time: 10:42)

591
Now, let us come to the more definitions. Here we have a hash define we are saying, some
sort of mask we have created which is nothing but all the digits, as you see except the
decimal point we are not using the decimal point in this experiment, so apart from that we
have ored all the bits. So, when I say segment A, when I say seg A, and we have seen what is
seg A, let us see here, seg A is BIT0 and what is BIT0, BIT0 is, BIT0 is of all the 8 bits the
0th bit is 1, that is the meaning of bits 0.

So, this is all 0, this is 0 to 7, 0, 0 all are 0 except 1. What is BIT1, instead of the 0th bit the
1th bit is on. This is 0 to 7, in this case it means this is 1 and these are all zeros. So, what we
have done with that mask is, we are oring all the masks values for segment A, B, C, D, and so
on. And then we are, we have inverted that value, we have toggled that value and we will see
why. Then we have created an array, and this by the way is an array which has 16 digits,
which have numbers from 0 to, to display numbers from 0 to F.

And then we have defined a variable, we have defined it to be volatile, we have covered
interrupts and we know that volatile is usually when you are interacting between the main
program and interrupt subroutine. In this case, there was no need, there is no need to declare
this variable as volatile. Also, it is not needed that this variable, because it is outside the main
loop it appears to be declared as a global variable, there is no need for this variable to be a
global variable, but it does not hurt.

Now, let us go inside, now we have the main code and as we have always seen we have
disabled the watchdog timer by oring the password with the bit required to stop the watchdog

592
timer. And then we write this bit combination into the watchdog timer control register, that is
the meaning of this statement, once we are disabled this.

Now, once you reset the system, it is going to, what clock it is going to use for the CPU, it is
going to use the M clock and M clock will be derived out of DCO and the DCO will be
working at 1.1 megahertz, that we have not changed that is the reset state of MSP430 and we
are happy to use our lunchbox at that rate.

Then, the first task we do is to define the direction of the port 1 bits. We have defined all the
bits as outputs from segment A to the decimal point, we are using all the bits, so all the pins
of port 1 we have defined as outputs. And then for port 2, we have defined this bit as input by
making it 0, when we make it 0 it becomes input, when we make it 1 it becomes output. Once
these two port directions are defined, we have entered a infinite loop while 1 and from here
we are going to remain into this loop for all the time.

In this what we are doing, we are waiting for a switch to be pressed. So, if the switch is not
pressed you are going to wait, the moment the switch is pressed you are going to go inside.
Which means, when the switch is not pressed you are going to get a logic 1, the moment the
switch is pressed it is going to go here. It is likely to bounce, although we have put a
capacitor outside so the capacitor is going to filter this out. But even if it does, we debounce it
because of this delay Loop. Then we wait for the switch to be released, which means for all
the time that it remains 0 you are going to wait here.

And then when it is released, again it is likely to bounce and then after the delay, it is going to
go high and when the switch is released, we are going to increment our variable i is going to
count up. The initial value of that variable was set to 0, and the moment you increment the
count you want to check the bounds because we want to count only from 0 to F, that is 0 to
15. If you keep on pressing at some point the value of i will become 16 but 16 is, you cannot
display here. So, you are going to reset the value of the variable to 0.

So, we are checking that after incrementing if the value of the variable is more than 15 you
set the value to 0, if not you proceed. And what you do, you are going to output something on
port 1 so as to display the number but before that whatever was being previously displayed
you bring that value and, and it with the DMASK.

And DMASK as you know, is nothing but the or of all these bits inverted which means it is
going to disable those LEDs which are on and it is going to or it with a number which is

593
nothing but into an array, which the array name is digits you are going to fetch a value
depending upon the value of I, depending upon the value of i that you see here, you are going
to fetch that bit from one of these, which will be one of these numbers.

And these numbers we have already seen are defined here, here. So, you are going to fetch
one of these values depending upon what is the value of i and that value you are going to
output on port 1. So, what will it do, it will display that number and that number will remain
as long you do not press a switch because it is going to go back here and wait for you to press
a switch.

So, this I recommend that you rebuild this code and download it into your MSP430 lunch box
and play with it, so that you understand what is happening, how the 7 segment display is
working. You can play with the value of the resistors as I mentioned here, if we are using a
1k kiloohm resistor, you can increase it. You should notice that the display intensity should
go down, if you reduce it you should see that the intensity of the display will increase and so
on.

So, I recommend that you experiment with the setup as much as you would like, so as to gain
useful insight into how to use a 7 segment display for showing information from a embedded
application to the outside world. Now, of course if we have only 1 digit to display, it is not of
much use. And in real life you may want a display a larger number. Now if you use a larger
number what options do we have.

(Refer Slide Time: 18:03)

594
Here, we can use two digits. So, on a MSP430 I can easily do that, I have two ports. So, on
port 1 I can connect one display and port 2 I can connect under the display, provided I am not
using an external crystal because external crystal takes up some of the port pins. But if I want
to do display numbers beyond this, I have a problem because I do not have enough pins. And
the way to handle this is what we have covered in the previous lecture, of using a
multiplexing technique.

In multiplexing technique, we will use multiple displays and, in our case, we have access to a
four digit display, so we will connect port 1 to 4 digits and the segments, the digits will be
controlled here, here, here, here through NPN transistor drivers. From, so this is NPN driver
and of course here we have resistors, see these are all the 8 pins, we have 8 resistors and 4
pins from port 2 we can use to control multiple 7 segment displays.

But the advantage that you get by controlling such a display using less number of pins you
have to pay in some way. And in this case, the payment is through a software overhead,
which means at any given time only one digit is going to be on. And how do you change it?
this is the topic we are going to cover in a subsequent lecture, how we can change from first
to second to third to fourth back to first and keep on doing it in the background while your
main loop can do other jobs of counting events, and counting numbers and having them
displayed on these four digit display.

We will show you one experiment using, after we have covered some information about
timers, we will show how we can use the timer infrastructure of MSP430 to multiplex
multiple 7 segment displays, thereby reducing the usage of physical pins of MSP430

595
microcontroller. This is going to be a topic of a subsequent lecture, till in this one you please
play with that setup of controlling a single digit display and you can gain some insight.

Having connected a 7 segment display to the MSP430 microcontroller, we are now ready to
evaluate and understand another important aspect of MSP430, one which is hallmark and
salient feature of MSP430 which is its ability to go from active mode where all the
peripherals, the CPU and everything in the microcontroller is working to your, to the
maximum capabilities.

You can switch from that to a low-power mode and there are several low power modes,
which allow you to conserve power. So, if you find that your application does not need to be
active, you can switch on to the low power modes and we will see how many lower power
modes MSP430 offers, and how to invoke them, and how to get back from the low power
modes into active mode so that you can process information as and when it is deemed
necessary.

(Refer Slide Time: 21:27)

So, we are going to consider the low power modes, the operating modes of MSP430 are 6 in
all. The first is the active mode where everything is working, the CPU is working, the
peripherals are working all the clock sources are working, all the clock signals are working
you can choose to route whichever clock signal into appropriate peripherals. But once you
are, once you have decided, once you have deemed that in a particular situation, you do not
want to be in active mode, you can choose various low power modes.

596
And there are five low power modes and we will see how much power reduction happens in
each of these modes and you can choose one appropriately. We will see how to enter those
modes and how to exit those modes.

(Refer Slide Time: 22:13)

Now, in the active mode if your processor is working, if your system is working CPU is
working at 1 megahertz, then this is, these are the operating diagram from the datasheet of
MSP430. And you see that, for 1 megahertz you are going to consume this is the active
current and this is the supply voltage, you can go from roughly 1.8 volts to 3.6 volts that
when the DCO is working at 1.1 approximately 1 megahertz the amount of current is, this is 1
milliampere. So, this is roughly 2-300 micro amperes, so this is what it is. At 2.2 volts supply
voltage you can go from to 230 microamperes to at 3 volts it is about 330 microamperes.

And here if the temperature changes then there is a impact on the frequency, DCO frequency
and then you see the current consumption also changes. So, this is as far as the current
consumption of MSP430 in full active mode at various frequencies, you can estimate from
here. For example, if your system is running at 16 megahertz at 3.5 volts, you can imagine
that its going to consume about 4.5 milliamperes, at 16 megabytes and that is a significantly
small amount of current.

So, you should refer to these graphs whenever you have to make estimates as to how much
current budget, how much, how much power supply specifications you must provide for so
that your system works flawlessly.

(Refer Slide Time: 23:55)

597
If you are not interested in remaining in active mode, then the first low power mode is called
LPM0, LPM stands for, Low Power Mode 0. What happens in that, the CPU is disabled
which means you are not executing any program but some of the peripherals, depending upon
which clock they choose to use some of those peripherals can continue to work. Why,
because ACLK and SMCLK are active. MCLK which is the Master Clock, which feeds the
CPU is off which means CPU is not working. And the supply current at 1 megahertz drops
from that 230 micro amperes down to 56 micro amperes. I must reiterate here, that because A
clock and SM clock are active the peripherals, if you have chosen A clock or SM clock as the
clock for those peripherals, those peripherals will continue to work.

(Refer Slide Time: 24:49)

598
Beyond LPM1, LPM0 you can choose to go for LPM1. Here also, the CPU is disabled. Your
A clock and SM clock are still active, your MKCL is disabled. Now, what is the difference
between LPM0 and LPM1, if the first two features are common in both of them, you see here
also you have. The part is that, if the DCO, the Digitally Controlled Oscillator is disabled, if
the DCO is not being used to power the SM clock. As you know, SM clock derive the clock
from DCO as well as the, VLO and low-frequency crystal oscillator.

If you have chosen the SM clock not to be source from DCO, then the DCO that is the
oscillator as well as the DC bias generator for the DC oscillator are disabled and this saves
you power.

(Refer Slide Time: 25:49)

599
Then you can go to LPM2 in which CPU is disabled. Now, M clock and SM clock both are
disabled the DCO can be on, the DCO’s DC generator remains enabled. And the reason why,
why the DC generator is enabled is because the DC generator biases the digitally controlled
oscillator. If the bias is on, the DCO, the DCO can be turned on quickly. The is, A clock
remains active and the supply current drops to about 22 micro amperes.

(Refer Slide Time: 26:30)

Beyond LPM2, you can go for LPM3. Here, the CPU is disabled your M clock and S clock
are also disabled the DCO’s DC generator is disabled. Now, if the DC generator is disabled,
if you want to switch back to active mode it is going to take some time because first the
biasing will be turned on, and then the DC oscillator will turned on it will take some time to
come back to active mode. A clock of course remains active which means some peripherals
can choose to use A clock for its operation and the supply current drops to a staggeringly low
0.5 micro amperes at 2.2 volts.

(Refer Slide Time: 27:09)

600
Here we have LPM4. And now the CPU is disabled, the A clock is also disabled the rest of
the clocks are also disabled, your DCO generator is disabled, the crystal oscillator is stopped.
And now you see, this is the least power consuming mode where only the contents of the
register will be maintained, rest nothing is going to work because all the clocks are disabled
and your supply current is going to drop to merely 0.1 microampere.

601
(Refer Slide Time: 27:42)

Now, you can use choose to enter these low power modes using the 4 bits in the status
register and these 4 bits are these and we will see how these bits, bit combinations could be
invoked appropriately to enter one or the other low power modes.

(Refer Slide Time: 28:00)

So, here we have when all the bits are 0 you are in the active mode and you see this is the
contents of the status register. And we have always mentioned, that when you reset your
microcontroller, the status register is cleared, which means all the bits in status registers are 0.
Which means, after reset your video enter in the active mode, after that you can choose if you
want to make the, enter the LPM0 mode you make CPU of bit equal to 1 and LPM1 you bit
turn this, bit on and on and so on.

602
And of course, your CCS, the Code Composer Studio allows you many macros to invoke
various modes without having to worry about which bits to turn on and off. Now, if you enter
any of the low power modes, the only way you can get out of it is through interrupts and
interrupts will only work if you have enabled the interrupts, which means the global interrupt
enable flag must be turned on. So, you can use either this macro and use it in your code to get
out of the low-power mode or you can use this combination of command to get out of the
low-power mode.

(Refer Slide Time: 29:22)

We will now illustrate this with the help of a code to show this operation. Now, we have seen
the various modes how to invoke them. We must put together, we must consider the low
power modes and the interrupts together because if the MSP is designed to remain in
low-power mode for most of the time, that is fine if you want to get out of it you must take
the support of interrupts. And oftentimes, the main code will you know program the
peripherals to do their job depending upon which low power mode you have chosen.

If you want certain peripherals to operate, you have to select appropriate clocks for feeding
those peripherals and you have to select appropriate low power modes. But, if you want to get
back into active mode, you must turn the general global interrupt enable bit as one and then
hope that these peripherals can generate an interrupt whenever some action is encountered, so
that the processor can come out for of the low-power mode and into the active mode.

603
(Refer Slide Time: 30:32)

Here is a code example, where what we have done is we are using the peripherals on the
lunchbox. We are not doing anything else; we do not want you to connect anything other than
the lunchbox to any other, you know connection on the breadboard whatever is available on
the lunchbox is suitable. We have one switch which as you know is connected to port 1 bit 3,
and we have a LED connected to port 1 bit 7.

Now, let us see what we are doing. What this code example shows, we and you will have to
play with this code and I will show you what part to actually see the impact of this program.
What this does is, that this program will enter into low power mode and by pressing a switch,
that is the switch connected to port 1.3 you can get out of it and let us see what it does. So,
first of all wherever we reset we are, the first instruction we are executing is to disable the
watchdog timer.

Then we are turning the port 1.7 bit as output and port 1.3 as input and before that, we are
turning the LED connected to port 1.7 off. And we have, this is very important, after we have
converted after we have decided that port 1.3 pin should be input, we are also enabling the
interrupt on port 1.3 in the rising edge mode and we have enabled the interrupt on that pin.
So, we have access to registers, port 1 interrupt enable and port 1 edge selection register. So,
we have decided that whenever the switch is pressed and released, at release you will get a
rising edge it should interrupt the system.

Then we have a variable declared I, we will see what we are doing with it. And then we enter
a infinite loop. Outside that here is your interrupt vector, where you are going to go whenever

604
the switch is pressed. Why, because we have enabled interrupts on port 1 and so whenever
the switch is pressed it will generate an interrupt, it will go into the vector. And as you see,
we have gone through that earlier, you are saying hash pragma vector is equal to port 1
vector. But before that, let us see what, what you do here.

So, this instruction is very important, right now this instruction will execute. In this what you
are doing, you are saying bit set in the SR register, so as to select LPM4 mode and enable the
global interrupts. Now, the moment you execute this instruction the CPU has got to stop,
which means nothing will happen till you get out of the low power mode, which means next
instruction which is here is not going to execute. So, nothing is going to happen on the LED
if the LED was off it will remain off, but if they really was on it will remain on.

The first time around the LED will be off. Now, what happens, you press the switch you are
going to go into this interrupt and in this interrupt, you are exiting from the low-power mode
why, you are clearing the appropriate bits in the status registers. You are also enabling the
interrupts again, and you are resetting the bit in the port 1 interrupt register, so that next time
around when the switch is pressed you can again register and interrupt. Now, because of this
instruction you are going to go in the active mode, which means when you come back here,
you will execute this instruction, which will turn the, which will toggle the LED.

Now, this instruction which deal is, is actually superfluous as far as running this code with
this instruction active. So, you can play with this and you will see that every time you press
the switch it toggles. And, but if you comment this instruction, if you comment this
instruction out, which means interrupts have really no, you know, you have, you are not, you
know turning the interrupts on, so interrupts are not going to work. Then, the only two
instructions in this loop are toggle the LED, delay, toggle the LED, delay.

So, in this mode you are going to see that the LED is continuously going to toggle, when,
when you comment out this instruction. If you comment out this instruction rebuild your code
and download it, you are going to just see LED on port 1 bit 7 toggling, at a rate of roughly,
you know few tags a second.

The switch has no impact because we are not reading it in the main program and the interrupt
is not enabled but the moment you comment out means, when you make this instruction
active as part of this code, then you will see that the if the LED is on it will remain on, it is
not going to toggle, it is only going to toggle when you press the switch.

605
Why, because when you press the switch it is going to enable the interrupts, in the interrupt
sub routine it is going to disable the low power mode, go back into active mode, and will
toggle the LED, and will come back, and again enter the low power mode. So, once you press
the switch, if it, if the LED was on it will be off, will remain off. Then when you press the
switch again, it will again exit the low power mode, go in the active mode, toggle the LED,
again go in the low power, and so on.

So, this is a interesting exercise to see how you can play with the low-power mode, how you
can have external peripherals exit the low-power mode. And I strongly recommend, that you
experiment with this code, specially by playing with this instruction, by commenting this
instruction out or keeping it in your code to see the impact. So, we are done with the
description of the low power modes, as well as how to connect simple 7 segment display to
the pins of MSP430 microcontroller. In a subsequent lecture, we will deal with timer and
other issues. Thank you, for watching.

606
Introduction to Embedded System Design
Professor Dhananjay V. Gadre
Netaji Subhas University of Technology, New Delhi
Lecture 28
Interfacing Liquid Crystal Displays (LCD)
Hello and welcome to a new session for this ongoing online course on introduction to
embedded system design. I am your instructor Dhananjay Gadre and in this session I
will be talking about how to connect additional output devices for human interaction
namely the liquid crystal display.

So, liquid crystal displays are commonly called as LCD outputs and we are going to
talk about how to connect them to our favourite MSP430 micro-controller. Now, you
would have seen LCD displays commonly around you in many of the gadgets that you
use on a regular basis. For example, on your calculator, on your specially the AC
remote and so on. And these are common output devices because they allow very low
power operation.

(Refer Slide Time: 01:20)

These liquid crystal displays come in various types. The simplest one are called
numeric displays and these are the ones which are used in calculators. The numeric
displays will allow you to display information in seven segment format like you have
seen for seven segment displays which use LEDs but you have same format for LCD
also. So, you would have seen this on calculators.

607
Similarly, the seven segment display is not able to display a variety of information
and so you have another type of output configuration which is called alphanumeric
display which is similar to the numeric display except it has additional segments and
typical alphanumeric display will look like this. Something like this.

This allows you to display alphabetical characters with little more clarity than is
possible with a numeric displays. Then the third type of liquid crystal displays which
are common are called character LCD displays in which you can display ASCII
characters in the form of a 5 by 7 or 5 by 8 matrix of LCD elements, liquid crystal
elements. Something like this.

Now, on such a matrix you can display almost a large number of alphabets, numbers,
special characters and so on and so forth and that is why these are called character
displays. And the most common of the liquid crystal display is what is called as
graphics. In which row and column full of pixels are available that you can use to
create whatever graphical or numeric or alphabetical information that you would like
to display. So, these are the common LCD displays that are available.

We will now investigate how are LCD displays different from LED displays and the
basic difference is in a LED display emits light. So, it has a source of light namely the
light emitting diode. In the case of LCD we do not have the mechanism to generate
light in a way that a LED does. But LCD allows you to manipulate light.

(Refer Slide Time: 04:23)

608
So, LCD liquid crystal display works by manipulating light. What does it consist of?
It consist of several layers of structures. Initially a source of light, the source of light
can be ambient light as well as light from a LED source, followed by a polarizer in
which it polarizes the incoming light let us say in the horizontal direction.

Then you have the liquid crystal in between and then you have another polarizer
where the polarization happen in a vertical direction and then of course here is the
human eye which is able to see what is reaching the human eye. Now, how does it
work? If the 2 polarizers, polarize a light in such a way that one is polarizing it in
horizontal direction and the other offers polarization in the vertical direction no light
from the source would reach the human eye.

But the intervening liquid crystal has a great ability that once you apply potential to it,
it has the ability to twist the light meaning it has the ability to change direction of the
light which reaches this the crystal and change its direction and if it is aligned to the
vertical direction then the light will come out and you can see it, the human eye can
see it.

And so LCD is very different from LED. In LED you generate light, whereas in LCD
you manipulate existing light. So, this is the basic difference. Because it is not
generating any light, it is able to operate at much low power levels as compared to
LED display and that is the reason why LCDs are so common in everyday gadgets for
sharing information for human interaction.

609
(Refer Slide Time: 06:35)

610
These liquid crystal displays specially the so called character LCD displays, we are
not going to talk about numeric and alphanumeric because numeric displays and
alphanumeric displays do not have the ability to share too much variety of
information.

We are going to concentrate on character LCD displays in this lecture and I will
mention what all graphic displays, LCD displays you can have. In liquid crystal
display of the character type you get it in the form of what is called as 8 cross 1 or 8
cross 2 and these refer to the number of characters in the first instance and the second
information is the how many lines you have.

So, when I say that I have a 8 cross 1 LCD character display, it means I have 1 line
and this line has 8 characters. Each character can be any ASCII value, any ASCII
character you can display. Similarly, 8 cross 2 would be 2 lines of 8 characters. 16
cross 1, 16 cross 2 these are the most in fact 16 cross 2 is the most common LCD
display that you can find and in this exercise we are going to use a 16 cross 2 display.

Here is an example of a variety of this. This is a 8 cross 2, next to it is a 12 cross 2,


then you have a 16 cross 2 and you have a 20 cross 1. You may have seen this at
various locations and we are going to use this in our experiment.

(Refer Slide Time: 08:13)

611
Now, one could create a mechanism for connecting such a display to a
micro-controller and the most common interface for connecting such a display to a
micro-controller is what is called as Hitachi HD44780 LCD Controller. This has
become a defector standard for character LCD displays which spans the entire range
from 8 cross 1 to 20 cross 4.

It has a common interface as we see here. This is the interface that it requires certain
pins for sending information and reading information from the display for providing
power supply to this display, for providing power supply for the backlight. The source
of light which we are able to stop or allow to come out of the LCD that is the light we
were talking of initially and this has been available for a very long time. In this
display the one we are going to use in our experiment, we are going to use a 16 cross
2 LCD display.

This is the most common display that is available and therefore the cheapest that you
can find. The 16 cross 2 translates to 2 lines and each of the line allows you to display
16 characters. Each character can be displayed in a 5 by 8 matrix which means that a
16 cross 2 LCD, how many pixel it has? Let us calculate that.

612
(Refer Slide Time: 09:52)

A 16 cross 2 LCD where each of the displays, each of the character is 5 cross 8, that
means 40 pixels. Therefore, the total number of pixels on a 16 cross 2 LCD is 32 into
40 and that is a large number of pixels that you have. Now, obviously to be able to
turn control each of these pixels is equal to controlling so many LEDs that we have
seen in a previous lecture and the only way to achieve this is by way of multiplexing
except the responsibility of multiplexing is not on the micro-controller.

The LCD has resident micro-controller or a single purpose computer which is doing
that job on our behalf. All we have to do is send information to the controller that
what do you want to display and this information, this interface that we are talking
about basically allows an external controller such as MSP430 to communicate with
the resident single purpose computer on the LCD display, convey information to it so
that controller is able to multiplex all these LCD pixels to display whatever
information that the user may want to provide.

613
(Refer Slide Time: 11:30)

And the Hitachi controller HD44780 offers a unique and uniform interface which has
these 8 data lines, some control lines like this and this and a power supply here, a
power supply for the backlight and a contrast control. Using a 16 pin interface any
micro-controller such as MSP430 or any other micro-controller can display
information in a uniform fashion and it does not matter that you have a 16 cross 2
LCD, you can also have a 20 cross 4 LCD.

Even then the interface to the LCD will remain the same. That is the beauty of this
Hitachi HD44780 LCD controller. Let us go through the pin out of this LCD
controller. The most important part is what is the power supply required.

614
(Refer Slide Time: 12:26)

The power supply that you require is here ground and VCC and this is the commonly
available LCDs required 5 volt. Of course, 5 volt does not mean 5 volt. Usually it is 5
volt plus minus 10 percent which means you can have a supply voltage from 4.5 volts
to 5.5 volts. Apart from that you need to set the contrast and I will share the circuit
that you have to connect to be able to adjust the contrast of the LCD. Apart from that
you have data pins D0 to D7 as you see here and control signals which is read write
enable and register select.

These are the 3 control pins that you require for communicating with the common
LCD display and then you have 2 LEDs, 2 pins of LED, anode and cathode which
provide the backlight to this LCD. These LCDs are available in many colours like
green colour with black segments or any other colour and you can choose whatever is
available for you.

615
(Refer Slide Time: 13:40)

Now, these are the description of the pins. You have read write pin. If the read write
pin is 1 that means you want to read internal register. If you set this pin to 0 that
means you want to write into that register. You also have a enable pin which is like a
chip select.

You have to keep this signal low to be able to a negative edge on this signal which
indicates to the LCD controller that you are writing something. Then you have a
contrast adjustment on one of the pins. You have 8 data pins D0 to D7 and you have a
register select.

You have 2 registers. One is for command and the other is for data. So, if this value is
0 that means you are sending information to the command register. If this value is 1
that means you are sending information to the data register and apart from that you
have 2 pins which are the anode and cathode of the backlight LED.

616
(Refer Slide Time: 14:41)

Now, to create a uniform interface the Hitachi LCD controller offers a set of
commands and any controller can send these commands and the Hitachi controller
will react appropriately. At this point I would like you to take this LCD that you have
in your hand and flip it around and see what is behind that LCD.

You will find 2 black dots and those black dots are what are called as chip on boards.
Underneath those black dots are ICs which are the controllers and the memory for this
LCD controller. So, these are the commands. What commands you send. You can
send a command to clear the display. You can send a command to return the home.
Home means the initial position of the cursor. You can increment or decrement the
cursor. You can go forward or you can go backward and so on.

There are about 20-25 commands. Here as you see 21 commands which allow you to
interact with the LCD controller. Some of these commands we will see when we do
an exercise. Let us go towards that.

617
(Refer Slide Time: 15:56)

Now, one of the problems with the LCD 16 cross 2 or any other character LCD is that
it works at 5 volts.

(Refer Slide Time: 16:08)

Here, it works at 5 volts and so we have this issue that our MSP430 lunch box
operates at 3.3 volts but the LCD works at 5 volts. Now, how do you provide 5 volts?
So, in this lecture we have offered you several ways of creating 5 volts supply so that
you can power your LCD and the first method is to use a modified USB cable that
you may have or if you search the internet you can get access to what is called as a
breadboard power supply, small module that will fit into the power supply pins, the

618
side pins of a breadboard easily or if you have access to a lab power supply, you can
set it to 5 volts and you can use it to power your LCD also. I come to that in a brief
moment but let us go back to the interface of the LCD.

(Refer Slide Time: 17:04)

Now, because you have 8 pins for interaction the LCD, the controller inside the LCD
expects you to send commands over these 8 pins. But often times we do not have 8
pins. The Hitachi interface is very benevolent in that sense that it will adjust to send
you information on 4 bits also. Instead of 8 bits you can communicate with LCD
controller on 4 of the 8 pins and that is called the 4 bit mode. The default mode is 8
bit mode but if you like, if you do not have pins select the 4 bit mode.

619
(Refer Slide Time: 17:43)

In fact one of the commands as you see here, these 2 commands allow you to tell the,
communicate to the LCD, that no we do not have 8 pins to communicate to you and
we are going to send information on 4 bits also. So, you have to send these commands
and we will see briefly how you send these commands.

So, you have a 8 bit mode and a 4 bit mode. Now, in the 4 bit mode the actual
information is being send, you want to send 8 bit of information, but because the
communication connection only has 4 pins, you have to send information on those
pins twice so that you can send entire 8 bit of information. So, you have to tell the
controller that we are going to send 4 bits and then another 4 bits, the lower level and
the higher level and the way to do that, here is the sequence of instructions.

620
(Refer Slide Time: 18:38)

You send a information like this and say you send a value called 33. 33 is in
hexadecimal. Then you send 32 and then you send 28. When you send these 3 bytes it
conveys to the LCD controller that you want to communicate with the LCD controller
in a 4 bit mode and you want to have 2 lines and each of the line will have character
which are defined as 5 by 7 matrix.

And then these are additional commands where you are turning the cursor off and you
want the increment cursor automatically and you want to clear the display screen that
any previous information is cleared off. But the most important is that you want to
send these 3 bytes of information to the controller but you do not have 8 bits to send,
8 wires to send. You are sending it in chunks of 4 bits each. So, we will see when we
look at the code for doing this how we achieve that.

621
(Refer Slide Time: 19:46)

These are the connections you will find on a character LCD. You have anode and
cathode which are for the backlight LED. You have this 8 data lines and if you so
wish you can choose not to use 4 of the lines. So, you see these 4 lines D0 to D7, D0
to D3 are not being used and you can only use 4 pins and the numbers that you see
here are, they refer to the 4 pins of MSP430.

So, we are going to connect P1.4 to P1.7 to send data. We are going to use P1.3 for
the enable signal. We are going to use P1.2 for the register select and we also have
read and write and we have permanently grounded it. What does it mean? That we
permanently want to write into the LCD. We do not want to read any information
back. That saves you 1 pin.

So, with this you are able to using just 6 pins - 4 for the data and 2 for the control
signals. This one and this one with 6 pins available on your micro-controller you are
able to control a LCD. Apart from that you need a contrast which is achieved by
having a 10 kilo ohm pre-set where you adjust the pre-set to give you the contrast that
you want then you leave it there and this is the supply voltage, 5 volts but of course 5
volts plus minus 10 percent.

These are the connections that you require, that you need to make and connect it to
your micro-controller in this case MSP430 lunch box to be able to send information
and display that information. Now, coming back to the power supply requirements.

622
Since our MSP430 lunch box does not have 5 volt available easily, we have to find a
mechanism to provide 5 volts.

One option is that you take any USB cable whether it is a micro-USB or a mini-USB
output, plug it into your power bank or onto your laptop and on the other side you can
cut it and select appropriate wires to provide 5 volts and in this PPT we are going to
show you how we can do that.

(Refer Slide Time: 22:03)

So here is the, you take a USB cable like this. Cut one side off. This is the cut side.
Then you strip it of and you will find the insulator side there are 4 wires. The 2 of the
wires are yellow and black, red and black and that is the power supply plus 5 and

623
ground and then you have a copper wire which is like the shield and then you have 2
more wires. Those are for communicate data plus and data minus. We do not need
them in our application so we are going to cut them off.

(Refer Slide Time: 22:35)

Then you cut them off at different length. The black and red wire you keep of the
maximum length and the other 2 wire this one and this one you cut at different lengths
because you do not want to short them because that may give false information to the
cable where you are connected it.

(Refer Slide Time: 22:58)

624
625
Then leaving the black and red cable you bend the rest of the 3 cables and then you
tape them off like we see here. Use a insulating tape. Tape it off. Now, these wires
can be cut at different lengths. Why? Because we will see, we do not want them to be
of equal length. They may short with each other and they may create problems where
the USB interface.

So, you cut them at different levels. Those cut wires you tilt using solder wire. You
apply solder onto it so that the breads of the wire are all joined together. Then I
suggest you use a resistor on the positive wire.

In this case this is the 47 ohm resistor. You can choose any resistor up to 20 ohms.
The reason is if inadvertently you short these 2 pins the resistor will limit the amount

626
of current that can flow in this circuit and the safe limit for USB normal USBs 500
milli amperes. Till 500 milli amperes it will not damage the USB port. So, we have
put a 47 ohm resistor that means we are allowing up to 100 milli amperes of current
and this is suitable and sufficient for our LCD.

If you have a lesser value resistor up to 20 ohm that is suitable. So, you can choose a
22 standard ohm up to 47 ohm resistor like this and this once you solder on the 2
wires it provides you 5 volts that you can use safely to power your LCD. Now, here
we are looking at the hello LCD code. This is the code we are going to write on our
code composer studio. We are going to build and compile it and we are going to
download it in our lunch box and we will see here which connections we have made
to the LCD.

(Refer Slide Time: 24:57)

Let us go through those connections. So, these are the pin outs. The LCD output we
are going to take out of P1. So, we are taking it P1. The direction is set here that they
will all be output and these are the 4 bits of data. As I mentioned we are going to
interface the LCD in the 4 bit mode.

So, we have 4 bits - bit 7, 6, 5 and 4 and the resistor select and enable pin are going to
be derived from P1.2 and P1.3. Now, we are going to come back here later. Let us go
back to our main program. So basically, what you need to do is using this pin out, you

627
need to connect your MSP430 micro-controller to the connections of the LCD that we
have seen earlier.

You need to also connect the 5 volt and ground. You need to connect the
potentiometer between VCC that is plus 5 volt and ground and the centre of the
potentiometer or the pre-set you need to connect to the contrast pin of your LCD.
Apart from that these 4 data pins, the register select and enable pin you need to
connect to the port 1 pins and the other pin that we mentioned, RW pin you need to
connect to ground. Once you make those connections on your LCD which you can
insert in your breadboard, you are ready to go. Let us see the main program.

(Refer Slide Time: 26:52)

So, the main program starts here. The main program is actually very simple but that is
because most of the functionality has been outsourced to in the form of functions. The
first thing that we do the moment we enter into the program is that we disable the
watchdog timer. We do not want the watchdog timer on our MSP430 to interrupt us.

Then we call a subroutine to initialize the LCD and then we set the cursor to the home
position that is 0, 1 which is the top left pixel is our home position and then we want
the LCD to print Hello Embedded on the first line and on the second line we want to
print Systems and then we are going to wait here in this, doing nothing. That is the
main code. Now, let us go through each of the functions and see what it does. Let us
see what LCD in it does.

628
(Refer Slide Time: 27:39)

So, LCD in it what it does is, it initializes the port 1 pins to be output and it sets the
direction as output and it defies them as output. This is what it does and it makes all
the pins equal to 0. The register select is 0. The enable is 0 and all the data pins D4 to
D7 are set to 0. Then it calls a delay of certain amount which we will see what it does
and then it writes a value called LCD write here. Let me erase this. It calls a function
called LCD write and in that LCD write there are 2 variables, 2 parameters.

One is number called 33 and then it say this number should be treated as command.
Now, you remember the LCD is able to accept either command or data using the
register select function RS. If we are sending a command, that value has to be 1, if

629
you are sending a data that value has to be 0, you are basically conveying to the LCD
write function that this value, this number 033 0x33x should be sent as a command.
Then you are delaying for some more time and you are sending another command
with a value 32. Then you are delaying for a lesser period of time.

Now, you are sending these 4 commands basically as you can correlate with the
commands that you can send to the LCD. This is allowing you to initialize the LCD in
4 bit mode, the 2 lines. You want the cursor display to be on, you want the cursor to
be off and you want the cursor not to blink and then you clear the screen using this
command.

After some delay you are setting the cursor for auto increment meaning when you
write one character, you want the cursor to go to the next character and initially you
want to set the cursor to 0,0. This means in your display, this is 1 line, this is your
second line, you want it to go here.

This is the initial location. Once you have initialized the LCD you are executing the
second command where you are saying set the LCD cursor to 0, 1.

(Refer Slide Time: 29:54)

630
So, let us see what that command is LCD cursor. Here you are sending some
information which uses the same LCD write. You are sending this information and
you are sending the offset of the values to the LCD and then you are delaying it for
some time.

Let us go back to the program. Then you are saying Hello Embedded. You want to
print this information. You want to print these characters on to this LCD. Let us go
back to the LCD print. What it does?

(Refer Slide Time: 30:29)

631
Now you are passing a array to the LCD print and you are passing its pointer. So, till
the pointer does not give you a null because when the pointer ends, the value is null.
Till the null point, null value is received, you are sending information and you are
saying that this information should be treated as data. What does it consist of?

This consists of the characters under the apostrophes Hello Embedded. So, you are
sending one byte at a time to the LCD write function here.

(Refer Slide Time: 31:12)

So, let us go and evaluate the LCD write function. Here is the LCD write function
here.

632
(Refer Slide Time: 31:29)

In the LCD write, before that let me mention here that in our program we have chosen
to use a variable of the type uint8_t. This means unsigned integer of a size of 8 bits
which is not very different from unsigned character but this is not available in your
normal MSP430 header file. For that you have to include a different header file and
that is this int types.

(Refer Slide Time: 31:52)

633
In int types there is a definition of how to invoke uint8 kind of variables. So, we have
used that.

(Refer Slide Time: 32:04)

634
So, LCD write requires 2 values. One is the value and the other is what is the mode
meaning in what mode should these values be sent to the LCD. So, this mode can be
either command or it can be data and whatever value is there it will be set. But this
value will be 8 bits. But as we know we are not able to send 8 bits of data from the
controller to the LCD. We are sending 4 bits at a time.

So, this LCD write function will actually split the 8 bits of data that you get here and
split it into nibbles and send one at a time. Let us see how it does that. So, first of all it
says that it going to generate a low command on RS for command mode. So, it is
going to generate a pulse like this, making this using this command. It makes RS 0
and using this makes RS I.

635
Then it is going to output the 2 values which is there in the value here. You are going
to take the upper nibble by ending it with F0 and the original LCD out value you are
retaining the lower values but the upper values you have made 0 by ending it with 0F
and that value is being odd with this information. And then you provide this value
onto the port 1 pins that is LCD out. Then you pulse the EN pin which makes the
LCD controller receive this information. Then you delay for some time.

Now, you are still left with sending the lower nibble. The value in the lower nibble is
shifted to the upper nibbles and with F0 so that the other bits are 0 and same function
you operate here and create a value to be send to port 1 and once you send it to the
port 1, you pulse the signal on EN and then you delay and you go back and what does
pulse EN does? It does nothing but it creates EN equal to 1 and then it makes 0.

So, these are the sequences of operations that LCD needs to, the controller needs to
perform so as to send information to the LCD. So, I recommend that you download
this code, build and compile and download it into your MSP430 lunch box.

(Refer Slide Time: 34:45)

636
Make the connections to the LCD as discussed and this is what it would appear that
you have made appropriate connections to the LCD and when you run the program
you will see that the LCD prints this message. So, this is one part. Now the LCD is
capable of creating custom characters also. These are all built in ASCII characters that
it is able to print. But what if you wanted to print a smiley?

Something like this or a heart. Something like this. It is possible to print the heart like
this by creating a pixel character and store this information in the RAM that the LCD
has and then invoke them so that you can print these characters.

(Refer Slide Time: 35:32)

637
So, the second part of this code we are going to show, how we can create custom
characters, store them in the memory of the LCD and then invoke them and tell the
LCD controller to display them.

(Refer Slide Time: 35:57)

The information can be stored in a RAM that is available on the LCD that is called
custom graphics RAM and that information that size is you are getting 64 bytes for
each character you are getting 8 bytes.

(Refer Slide Time: 36:07)

638
Out of these 8 bytes as you see here you can have 8 characters. Each character
requires 8 bytes. Out of these 8 bytes you are ignoring 3 bits because your character is
5 columns and 8 rows. So, you can specify into this 5 by 8 or you can think of it as a 8
by 8 RAM which of the bits have to be 1 and once you write that information you can
then invoke them later on and the first character is stored at address 40 and its address
is 0. The second character is stored in these are RAM addresses. 40, 48 as you see
they are all 8 bytes apart.

So, you can write information into these RAM locations and once you have written
you can invoke them by sending information to the LCD that you want to display the
characters stored at address 0 or 1 or 2 and so on.

639
(Refer Slide Time: 37:07)

So, I strongly recommend that you go through this code. It is not very different from
what we have discussed earlier.

(Refer Slide Time: 37:11)

The only addition is that we have stored custom characters. In fact, we have stored a
hearty. We have stored a heart like this in the CG RAM and you can invoke it and
display this into your display.

(Refer Slide Time: 37:31)

640
So, I strongly recommend that you go through this. The codes are very well
documented. Reading it will tell you what we are doing.

641
(Refer Slide Time: 37:43)

And once you connect the connections are not very different. Other than the LCD you
only need to connect a switch here. So when you press the switch, when you
download the code you will see the same hello embedded systems, when you press
the switch you will see that 2 hearts appear around before and after the systems. When
you press the switch again they will disappear and so on and so forth.

So, I strongly recommend that you go through that code. That code is not very
difficult. That code is not very different from the earlier code. The only addition is to
add custom characters and the code is quite readable. I recommend that you go
through it and use that template for creating your own custom characters and use it
whenever your application demands so. So, with this we are at the end of this lecture
where we have illustrated how we can connect character LCDs to your projects using
MSP430 and we will see how we use it in our future projects. Thank you. See you.

642
Introduction to Embedded System Design
Professor Dhananjay V. Gadre
Netaji Subhas University of Technology, New Delhi
Lecture 29
MSP430 Timer module: Introduction and Timer Capture
Hello and welcome to a new session for this online course on Introduction to Embedded system
design. I am your instructor, Dhananjay Gadre and in this session I am going to cover a very very
important aspects of embedded systems which is the ability to count time, measure time, count
events so on and so forth.

And the basic building block peripheral, critical peripheral in any micro controller ecosystem is
the ability to count time without the intervention of the micro, the CPU and such a peripheral is
called Timer and often times it is called Counter/Timer which means it can count as well as
count events as well as count time. The basic building block in counter timer is actually a
counter. Now, what is a counter?

(Refer Slide Time: 01:20)

If I show you a n-bit counter and typically what you will have n-bits going out. And you would
have a clock input, may be you will have a reset pin so when will assert the reset signal, all the n
outputs of this counter. So, this is a counter or reset to 0. Thereafter for the given configuration
of the clock signal, every time there is a rising edge, the count will increment by 1.

643
If this was a down counter, then it will decrement by 1. So let us say, this is an up counter and so
on. So, if from here if the initial value before this was 0 then and this was an up counter, the
count will be 1 here and it will be 2 here. Now, whether the signals which are applied to the
clock are like this or like this.

Here it will be one and it will be 2 at this point of time. these are the time and these are the pulses
you are getting. If the frequency of the signal which is connected to the clock pin of the counter.
We do not know the frequency then we cannot say that how much time is elapsed. All we can
say how many events have come, how many clock signals have come and in such a case you are
operating this building block as a counter.

(Refer Slide Time: 02:50)

On the other hand, if I use the same hardware. I still have a n-bit counter, n-bits and let us say it
is a up-counter. You have a clock signal, you have reset signal but now instead of an external
signal which is generating some pulses, if this connected to a oscillator, rectangular output
oscillator something like this whose frequency is fixed and after I reset assert reset on this pin. It
will count these pulses.

And if I query, if I am able to read this n-bits and I find let us say the count is 1030 1350. If I
find that the count is 1350, then I can also tell how much time is elapsed since the time I reset
this counter. How much time is elapsed? It is 1350 into the T oscillator that is the period of the

644
clock signal. Once I know this by performing this small calculation, I would be able to estimate
the time it has elapsed since the time I reset this counter.

So, the basic building block in a micro controller is the time is the counter. If you connect the
clock input of that counter to that external pin and expect external signals to be used for clocking
the counter, you are maintaining a counter. On the other hand, if the clock input of this counter is
derived from an internally generated clock then and if you know the frequency of that clock then
you would have converted this counter into a timer. And MSP430 is immensely capable in
providing various functions of this timer counter. Let us investigate what all we have.

(Refer Slide Time: 05:12)

Now, why do we need timers? We can also use the program to count time. The reason why we
want to use timers is that we can use the peripheral function to generate timing events. We can
use them for generating delays. We can use them for creating what we called as baud rates which
we are going to cover in a serial communication lecture subsequently. Or you can use these
timers as mentioned for counting the external events and so on.

Having a dedicated hardware for performing this function frees the CPU from performing the
task. You can also use the CPU, for example one of the pod pins could be connected to a external
signal where you are getting pulses and you can write a program saying, if this pulses high wait
for it to be low. Once it goes low, one pulse has been received you can count it and so on. But if

645
you did that your entire CPU life is going to be spent only counting pulses, you would not be
able to do any other activity at the same time.

By off loading this counting business to a counter, your CPU can perform other functions and
keep on finding out from the counter. How much, how many events have happened. This is what
the infrastructure related to a counter and a timer micro controller usually allows you to do. And
MSP430 is no exception. If you use a program to use generate leads as we have seen how we can
write a delay function, again the delay function depends on the accuracy of the CPU clock. And
if it is not very accurate the delay period will not be very accurate.

On the other hand, if you use the timer, you can use a external crystal oscillator like we have on
the MSP430 to provide clock to the timer and then it can generate very accurate delay periods.
MSP430G2553 has 2 16-bit Timer A and they are label timer as 0A and Timer1A. and this is
over and above the watchdog timer that it has which can also function as a Timer.

(Refer Slide Time: 07:18)

The timers on the MSP430 are 16-bit counter which means they can count from 0 to 65535
which means they can count a very large number. The timers can be used for capture and
compare functions. I will come to this feature shortly. And it can also used to generate Pulse
Width Modulation signal which we have briefly mentioned in a previous lecture.

646
The timers can be used to generate interrupts on a timely fashion. You want to generate interrupt
every one second or every 100 mille seconds, you can employ a timer by appropriately
programming it, it can generate very accurate interrupt events which you can used to do some
housekeeping jobs.

You remember in a previous lecture we said, we want to connect 4 7-segment displays and we
want to multiplex them and multiplexing requires that you refresh the display which means one
digit which was on you have to turn it off. And after a pre-determined period of time you have to
turn second digit on.

Now, you can do the job with the help of the interrupted generated by the timer. You can also
use the timer infrastructure to measure frequency of the external signals. You can use it to
measure period of external pulses. And you can use it to output information on pins on
pre-determined intervals. So, these are the features of the timer.

(Refer Slide Time: 08:46)

647
Here is a block diagram and I am going to broadly tell you that any timer has actually two parts
the timer part that is the counterpart and the rest of the parts which allow you to compare the
value of the timer to pre-determined value. So, that you know you have started the timer from 0,
I want the notification when the count reaches 5000. So, you are going to compare the value of
the timer with the value in a register which you write 5000 whenever that match happens, it will
inform you.

So, here is the 16-bit timer. This is called TAR which means Timer register and then you have 3
compare capture channels, they are called CCR0 Capture Compare Register 0. Capture Compare
Register 1 and Capture Compare Register 2. So, with one timer, you have 3 channels of capture
and compare features. Of course, you can either capture or compare and by choosing a
appropriate function whether we want to capture or compare.

What is the meaning of capture? You have to capture the value in the timer. What is the meaning
of the compare? You have to compare the value of the timer register with the pre-determined
value stored in that compare register. And using these two compare and capture registers; you
can do amazing things with the timer.

The for this counter, although it says the timer as I mentioned. It can basic building block is the
counter. The clock of the timer can be derived from these sources as you see here, you can have
the A- clock, Auxillary clock or you can have SM clock and TA clock in this case is actually a

648
pin which means the signal of the pin is used to clock the counter and these feature can be used
when you want to count the external pulses, when you want to count external events.

You may remember in one of the previous lectures, suppose in this room we have to count how
many people have entered, you can easily install the censor which detects human presence and
when it detects the human presence it will generate a pulse. This pulse can be connected to the
TA clock pin and it will increment the timer. And you can query the timer at any given point of
time after resetting at onset that what is the value at this point of time and you know how many
people have entered the room.

So, this is then A clock and SM clock allows you to operate the timer in the timer mode. Why?
Because A clock and SM clock is locally generated clock signals and you know the frequency of
these clock generator. So, the count in the timer will tell you how much time is elapsed, since
time you have started the timer.

Now, when do you compare and when do you capture, you can do that based on signals on
micro-controller as well as events within the micro-controller. You can use it to capture the value
of the timer. You can use it to compare the value of the timer, using the value written in the
comparator. And are going to use this feature to see various activities. So, this is the basic block
diagram. You have another timer so this is TimerA0 and TimerA1. And both of them have these
three channels which allow you to do multiple things.

649
(Refer Slide Time: 12:35)

So, the major components of the timer are Timer Counter register as we have seen TAR in both
the timers we had they all 16 bit registers. They all read-write registers.

(Refer Slide Time: 12:48)

You also have timer capture and compare register and there are three capture and compare
register for each of the timer. Timer A0CCR0 Timer capture compare register 0, Capture
compare register 1, register 2 for Timer 0A and capture compare register 0, 1 and 2 for Timer
1A. And both these three channels for say for this will use a given timer. These three channels

650
will use a second timer register and you can write values in this, you can read values from this to
know whether you want to capture or you want to compare and so on.

(Refer Slide Time: 13:38)

In the capture mode, the value of the timer is stored and captured in the capture register and you
can read it thereafter. In the compare mode, you load a value in the register and wait for timer
value to reach that number. When that number is reached some event will happen. And usually a
flag will be set and if you want a interrupt will be generated and these feature is used to generate
Pulse width modulated signal.

651
(Refer Slide Time: 14:08)

The source of the timer can be A clock or SM clock and you can source it from an external pin
like TA clock. The clock source is selected with the help of the registers in this these register bits
and once you have selected the source of clock, you can also further divide it, so you can divide
it by 1, 2, 4 or 8 and so on.

(Refer Slide Time: 14:35)

These are the modes of the timer, the basic timer that is the TAR works in 4 modes. You can stop
the timer which means once you stop it, it can hold the value. Or you can use it in the up mode

652
means it can count from 0 and it will keep on counting till a highest value but the highest value
in the capture compare register are 0. The other second mode of operation is what is called as the
continues mode in which it will go from 0 count upto the maximum count which is FFF and
again reset to 0 and again keep on counting.

And then you have an up down mode where it goes from 0, counts upto maximum value and
decrements from maximum value to 0. And so on and so forth. So, you will see in up count it
will goes like a ram and in the continuous mode it also goes to ram but the value the maximum
value is FFF. In the up down mode it goes like a triangle way form. Will see this in diagrams
here.

(Refer Slide Time: 15:40)

So, this is the up mode, it goes from 0 but the maximum value you set in the Timer A capture
compare register 0. So, the point to note is the value in capture compare register is very
important. That is the register which decides upto what value the timer will count.

653
(Refer Slide Time: 16:02)

In this mode, you can use it to generate interrupt at two times. One once when it reaches this
value and once when it resets to 0, when it become 0. As you see here, you have generate a
interrupt here when it goes from here to here and when it is here. So, there are two times this
counting process when interrupts can be generated.

654
(Refer Slide Time: 16:30)

Then you have the continuous mode, very similar to the continuous mode except the value the
maximum value will be this. It will start from 0 and it will go to maximum capability of the timer
and it will reset to 0. And when it resets to 0, it will generate an interrupt as you see here. When
it resets to 0, it is generating an interrupt.

655
(Refer Slide Time: 16:53)

In the up down mode, it goes from 0 to the maximum value set in this register. And once it
reaches there it decrements it till it reached 0. In this mode, it is going to generate when it is just
reaching that and when it is reaching 0.

656
(Refer Slide Time: 17:13)

These are the registers associated with the timer. And I strongly recommend you to go through
the data sheet to understand each of these. The best understanding will come when you write a
program and play with the various features.

(Refer Slide Time: 17:26)

This is the timer control register. And as you see these are the bits which allow you to turn the
timer on and off. These are the bits which allow you to unable the interrupts.

657
(Refer Slide Time: 17:41)

I recommend you again to go through these registers.

(Refer Slide Time: 17:46)

This is the capture control register. This are the values, bits which you can decide which mode of
the timer whether it is going to operate in the capture mode or the compare mode.

658
(Refer Slide Time: 18:07)

And this is the interrupt vector for the interrupts that will be generated because of the Timer A
operation and as you see, many of the interrupts are shared. Here is the interrupt of capture
compare 1 and this is the interrupt of the capture compare 2. This is the interrupt of the timer
overflow for a given timer.

(Refer Slide Time: 18:30)

And there are many many sources of interrupts for these timers. I again very strongly
recommend you that you go through the slides as well as the data sheets.

659
(Refer Slide Time: 18:42)

Now, we are going to run a little program to illustrate what can be achieved with the timer. Now,
in a previous exercise, we saw that we can use a delay function to toggle LED at a certain rate by
changing the delay period, you can slow down the toggling rate or you can make it fast. Here, we
can do that except we are not just toggling a single LED, we are actually counting, the count on 8
LEDs which we connected to port 1 bits.

We have connected 8 LEDs, as you see this part of the LED is grounded all these LEDs are
grounded which means whenever this bit is one that LED is going to glow. Now, we are going to
have a internal counter which will count from 0 to 255. When the value 0 all the LED will be off.
When it is 1, one LED will be on, when it is 2, the first LED will turn off, the second will turn on
and so on and so forth. So, you will you are going to see the counter value in a binary form.

But who is changing the count, the count is changing at every one second but that one second
duration is not being achieved by some delay loop. And instead we have used a timer to generate
an interrupt at every one second. And at every one second interval, we are incrementing the
count and outputting the count onto the port 1 register. So, that you will see the LEDs blinking or
rather counting information at the rate of one second. There is no other interaction; there is no
switch anything like that. Once you load the program and download it and power it up, you will
see the LEDs blinking.

660
(Refer Slide Time: 20:40)

So, here in this program, we have certain registers, we have certain sub-routines. These
sub-routines simply determines that all the pins of the port 1 should be set as output and their
initial value set to 0. So, that when you turn on the values will be 0. Here, we are choosing the
timer various modes of timer 0. What we are doing is, we are saying that we want to generate a
interrupt on capture compare register 0.

The clock for the timer is A clock. And A clock is source from the low frequency crystal as you
know on our MSP430 lunchbox, there is 32.768 kilohertz crystal. The frequency of that crystal
will be use to drive this counter, drive this timer and we want to compare when that count
reaches 32768 by loading the capture counter register to 32768.

When it reaches 32768 that means 32,768 pulses from the oscillator have elapsed. And since the
frequency is 32.768 kilohertz that means one second has elapsed. Upon that event it will generate
an interrupt.

661
(Refer Slide Time: 22:06)

See let us see the program, what we are doing as we always do. This is the main void and we
have disabled the watchdog timer. Now, you remember when we were discussing about the
clocks, the ACLK clock derived out of low frequency oscillator as well as low frequency low
frequency crystal oscillator. Both have to start working.

They are not very fast oscillators which means they will not start working right away after reset.
It may take some time to oscillators to build and stabilize and to do that you have to check for
this flag as we have seen in the previous lecture. We are just repeating that code here. We are
waiting in this loop to make sure that our oscillator is stable, was that oscillator stable. We are
calling this sub routine which we have seen previously here. Here we are here we are feeding
that A clock to timer 0 A0.

662
(Refer Slide Time: 23:08)

663
And then we are calling this sub routine to make all the bits of port 1 to be turned off. Then what
we are doing, then we are entering, we have loaded a value into starters register to enable the
global interrupt flag. This is very important. But we also have chosen to use low power 3. Low
power mode 3, this will disable everything except, it will keep on keep the A clock active. And
since we have chosen A clock to feed the timer which means timer will keep on working.

Also, the peripheral such as the ports will keep on working. So, once you execute this
instruction. Let me remove the comments here. Once you execute the comments here, you can
immediately go in the low power mode 3. And you are enabling the interrupts and before that
you have already enable the timer. The timer clock is selected from A clock that means once one
second gets over, you are going to go in the interrupt. And this is the interrupt program. We are
saying that our vector is timer is 0_A0 vector and this is the code for it. And what is the code?
Simply, have a count where you are saying the count is equal to increment the count and what is
count.

664
(Refer Slide Time: 24:41)

665
If you see here the count is see very important. Count is declared as volatile variable of the type
CAR which means it is a 8 bit counter and the initial value 0. Now, volatile means whenever you
increment it, it will be fetched again and again from the actual location instead of copy being
read from any register, internal register. It will be read from memory because this is going to be
initialized in memory.

So, we have declared this variable as volatile. And in that variable, we are incrementing and that
value incremented value simply outputting on the port 1 bits. So, once you compile, rebuild and
download this program. What you should see that every one second, the 8 bits LEDs will start
working like a binary counter and it will keep on counting from 0, it will reach all the LEDs are,
at 0 all the LEDs will be off.

Then as it gets every one second it will increment and at 255 seconds, you will see all the LEDs
on. And then in next second all the LEDs will be off again. And this will keep on happening.
And this is basically to show that the delay period of incrementing the LEDs, incrementing the
count display on the LEDs is not being done with the help of a CPU program, with the help of
the code but it is being performed by the peripheral which is the timer A_0.

And we will see more activities involving the timer such as the capture compare modes. And
also how to use the timer in the PWM generation facility. We will see in our subsequent lecture.
I suggest you play with this, if you want to change the frequency at the rate the clock the count is
being updated, you can go into this part of the code.

666
And change this number to a lower value and you will see that it blinks the LEDs, it counts the
LEDs faster. If you increase this you can have a slower update. So, I suggest that you play with
this code, update it, modify it, download it and see how various changes to the code will impact
the actual performance. Thank you very much, I will see you very soon, bye bye..

667
Introduction to Embedded System Design
Professor Dhananjay V. Gadre (NSUT) & Badri Subudhi
Indian Institute of Technology, Delhi
Lecture 30
Pulse Width Modulation, PWM Using Timer Capture

Hello, and welcome to a new session for this online course on Introduction to Embedded System
Design. I am your instructor Dhananjay Gadre. In this session we are going to consider a very
important aspect which is to be able to create analog waveforms using digital control. There are
many methods of generating analog voltages with the help of a microcontroller. And 1 such
method uses the timer building block that is a common peripheral in many microcontrollers and
MSP430 is a very rich is very rich in this resource.

We have already introduced ourselves to the use of timer, how we can generate interrupts at
predetermined intervals and periods using the timer. In this lecture, we are going to look at
various methods of generating pulse width modulation signal, which is 1 method of generating
analog voltages. Using a software approach as well as using a hardware approach which uses the
timer.

So, the main topic of our discussion today is to be able to generate analog voltages, we will take
two approaches, a software method which does not require any timer but we will tie down the
CPU in just generating that analog voltage, it will not be able to do many other things
simultaneously. If we want to do that, then we must rely upon the timer operation and many
timer operations offer a PWM generation mechanism and we are going to explore that in this
lecture today, so, let us begin.

668
(Refer Slide Time: 2:01)

Pulse width modulation, as the name suggests, is a mechanism of modifying the width of
modulating the width of a pulse waveform. Here by modifying the width, we are able to change
the average value of the signal. Here is a sample signal we see there is a certain on time as you
see here, the time for which the signal is high of the total time of time period of the signal. The
ratio of the on time and the total time is defined as the duty cycle say D multiplied by the voltage
the maximum voltage of that pulse waveform will give you the average voltage.

So, V average by changing the duty cycle of this waveform, which can go from 0 to 1, I can vary
the average voltage from 0 to Vcc. This is a very good method of generating analog voltages.
Now, the voltage itself appears rectangular, how do I get out of this the analog voltage which is
proportional to the duty cycle? Well, you can do that by applying this signal to an appropriate
low pass filter, we will see how to calculate the value of that filter and what sort of filter is used.

669
(Refer Slide Time: 3:38)

The property of pulse width modulation signal is that as you increase the on time, the duty cycle
of the pulse width pulse increases and so does the average value. Now, if we apply the PWM
signal to output device such as an LED and if we can keep frequency of the PWM signal
frequency of the PWM signal F PWM is equal to 1 by here the T on plus T off, T on plus T off.

If the frequency of the PWM signal is much higher than the rate at which the human eye can
perceive on and off of a LED, then the eye will not perceive the LED as on and off instead, it
will be able to only perceive intensity which lies between 0 and maximum, proportional to the
duty cycle.

And this is because of the limitation of the human eye called persistence of vision. Apart from
LEDs you can use a pulse width modulation signal to drive a DC motor and by changing the duty
cycle you can change the average voltage applied to the DC motor and thereby you will be able
to control the speed of the DC motor. We have discussed this in the past the speed of a DC motor
is proportional to the voltage applied across the terminals.

And therefore, this is a good method by which we can mimic an analog voltage from a digital
signal.

670
(Refer Slide Time: 5:23)

Here are examples of the average values of the PWM signal in this case, there is no waveform
therefore, the average value is 0. Here the on time is 25 percent of the total time this is the total
time the on time is 25 percent therefore, the average voltage is Vcc by 4 here it is 50 percent.

So, the average voltage is 50 percent Vcc by 2 in this case it is 3 fourth of Vcc because the duty
cycle is 75 percent. And if the output is continuously high, the duty cycle is 100 percent and so
you get full Vcc out.

671
(Refer Slide Time: 6:01)2

Now, as I mentioned we can generate PWM signal using a software loop, all you have to do is
write a program in which an output pin any pin which can be converted which can be
programmed as an output pin of a microcontroller can serve as a PWM output.

What you do is you find out you decide some amount of delay and that delay you should be able
to replicate. So, let us say that I am able to let us say I have a total delay of Td. Let us say the,
this is the delay function I can write, this is the amount of delay that I can generate in a

672
guaranteed way. Now, what I will do is, I will have let us say 256, 256 periods of this Td, into
Td.

Now, in this period of 256 into Td, I can choose that the signal the pin is high for certain period
and is low for the rest. Now, if this is some integer multiple n into Td is equal to is kept at logic 1
and therefore 256 minus n into Td is the time for which the output is 0. And therefore, I will be
able to generate a duty cycle which is equal to n upon 256 is equal to the duty cycle. Now, by
changing this n so, I can use increase in from this to 256.

As the value of n increases, you will see that the duty cycle increases. And because this is being
done as a software program by writing an appropriate value of n, I will be able to change the
duty cycle from any value of n equal to 0 to n is equal to 256 and therefore, I get a range of duty
cycle which gives me a resolution that is I am able to resolve the duty cycle of 1 part in 256. This
is the variation I cannot if I want to make output to analog voltage smaller than this resolution,
this particular arrangement will not be able to do it, but 1 by 256 is the resolution into Vcc, into
Vcc is the kind of minimum voltage that I can generate out of such a waveform.

(Refer Slide Time: 9:05)

673
674
Let us see what kind of program we can write. so that we are able to generate this PWM signal,
what we are going to do here is we are going to apply this software generated PWM signal on to
the onboard LED of the lunch box. Therefore, you have to make any additional connections all
you do is understand this code, download this code, rebuild it and download it into your lunch
box.

When it starts working you will see that the intensity of the LED increases from minimum to
maximum it goes up then it falls like this. Then it goes up again and so on and so forth. This is
how it will appear. Let us go through this program. Now here to clarify, I have mentioned that
there is large delay the reason for this large delay is so that when you see This PWM waveform
being applied to the LED you can perceive you can easily see that the LED intensity is going
gradually from minimum to maximum and then it is decrementing from maximum to minimum
in the same at the same rate.

If we want to see this waveform on the oscilloscope we will have, will make some changes to the
code by reducing the delay time period. So, let us see the first part of the code is that we have
defined we have hash included the mandatory MSP430 header file. We have defined our LED to
be on bit 1 point, P 1.7. Then we have created this delay function which is nothing but it goes
through a certain amount of loop calling this sub routine where the variable is 50.

675
This gives you a certain amount of delay we will see how much delayed gives you and then this
is the main part of the program that is all you require this entire code is able to generate software
PWM in which it changes the duty cycle from 0 to maximum and then from maximum to
minimum and it repeats it. And so, the end result is when you download this code on the lunch
box, you will see that the LED on the lunchbox the intensity of the LED goes from minimum to
maximum gradually and then in the same graduality it drops from maximum to minimum.

So, what we have done is we have as is mandatory when we are not using the watchdog timer we
are turned off the watchdog timer. We have set the LED which is connected we have set the pin
to which the LED is connected that is P 1.7. We have set the direction to be an output pin and
then we enter into a infinite loop here. We have infinite loop. What are we doing in this? We
have a variable J, which is going from 0 to 256.

And for that period for that loop, it turns the LED on here we are turning the LED on, then it
goes to execute a delay subroutine equal to the value of J. So if the value of J initially is 0, it is
not going to execute that delay subroutine. On the other hand, if j is any non 0 value, it is going
to call the sub routine delay with the variable j. That means, if j is 1, it is going to go back into
this and it is going to loop through this ones.

If j was 2 it is going to loop through it, loop through it twice, and so on. So it is going to turn the
LED on for a certain period of time from time t equal to 0 to multiples of this basic time period
into the value of j. And so what you will see is that the LED is for certain amount of time and for
the rest of the time that is 256 minus this count is going to keep the LED off, we are turning the
LED off here and then we are delaying for how much time 256 minus j and we are going through
this loop by changing the value of j from 0 to 255.

So, what should you see that you will see that the LED intensity goes from minimum to
maximum, then once this loop is over, it enters into the second loop here it decrements the value
of j from 255 till it reaches 0. Now the duty cycle we will see goes from maximum to 0 and then
this loop repeats. Now, based on the duty or the delay cycle here you would expect a certain
amount of period.

676
The period of your PWM signal will be 256 into the delay period, delay time period, delay
function. This is the basic, this is the basic period of the period of the PWM signal. Now, this is
sufficient and suitable if you want to see the intensity of the LED, but if you want to observe it
on the oscilloscope, this may be too slow and therefore, what we have done is we have simply
recompile this code by changing the value of the delay cycle here from 50 to 1.

It is still going to call this function x number total number of 256 number of times for 1 period of
which certain amount goes for the time when the LED is on and the rest the LED is off or in this
case, pin is high and for the rest 256 minus that amount the pin is low.

(Refer Slide Time: 14:53)

677
So, what we do is we recompile this code now, you see the delay cycles we are invoking is just
1. This will lead to a certain amount of time period and let me show you the PWM signal you see
the time period of the PWM signal from, you receive from here, from here to here is as you see
here it is 1 kilohertz.

678
Now in this 1 kilohertz waveform, what are we doing that this 1 kilohertz waveform we are
repeating we are changing the value of duty cycle in every step from minimum to maximum in
256 steps and then from 256 to 0. So, therefore, there are 512 steps in the overall variation of the
duty cycle from minimum to maximum and from maximum to minimum. Therefore, what kind
of waveform of the signal that you expect the analog signal it will be 1000 hertz approximately
divided by 512 approximately you should get 2 hertz.

Let us see whether you get a 2 hertz signal or not. Now, as I mentioned to be able to get 2 hertz
or whatever signal which is being used to modulate this duty cycle, the frequency of your PWM
signal is here, this is 1 kilohertz and your message or the information which is modulating this is
somewhere here and you want to extract this. So, what you do is you apply a low pass filter you
pass this PWM signal through a low pass filter and the simplest low pass filter is a RC filter
which is like this.

(Refer Slide Time: 16:37)

679
680
If I take R and C this is R then C the product of RC this frequency that comes out of here 1 by 2
pi RC is the 3 db frequency equal to here in this case for 1.5 and 10 micro farad you get 10 hertz.
Which means of my, of my signal I have a something like this. So, this 3 db is 10 hertz here, but
my carrier frequency that is the PWM carrier frequencies 1 kilohertz as you see it is much higher
and my signal the signal which is modulating this is much lower as I mentioned, we estimate this
signal to be 2 hertz. It is very well within the pass band of the low pass filter.

So, if I apply a low pass filter to the PWM signal at this point I should be able to see the signal
going from 0 to maximum back to 0 and so on. And the period of that signal should be what we
are predicted to be around 2 Hertz that what we did was we took the output from P 1.7. Applied
external RNC as you see here this is the resistor here and this is the capacitor. This is 10 kilo
ohm, 1.5 kilo ohm in fact, as you see here 1.5 kilo ohm resistor and 10 micro farad in a
electrolytic capacitor the resultant was this frequency and here is the filtered output.

681
And as you see here, the time period is indeed 2 hertz that is the time period from here to here
this is the time period is 2 hertz and this matches exactly what we have been saying the
requirement is that there should be large gap between the PWM carrier frequency that is the
frequency of the PWM signal and the signal frequency which is your message and once that is
there, you can easily filter out the PWM carrier waveform by passing it through a low pass filter.

If the difference is not large then you will need a much sharper low pass filter which means you
will have to increase the order of this filter. We have already seen this how the duty cycle goes
from in this case 28 percent and 52 percent and 72 percent but the period remains the same
period remains the same, why? The sum of on time and off time is constant. Now, this is a
method, which uses a program to generate a PWM signal if we do that, then the microcontroller
is unable to do anything else.

And so, this is very useful only when this is the only thing your microcontroller has to do, but if
the microcontroller has to do multiple things, while generating a PWM signal, then the only way
you can achieve that is by outsourcing by offloading the job of generating the PWM signal to a
peripheral and in this case, a timer is often very useful for doing that. In fact, MSP 430
microcontroller time have specialized features which allow it to generate PWM all you have to
do is specify the duty cycle that you would want the PWM signal to operate at the frequency of
the PWM signal and the resolution.

682
(Refer Slide Time: 20:25)

Now you can control all these 3 things using the hardware PWM feature of MSP 430. Let me
repeat what can you do you can specify duty cycle you can specify the P the time period that is
the frequency of PWM. And 3 you can specify the resolution, resolution meaning what is the
minimum variation in the duty cycle that you can achieve in the entire period which means if I
have an 8 bit counter; my 8 bit counter has 256 possibilities.

So I can only change the duty cycle, 1 count in 8 bits, 1 count in 256 counts. On the other hand,
if I have a 16 bit if I have a 16 bit time counter, 16 bit, then I can still vary 1 bit, I can change the
duty cycle by 1 bit, but 1 bit out, out of how many 1 bit in 65,536. So, MSP430 allows you to go
all the way from any arbitrarily small range to a large range of 16 bits. Now here is the impact of
choosing or varying the resolution of the PWM signal.

683
(Refer Slide Time: 22:00)

If you choose a 8 bit, if you choose 8 bit PWM signal, 8 bit PWM signal. What that does
essentially is that, here is my PWM generator. PWM generator requires a clock the system clock
or the clock that is being fed to this generator in this case a timer. It will generate PWM, the
frequency of PWM will be equal to F clock that is the frequency of this clock signal divided by 2
raised to power n, where you are chosen a n bit PWM.

So, if n is 8, and let me take an example let us say the clock is as we know the default clock
when you run your timer when you run your MSP430 the default clock at which the CPU starts
working on the same clock can be fed to the timer is 1.1 megahertz then what happens is you
have 1100 kilohertz divided by 256 is the frequency of the F PWM will be this and this will be
roughly 4.3 kilohertz.

Now, the PWM frequency needs to be very high, why? So that it can keep you can keep a
distance between the signal frequency, the frequency of the signal of interest, the message
frequency and the carrier frequency. The frequency of the PWM signal is what we call as the
carrier frequency. You want to have a large gap between the two why, so that a reasonable filter
can remove the carrier frequency and so that you can extract the analog voltage and therefore, it
is very important that we should be able to have a high frequency of PWM signal.

684
But the PWM frequency is largely determined by this system frequency that is the frequency at
which the timer is being clocked. And as you know, I can change the I can dynamically change
or I can at reset I can decide to have an arbitrary value of the clock frequency, the default is 1.1
megahertz, but I can change that and I can use the DC and use the DC to generate a M clock and
SM clock the 2 clocks which are used by the micro controller and I can go from 1.1 megahertz to
16 megahertz.

(Refer Slide Time: 24:51)

So, if I have if I choose to have a 16 megahertz clock and now if I choose to have a 8 bit PWM,
what will I get? 16 megahertz divided by 256 will give you roughly 16 times more frequency
than the 4 kilohertz that you have got, you are getting about 4 kilohertz when the signal clock
frequency was 1.1 megahertz, now it has become 16 times more therefore, this will lead to
roughly 64 kilohertz, PWM signal, f PWM for 8 bits.

Now, if I want higher resolution, let us say I want a 16 bit resolution, then what I can do is I can
still choose to have the highest because I cannot go beyond 16 mega hertz on the MSP 430​G
2553 and G Series of microcontrollers. But 16 megahertz divided by 65536, this will roughly
give you, let me calculate here for you, it will give you roughly 240 hertz PWM carrier
frequency.

685
And so, in many cases this could be sufficient. If not, you can trade the resolution you can
choose to have a low resolution instead of 16, this is a 16 bit resolution, instead of 16 bit
resolution you can go for it to 12 bit resolution 12 bit will give you 2 raise to power 12 which is
4096 and therefore, you will get roughly 16 times this frequency about 3, 3 and a half kilohertz
PWM frequency.

So, you can using the keeping the constraint of the clock frequency in mind, the system clock
frequency in mind and the resultant PWM frequency you can choose to have higher resolution or
a lower resolution, but be aware that it is going to impact your carrier frequency of the PWM
signal and if for a given application the carrier frequencies sufficient and suitable, why not, you
can choose to have a higher resolution.

(Refer Slide Time: 27:24)

686
If not, you can give up the resolution choose a lower resolution and have a higher frequency of
PWM signal. So, let us see how the timer functions, timer modes allow us to generate the PWM
signal. For that, please look at this block diagram of the timer as we saw in a previous lecture on
the timer operation, it consists of many parts the most important part is the timer, which in this
case is a 16 bit timer MSP 430 timers are all 16 bit timers.

The source of the clock for these timers can be through many of the input signals input signal
which is available from 1 of the pins or a clock which has which is internally generated as you
see, you can choose the a clock Aclk or the SM clock to be the source for the timer the counting
purpose. Now, you can you also know that the timer has a control register through which you can
choose the mode of the timer in though there are 4 modes 1 you can stop the timer you can make
it go in the up mode or you can go it in the up down mode or you can make it go in the
continuous mode.

Now, based on that the count the timer will go from 0 to the maximum value. If it is the
continuous mode the maximum value is the maximum value of a 16 bit number which is FFFF.
On the other hand, in the other 2 modes, that is the UP mode and UP DOWN mode you have the
maximum value that the timer will count up to will be determined by the control capture register
are 0. Alright?.

687
So it is going to go count up to that and maybe it will come to 0 in the UP mode or from that
value it will decrement to 0 1 bit at a time that depends on the mode of the timer. Now, that timer
values available on the output bits of the timer 16 bits. They can be compared to a register whose
value is in timer compare registers R2 or for that matter R1 or it could be captured into this or it
could be compared with a value which is stored in this these registers

So, there are 3 channels, channel 0 is special, but channel 1 and channel 2 can be used to capture
the value of the timer or the captured value could be compared with a value stored in those
registers. And using that, in the last exercise when we looked at the timer what we saw that using
this we were able to generate interrupts. So, that we knew we from the time that we started the
timer we wanted an interrupt after a certain period of time.

And once that interrupt was generated we restarted the timer and so on. Now, in this case, what
we are going to do is that we can actually do more actions on the compare functions. Once the
value is compared, you can decide what you want to do, and we want to send the compared
output to output pins and this is the way that we will be able to generate a PWM signal. Let us
see how that works.

688
(Refer Slide Time: 30:46)

So, the timer A output unit has a capture compare block which contains an output unit, here is
the output unit, this part this is the output unit of the timer the compare mode is selected when in
the timer control register you have you set the value of CAP equal to 0. If CAP is 1 then it goes
in the capture mode, we are going to consider the capture mode in a subsequent lecture. When
the timer value is equal to value in the TACRRx, which is 1 of the internal signals, the EQUx
meaning if this is the TACCR1 then you are going to talk about EQU1 will be set which affects
the output according to the output mode.

689
Similarly, the output unit is used to generate output signals such as PWM using another mode.
Each output unit has 8 operating modes that generate signals based on the EQU0. On the EQU0
and EQUx signals EQUx here is either 1 or 2. The output modes are defined in the out mode bits
in the timer control register.

(Refer Slide Time: 32:09)

Let us see what are those output modes before that as I mentioned, the timer itself can be
operated in 4 modes and this is programmed in the timer control register you can stop the timer
you can make it function in the up mode in the mode the timer counts from 0 to a value stored in
TACCR0.

So, TACCR0 is a very special register, therefore, that is that cannot be used in PWM signal
generation R1 and R2 in some cases R2 can also be used. TACCR0 is used to store the value
with which the timer value will be compared. In the continuous mode it will go from 0 to a
maximum value that a 16 bit allows and in the up down mode it will go from 0 to the value
stored to this and then from here it will decrement to 0.

And so, in the up mode, the waveform is more like this in the up down mode it is like this. So
you get a saw tooth waveform of comparison in the mode and in the up down mode you get a
triangle waveform.

690
(Refer Slide Time: 33:19)

Here are the output modes if the output mode bits are 000 this is called the output mode and the
out signal will be immediately available on that pin. You can have the set mode you can have
toggle reset, but the 1 that we are interested in is the combination which is 111, in which the bit
is reset to 0 and then is set to 0.

691
When is it reset? The output is reset when the timer counts to the value stored in this and this is
for example, TACCR1 and it is set when the timer counts to value stored in TA​CCR0. So using
TACCR​1 and TACCR​0 using this mode, which is the reset set mode you will be able to generate
a PWM signal.

(Refer Slide Time: 34:12)

So let us look at that what happens. So you are you are chosen the up mode in which the value is
going to go from 0 to the value stored in TACCR​0.

When it matches the value of TACCR​1 here, this is the seventh mode, the output toggles and
then when it reaches this value it is set. So it is going to remain high for the time for the count
stored in TACCR​1, and for the rest of the time it is going to become 0. Therefore, by changing
the value of the count stored in TACCR​1 of any number from 0 to TACCR​0, you are able to
change the duty cycle from 0 to 100 percent.

The TACCR​0 itself can be modified and if you modify it, it will change the period overall period
of the PWM signal and that is what 1 means when you say that you are able to change the
resolution. So, if I choose TACCR​0 value to be the maximum value that is 65536 there is a
resultant resolution will be 16 bits. On the other hand, if I said TACCR​0 to 256 that means the
resolution of the PWM signal will be 8 bits.

692
We are going to use this mode we are going to load values in the TACCR​0 and TACCR​1 register
appropriately to generate similar waveforms that we generated in the software PWM mode.

(Refer Slide Time: 35:49)

693
Now, if you want to use the timer for PWM, the output signal can be routed on any given pin. In
this case we will route the pin on this P 1.6 that is TA 0.1. And let us see how we do that. These
are the pins which are associated with the timer A0 input and output pins we are interested in
this.

We are going to use CCR 1 here we are going to store the compare the value which will
determine the frequency of the PWM signal and this will give us output on P 1.6. You can also
route it to P 2.6 or you can route it to P 1.2 you can do that.

(Refer Slide Time: 36:49)

694
If on the other hand you are using timer 1 for PWM, then you have the timer CCR 1 available on
P 2.1 or P 2.2. Here it is P 1.6 which is pin number 14 and these are for 20 pin ICs which is the
ones we are using on our lunch box.

(Refer Slide Time: 37:14)

Now, to be able to tell the microcontroller because you see you are going to use P 1.6 which is
otherwise input or output pin export 1 bit 6 you want to use it for timer function that is PWM
function. So, you must tell the control registers associated with the port 1 that you want to use
this pin as a PWM signal and for that, what we are going to do is for this pin, we are going to
invoke this function so, in the P 1 register it is 1 so that it is an output. P 1 select we will write 1,
P 1 select 2 we will write 0 and for the rest of them we will write 0.

And so, you must program the ports associated with P 1 point port 1 in this fashion so that P 1.6
can act as a PWM output signal associated with timer 0.

695
(Refer Slide Time: 38:20)

These are the registers associated with timer A we have already seen that in the previous lecture,
so, I am not going to repeat that you will see it when we look at the code.

(Refer Slide Time: 38:31)

Now, to use the PWM signal or using a timer, you have to do various steps. You have to
configure the timer in up mode. The timer value goes from 0 to the value stored here and it
repeats. In up mode the up mode is selected by OR​ing this, this is a mask to the timer control
register another step the value of this is filled and this will determine the frequency or the period

696
of the PWM signal. And then you write a value in the CCR 1, which will decide the on time that
is the duty cycle of the PWM signal.

(Refer Slide Time: 39:16)

And last but not the least, you must tell the port that you want to route the output signal, you
want to select the output mode 7 and you want to route it into the P 1.6 pin. Now, here is an
example what will happen that when the counting starts the output will become high and it will
remain high till the counter value reaches TACCR​1, then it turns low, and it remains low till it
reaches the value of TACCR​0, and then the cycle repeats.

Now as you can see, if I increase the TACCR​0 value, it is going to increase the period that but it
will give me higher resolution. If I reduce it, it will reduce the period meaning it will increase the
frequency but it will also reduce the resolution.

697
(Refer Slide Time: 40:10)

In our lunch box, we do not have any LED on the PWM in on P 1.6. As you know we have LED
on P 1.7. But unfortunately we cannot route the PWM output on P 1.7. So, we have to connect an
external LED we with a series resistor to P 1.6.

(Refer Slide Time: 40:32)

Here is the code we have decided we have connected a LED to P 1.6. These are the resistors, this
is a subroutine which we are going to call for timer 0. We are selecting the LED as output and

698
we are selecting the timer output on this. And then we are setting a value in CCR 0 equal to 255
which means we are choosing a 8 bit resolution.

We are choosing mode 7, output mode is mode 7. The value in CCR1 resistor is initially set to 0
which means initially the duty cycle will be 0 and the as interrupt is enabled. So, that after every
compare, after every P time P 1 period of PWM signal will have an opportunity to either change
the value of CCR1 or CCR0 if you like. So, we have enabled the interrupts and we are using the
timer clock, getting the timer clock from SM clock and the mode is in the up mode.

(Refer Slide Time: 41:45)

Here is the main program, we have simply turned the watchdog timer off, we have called that
function which we have just discussed and we have enabled the interrupts and we are just
waiting in a infinite loop. Now, every time the timer overflows that is when it reaches the
TACCR0 it will generate an interrupt and it will go into this. Where what we are doing is we are
simply incrementing the value of CCR1.

And so, CCR1 as we saw CCR1 started with 0, it will keep on incrementing because of this but
the moment it reached 256 we want to make it 0. So, if after incrementing value as 256 make the
value of CCR1 equal to 0, which means the value of CCR1 will go from 0 to 255. And when it
goes when it is 0 the duty cycle will be 0, when it is 255 the duty cycle will be 100 percent. And

699
once you run this program you will see that the intensity of the LED goes from minimum to
maximum abruptly going to 0.

So, that the intensity will give you a saw tooth waveform because of this.

(Refer Slide Time: 42:57)

Here is the filtered output. Since we know that we are the DC frequency is 1.1 mega heartz and
we are choosing the 8 bit resolution the resultant frequency will be about; here is the PWM
signal, it will be about 4.3 mega, kilo hertz which we just calculated. And because there are 256

700
levels, so, 4.3 kilo hertz divided by 256 will give you the resultant signal which as you see here
is 16 hertz, 16, 17 hertz.

And this value has been obtained, this signal has been obtained by filtering the PWM signal. This
is what being generated by microcontroller by itself, this is the result of the filtered output and
the filter characteristics is that it has a frequency of, cut off frequency of 154 hertz because of
these values involved and this is much lower than the PWM signal frequency. Therefore, the
PWM signal will be filtered out and it is much higher than the message that is the signal
frequency. Therefore, that saw tooth waveform will flow easily out of it and that is what you see
here.

(Refer Slide Time: 44:17)

Here is another program in which certain things are done, 1, the DCO frequency has been jacked
up from 1.1 mega hertz to 16 mega hertz, rest everything is changed apart from instead of 8 bit
PWM we have chosen 16 bit PWM. I strongly recommend you go through this program and see
the output.

701
(Refer Slide Time: 44:33)

702
Now, you see because the 16 mega hertz frequency is used divided by 65536 will give you
PWM, basic PWM frequency of just 236 hertz and this if you further divide by, if you are going
to change the duty cycle all the way from 1 to 65536 will give you a frequency which is 234, 236
hertz divided by 65536 will give you a very very small frequency and that what you can see here.
The frequency is 3.56 mili hertz and this has been obtained by putting a RC filter, low pass filter
of just 3.28 hertz.

So, I strongly recommend that you go through this program and understand how a high
resolution PWM based on the hardware feature has been generated using this microcontroller. I
thank you for listening to this, I hope it opens your mind as to how a digital signal of the type
called PWM can be used to generate all of waveforms. You can use the same feature to generate
arbitrary waveforms, you can create sine waves, you can create cosine waves, you can create sine
and cosine together.

703
(Refer Slide Time: 46:00)

Something like this, suppose I want a sine wave here and I want cosine wave say something like
this. So, this is 0 and this goes let me try it again. So, let us say this is a sine wave and you
wanted another waveform which is synchronized with this but something like this. So, you can
easily create two waveforms which are matched locked to each other used under the control of
the microcontroller you can easily do that using a PWM function.

704
I am going to put up some exercises for you so that you are able to generate such waveforms
using the PWM function. Thank you very much.

705
Introduction to Embedded System Design
Professor Dhananjay V. Gadre (NSUT)
&
Badri Subudhi (IIT Jammu)
Indian Institute of Technology, Delhi
Lecture 31
Analog to Digital Converter in the MSP430

Hello and welcome to a new session for this online course on Introduction to Embedded System
Design. I am your instructor Dhananjay Gadre and in this session we are going to talk about
another important aspect of embedded system that is the ability to read external analog voltages.
And to be able to do that, we need to have the support of a peripheral which is often available on
most modern microcontrollers that is the analog to digital converters.

Now why do we need ADCs? ADC means analog to digital converter. Why do we need them?

(Refer Slide Time: 1:01)

706
We need them because the world is analog which means the values that surround us, the features
that are around us, they are all changing their parameters continuously. They can take any
arbitrary value. Information like temperature or pressure or distance or light intensity as we have
seen, they are all continuous in nature. And so we need to convert that continuous voltage
continuous parameter into discreet numbers discreet values.

Examples of sensors which provide continuous values are for using a Potentiometer or Light
dependent resistor or negative temperature coefficient thermistor, load cell, microphone there are
so many. Now problem is that the CPU cannot read analog values, it can only accept digital
numbers 0s and 1s. And so we need a mechanism to convert these analog inputs in digital value
and that is where an ADC comes into use. So that is the justification for having an analog to
digital convertor mechanism connected to the micro-controller.

(Refer Slide Time: 2:27)

This is how ADC works. You have the analog signal in the form of the output of a particular
sensor or a voltage. You need to sample it that is you decide at what point of time you want to
look at this value. Now the input is asynchronous, meaning it can change whenever it wants to
but while the conversion process from the analog voltage into a digital number is in process, you
do not want the input voltage to change. So you include a circuit which can hold the value of the
analog voltage to a fixed value to that value when you start the conversion and hold it till the
conversion is over, such a circuit is called a sample and hold circuit.

707
Then, once you have started the conversion and you convert it, you quantise it into a discreet
number and you encode it meaning assign a digital code to this quantized number. And once that
is done the analog voltage which started from here is available as a digital signal ready for the
micro-controller to be processed or stored or whatever else you would want to do.

(Refer Slide Time: 3:48)

Here is a Sample and Hold Circuit. You have an analog input; you can pass it through an
operational amplifier which provides very high input impedance using a switch, when the switch
is closed it will charge its capacitor but when you open the switch the capacitor will hold the
value to which it was charged. And as long as the input impedance of the subsequent amplifier is
very high the capacitor is not going to discharge. Therefore, it will hold the voltage to a fixed
state fixed value for the ADC to complete its function.

Quantisation, this is the next important step. After the sample and hold process which we have
seen, the signal becomes discreet in time, meaning it has been held to a value but it is still
continuous in amplitude meaning the value could have been any value in the range that is
acceptable. You need to have a reference voltage against which this analog voltage will be
compared and will be divided in small discreet steps and from there on it will be converted into a
number.

708
(Refer Slide Time: 5:06)

This is where the encoding comes into picture, the process of assigning a binary code. Do you
want it to be linearly converted or do you want it to have a non linear function or do you want to
have a 2’s complement. All this you can include in the encoding function of the ADC.

709
(Refer Slide Time: 5:23)

There are many types of ADCs, depends on the kind of functions that you want to perform that is
the kind of input that you have, the kind of speed that you want with the ADC because ADC is
not a very fast process. It takes some time for the sample and hold and rest of the circuit to
operate. And therefore, each type of ADC has a specific application. The simplest of the ADC is
called a Counter ADC, Counter-Type of ADC which we use as a counter and a comparator to
convert the analog voltage into a number.

The most common ADC is called Successive Approximation Type of ADC and the ADC that we
have on MSP430 is actually a Successive Approximation Type of ADC SAR. Then we have a
Dual Slope it is also is a counter type except now you use two slopes, one where you are
charging the voltage to the input value and then from the input value you discharge to a non
reference value.

Then you have very fast ADCs of the type called Flash ADCs. In fact, the most common use of
ADC is that you would notice that in your engineering life would be in the use of a digital
storage oscilloscope. A DSO is a digital device but the voltage is that it is able to sample are
analog in nature. And therefore at the front end after you have your amplifier you have a ADC
and the ADC you have in these DSO are f the type called Flash ADC. The reason why they are
called Flash is because they are very very fast.

710
But because they are very fast the kind of fastness comes from the architecture of these ADCs,
they consume a lot of power. And usually these ADCs offer a resolution from 8 to 10 bits but
they offer blistering speeds. For example if you look at the front panel of the DSO it would say,
for example the one we had in our lab says 1 GSPS. This stands for one giga samples per second,
this is the kind of ADC that we have on these modern digital storage oscilloscopes.

And then the next type of ADCs that we have is called Sigma-Delta type of ADC. They are used
in voice encoding. So these are the various types. But since our micro-controller is a general
purpose microcontroller, is not specifically useful for high speed conversions. The ADC that it
has is a SAR type ADC. So we are going to look at ADC in this context.

This is a ADC where you do binary search, compare analog voltage that is applied to the ADC
with binary with a voltage generated through a binary number. And when the number matches
then you stop the conversion. You can go through this slide to go through the entire conversion
process.

(Refer Slide Time: 8:34)

This is the block diagram of the SAR type of ADC. SAR type of ADC requires a clock, so you
need to decide what type of clock source are you going to use in your MSP430 ADC. We have
option of a lot of clock sources. You also need a reference voltage against which the values will

711
be compared in this comparator. Here is the input voltage held to a value using the sample and
hold circuit ad when that value matches then you stop the conversion.

(Refer Slide Time: 9:10)

Now these are the features of ADC on the MSP430, we call it ADC10. The reason is that
resolution of ADC is a 10-bit resolution, which means from the entire range of input voltages
that it can accept, the range is divided in 10-bits and therefore the number of levels that you have
from the minimum to maximum is 2 raised to power 10 which is thousand twenty four discreet
values.

The ADC on the MSP430 offers quite a fast conversion speed. These conversion speeds are up to
200 kilo samples per second, of course these is very small compared to the ADCs that are
available in digital storage oscilloscopes as I mentioned, they offer speeds up to one giga
samples or more giga samples per seconds.

The module implements at 10-bit SAR and it has a mechanism to select the input channel
because in this case you do not have multiple ADCs on your micro-controller. You have only
one ADC but you have a analog multiplexer which allows you to select a particular source of
voltage through the analog multiplexer and use the common ADC feature to convert that voltage
and then you can change the multiplexer and convert another voltage.

712
The reference, the converted value is handled by a data transfer controller called a DTC. The
DTC allows the samples to be converted and stored anywhere in the memory without the CPU
intervention. So your program simply instructs the ADC which channel you want to convert and
where do you want to store the results.

The DTC will take care of it. You can do up to eight external input channels you can convert
voltages on eight external inputs, of course not simultaneously but in a sequential or serial
fashion. You can through software select the reference voltage, the MSP430 micro-controller
offers on-chip reference voltage which you can select to be of 1.5 volts or 2.5 volts or if you
want you have a special requirement you can provide external voltage reference also through a
available pin.

And the ADC core that is the peripheral which controls the ADC and the reference voltage can
be powered down meaning you can enter a low power mode so that these peripheral devices do
not consume power.

(Refer Slide Time: 11:46)

Here is the block diagram of the ADC. This is the core part of the ADC here, this is the actual
convertor. Here is the analog multiplexer that allows you to select so many input channels. Here
is the part which allows you to select the reference voltage. You can have an internal reference
voltage of 1.5 or 2.5 volts. You can have internal, interestingly MSP430 has an internal

713
temperature sensor and the output of that temperature sensor can also be routed through the
multiplexer into the ADC so that you can determine the temperature of the micro-controller, the
temperature of the chip of the micro-controller.

And you can also have, read the voltage through the divider here. Now, once the ADC converts
the value it is sent to this ADC10 memory from where it can decide to send it to appropriate
memory location so that the processor can implement a new conversion. So this is the basic
block diagram of the ADC that we have on MSP430.

Refer Slide Time: 13:05)

The ADC core converts analog voltages using a 10-bit representation. The reference voltage as
we have discussed can be selected by the user. The digital output full scale is when the input is
higher or equal to the positive reference voltage and a 0 when it is 0 or equal to or less than the
negative reference voltage. In this case it is 0.

The conversion formula for the binary format of the number is this that is the N bits that you will
get, the value of the 10-bits that you will get will be represented by this information. Here is the
input voltage and here is the reference voltage with which it is being compared. The clock that is
the rate at which the comparison will be made in this successive approximation register module
of the ADC, the clock source can be selected from a variety of sources. And this is available
through these registers through these bits.

714
And the sources could be SM clock, M clock or A clock and you could also have an extra
internal dedicated oscillator called ADC10 oscillator.

(Refer Slide Time: 14:30)

The ADC on MSP430 offers multiple ways of conversion. One of them is that you can do a
single channel conversion or you can do sequence of channels meaning you can do channel
1,2,3…1,2,3 like that. You could repeat a single channel that is selected channel you can have
continuous conversion or a sequence of channels you can do repeat of conversions on those
channels.

715
(Refer Slide Time: 15:02)

These are the registers associated with the 10-bit ADC. You have the control register 0 which
selects the reference voltage, the sample time and it also allows you to generate interrupts once
the conversion is over. So that your micro-controller can keep on doing something whenever a
conversion on the selected channel is complete, the micro-controller the ADC module will tell
the micro-controller that the conversion is complete and please look at the numbers and do
whatever you can with it.

You have another control register 1 which selects the input channel, the format of the input data,
the clock source and the divider. Then you have the analog ADC 10 analog enable 10 control
register 0 which is used to select analog inputs A0 to A7. And control register 1 which allows
you to select inputs A12 to A15. And this is only available for devices which have those
additional pins.

716
(Refer Slide Time: 16:08)

Then you have ADC10MEM register which allows you to store the result in binary or 2s
compliment format as selected in the control register. This ADC10DTC0 is date transfer control
register 0 which selects the mood of the conversion control, the transfer control.

ADC10DTC1 selects the DTC transfer whether it defines the number of transfers in each block.
And then the start register once you have start register address, once you have started the
conversion and you want to convert a whole set of numbers where do you want to store them
because if you overwrite a memory location then there is no point in having a series of
conversions.

So you have you can define the start address and it will convert the first value and store it at the
start address and the next address and so on. These are the registers and the memory locations. I
strongly recommend that you go through these slides so that you understand that this is nothing
but a repeat of what I have just gone through. Now what we are going to do is we are going to
look at the few exercises so that you can get familiar with the whole process of initializing the
ADC, selecting an appropriate channel, selecting the clock for the conversion and once the result
is available what do you want to do with that result, you want to store it in the memory location
or do you want to send it to some output port or change the duty cycle of a timer for that matter.

717
(Refer Slide Time: 18:03)

So we are going to look at some examples. In the first example the code example we are going to
read the analog voltage connected using this mechanism where we have connected a
potentiometer. And the central tap of the potentiometer we have connected to the P1.0, we will
ensure that the P1.0 becomes an ADC input. And the result of the ADC will be used to send to
LED connected to P1.6, remember P1.6.

718
(Refer Slide Time: 18:28)

So this is what the definitions are, you have decided that you are going to connect a green LED
to bit 6. You are going to have ADC on bit 0. Then we have a map function, we will come to this
later.

719
(Refer Slide Time: 18:44)

Here are the register settings for ADC 0. What are we going to do, we are going to use P1.0 for
ADC input and we are going to use Vcc as the reference and we are going to use 64 clock cycles
for sample and hold. This allows the values to be stabilized. Then for the timer 0 we are going to
connect the timer output to P1.6 and we have selected P1.6 as the output and we have selected to
be timer output.

And we have CCR0, you may recall that in our previous discussions we discussed that CCR0
decides the resolution and the time period of the PWM signal. So we have decided CCR0 value
to be 255 which means we have chosen 8-bit ADC, 8-bit PWM. The we are choosing the output
mode to be output 7 which means PWM output and the initial value of CCR1 is 1. And the clock
source of the timer is going to be SM clock and it is going to operate the timer in the up count
mode.

720
(Refer Slide Time: 20:10)

Here is the main code, as usual we have stopped the watchdog timer and we have called this
function for register setting for the ADC and register setting for the timer 0. And then we simply
enter infinite loop in which we read the value of the ADC and once the ADC tells that it has
completed the conversion we simply call this map function.

Now the ADC result is a 10-bit value but our PWM requirement is 8-bits. So we have to map 10-
bits to 8-bits. Instead of doing the bits yourself, we call this map functions. So basically it does 0
to 1023 values the output of the 8-bit, 10-bit ADC be mapped to 0 to 255. And the best way to
think of it is imagine that out of those 10-bits the least two bits are thrown off that is how you
can map very easily a 10-bit number into a 8-bit output. And so what you should see when you
compile and output load this into your lunchbox.

Let me correct myself here LED is connected to P1.6 which as you recall in our previous
exercise I not an onboard LED, onboard LED is on a different pin.

721
(Refer Slide Time: 21:44)

Here an onboard LED is on a pin which does not have a PWM function. We have connected the
LED to P1.6 which I connected to here so you need a bread board to connect a LED. Here is
another bread board connection which allows you to connect a potentiometer to an appropriate
pin as discussed earlier to the ADC input. Now when you move the potentiometer from
minimum to maximum, you should see that the LED intensity goes from off to fully lit condition.

And you will see the intensity of the LED can be changed by changing the potentiometer setting.
So this is the objective of the code. Is strongly recommend that you download this code, build it
and send this code into the memory of lunch box and make this connection on the bread board to
see the impact.

722
(Refer Slide Time: 22:35)

Now we have another variation of the same code not much is changing here except instead of
modulating the PWM duty cycle we are just printing the value as read by the ADC and printing it
on our LCD. We already covered LCD, so you know how LCD can be connected to the MSP430
lunchbox. In this case the ADC is still connected to P1.0; these are the same connections that we
considered last time when we were talking about the LCD. So those connections remain the
same.

Here is the code, I am not going to go through that code this is nothing but a mix of code for the
previous exercise of reading the ADC value of the connected to the potentiometer and changing
the duty cycle instead of changing the duty cycle now we are outputting a number onto the LCD.

723
(Refer Slide Time: 23:35)

Here is the display that you see, it has been converted into a voltage instead of the binary number
it has been converted to a voltage. So you should see the voltage going from 0 to 3.3 volts
because we are choosing the reference to be 3.3 volts which is the power supply voltage.

(Refer Slide Time: 23:48)

Now in the block diagram of the ADC you saw that the ADC also has an input from the
temperature sensor that is on-chip temperature sensor and we can modulate the ADC control
registers so that we can select that channel which is connected to the on-chip temperature sensor.

724
So in this third code example what we are going to do is read the value, convert it in the formula
that is given here recommended in the application note and user manual of MSP430 and the
number that you get out of that ADC can be directly mapped to the actual temperature. These are
the formulas that you have.

(Refer Slide Time: 24:46)

And once you understand this code, build and download it into the MSP430 lunchbox, what you
would see is that the display would tell you the temperature at which the MSP430 is currently
operating at and you can see the impact of it by trying to cool it or maybe you connect your you
know the soldering iron gently onto the MSP430 IC and you should see this temperature reading
changing. This is the current temperature when this experiment was being performed; this is the
temperature of the IC at that point of time.

So I strongly recommend that you go through the codes, the three codes that have been discussed
here. The first one was to read the value of the potentiometer and change the duty cycle of the
LED connected on P 1.6. In second code example we took the value coming out from the
potentiometer but instead of manipulating anything else we started displaying it on the LCD.

And in the third code example what we did was, we took the instead of reading the voltage from
an external source we use the internal temperature source to feed the ADC, converted the values,

725
applied these equations to convert these numbers into temperature and then printed the value
onto the LCD display.

So this will give you a brief outline and idea about how to use the ADC and how to convert
analog voltages connected to the ADC input of the MSP430 and use them in any which way.

(Refer Slide Time: 26:29)

Now one every important point I want to make here is that in many of the cases that you have
here, let us draw a block diagram. So here is your source of analog voltage which could be a
microphone or it could be a temperature sensor or it could be any other source. You should not
connect, let us say this is our MSP430, and let us say this is the ADC input. It is not
recommended that you convert; you connect the output of this source directly reason being
depending upon the rate at which the source voltages may change.

Although you are saying that your sample and hold is going to hold the value it is still
recommended that you incorporate a filter, a low pass filter in this and this low pass filter is often
called Anti- aliasing filter, such that the conversion rate that you hope to have in your ADC the
input source remains much lower in frequency compared to the conversion rate. And in our
previous examples because the input voltages are not changing that much fast, we did not
incorporate such a anti-aliasing filter.

726
But an anti-aliasing filter is nothing but a low pass filter which can make out of using the R and
C. And the requirement is that the this filter will be less than much less than half the conversion
rate.

So to take an example, suppose your ADC is going to convert at ten thousand samples per
seconds. Now because of the nyquist rate, we require that the input to the ADC should never the
frequency of the input connected to the ADC input should never be more than five thousand
hertz, five thousand times or seconds, it should not change. And therefore this filter should, the
low pass filter should have a bandwidth of five kilo hertz less than five kilo hertz.

So the input should never exceed that, so you should always include a low pass filter to serve as
an anti aliasing filter. In our case in the input filters we saw, a potentiometer or an internal
temperature sensor it is not going to change so fast because we are converting the ADC at a
much higher rate. Therefore, we are not bothered about having an external anti aliasing filter but
wherever you expect that the input frequency could go higher, you need to remove those
elements from the spectrum so that the ADC can perform as per the nyquist rate.

So having an anti-aliasing filter is very important. And I hope that in any application where you
expect the input source to have a component which is exceeding the nyquist rate, that you would
cut down the source using a low pass filter to conform to the nyquist rate. So I hope that this
lecture has introduced you to the great feature of 10-bit ADC that we have on MSP430.

It offers so many input channels; it also has an internal temperature sensor as an input to the
ADC, an internal resistor divider which allows you to read the live voltage that is available on
the MSP430 that powers the MSP430. You can read that through the ADC. I hope you will play
with the ADC features and find how any various ways external signals you can convert using the
ADC of MSP430.

In one of the next lectures we are going to not only look at some applications of the ADC by
converting voltages being produced by thermistors but we are also going to use the ADC as the
mechanism to give us random numbers or at least the seed for a random number. We are also
going to consider how MSP430 can be programmed with additional hardware to produce analog
voltages.

727
In this case we have seen how MSP430 can read analog voltages but we also need to generate
analog voltages. We have already seen one mechanism which is using the PWM and using the
low pass filter. But we will see additional mechanisms by which we can generate analog output
voltages.

So I will see you very soon in a new lecture. Thank you. Bye bye.

728
Introduction to Embedded System Design
Professor Dhananjay V. Gadre
Electronics and Communication Engineering
Netaji Subhas University of Technology
Badri Subudhi
Electrical Engineering Department
Indian Institute of Technology, Jammu
Lecture 32
ADC and DAC using R2R Ladder and Random Number Generation using LFSR1

Hello and welcome to new session for this online course on Introduction to Embedded System
Design I am your instructor Dhananjay Gadre. In this session, we are going to consider
remaining topics related to analog and digital converter and the ability of the microcontroller to
read and generate analog voltages.

We are also going to consider how the microcontroller can generate random numbers and a little
bit part about one of the experiments that you previously saw that we did which was to power
MSP-430 microcontroller using a lemon battery invoking the low power modes I am going to
show you little more details about it.

(Refer Slide Time: 01:18)

So in this lecture we are going to talk about first of all the random numbers generators. Now
random numbers are very important for embedded applications. A random number generator
produces a random number which cannot be reasonably predicted part from being by random

729
chance. These can be true hardware based random number generators although there are no true
random number generators all mechanisms are some sort of pseudo-random number generators.

You can do that using hardware approach or you can utilize some software approach. We are
going to discuss both these methods here.

(Refer Slide Time: 01:55)

Now what are the applications of such random number generators? You would use it in computer
stimulations, you can also use it for gambling, you may have seen that one of the projects that we
demonstrated in the second lecture was dice. And for that we use some sort of random number
generator. You could use it in cryptography and many security applications and there are many
such applications.

730
Now what are the various methods by which you can generate such random numbers? One is
using a noise because noise is random, so if you sample that noise you would get a value which
is random and therefore this could be a source of your random number.

(Refer Slide Time: 2:51)

You could use for that noise source you could use a high value resistor, you could sample
external sound and so on, another source of such hardware noise is through a Zener diode, you
could use a switch to stop high frequency counter, the value in that could be random if the switch
press is asynchronous event that is a human has pressed it you can use a interesting topology
called a linear feedback shift register.

We are going to dedicate few slides on describing what a linear feedback shift register is, we are
going to show couple of experiments how we can use LFSR to generate pseudo-random numbers
and at the end you can also use built-in random function that many embedded C compilers
support.

731
(Refer Slide Time: 03:33)

Now a linear feedback shift register is a shift register basically it is a whole few D-type flip-flops
which the output of one feeds the input of the second and so on. And then the last one is fed back
into the input. The of course, you just do not connect it like that, you operate on the outputs in
some way and the linear function could be through a EX-OR or EX-NOR gate. Now because
these are flip-flops you need to initialize them with some value when you turn the power on and
that value is called the seed value.

732
(Refer Slide Time: 04:13)

The linear feedback shift registers work on the principle that if you have n-bits of flip-flop then if
you chose these feedback functions appropriately you could have in principle 2 raise to power n
minus 1 combinations, so this is just like a counter when you have n bits of D-type flip-flops you
can generate 2 raise to power n combinations except in a counter these are always you know
either it is increasing value or decreasing value, up counter or down counter.

So you have 2 raise to power n, in the case of LFSR what is called as a maximal length LFSR
you will not get 2 raise to power n combinations but one less and that is why we say it is 2 raise
to power n minus 1. We will see why it is so.

733
(Refer Slide Time: 05:08)

Now basically LFSR consists of D type flip-flops as you see here, here is the input of the first
one that feeds the second one and so on. Now, from some of these flip-flops you take the output
and pass it through certain EX-OR gates and that feeds the input. Now, when you load it with a
initial number and then you apply the clock for every clock signal the values that the flip-flops
will produce they will appear random and that is why this is called a pseudo-random number
generator.

Now, the combination in this case we have shown a 8-bit LFSR now wherever you take the value
out here, here, here and here these are called taps. So we have taps at 8, 6, 5 and 4 for a 8-bit
shift register. Now how do we find out where these taps should be applied when you have a
different length of LFSR?

734
(Refer Slide Time: 06:04)

Well, you do not have to sweat too much if you search the internet you will find many sources,
for example we have taken this source from a Xilinx website and they have linear feedback shift
register which instead of using EX-OR gate it uses EX-NOR and it has a value of n that is the
number of flip-flops from 3 to 160 bits and you can imagine the total number of random
sequences that will produce is 2 raise to power 161 minus 1 and that is a very-very large number.

Remember that 2 raise to power 20 is appropriately a million, 2 raise to power 30 is a billion and
so you can imagine what 2 raise to power 60 would be, a very-very large number. So the
sequence is that such a shift register will produce compare to the last value you cannot predict
the next one and that is why this comes in a category of software based random number
generators.

Now why do we have minus 1 here? Why do we always have 1 less is if the shift register had a
initial value of 0, then no matter what operation that you perform on it, it will always remain 0.
So we have to exclude that from the number of combinations that are available and that is why it
is always 2 raise to power n minus 1.

So this is what you get, now the question is how do you get the seed value? if you write a
program in which you define the shift register and the taps you are problem will be how do you
initialize the shift register? If you always initialize it with a known value because in the program

735
you say seed is equal to so and so forth it will always you will always predict the, can always
predict the sequence. So getting first seed value is a tricky proposition but there are many
options.

(Refer Slide Time: 07:57)

If you have a microcontroller such as MSP-430 and it has analog input if you put a large enough
register or even if you keep the analog input open, and if you sample this signal you will find that
it reads the random number or it reads the value which you cannot predict and this could act as a
seed. So what we have done is we have used this mechanism to illustrate some a couple of code
example.

736
(Refer Slide Time: 08:25)

In the first code example we are going to have connector switch on our MSP-430 lunch box on p
1.3 we have also connected displays as we have seen in our previous examples in the 4 bit mode
and we have connected a very large value resistors 1 mega ohm resistor to ground. What we do,
that when you run this program every time when you initialize it, when the program starts
running for the first time it will sample the analog input.

We use this value as a seed initialize the LFSR with the seed and then every time you press the
switch it will generate the next number and you can find out what does numbers are.

737
(Refer Slide Time: 09:06)

This is the code example I am not going to go through it, it is by this time you would be able to
very easily understand how it works.

(Refer Slide Time: 09:18)

738
Here is the seed part initialization and now you are trying to count numbers and print them. Now
what you will see is when you press the switch first time it will when you turn it on you will get
a seed value and now when you press the switch it will feed the seed value into the LFSR which
is a 8-bit LFSR and will produce the next number.

So every time you press a switch, you will get a new number and try to play with it to see
whether you can predict the next number.

739
(Refer Slide Time: 09:52)

We have new modification, where we modify the shift register LFSR to 32-bit size and instead
of using a switch we just constantly update it the value that is shift the numbers and the least
significant bit we send it to the onboard LED of the lunch box.

What would you expect? You would expect that the LED will be on and off, on and off but
whether it is on or off for how much time it is on or off will be pretty random, so what you
would notice is that the LED appears to flicker. So this would be a good way to create a candle
like performance on a LED it would appear like a flickering candle.

So if you compile and download this second code example you and you run it, you would see
that the LED which is connected to port 1.7 is flickering at a random rate and it would appear
like a candle. The second part of this lecture deals with the mechanism or the requirement of
converting digital numbers into analog voltages.

We have already seen this in our previous lecture using the pulse width modulation technique.
But the problem with pulse width modulation technique is that it is not able to produce analog
voltages at a very fast rate, why? Because of the limitations of the frequency of the PWM signal
itself. And so we are going to look at various other options of generating analog voltage using a
D to A converter.

740
(Refer Slide Time: 11:27)

And there are many mechanisms to do that the block diagram is that you have certain number of
pins here n-bits so you would be able to generate 2 raise to power n voltages in the range of 0 to
some maximum voltage.

(Refer Slide Time: 11:39)

There are various methods, the first method we have already seen using a PWM then you can
have DAC made out of resistors and current sources and switch capacitor and resistor using R-
2R ladder as well as successive approximation type of DAC.

741
(Refer Slide Time: 11:57)

In this example here we are going to create a R-2R ladder network it is called R-2R because it
only uses two values of resistor, R and a 2R. For example, you could choose R to be 10 kilo ohm
and 20 kilo ohm. So you could choose these 2 value of resistors and connect them in this fashion,
this is the R-2R ladder network and it is a 8-bit DAC because we have 8 output pins form the
microcontroller feeding this DAC and here is the output and this is the equation that governs the
bit values and its impact on the actual output.

742
(Refer Slide Time: 12:36)

When you run this code it is going to generate a saw tooth waveform on your output pin which is
the output pin here after (())(12:48). Now, it is very important that the value of these resistors are
all equal, 10 kilo ohms and 20 kilo ohms. But how do you ensure that you get accurate 10 kilo
ohm resistor? What you can do is you can have a bunch of resistors and then you can using a
multi-meter find out few resistors 10 kilo ohms and few 20 kilo ohms which match each others
values as much as possible and then use that to create such a DAC.

743
(Refer Slide Time: 13:20)

When you run this program here I have shown that you connect port 1 pins to R-2R ladder
network and when you connect it to the oscilloscope here is what you would get as a 8-bit DAC
and this frequency is very low but that is because the number of bits are large 8-bits and the
frequency is not very high. And also you will feel that this saw tooth is not really a straight line
and that is because the resistors are not really matched values.

So if you have a better values of resistors which match each other well then you would find that
the DAC output in this case is much linear.

744
(Refer Slide Time: 14:07)

And the reason why the frequency appears to be very low is also because certain amount of delay
has been introduced in this code. If you remove this delay you would find that the saw tooth
waveform is of a much higher frequency.

(Refer Slide Time: 14:25)

745
Now instead of 8-bit DAC you can have a 4-bit DAC and now you see the frequency has
improved also because the number of steps that you have instead of 256 steps you have only 16
steps.

(Refer Slide Time: 14:40)

746
The third part of this lecture is about revisiting the lemon battery that we created in the past as
you remember we I showed you this demonstration that we created a battery out of lemon and
two dissimilar metals as electrodes.

One was the copper here, this is copper and what is inserted in the lemon is a different metal,
actually extracted out of alkaline battery and using this combination each of these, so this are 4
cells each of these cells produces 0.9 volts, so roughly from this battery you get about 3.6 volts.

747
(Refer Slide Time: 15:30)

And using setup which was like this that this is the lemon battery 1, 2, 3 and 4 we connected it to
a microcontroller MSP-430 remember we programmed it in the lunch box, then we took the IC
out put it in the breadboard and connected the crystal to the crystal pins so that is working at 32
kilo Hertz and then on the P1.7 pin we connected the LED like this and the microcontroller this
is the VCC and this is the VCC pin, this is the VSS that is the ground pin and ofcourse the crystal
was connected to appropriate pins of the microcontroller.

And you saw, notice that this pin, this LED would blink every second in a flash and so I am
going to go through the code and also talk about the current that this entire setup consumed. We
monitored this battery over a period of 14 days that is this battery continued to operate work
non-stop for 14 days. We measured the current that was being consumed by the setup I will tell
you how and then we estimated what was the capacity of this battery.

Now when the battery volt this battery typically has a very large output impedance which means
if you try to draw large current the voltage will drop. And so to make sure that the
microcontroller is not effected when the LED is turned on it would take more current, so we
connected large capacitor for measurement about 4700 micro farad. So that it would filter out
whenever the LED is being turned on.

748
(Refer Slide Time: 17:46)

And we noticed the setup let me show you the setup what we did was, we took the battery here
and connected it to the microcontroller VCC and had a small resistor connected here this is the
ground pin of the MSP-430. And we connected a very large value of capacitor across this and
then we use this, this was about 100 ohm resistor and we observed the voltage on this.

And from this we estimated and ofcourse you had the LED connected here and from here we
estimated the amount of current being consumed by this. The average current when the LED was
on it would consume about 500 micro amperes of current when the LED was not on it would be
less but the average current was roughly 300 micro amperes.

So 300 micro amperes into 14 days into 24 hours into 60 minutes will give you roughly 100 mah
battery capacity. So this is the kind of performance you can expect out of a simple battery that
you can create on your own.

749
(Refer Slide Time: 19:18)

This is the code, you can compile and download this code. Here is the main program the
watchdog timer has been turned off. The code was using the crystal oscillator and so it has to be
ensured that the oscillator is working.

So the oscillator bit was monitored if the oscillator flag shows a fault you are going to wait for it
and after that you turned the timer on to give you 1 second interrupt, you turned the pins so that
you are making the port P1.7 as output and then you turned the microcontroller to operate in the
low power mode 3 with the interrupt enabled turned on and so every time the timer expired it
would take you to the interrupt vector which is here.

In that the bit was made high for a little while and then made low and then you would go back
into low power mode and that was the reason why the microcontroller consumed very little
power for its operation, the only time it consume more power was when the LED was on. So I
recommend that you build this code and if you want you can create such a battery at you own
place and see how MSP-430 microcontroller operates in such a low power situation by turning
everything off expect the time when the interrupt is generated and the LED is turned on.

So, this is to highlight the low power operation of MSP-430 and with this we cover how
MSP-430 can be used to generate random numbers, how MSP-430 can be used to generate
analog voltages and also how MSP-430 has this rich low power modes of operation and you

750
could optimize your system so that it conserves as much power as possible. I am going to stop
this lecture here and I will see you soon with the new topic, thank you.

751
Introduction to Embedded System Design
Dhanajay V. Gadre (NSUT)
Indian Institute of Technology Delhi
Lecture 33
Serial Communication Protocol, USCI Module in MSP430
Hello and welcome to a new session for this online course on Introduction to Embedded System
Design, I am your instructor Dhanan V.Gadre. In this session, we are going to talk about one of
the peripheral functions of a microcontroller namely, communicating with the outside world.
Now, if you want to communicate a microcontroller wants to communicate with the outside
world, there are many ways of communication, but the common methods require you to send the
data and receive data in a serial fashion.

Why? Because it minimizes the number of connections that you would require for
communication, the data in a microcontroller or in any computer is in the form of bytes or words
and so, if you want to transmit a byte of data, otherwise you would require eight bits that is eight
wires, one for each of the bits and then ground and some other handshakes signals as they call it.

So, the number of wires that would be required to connect between two devices would grow too
much and this is not preferred and therefore, any communication that normally happens is in the
form of a serial form that is the byte or word that you want to transmit is serialized one bit at a
time and transmitted similarly it is received in that fashion. So, in this lecture, we are going to
look at the various methods of communication with the outside world meaning with other
devices which have similar capabilities of communication. How do we get our MSP430
microcontroller to communicate with them.

752
(Refer Slide Time: 02:03)

Now, this is defined as communication protocols. Communication protocol is simply a set of


rules and formal descriptions, which are defined for communicating information between two
devices. In other words, this communication protocol defines the format of the data that will be
sent because you are sending parallel, you have parallel data, but you want to send it serially. So,
you have to decide what is the format of that data and at what rate are you sending each of these
bits. A communication protocol basically defines these rules.

(Refer Slide Time: 02:37)

753
Now, when we communicate between two devices, let me draw them here. For example, if I
want to communicate between device A and device B and this could be electronic devices,
humans and so on and so forth. Let us say, this is A and B and you want to communicate
between them.

If you only transmit between, from A to B with no possibility of B responding to you this would
be called simplex mode of communication. Then you could have half duplex in which yes it is
possible for A to communicate information to B as well as for B to send back information to A,
but not at the same time this is called half duplex and when you have full duplex, which means,
when you transmit from A to B and B to A and these two transmissions can happen
simultaneously this is called full duplex.

In real life in normal life we have examples for example, simplex communication happens if you
are talking to somebody and there is no mechanism. For example, radio transmission, broadcast
transmission suppose you are listening to FM channel, the transmitter is transmitting and you
only receive.

On the other hand half duplex is what normally happens using a walkie-talkie. There is a button
called push to talk, the one who pushes that button is able to transmit the rest everybody can
receive and then when they want to talk, they push their push to talk button, then they talk and
the receiver rest of the receivers can receive information and full duplex is what happens when
you make a telephone call. Both the people can talk at the same time.

Of course, in the case of humans, both people talking at the same time, they may not listen to
what the other person is saying. But that is a different matter. So, there are three modes of
communication simplex, half duplex and full duplex.

754
(Refer Slide Time: 04:38)

Now on our MSP430 we have several communication protocols, several serial communication
protocols and the most common of them is the UART. It stands for universal asynchronous
receiver and transmitter. Then we also have a mechanism for higher speed of communication this
is called Serial Peripheral Interface and the third method is called I square C, which is inter IC
communication.

We can think of these you may recall that in, when we were talking about the six box model for
embedded systems and we considered the various communication methods, we classified the
communication methods in two ways, one was called communicating within a device and we call
that intra device communication and then we had another mechanism called inter device
communication that is, if there are two individual independent entities, if they want to
communicate, what kind of protocols are suitable for communicating between two independent
devices and we call that inter device communication.

Now, you are typically in suitable not only for intra device that is within a device. If there are
devices within a, if there are building blocks within the device, they want to communicate
serially you could use a UART, it is suitable for that and it is also suitable for communicating
between two independent devices.

755
So, it is also suitable for inter device communication. SPI and I square C on the other hand are
most suitable for intra device communication, intra device communication and we will see what
all, where all these two protocols are used. Now UART is the most common method of
communication between a microcontroller and another microcontroller or a microcontroller and
a desktop computer or many other examples.

In fact, you are using UART every time you connect your MSP 430 lunch box to your desktop
computer it is using although on the desktop side it is using a USB interface but on the
microcontroller side the USB protocol is converted into a UART protocol and appropriate pins of
MSP430 which are able to communicate using the UART you make that connection and that is
how the program is being downloaded from the desktop computer into the memory of the MSB
430 lunchbox microcontroller.

(Refer Slide Time: 07:23)

UART uses dedicated hardware and it is communicating in a serial fashion. When you are
transmitting data serially, you had to decide what is the duration of each data because each bit.
Because we are saying the communication type is asynchronous, which means there is no
accompanying clock with the data that is being sent.

And therefore, some other method of knowing when one bit ends and the other bit starts, the next
bit starts has to be decided and one method of doing that is to finalize and agree upon a certain

756
time for which each bit will last and this rate, the resultant rate is called bit rate or baud rate and
the user has to define this before any communication can happen and of course, both the devices
must agree on that bit rate or baud rate.

Also, since you are sending data serially for historical reasons, in the olden times, you did not
want to send eight bits of data. In fact, if you recall, ASCII standard is defined for seven bits, the
original ASCII standard is seven bits. So, if you wanted to send ASCII information, you only
want to send seven bits.

But these days you want to send entire eight bits of data and in fact, ASCII there is a advanced
additional ASCII format which allows for eight bits and so you may choose to decide how many
data bits will be sent in each transmission and together with the rest of the bits, we call this one
data packet and this consists of 1 start bit between 5 to 9 data bits and then you can also have a
parity bit, the parity bit allows you to detect whether in the transmission of the data bits if there
has been any error because of noise.

It does not tell you which bit went wrong, it will only tell you if any bit went wrong and it can
only tell if one bit went wrong, if two bits went wrong the parity error may not be able to tell you
that possibility and then after the parity bit, you can add one or two stop bits and there is a
method of specifying the format of your communication as an example, you could say that we
are going to communicate at 96008 and one I will explain what this, what these numbers mean.

(Refer Slide Time: 09:54)

757
So, the first value is the bit rate or baud rate as they call it, often. Then the second value is data
bits, number of data bits that you want to transmit, then the information about parity and the last
is the stop bits. There is no option of specifying the number of start bits. The information
regarding start bit is fixed and it is only one start bit per packet transmission and so if I say my
format is 9600, 8, N, 1, that means my bit rate is 9600 bits per second, I want to transmit eight
data bits per transmission. I do not want to have any parity.

The options are, so bit rates we will see, what are the various options standard bit rates are
available, data bits can be 5, 6, 7, 8 and in some microcontrollers it also offers nine bits of data.
The parity bit there are three options no parity, odd parity or even parity and for stop bit,
historically, it offers three options one stop bit, one and a half stop bit or two stop bits.

In the case of MSP 430 you have the options of one or two and you can choose whether you
want to have parity or no parity at all and if you want to have a parity whether it is odd parity
you want to include or even parity.

(Refer Slide Time: 11:28)

758
Here is a list of standard baud rates. Now the meaning of standard baud rates means that if you
have a existing device, let us say a standard laptop or desktop, which would have offer certain
serial communication protocols, it would offer the communication rates which can be from one
of these numbers.

Of course, if both the devices that want to communicate using the UART protocol and both the
devices are your devices, you can choose arbitrary rates of communication, there is nothing
wrong with that, but if you want to communicate with the existing devices, then these are the
standard baud rates that you must choose from 300 bits per second, 600 bits per second so on and
so forth.

If you see there is a factor of two as you go down this list the number of data bits per second they
double and the maximum bit rate you can get is there is a zero missing here 115000. So, these
are the standard baud rates that are available and these baud rates because, so if I say 9600 bits
per second that means each bit is going to last for this duration, the value of bit time, bit time is
equal to one by the bit rate, so it is 9600 and in this case this becomes 104 microseconds.

Now because there is a timing information involved, there has to be a mechanism for the
microcontroller to generate this timing information, so that it can change each bit after 104
microseconds and of course the microcontroller has timing information in the form of various
clock signals. In the case of our MSB430, we have A clock, we have SM clock and we have M

759
clock and we can choose which of these clock signals will provide the timing information
necessary for serial communication.

(Refer Slide Time: 13:44)

Now, the basic block diagram of communication between two devices is illustrated in this
diagram, you have device one and your device two, the two pins of serial communication are
called TX or oftentimes they are also called TxD. I could also call this TxD and the other pin for
receiving is called RxD.

760
So, you have to connect the transmitting bit to the receiving bit of the second device and vice
versa and of course, you need a common ground connection. So, these are the three pins that are
required for, minimum three pins that are required for communicating between two devices,
whether one device could be a microcontroller is fine. It could be a microcontroller and the other
device could be some peripheral or you could have both the devices as microcontrollers you, it
could be two independent devices, they would want to communicate with each other, it could use
the UART protocol.

Now, if the distance between these two devices is small, of the order of few inches, then you can
simply take the transmitting pin of one device and connect it to the receiving pin of the other
device and all this would work fine. Of course, the logic levels on these pins must match each
other which means if this device is powered at 5 volts, then the second device should also be
powered at 5 volts, if this device is powered at 3.3 the other should also be powered at 3.3.

Now as the distance between the two devices increases and if the two devices are not being
operated at a common or identical supply voltages, then making such a connection may not result
in reliable communication and therefore, some sort of line drivers that is some sort of amplifiers
on these lines will be required, so that the distance between the two devices does not induce
noise in the data that is being transmitted and based on the type of line drivers that you include,
will lead to different types of protocols. We will see what are those protocols that are available.

(Refer Slide Time: 15:47)

761
Now, when you transmit the data as I mentioned, at the beginning of the transmission, the logic
on your output pin is logic one and when the device is ready to transmit it will take the TxD pin,
it will take it low for a certain amount of time equal to bit time and then depending upon the
value of the actual data bit, bit 0 that bit can go high or it can remain low depending upon the
value of D0 and so on and so forth and you are going to transmit D0 D1 D2, all the way till the
last bit and then depending upon the parity bit that is the parity of these bits can be stuffed can be
added at the end of this.

After that you will add a stop bit which is offer logic high and then when the stop bit end you can
start a new transmission. This is the format of data that is serially transmitted between one device
and will be received by the second device. As I mentioned, we need line drivers so that data is
effectively and noiselessly communicated from one end to the other end.

(Refer Slide Time: 17:06)

And one protocol which is very popular is called RS232. It requires line driver like this on this
side and this here simply means that the distance between the transmitter and receiver can be
large and then you need to have a line receiver IC or line receiver amplifier. As you see here, this
line driver also inverts the logic that is if you send 0 here, the value will be inverted. But the
voltage levels at which the RS232 line drivers work they operate as follows.

762
(Refer Slide Time: 17:37)

If the input is 0, then the output RS232 is plus V some voltage V. If the input is 1, then it is
minus V and what are these voltages? The value of V could be anything greater than 3 volts and
less than 15 volts which means, this line driver and similarly this line receiver has to have a
separate power supply.

For example, let me give an example. Your microcontroller can be working at 3 volts and the
RS232 line transmitter and line driver and receiver can work at plus minus 5 volts or plus minus
10 volt. Now, how do you generate plus minus 5 volt from 3 volts? Either you supply individual
voltages by polar voltages of this value or many of these line drivers have a mechanism have a
built in DC to DC converter, which converts the supply voltage of 3 volt to 5 or 10 volts standard
line driver ICs, transmitters and receivers are available. For example, there is IC called Max 232
this will convert the TTL or 3 volt logic levels into RS232 protocol.

763
(Refer Slide Time: 19:36)

On the receiving side it will receive the bipolar voltages and it will invert the logic and again it
will give you the same logic level as required by this device. So, this is let us say this is device
one and this is device two. Remember that this transmitter and receiver here are being, are
connected to this device, so they may share the supply voltage from device two which could be 5
volts this could be 3 volts, this driver and receiver is connected very close to the device one and
it may have a different supply voltage, it does not matter.

764
What matters is that the voltages on the RS232 signals will conform to these levels and they may
be different and yet these two devices, these two line drivers and receivers will convert the
RS232 levels into the logic levels corresponding to the actual device on their side.

Using this protocol, using this method you can have standard baud rates going up to 115200 that
is 115200 bits per second. You can have the distance between the transmitter and receiver to few
10s or 100s of meters. Now as the distance between the transmitter and receiver increases the
possibility of noise corrupting the data increases and one method of reducing that noise is to have
a different kind of line driver and receiver one that is called as differential transmitter and
receivers. It leads to a different protocol and that protocol is called RS422. But remember our
UART here is still the same, it also has the same data format voltages are also the same.

765
(Refer Slide Time: 21:36)

But the voltages that are available on these lines the serial communication lines now conform to
RS422 format here. The line driver has a true and a inverted value and these are again received
by the receiver it takes the difference of these two voltages and any common mode noise that
may have corrupted the two data lines would be subtracted out and you would get your actual
value back here and so, these differential, these are called differential transmitters and receivers,
they are able to communicate between two devices for a longer distance and a higher bit rate.

Now, in all these discussions till now, we have seen that there is only one transmitter and one
receiver that is, there is a transmitter on one end and receiver on the other and the other side has
a transmitter and receiver. This allows for up to full duplex communication and what if you
wanted to communicate between more than two devices like here we have device one and device
two, what if I wanted to have one more device using these protocols it is not possible.

766
(Refer Slide Time: 22:56)

But there is a modification and there is a new method, a different method called RS 485. It is
derivative or the RS422, except if you see here now, the line driver not only has a differential
output, but it also has a enable pin. You see here it has a enable pin. Now if the pin is not
enabled, the line driver would tristate the outputs meaning it would disconnect it from this cable.
Similarly, the receiver has these two inputs connected and of course, if the transmitter is not
transmitting anything, it will receive the value from somewhere else.

Now, using this enable mechanism, you can connect multiple devices. Now, the moment there
are multiple devices, question arises as to who would be transmitting, because we still have a
common set of wires and therefore, at any time only one person can transmit, if more than one
device transmits it would lead to what is called as data corruption, it will lead to collision of data
and you do not want collision of data.

And therefore one method of saving that possibility is to have a master slave protocol, where
there is a master, the master would decide which slave can communicate back and this method is
usually what we have in the classroom, the teacher is the master and all the students are the
slaves, the teacher can allow a particular student to ask a question and till the permission comes,
nobody can ask a question and using this protocol, you can have multiple devices connected to
each other to create a sort of network of microcontrollers.

767
You may recall that in India there is a very popular program called ‘Kaun Banega Crorepati’,
‘Who Wants to Be a Millionaire’ international version of that program. In that, you see many of
these participants, they offer a vote they are able to vote based on the person, requirement of the
person on the hot seat.

How did they communicate their vote? it you could implement such a network using RS485
protocol where each of the viewer or each of the audience in the hall would have a keypad on
their seat which has four pins four keys, ABCD to offer the options and all these chairs could be
networked using RS485 protocol and it could be received at the desktop computer of the host to
get the information of the votes and a simple network made out of RS485 can easily satisfy the
requirements of audience voting, audience pole in the case of such a requirement.

(Refer Slide Time: 25:43)

Now what are the steps of transmission, when you want to transmit data, you have a
microcontroller that is the CPU and you have the UART. Of course in the microcontroller, this is
your CPU and this is your UART. Both of these sub these building blocks are integrated in the
same chip, but the CPU will transmit information of the data that it wants to transmit from the
CPU to the UART. The UART will add the start bit, then it will serial it will send the start bit it
will serialize the received data at the end of it, it may add a parity bit as well as top bit and this
data will be sent on the Tx line TxD.

768
(Refer Slide Time: 26:29)

In the case of reception, you reverse the format now the UART is going to receive data from
transmitter here, it is going to come in to the Rx pin, Rx pin and this will communicate to the
CPU. This is your CPU, this is your UART. The UART will receive the start bit it will start
receiving the data bits and then the parity and the stop bit, it will strip off the start bit, parity bet,
and stop bit.

Of course, it will use the parity bit received from the transmitter and compare it with a local
computed parity bit, if they to match that means no error has been encountered in the
transmission and then it will remove the data bits and present them to the CPU. This is how the
reception happens.

769
(Refer Slide Time: 27:21)

So, this is as far as the UART protocol is concerned. The second protocol that is available on
MSP430 is this Serial Peripheral Interface. This is a full duplex synchronous, the previous
protocol was asynchronous, which means there was no separate clock that was being sent. But
here you have to send a separate clock and you it is a, you can create a network of devices using
SPI and you have a master and you can have one slave or multiple slaves and you can have full
duplex communication.

(Refer Slide Time: 27:53)

770
This is the signal connections between a master and a slave or you could have multiple slaves.
You have MOSI that stands for ‘Master Out Slave In’ this is the receiver part master out and
slave in is on the slave is receiving pin. ‘Master In Slave Out’ is a receiving pin on Master, but it
is a transmitting pin on the slave. Then you have a ‘Serial Clock’ which goes from the master to
the slave and you have a ‘Chip Select’ which enables a particular slave. So, if you have multiple
slaves, you would need multiple chip select devices, so that you can select which slave you want
to communicate with at any given point of time.

(Refer Slide Time: 28:33)

The timing diagram of the various signals that is chip select serial clock, MOSI, MISO is shown
here. It starts from the master and then once the master has sent the data here, this is the data
being sent by the master the MISO at that time will be in high impedance state and once the data
has been transmitted, it may expect the slave to respond back and this is the data received from
the slave.

In this way, you can have communication, full duplex communication and this can overlap you
can also have data being transmitted from the master to the slave at that time, synchronized with
the clock signal and using this one or multiple devices can communicate with a MSP430 or
similar microcontrollers.

771
The clock rate is quite high, it can go up to 4 megahertz or even more and therefore, the data rate
of communication between two devices using the SPI protocol is much higher compared to the
data rate that you get on UART. But remember, SPI is not used for communicating between two
devices. It is used between for communication between within the device between the
microcontroller and a peripheral device.

(Refer Slide Time: 29:52)

Now the advantages and disadvantages of this protocol are listed here. Since there is no start and
stop bits the effective number of bits is, you know does not have that over it. So, your data rate
will be higher. You can support multiple slaves. But you cannot use this for long distance
communication between two devices and if you have multiple slaves, it will require multiple
chip select pins from the master that is the only, you know disadvantage of this method.

772
(Refer Slide Time: 30:23)

The third method of communication that MSB430 offers is called inter IC communication, as
you see here, is called I square C. It is a half duplex communication protocol and you can
connect multiple devices multiple slaves to the microcontroller and you can collect up to seven
additional devices. That is the beauty of this protocol.

The communication rate is not as high as you would get on the SPI but higher than what you can
achieve on the UART and therefore this is very, very preferred when you have to connect
multiple devices and you do not have many pins because on SPI bus you can connect many
devices. But as you increase the number of devices the number of chip select pins will linearly
increase. That is not the case with I square C.

773
(Refer Slide Time: 31:13)

Here is what is required you only have two pins, one is called serial data and the second is called
serial clock, The clock starts from the master goes to the slave and the data is bidirectional, you
the master starts the communication the slave receives it, and then if required the slave can
respond. Now, if you want to have multiple such devices, you can connect them to the same pins
in the following way.

(Refer Slide Time: 31:40)

774
Here is your master, this is your master and we are talking of I square C protocol. You could
have slave 1 and up to slaves 7 and using only two wires. Let me draw the second wire with a
different color you can have and you would, of course need a pull up resistor on both of these
wires.

Now, how does a particular slave get selected? Well, each of the slaves has an address, Master
address 0 and then you have slave address from 1 to 7 and the transmission includes the address
of the slave and how does the slave know its address? Well, in many of these, if this is a
peripheral IC, it would have a mechanism either that addresses hardwired into the IC or
oftentimes there are three address lines and you can set these three address lines to any particular
combination that you would like to have.

(Refer Slide Time: 33:01)

Here is the timing diagram of communication on the I square C bus, you have to initiate a start
condition which is when the serial clock pin is high and there is a high to low transition on the
SDA bus and then you have certain number of bits and then you end that transmission with a
stop conditions in which the clock pin is high and you have a low to high transition on the SDA
pin this will terminate that channel that packet of data and the slave can then respond.

775
(Refer Slide Time: 33:34)

Only two devices two pin two wires are required, so it is a advantage and you can have a master
and multiple slaves, but the rate of communication is much lower compared to what you can
achieve with the SPI.

(Refer Slide Time: 33:49)

Now, let us look at the serial communication capabilities within MSP430 in the context of these
three protocols and we will see how the peripheral, serial communication peripherals on MSP430
allows you to select one of these three protocols and so on. Now, there are two serial

776
communication interface modules in MSP430G2553 that we are using and they are called
Universal Serial Communication Interface. The reason why they are called universal because
each of these modules offer multiple protocols there is support for multiple protocols.

The A0 module offers UART it has a infrared data communication as well as a LIN protocol and
the SPI mode and whereas the B0 module offers only the I square C and SPI mode. So, if you
want to have one UART and one I square C it is possible. If you want to have two SPI it is
possible, if you want to have one UART and one SPI it is possible. So, combinations of these
protocols can be implemented on MSP430 microcontroller.

(Refer Slide Time: 35:00)

Now for UART, you had to use the A module, A0 module and it uses two pins those two pins
will be listed on the microcontroller as RxD and TxD. Of course, these pins are mapped on
available port pins, the module can send eight or seven or eight bits of data with odd even or no
parity, it has independent transmit and receive shift registers, which is how it is able to
communicate in a full duplex fashion.

Remember, you are sending parallel data from the CPU to the peripheral and the peripheral
converts that parallel data into a serial bit stream. So, essentially the UART interface acts like a
serial register meaning either it works parallel in serial out for the transmitter and for the receiver
it is like serial in parallel out.

777
You can decide whether you want to send the LSB first or MSB First, the standard method is to
send the least significant bit first you have programmable baud rate, which means you can
change for given clock signals available on your microcontroller, you can change the bit rate to
support any of these standard bit rates.

There is a mechanism to exit the low power modes once serial communication data is received.
There are flags which detect if some error has happened in the communication and there are
independent interrupt capabilities for receiving and transmitting functions of the Universal Serial
Communication Interface on MSP430.

(Refer Slide Time: 36:38)

778
Here is a block diagram. Let this block diagram not intimidate you. I am going to go through
that. So, you see the most important part is the part which is the baud rate generator here. It gets,
it has a possibility of selecting a source of clock. There is a internal clock generator you could
choose or you could choose the a clock, auxiliary clock or you could choose the SM clock, this
with the help of certain registers will divide the clock frequency down to get the bit rate clock.

Now, this clock is shared to the receiving section as well as the transmitting section, in the
receiving section, the data that is coming from the RX pin goes into the shift register and once
the data is received, it is transferred to the buffer receiver buffer and then the microcontroller

779
will get to know that a data byte is available on the receive buffer and then it can be transferred
to the CPU.

On the transmitting side, the CPU writes data into the transmit buffer from the transmit buffer it
is transferred into the shift register, so that the data is serialized and sent out to the TX pin. That
is essentially the entire simplified explanation of how the UART module on MSP430 works. Of
course, to be able to do that it requires many-many registers and we will just go through those
registers.

(Refer Slide Time: 38:12)

The UART format as I mentioned can be D0 down to the last bit and then you have parity bits
and so on and stop bits.

780
(Refer Slide Time: 38:19)

You have baud rate selector there are three register baud rate 0, register baud rate 1 and
modulation control registers and the values that these registers must be initialized. The user
manual has a useful guide which tells you, if this is your clock source and you want to
communicate at certain baud rate what should be the values that you should load into the baud
rate register 0, baud rate register 1 and the modulation control registers.

(Refer Slide Time: 38:49)

781
Here are examples that if your clock is 32768 and you want to do at 9600 what values should be
stored in the baud rate registers and the modulation registers.

(Refer Slide Time: 39:03)

Then once you have, you want to transmit data, you can do that with the help of an interrupt,
there is an interrupt vector for transmit which means the moment the output buffer is empty, it
will generate an interrupt to the CPU and the CPU can then load a new value into the buffer and
there is a flag interrupt flag which tells whether the transmitter is ready and you can also enable
and disable this interrupt.

(Refer Slide Time: 39:33)

782
You also have a independent interrupt for the receiver receiving function and whenever the
interrupt flag is set, that means a new character is available in the buffer and the CPU can read it.
The interrupt request is generated if this flag is one and you have enabled the global interrupts
and you reset it by resetting this flag and it is also reset on power up clear condition and this flag
is automatically reset when you read this buffer register. So, when you read it, you do not have to
clear that flag, the enter flag is automatically cleared.

(Refer Slide Time: 40:11)

783
These are the various registers for UART module, there is a control register 0 and 1 for A0 there
is a baud rate register as I mentioned baud rate register 01 and a modulation control register. This
status register will tell you, what is the state of transmission and reception, whether a new byte
has been received or the old byte has been transmitted.

If there is an error in those transmissions, then you have receive buffer and a transmit buffer you
have a, there is a mechanism to automatically detect the baud rate of incoming data and you can
use that, then there are registers for infrared communication and then you have interrupt enable
register as well as inter flag registers.

784
(Refer Slide Time: 40:59)

I strongly recommend that you go through these slides to understand the operation of the control
register. For example, here you are selecting whether you want the parity to be enabled, do you
want the MSB first or the LSB first, what is the size of the data transmission seven bits or eight
bits, whether you want a one stop bit or to stop bits, whether you want to operate in the UART
mode and so on and whether you are doing synchronous or asynchronous mode of
communication.

(Refer Slide Time: 41:29)

785
Then the control one register allows you to select what sort of clock source you would like to
have and so on.

(Refer Slide Time: 41:38)

Then these are baud rate registers, registers 0 and 1. We will see a code example to understand
these registers better.

(Refer Slide Time: 41:46)

You have the modulation control register, the modulation control register is there, so that the bit
rate which is generated by dividing the system clock or whatever clock source you have chosen.

786
If there is a error then the modulation control register will allow you to minimize the effect of
that error.

(Refer Slide Time: 42:06)

This is the status register. Status register which tells you whether data has been, whether there is
a parity error, whether receive any other error on the receiving function and so on.

(Refer Slide Time: 42:20)

787
Then these are the receive buffers, here and the transmit buffer registers so that you can receive
and transmit data. These are the two registers in which you are going to write data for
transmission and you are going to read that register whenever serial data is received.

(Refer Slide Time: 42:36)

You have the Interrupt enable register 2, and interrupt flag register 2, you can disable or enable
those interrupts through these registers.

(Refer Slide Time: 42:47)

788
And here is now, as I mentioned, the transmit and receive pins are shared with port pins. In the
case of MSP430G2553 the transmitting pin is on, receiving pin is on P1.1, here p1.1 and the
transmittal pin here is on P1.2. So you have to, the direction is automatically determined when
you write into the USCI register.

But the cell one and cell two bits you have to for RxD you have to write one and one here and for
transmitting also have to write one there one here, once you write these registers you are set the
two pins P1.1 and P1.2 are configured for receiving and transmitting serial data using URAT by
writing appropriate numbers into the baud rate register, you have decided the baud rate by
writing into the interrupt registers, you have decided whether you want to interrupt on
transmission or reception and by writing into the other control register you are set and then, let us
see an example. What we are going to do is we are going to take the MSP430 lunch box.

We are going to communicate to PC on the PC, we will show what kind of software, you should
install, so that you can transmit data from the PC, you type any key on the keyboard of the laptop
or desktop, that value will be encoded serialized and sent and the microcontroller MSP430 lunch
box will receive it. It will increment the value and send it back and the reason why we have
chosen to increment the value is, so that if by mistake the RX and TX pins are shorted. If you
just use a echo function that is if I send A, I should get back A.

(Refer Slide Time: 44:39)

789
That is if here is your PC. Let us say here is your PC and from this PC, this is your
microcontroller, this is the transmit pin, receive pin if by chance they get shorted. Then if this
fellow sends a value it will be received back and you might think, oh it is working fine, but it
could be because the pins are shorted.

So, I do not recommend a echo function. I have a modified echo function which means whatever
value is sent. I increment it and send it back and if you transmit information using ASCII
protocol you know that the code for A, if you add one to it you get a ASCII code for B. If you
send 1 you will get 2 and so on. So, this is a very good test visually, you can decipher whether
the value that you are transmitting, whether they are being received properly or not.

(Refer Slide Time: 45:31)

Let us go through that it is a just a single page of code, you have in the main program, all you
have done is you have, reset the stop the watchdog timer as we always do and then we are calling
a sub routine for setting the UART registers here is that register, in this the P cell 1 and P cell 2
bits are written appropriately, so that you can map the transmit and receive functions on P 1.1
and1.2.

790
(Refer Slide Time: 45:54)

Then you have chosen to use the UART clock from ACLK, in our case ACLK is coming from
the low frequency crystal oscillator that is 32768 the bit rate values are stored in these 2 registers
value of 3. That is 32768 divided by, 9600. You will get a value of 3.41. So, this 3 you are
writing into one of the registers. This 0.41 into 8. The resultant value you write into the
modulation, register here.

The three value and then you initialize the UART module by writing into the control register and
then you enable the receiving interrupt. So, what we are doing is the MSP430 lunch box is once
it is programmed, it is waiting for byte to be received from the transmitter from the external
world, in this case the PC, once that value is received, it will. We will see what it does.

791
(Refer Slide Time: 46:55)

So once the, and then UART is programmed then it just sets the registers in the status registers to
status register to enable the global interrupts and when a byte is received it will generate a
interrupt vector. Here, we are going to go into the receive vector. In that receive vector, we are
waiting, we have received the byte but since we want to increment and transmit it, we want to
make sure that the transmit buffer is available.

So, wait if the transmit buffer is not available. Once that is available you simply write into the
transmit buffer, the value that you get from the receive buffer plus 1. This is the entire code, I
strongly recommend that you build and download this code into your MSP430 lunch box. Now,
there is a little catch here, because our MSP430 lunch box. Since we are using the bootloader
mechanism, the pins for bootloader serial communication are different from the two UART pins
that is TxD and RxD.

So, we have jumpers on the MSP430 lunchbox, which you must modify, after you have
downloaded the program from the laptop or desktop into the lunch box, then you should remove
the jumpers and place them in the appropriate location, which I will show you in the next
photograph and then you should invoke a program on your laptop which I will show.

792
(Refer Slide Time: 48:20)

So, first of all this is the jumper settings for programming, for programming download the
programming program from the desktop into the microcontroller the jumper settings there are
three pins here in this, these two should be shorted. When you are downloading the program.
Once the program is downloaded. You have to remove this shorting jumpers and you connect
them on this side, on these two sides. Now, your microcontroller is ready to communicate with
the PC using UART.

(Refer Slide Time: 48:53)

793
And what do you do, you install a software called PuTTY. PuTTY allows you to select the baud
rate and the rest of the data bits and then when you have initialize it

(Refer Slide Time: 49:04)

And when you transmit this is what it receives. So, we sent A, we got B. We sent B we got C,
and so on. So, if you send A you will get B, if you send B you will C, you will send a capital A
you will get capital B and so on. You will send 1 you will get 2 and so on.

So, if this works on your PuTTY on your laptop or desktop that means congratulations the
microcontroller is working as expected. It is communicating with the PC at the rate of 96008 N 1
protocol and of course you can experiment with other bit rates to see whether that is possible.

So, in this lecture, we have seen how MSP430 microcontroller can communicate using a variety
of protocols, but because of the limitation of the coverage that we can do in this course, we have
restricted ourselves to communicating using only the UART.

You are free to read the datasheet to understand how the SPI and I square C bus works and you
could use your MSP430 for communicating with external devices within the same
microcontroller system, embedded system to utilize the SPI and I square C bus also and you can
use the UART to communicate between two microcontrollers or between one microcontroller,
and one PC as we have illustrated here.

794
The code example that we have shared can be extended for use between two microcontrollers
and so on. So, with this, I finish this lecture here and I will see you soon with a new lecture.
Thank you.

795
Introduction to Embedded System Design
Professor Dhananjay V. Gadre
Electronics and Communication Engineering
Netaji Subhas University of Technology
Badri Subudhi
Electrical Engineering Department
Indian Institute of Technology, Jammu
Lecture 34
MSP430 Timer in Capture Mode

Hello and welcome to a new session for this ongoing online course on Introduction to Embedded
System Design. I am your instructor Dhananjay Gadre. We are going to continue our discussions
on using the timer feature of the MSP430 Microcontroller in the new mode today. In the past we
have seen how to enable the timer, how to use it for measuring time for some duration.

And then in subsequent lecture we saw how we could use the compare function of the timer to
compare the value in the timer register with some value stored in the compare registers R1 and
R2 and using that feature we were able to generate pulse width modulation signals.

Now what we want to do is, we want to use a timer for capturing external events or internal
events and measure store the value of the timers, so this is called MSP430 timer in a capture
mode.

796
(Refer Slide Time: 01:29)

As usual this is the block diagram of the timer and let us go through it from top to bottom. Here
is our 16 bit timer register. The source of the timer can be an internal clock ACLK or it can be
SM clock and now what I want to introduce you to you is an external pin TA clock.

That signal can be derived from a pin of the MSP430 of the microcontroller which means an
external signal would be clocking the timer, would be incrementing the timer and this would
effectively put the timer in a counter mode because if we do not know the frequency of that
incoming signal all we can say is that we have counted X number of pulses from that signal.

We can also divide once we select what source we want to have we can divide it with the
pre-scalar here and then it will be used to feed the clock for the timer. Coming at the bottom we
have 3 compare registers, compare capture registers CCR0, CCR1 and CCR2. CCR0 is very
special as we have seen in a compare lecture, in a previous session that you store a value in the
capture compare register 0 and this is used to decide at what time the timer will reset.

But now what we want to do is, we want to see the capture mode. Now capture mode means that
we want to use an external event or an internal event to capture the values of this timer. These
values are coming here and they can be captured in this register, they can be captured in R0
capture compare register 0 as well as 1 but this is repeated here so this is what is being shown.

797
And what, what event would capture it? You could have a pin called CCI2A or 2B for the
capture compare register 2 similarly you would have pins for CCR1 and CCR0. And you also
have this, now why do you have a ground and VCC? So that you can generate a signal growing
from high to low which you can select the multiplexer, you can set the multiplexer to ground
selection.

And then when you will change it to 1 it would generate a high to low signal this could be used
to capture into this register the value from the timer. Similarly, if you want high to low you set
the value of this multiplexer to VCC and then you change it to 0 to ground and this will generate
a high to low transition which could be used to capture the value from the timer into the capture
compare register.

And then you can do various things with it you could read the values and so on and so forth. So,
in the previous lecture in the compare mode we use this and use that information of comparison
and outputed the signal as a PWM waveform. Now, in this lecture what we are going to do is we
are going to see input pins which could be used to create events for the timer.

(Refer Slide Time: 04:49)

As usual these are our timer registers you have the timer control register, you have the timer
register as it is which actually counts pulses or signals clock signals, you have capture compare
control register 0, you have capture compare register, capture compare control 1, capture

798
compare 1, capture compare control 2 and capture compare register 2 as well as the interrupt
vector register.

(Refer Slide Time: 05:21)

Now, in the control register these are the bits lets go through these bits relevant to the capture
part. As I mentioned we would like to select the source of the timer instead of being the internal
clock signals we would like an external pin to provide the signal and in this case we will use
these bits TASSELx and select this combination TACLK this is, this would be a map to a pin we
will see which one.

799
We could if you like you could divide this signal coming there but we may not want to do that
and then you want to decide whether you want to operate the timer in up mode, continuous mode
or up down mode and then whether you want to have the interrupt associated with the timer and
the flag which tells you whether an interrupt is pending or not.

(Refer Slide Time: 06:14)

Here is the second part of the capture control register and lets see the bits. Here we now we want
to say, do you want to capture mode or not? Now, in the previous one we said we want to do

800
compare mode so the CAP bit was set to 0. In this lecture we are going to see how we will set
this CAP bit to 1 to indicate to the timer that we want to capture.

Now the question is, once you decide that you want to capture, these bits will decide on what
event are you going to capture are you going to capture on a rising edge or falling edge or do you
want to capture on rising as well as falling this option will allow you to do that. And then the
source of the signal that capture signal is it going to be a pin CCI1A or 1B or a transition of these
two signals. And do you want to synchronize this capture within internal clock you can select
using this.

(Refer Slide Time: 07:16)

This is the timer control register we saw this in the previous lecture these are the output bits and
we if you recall for PWM we selected this combination. But now we want to actually go here
that do you want to have the capture control interrupt enabled? Do you want to have find out the
value what is the value of capture input? And in this case whether there is a capture overflow and
interrupt flag associated with the capture signal.

801
(Refer Slide Time: 07:55)

Now associated with the various you would have lot of interrupt sources, you have capture
compare register 1, register 2 and a timer overflow and this would be available for both the
timers.

(Refer Slide Time: 08:12)

The timer capture select mode you have to select that we want to do a capture so CAP is equal to
1. The CCIS bits will decide the capture inputs and the capture inputs this or this will be selected

802
map to the external pins. When an event occurs at the input signal the value in the timer register
will be stored in the selected capture compare register 1 or 2 or 0.

The CMx bits will select the capture edge of the input signal do you want it on rising or falling
and so on and if a capture occurs then the timer value is copied into this register and the interrupt
flag CCIFG set in this control register so that an interrupt is generated provided the global
interrupts have been enabled.

(Refer Slide Time: 09:09)

803
In the timer capture mode the state of the selected input can be read in the CCI bit and to show
you where that bit is let me go back to the block diagram here. This is the CCI bit here, this one.
Now this input can be synchronous, synchronized to the input clock or it can be asynchronous
you can choose what you want. Capture events are then synchronized with the next following
edge of the timer clock that follows the trigger, midway between increments of the timer register.

(Refer Slide Time: 09:55)

Now this is what happens your timer clock whatever be the source you are going to capture the
value into the capture register whenever the appropriate condition arrives it will capture the value
here of the timer into the selected register. Now, why do we want the capture a mode? So, that
many applications require you to measure time between two events.

So the way to do that would be on first event you capture the value of the timer, let the timer
continue operating. Who is going to clock the timer? A known signal internally generated and
then on the second event you capture the second value of the timer and the difference of the two
values will give you the time that has elapsed between two events. This is what is listed in the
slide.

Now to illustrate the capture features we are going to perform an interesting exercise which is to
measure frequency of external signals.

804
(Refer Slide Time: 10:55)

For example, there is a instrument called frequency counter. What does a frequency counter do?
It measures the frequency of external signals. Of course if the signal is sinusoidal or triangular it
converts it into a digital equivalent signal and then using some mechanism it measures the
frequency of that signal.

Now, to measure the frequency of the signal obviously you need to measure the pulses, the
incoming pulses for a certain period of time. If you, if your measurement period is 1 second the
number of pulses you have counted in that one second period is will give you directly the
frequency of the signal. Now to derive this one second reference you would have a internal clock
which must be very accurate because if the clock is not accurate that one second period will be
erroneous and you will infer a wrong frequency.

Now depending upon the source of the clock which is responsible for generating the one second
period you have to decide if the incoming frequency that you want to measure is much higher
than this clock signal or is it much lower.

If the frequency is much lower, if the frequency of the input signal that we want to measure is
much-much small, very low then it is better instead of measuring the period it is better to
measure instead of measuring the frequency it is better to measure the period. Once you measure
the period you can do one by period to estimate the frequency.

805
If the frequency of the incoming signal on the other hand is much higher than the reference timer
clock in the measurement instrument then it is better to measure just the pulses in that 1 second
period and you would directly get the value of the frequency to a resolution of 1 second, 1 Hertz.
If you want to have a resolution of 0.1 hertz, what should you do? You must increase your
measurement window to 10 seconds and then divided by 10 so that you know is it 25.1 Hertz or
25.2 Hertz. So that is the method of measuring frequency directly.

Now, we will see how MSP430 could be used to perform both of these operations: the direct
frequency measurement and the period measurement.

(Refer Slide Time: 13:24)

Now when you want to do period measurement we are going to use the timer in the capture mode
and what are we going to do? Here is our reference signal this reference signal is an internal
signal. The idea is that between this period of the unknown signal whose frequency we want to
measure we do not want to measure frequency directly instead we want to measure the period of
the signal and this can be done by counting the pulses of known frequency between the two
rising edge of the unknown signal.

So, if I know how many pulses I have counted in that one period of the incoming unknown
signal, if I know the period of the reference signal multiplying the count with the period I get the
total period.

806
(Refer Slide Time: 14:16)

As an example, suppose the incoming the reference frequency inside reference signal that I have
inside is let us say 1 megahertz that means the time period is 1 microsecond. And let us say the
incoming frequency I do not know the frequency, I do not know the period let us say I enable the
counting process and in that counting process between the two rising edge of the incoming
unknown frequency from here to here I accumulate a count of 65800 counts.

Since, I know the period of 1 clock signal of the reference which is 1 microsecond therefore the
total period is 65.8 milliseconds and from here I can estimate the frequency therefore the
frequency of the unknown signal is equal to 1 upon 65.8 milliseconds.

Now, because we are doing all this in a embedded computer such as MSP430 and embedded
computer can very easily perform this calculation. In the olden times when we did not have
computers to perform this measuring period as a way of measuring frequency was left to just
measure the period and display the period and leave it to the user to note the period and perform
this calculation manually to estimate the frequency.

But today we do not have to do that, today we can measure the period and perform a
mathematical calculation in the C program to estimate the frequency and we are forced to do this
because the time period here is very-very low. See, if I have a 65 milliseconds and if I

807
approximate to 100 millisecond that means (the time) the frequency of is of this unknown signal
is roughly a 10 Hertz.

In the case of 65 it will be about 13 Hertz. Now I want to measure the frequency of this unknown
signal which is round about 13, 10, 20, 10 to 20 Hertz to a accuracy say of first digit. Then I
would have to have a measuring window of 10 seconds so that I count 130 pulses divided by 10
to know whether it is 13.0 or 13.1 Hertz. 10 seconds is a very large window.

Now instead of doing that the period of this 13 Hertz signal is 50- 60 millisecond I can easily
which is a very small period in that I can easily count the number of clock signals of a known
signal generated internally and then estimate the frequency to a second or third decimal place
without spending 10 seconds that is the advantage of measuring the period as means of
measuring frequency.

And the rule of thumb is if the frequency of the unknown signal is much lower than the reference
frequency of your instrument you should measure period. If the frequency of the input signal is
much higher than the reference frequency in your instrument then it is better to measure direct
frequency. So we are going to in this first exercise we are going to measure the period of the
unknown signal and from there estimate the value of the frequency.

(Refer Slide Time: 17:59)

808
For that we are going to use timer 0 in the timer 0 the timer itself will be clocked by an internal
signal derived out of the A clock, A clock is from the low frequency crystal oscillator because
then it will be accurate as you know which is 32768 Hertz and we divide it by 4 so that we are
roughly getting 4 kilo Hertz, 4096 hertz frequency which is now we are going to be used as a
reference frequency.

We are going to, we are going to count these pulses in the timer register. And the external signal
whose frequency we want to measure the rising edge at the first rising edge we will capture the
timer register value and on the second we will and we will note this value down in a variable and
then when the second rising edge comes we will note the timer value again.

We know the timer is being clocked with ACLK by 4, so we know the period and once we know
this second count we take the difference from the first count multiply it with the period of this
reference signal which is 1 by 4096 Hertz because the frequency is 4096 Hertz so the time period
is 1 by 4096 you will get the period of the unknown signal and then mathematically you can
calculate the frequency also.

(Refer Slide Time: 19:28)

Now, to be able to measure obviously I need some source of unknown signal which I can verify
so what we have done here is we will display the frequency and period on LCD we already
covered how to interface the LCD to our MSP430 in this case we have used port 1 pins and to

809
generate the unknown period or unknown frequency we have rigged up a 555 based astable
multivibrator.

In fact this IC used here is 7555 so that it can work at 3 VCC here is 3.3 volts. The VCC for this
is 5 volts as we have gone through this earlier you remember the LCD works at 5 volts so the
supply voltage for the 7555 is 3.3 volts and it is used to generate signal which is available on the
output pin 3 and we are going to connect it to P1.2, why? Because, P1.2 will be the capture input
capture compare input and that will be used to capture the value of the timer into the capture
compare register.

(Refer Slide Time: 20:44)

Now, since we are going to capture the you know the incoming frequency on P1.2 let us see
which here is the P1.2 signal we want to select the capture compare register 1 it is an input so the
direction of that is 0 and the rest of the PISEL and PISEL 2 bits are 1 and 0 that puts P1.2 that is
the port 1 bit 2 as timer capture compare input that is what you have to write in your program.

810
(Refer Slide Time: 21:19)

811
812
Here is the entire program. I am not going to go through the program I have also I have already
explained the crux of the program much of it is about the LCD which you already seen here are
the generating the enable pin for the enable signal for the LCD this a function to write into the
LCD. This is to print values which you have the data, the information that you want to print.

This is for printing numbers, this is to set the cursor, this is to initialize the LCD, this is to
display the actual frequency values the period values and from there estimate the, calculate the
frequency. This is important this is the register settings for timer 0 what we have done that we
want to use P1.2 as a input in the capture mode and we want to use a rising edge, we want to
have interrupt enabled and the source is (CCIA) CCI0A which is P1.2. And the clock for the
timer is coming from ACLK divided by 4 this is the meaning of this line of code.

813
(Refer Slide Time: 22:35)

Here is a main program as usual we always disabled the watchdog timer, we have initialized the
LCD, we have called the subroutine for the timer 0 initialization and now we are waiting in a
infinite loop we are this is the infinite loop here.

In that we first display something in the LCD which maybe initially all wrong then we set the
status register bits to enter in a low power mode because we only want to exit the low power
mode whenever the interrupt is generated based on the rising edge of the incoming signal and we
have enabled the global interrupt flag.

Now we are saying so this edge 2 and edge 1 are two variables into which the value of the timer
registers are going to be stored. If they are, if edge 2 value is more than edge 1 now you can
calculate the period and from there you can calculate the frequency and the time period like this.

814
(Refer Slide Time: 23:36)

Here is the interrupt vector the ISR for timer. Many as we saw the same interrupt will mean
things could have happened. So you have to 0 on the right one and in this case it is capture
compare flag being setup and now there is a internal there is a flag called count if count is 0 you
are going to capture the value of the timer and store it in a variable edge 1. We enabled the count
to 1 and then next time around when the interrupt happens which means you are getting the edge
2 values and then rest of these do not matter you go back.

So now you have edge 2 value and edge 1 value from here in a main program you can take the
difference and from there estimate the period take inverse of it and you will get the frequency. So
this is about measuring the frequency of incoming signal which is estimated to be a low
frequency so instead of measuring a frequency directly you measure the period.

815
(Refer Slide Time: 24:37)

Here is the setup as you see here the frequency is very low as an example 18 Hertz and you see
our now this is the information given by the oscilloscope which may not give very accurate
values. Here we see the frequency is actually 18.28 Hertz ignore the period part because it is not
printing the second decimal or third decimal in this case.

Here is the LCD the setup for the LCD and here is the setup for the 7555 to generate the
unknown signal, here is a potentiometer so that we can vary the frequency and measure it on
P1.2 and display the value here. This is the setup for the period measurement.

As I have discussed earlier if the frequency of the incoming signal is high then instead of
measuring the period you can directly measure its frequency by enabling a mechanism to count
the incoming pulses for 1 second period. Alright, let me go back here and may be you know
recall this again.

816
(Refer Slide Time: 25:45)

So imagine that you have a AND gate, and here is your incoming signal which, whose frequency
you want to measure. Imagine the second signal is a 1 second pulse. Now, because this is AND
gate is going to allow incoming signals to pass here which could be high frequency like this and
therefore you are going to get nothing and then high frequency for 1 second and so on. So, if this
signal you feed it to a counter the counter at the end of for this 1 period is going to give you the
frequency.

On the other hand, if the incoming frequency is very low then you do the following. You bring
the incoming signal divide it by 2, why do I divide it by 2? So that I can get high for this and
then low for the same period so in this one entire period of the unknown signal I measure a
in-house high frequency reference signal.

Now, what will happen? I do not know this period this is some value T, but I know the frequency
of this which is being generated internally so if I count how many pulses I have accumulated in
this time period I can estimate the value of this T. So, this is the period measurement and this is
the frequency measurement. We have already seen the period measurement earlier now let us see
how do we measure the frequency directly.

817
(Refer Slide Time: 27:38)

We create reference internal reference signal of 1 second. Now, we cannot do both of this things
using a single timer so for frequency measurement we are forced to use two timers. We are going
to put the unknown signal on the input pin of the timer instead of an internal clock signal we are
going to derive it out of a external pin and in that case it is TACLK we will see which pin it
maps to and this is going to clock timer 0.

And we are going to generate 1 second reference signal on timer 1 that is the meaning of this
setup. This is our unknown signal, this is our unknown signal here whose frequency we do not
know but we know that internally we are able to generate 1 second reference period which we
are going to generate from timer 1 and the incoming signal unknown signal we are going to feed
to timer 0 into the timer signal directly into the timer.

And using we are going to generate interrupt here read the timer 0 value store it and when the
second interrupt happens, when the second interrupt happens here this time in the falling edge we
are going to capture the value of timer 0. Again, and the difference will be the frequency directly.
Why? Because this period is 1 second.

818
(Refer Slide Time: 29:09)

Again for the setup we have created mechanism to display on LCD same as past and we have
created a source of frequency which we can measure. But, instead of in the previous one the
unknown signal being generated out of this 7555 IC it is in the astable multivibrator by the way
both the cases. Here the frequency is higher and that you can how do I ensure that?

Let me go back to the previous setup here the period of that astable multivibrator is decided by
this capacitor as you see this is 1 microFarad. Compare this with the frequency with the capacitor
of this timer 555 here it is thousand picoFarad, 1 nanoFarad. And so the frequency that will be
generated here will be much higher than the previous case.

819
Instead of putting that unknown frequency on P1.2 we have to now put it on P1.0, why? Because
this is going to feed the TACLK, TACLK signal of timer 0.

(Refer Slide Time: 30:24)

Our signal is going to come from P1.0 and we see P1.0 this so we have and this is a input now
and so the direction is 0 and the P1SEL and P1SEL2 bits are 1 and 0. This is what we have to
program the port 1 register.

(Refer Slide Time: 30:51)

820
821
822
Here is the program for doing that again LCD part, the writing of the LCD, the setting of the
cursor here, this is to initialize the LCD in four bit mode to display the value directly the
frequency here and here is the register setting for timer 1 which is important because that is
going to generate the 1 second period. This is the main program.

Since, we are generating the 1 second period from the, the low frequency crystal we have to wait
for it to stabilize. Then bit 0 is the input P1.0 so that we have decided as input then we have
initialize the LCD and we have call the function for timer 1 as we saw here and now we are
waiting. Once the interrupt happens you are going to go in this interrupt subroutine and you are
going to directly capture the value of the timer 0 value and use that as the count which is directly
the frequency.

823
(Refer Slide Time: 32:10)

Here is a setup, as you see here the frequency of this unknown signal from the 555 is estimated
to be 26.6 kilo Hertz. And the actual frequency down to 1 Hertz resolution measured by our
setup is 26675 Hertz.

So, we have seen how the timer modules in the MSP430 microcontroller could be used for
capturing external signals and using these modes you can measure frequency and period of
unknown signals which is a very important activity often times in embedded applications. So,
this completes the timer capture mode and I will see you very soon with a new lecture. Thank
you.

824
Introduction to Embedded System Design
Professor Dhananjay V. Gadre
Electronics and Communication Engineering
Netaji Subhas University of Technology
Badri Subudhi
Electrical Engineering Department
Indian Institute of Technology, Jammu
Lecture 35
Coding Ninja

Hello and welcome to a new session. I am ​Dhananjay ​Gadre and we are here because I am
offering a course on Introduction to Embedded System Design. In this lecture today we are going
to get involved with programming aspects and we hope to convert you into a coding ninja. That
is, we hope that at the end of this lecture you would be able to program like a ninja, like an
expert.

Till now we have covered so many features about MSP430 microcontroller. We have done
experiments related to digital input and output. We have done ADC. We have done timer
experiments. We have introduced ourselves to the concept of interrupts. We have looked at serial
communication.

Now, is the time to actually integrate all these features that we are now aware of and to be able to
program like a pro, alright. And so, the topic of this lecture is how to code like a ninja. What we
have probably not covered enough and we want to address that here is the mechanisms of related
to mathematical manipulation of information, of data.

Till now our manipulation was simple. We were adding numbers, we were doing bit
manipulations and, you know, simple stuff. But what if we wanted to do more mathematically
involved calculations? Like we wanted to calculate the logarithm of the numbers or exponential
of the numbers and so on. Is a microcontroller capable of doing that? Yes, it is.

Ofcourse, if you were to program the microcontroller in assembly language, it would be a big
challenge but because we are programming our embedded systems, our microcontrollers in C
doing all these operations is quite a breeze. As in there is no, not much challenge in terms of
writing program. Ofcourse, it takes a lot of time when the program is calculating complex
mathematical operations.

825
It takes time and so we must be aware of that. And so, the beginning of the exercise is how to
read information from the outside world, how to process it with more complex mathematical
operations and how to see the result of those operations.

(Refer Slide Time: 02:57)

And so, in the first example, what we are going to do is, here is the setup. Maybe it is shown
here. We are going to read the analog value of this potentiometer which is 10 kilo ohm
potentiometer connected to P1.0 and it is going to read it. And as we know, we have already
dealt with the ADC. The ADC on MSP430 is a 10-bit ADC. And therefore, the number will
range from 0 to 1023.

Oftentimes, you do not need such a large variation in the number. You would like to represent
this range with the smaller values of numbers. And one way to do that is to take a logarithm of
the of this number. And so, in this exercise what we are going to do is we are going to read the
ADC as frequently as we can. And once we read number, we would like to calculate the
logarithm of this number.

Now because the number is between 0 to 1000 or so the numbers will range from 0 to 3.
Eventually, in the second part of this program, a second variation of this program we are going to
display that number on our local display. In which case it is Charlieplexed LED display. We
have already covered Charlieplexing in the previous exercise. So, you are aware of what is
Charlieplexing.

826
This is a form of multiplexing which allows you to control a large number of, relatively large
number of LEDs using relatively smaller number of pins. And so, we are going to rig up on the
breadboard we are going to rig up a Charlieplexed display with 6 LCDs. And for 6 LEDs you
only need 3 pins. So, using 3 pins and 6 LEDs we will display the numbers calculated from this
exercise, taking the logarithm.

But because the numbers are going to be in the range of 0 to 3 and we have 6 LEDs, we will
multiply it by 2 and then display it on the Charlieplexed LED display. In the first part of this
exercise, we are not going to do anything like that. We are going to calculate the log and then
using the serial print mechanism.

You may recall that in one of the earlier lectures when we were talking of the gate and CCS and
we talked about various aspects related to embedded C programming, we introduced to you a
black-box approach of including a certain lines of code which basically initialize the UART to
communicate with the outside world at the rate of 9600 bits per second.

And you could use that mechanism to print information as long as your microcontroller is
connected to a computer, and the computer is running some terminal emulation program. The
information which is being sent from the microcontroller could be monitored on the PC. And so,
this is very useful when you are developing your program. You want to see what numbers are
being calculated.

And since your microcontroller does not have elaborate display features, you could use the
display of your laptop or desktop computer to monitor those numbers. So, in the first exercise,
we are going to read the value of the potentiometer, take a log of that, multiply it by 2 and then
print these numbers onto the serial monitor.

827
(Refer Slide Time: 06:17)

Here is the program. Now, we are saying that code like a ninja. Ofcourse, it would also mean that
the program becomes longer. And so, probably the programs that we cover in this lecture here
are by far the longest programs in terms of the size also. And so, here what we are doing is we
are defining that we have a potentiometer connected to the bit 0 that is P1.0. We have declared
two volatile variables.

One which will maintain the log of the value and the other which is a number which is been
initialized to 1. Then we have function where we initialize the ADC that convert the value,

828
connect the ADC to channel 0 that is P1.0. And then use the VCC as a reference and using clock
frequency 64 clock pulses per conversion for the sample and hold.

Then this is the main part of the program. We have just stopped the watchdog timer. We have
also; although we have not done this often in our previous programming exercises, we have
increased the clock frequency internally generated DCO to operate at the highest possible clock
frequency. Here in this case about 16 megahertz. And why?

Because we are doing mathematical calculations. Mathematical calculations using the built-in
functions take a lot of time; log and exponential and so on. And so, if we did not increase the
clock frequency it would slow down the entire processing time. It would take more time to
process that information and so we wanted to reduce that and so we increased the clock
frequency.

Then we are you calling this subroutine as we saw to set the various values for the ADC. Then
we initialize the serial printer and you know this function is defined in our lunchbox common dot
h file, as you may recall from a previous exercise. And then we enter this infinite loop where
while 1 what we do is we start the conversion, read the value from this memory location.

Once the conversion is over, the ADC writes the value in into this memory location
ADC10MEM. We have transferred it into the ADC value. And now based on the ADC values,
we are processing that information. And then just transferring that to the printf which actually
invokes the serial print. And then this is simply a delay value.

829
(Refer Slide Time: 08:59)

Now when you run this program, you would see that based on this it prints the ADC value, also
the log and also the converted value. And you see, as long as whatever the number you can
verify that using a calculator what should be the log 10 of this number into 2? Is it matching
these numbers here?

Ofcourse, you are not been able to take a larger variety of these numbers. But please verify when
you compile this program, rebuild and download after making appropriate connections. In this
case, there are not many connections to be made. The lunchbox itself is quite sufficient. All you
have to do is connect a potentiometer.

One part of the potentiometer to Vcc, the other extreme to ground and the centre point to the
P1.0 pin. And when you run this program, you can verify that the ADC value will be printed and
also the converted value.

In the second part of this exercise where the conversion and all is not changed. But now instead
of displaying the result on the serial monitor we would display the numbers on a Charlieplexed
display. And for that we use certain pins as we see here. There is the Charlieplexed display. Here
is the whole block diagram in a way of the exercise, the circuit that will use for the exercise.

830
(Refer Slide Time: 10:15)

We are going to connect a potentiometer to P1.0 as earlier. But to P2.0, 2.1 and 2.2 we are going
to connect 3 LEDs; 3 pins we are going to connect 6 LEDs in the Charlieplexed display fashion.
And these displays, these LEDs will be handled in a interrupt subroutine. And we will see how
that happens.

831
(Refer Slide Time: 10:38)

We have already seen how interrupt programs work and so I am not going to go through that.
The important point is that these 3 pins are defined here for the display. Here is the pin definition
for the potentiometer. Here are 2 variables: one which contains the log value and the other which
is a number which is going to go from 1 to 6 and so on.

Here are 3 arrays into which the port values are stored to respond to correspond to the
Charlieplexed display that when a particular LED is to be turned on, the pins that connect to that
LED have to appropriately turn the LED on. That means the anode has to be high; the cathode
has to be low, and the other pin has to be set in the high impedance mode.

832
And the way to do that is to program that pin which connects to that LED, the third pin to
operate in as an input pin with no pull up or pull down resistor. It would make it high impedance.
And so basically these 3 arrays deal with that. Here is a subroutine called Charlie which based
on the number to be displayed, it appropriately sets the direction of the ports and converts the
third pin whichever that third pin might be for that number, into high impedance.

Here is the register setting for the ADC. It is similar to what we did previously. Here is the
register setting for timer. Now, this is an additional subroutine into this program because we are
using the timer to generate an interrupt at roughly 1 kilohertz using the internal 32 kilohertz
clock. By dividing it appropriately, we are generating a timer interrupt every 1000 times a
second that is at a rate of 1 millisecond. So, the Charlieplexed LEDs will be refreshed 1000 times
a second.

(Refer Slide Time: 12:34)

Here is the main code where we have disabled the watchdog timer. We have changed the
frequency to about 16 megahertz and we have called the subroutines to program the ADC and
the timer, and we also enable the interrupt. Now, why we have enabled the interrupt? Is that
when the timer expired, it will generate an interrupt and go into the interrupt subroutine where it
will refresh the LEDs and come back.

833
And then we enter infinite loop where we are reading the ADC. Then we copy the value of the
ADC from the memory location and then perform the log calculation and then store the number
result into these log values.

And from there, what it does is the interrupt goes into the interrupt subroutine; the program goes
into the interrupt subroutine whenever the timer expires and the information is converted to from
log it is converted into appropriate numbers and displayed on the Charlieplexed display.

So, I strongly recommend to you that go through this program, understand what is happening and
see how the internal functions the available functions on the code composer studio for MSP430
allow you to manipulate data mathematically using complex functions. Now, that was the
objective of this exercise.

Now we are coming to the part two of this program; part two of this lecture where we are going
to deal with more elaborate scenario, where we have created a mechanism where multiple
activities are taking place and how does a microcontroller look at multiple activities. We are
going to illustrate this requirement or illustrate this need in 2 methods. Of course, the first
method is to illustrate the shortcoming of that method and that we are only doing it to convey to
you that this is not the method of handling information in that way and that the better method is
to use the interrupts.

834
(Refer Slide Time: 14:42)

So, what is the objective of our exercise? The objective of our exercises is that we have created a
4-digit display. Now, how do you connect four 7 segment digits to a microcontroller with limited
number of pins is that you employ what is called as multiplexing. And so in multiplexing instead
of each digit having its own independent seven or eight pins, we are sharing the pins.

And so instead of if you are to connect four 7 segment displays, you would require 32 input
output pins. And we do not have 32 output pins on our microcontroller. And so instead of
connecting one 7 segments to its own private 8 pins, we have shared the pins using this technique
called multiplexing, where the segment's A, B, C, D, E, F, G, and decimal point, that is eight
segments are connected to pins of the lunchbox in this fashion. You see, because of some of the
pins being allocated for certain functions, there is no sort of a sequence in those pins, but that is
alright our program can handle that.

And then we are turning one digit on, displaying the information there. Then we are turning the
turning this display off, then displaying the second digit and so on so forth. And when we read
the last digit after that we come back to the first digit. And if we did this exercise fast enough,
then fast enough to beat the shortcoming of the human eye that is the persistence of vision. If we
change these displays or we multiplexed these displays faster than the persistence of vision limit
of the human eye, you would notice, you would see that all these displays are ON at the same
time.

835
While we are multiplexing the display, what do we want to do? We want to count the number of
times the switch connected to P1.3 is pressed. So essentially the objective of this exercise is
count the number of times that switch S1 connected to P1.3 has been pressed. Every time the
switch is pressed and released; it should increment an internal counter. And because we have a
4-digit display, the counter we have programmed to go from 0000 to 9999. If you press more
than that then it will reset to 0000 again, and that process will continue.

Now the objective of this exercise is not just to count and display but also to illustrate this
wonderful concept called multiplexing, and how the rate of multiplexing should be high enough,
so that the human eye in the normal circumstances is able to see all the digits at the same time.
But in reality, is that what is happening? No.

In reality, what is happening is that only one digit is on at any given time. But it is changed so
fast that the human eye is unable to follow that change. And so, what we are doing with this
exercise is not only counting the times that the switch is pressed and displaying the count on the
digit but we are also controlling the multiplexing rate. And for that we are inputting that
information through a potentiometer.

And so, obviously, as a designer, if you are going to implement this system, you have to have an
idea as to how are you going to change the multiplexing rate using an external input. And so, we
have connected a potentiometer to the ADC input. And when the way we have connected when
the centre tap of the potentiometer is connected to the ground pin, it will the ADC will read a
value of 0. When the centre tap is connected to the other extreme, it will read the maximum
count which in this case will be 1023. So, using a count which varies from 0 to roughly 1000, we
want to use this information to vary the rate of multiplexing. And so, one way could be that
forget the 0 part. That is when the value read by the ADC is 0.

Let us say that the value read by the ADC is 1 to 1023. We could map these values directly in
terms of the time for which any given displays on at any given time. So, for example, if the
setting of the ADC is such that the ADC values 1, one way to deal with that would be that 1
means the count means the time or let me rewrite it. Let that the ADC count is equal to digit; any
given digit ON time.

836
So, if the ADC count is 1 that would mean that each digit will be on for 1 millisecond. And so,
one millisecond, one millisecond, one millisecond, one millisecond to the last digit again it will
come back. And of course, this is a very high rate of change and my eye will be unable to follow
that change. So, at this extreme of the ADC value, the display will be very crisp. You will be
able to see all the 4 digits at the same time. If you press the switch at any given point of time
(switch S1), it will count and update the count and you will see that on the display.

Now, how do you handle such? So, there are 3 activities going on if you see. One activity relates
to reading the ADC value and using the count result of the ADC to change the rate of refresh.
Meaning if the ADC value is 1, the time for each display is one millisecond. As this ADC value
increases, let us say the time is 10 milliseconds. That means each digit is now
ON for 10 milliseconds.

So, the total time cycle time is 10 plus 10 plus 10 plus 10, which is 40 milliseconds. This would
give you a refresh rate of about 25 hertz. Now if you keep on increasing it even more, so you go
from 1 count of ADC of 1 to count of let us say 1000. And we since we are saying that the count
is directly translated in terms of milliseconds, a count of 1000 from the ADC would mean that
the time for each digit is 1000 milliseconds. That is 1 second.

And so now you would be able to see each digit being turned ON for 1 second. Next second, the
second digit, third digit, four digit and so on. And so, you would not see all the 4 digits ON at the
same time; you would actually see each digit, only one digit ON at a time. However, even so, it
would the microcontroller would still be able to count or should be able to count the switch being
pressed and released and the changed count to be reflected on the display. Now, how do we deal
with such a requirement?

837
(Refer Slide Time: 21:38)

And so, the first part of the program is to deal with this in a sequential fashion. How? So we
write infinite loop like this. While (1) and then in that loop we say read ADC; read the
appropriate channel of ADC. Then read wait for switch to be pressed. Now, what if the switch is
not pressed? If the switch is not pressed of course, you still have to display whatever the last
value of the count.

And therefore, you can say all right, nobody has pressed the switch. Let me if the switch is, if
pressed, if pressed, wait for it to be released and then increment count, increment count. If it is
not pressed you come here directly. If it is pressed then you come after it is incremented. And
now what do you do? Break that count into 4 digits. Display digit 1. Then display digit 2, 3, 4
and then here your loop terminates which means you are going to now go back, read ADC and so
on.

Now see what is going to happen? The time for which this display each digit is ON will be
determined by the ADC value. And so, suppose the ADC value resulted in 1 millisecond. Of
course, I need to add here delay appropriate count say delay based on the value of the ADC
count. And so, you are going to repeat this here, here and also here. And then you will go back
into this loop, go to read the ADC again.

So, the ADC count is 1 millisecond. After you read it, you are going to wait for the switch to be
pressed. Suppose the switch is not pressed. Fine. Let us say the count before that and so which

838
means before the count and say count is equal to 0. So, you are going to display 0000. And once
you have displayed all the digits, you come back. Now let us say I do not touch, so the ADC is
still 1.

Now I go for the switch and now I press the switch. Now if I press the switch, I am going to wait
for the switch to be released. And suppose I keep the switch press for a very long time. What you
would see when you compile and download this program is that for the time that I keep the
switch pressed, the display is going to vanish, all the digits will be off. Of course, when you
release, the count would be updated and you would see them on the 4 digits. But it certainly
shows that yes, it is, it appears that it is possible to do multiple things in an infinite loop. Each
activity takes a certain amount of time, then you go to the second activity, third and so on. And if
you did it fast enough, it is possible to keep doing all the activities so that everyone is happy.

But here is a situation where somebody. some part of that repeated act repeated activity takes
hogs all the time of the microcontroller, then it is going to deprive the other activities and, in this
case, the other activities are to turn the 4 digits ON one after the other. The processor, the switch
press activity is going to deprive the display multiplexing and therefore, you will see the display
is black-off.

And so of course, this is just to illustrate that this is not a very good idea of programming. And
so, yet I would like you to understand this program where essentially it is doing what I
mentioned here. It is reading the value of the ADC. Based on that it is after that is going to read
the switch, wait for the switch to be pressed. If it is not pressed, is going to go to the displaying
the values. I want you to understand this code, compile it and download it into your MSP430 kit.
And of course, the lunchbox would need to be connected to these 4 digits. So, you need a
breadboard and so on.

839
(Refer Slide Time: 26:05)

You would also need; let me go back here to the circuit, the block diagram. So, you will need
these 4 digits and in the cathode driver here, you are going to need to connect NPN transistors.
And the circuit diagram for the those NPN transistors will be something like this. So, suppose
this is your digit with all the ABCD. Here is the common part which we call the CC. You need to
connect the NPN transistor like this to ground and the base of this you can connect to an
appropriate, I would say roughly 1 kiloohm resistor.

And this would be coming from say P2.0, 2.1. So, you are going to need 4 NPN transistors and
appropriate transistors could be BC547 and so on; general purpose NPN transistors are enough

840
and four 1 kiloohm resistors. And this you are going to connect one such combination for each
digit. Since we have 4 digits, you are going to need 4 such setups. And so that will form the part
of the block diagram here called the cathode driver.

Now let us keep the same circuit diagram. Let us not change anything on our breadboard and the
way the connections are made from the lunch box and recall that the switch which is connected
to P1.3 is on the lunch box. So, you do not need to connect any other switch on your breadboard.
The only thing you need to connect on the breadboard are these 4 digits, these 8 resistors for the
7 segments, the 7 segments of the 7-segment display and the cathode driver in the form of 4 NPN
transistors and 4 resistors in series connected to P2.0, 2.1, 2.2 and 2.3.

Once you rig this circuit up, breadboard it and then connect it connect the lunchbox to your
computer. And this code, you download and execute. I want you to experiment with it. I want
you to play with that press of the switch and see by changing the potentiometer the refreshing of
the display changes from the one extreme where you see all the 4 digits at the same time to other
extreme where you are seeing one digit at a time.

But even so, even if the display or you seem to, it appears that all the 4 digits are ON at the same
time, the moment you press the switch, you see that there is the displays are going OFF. For such
duration that you keep the switch pressed. And of course, therefore, this is not a professional
method of doing multiple things at the same time. Multiple things being interfacing to a switch
and connecting to 7-segment displays.

And so, what we are going to do is we are going to offer certain, some changes to this
programming style. This one we call a sequential execution because you are doing all these
things one after the other. Now of course, the microcontroller has only 1 CPU and therefore, it
can only do one thing at a time. But imagine that we do all these things quickly without starving
the other activities.

And we can do that if we incorporate the concept of interrupts in this system. If we used
interrupts, then you would see suddenly the entire mechanism, the way the system works is far,
far better. That there is no display blanking happening. You can parallelly change the rate of
refresh using that potentiometer. And at the same time, be pressing the switch as frequently or
infrequently that you wanted and you would see that the displays are reflecting the count based

841
on the number of presses that you perform on that switch. And therefore, that is the appropriate
method of programming and I want to talk about it.

(Refer Slide Time: 29:57)

But before that, I want to also talk about that this whole mapping of ADC value directly to a
delay value is not a very good idea. And let me explain what I mean by that. We said the ADC
count is directly delay time in milliseconds. That means if the ADC count is 1, it means 1
millisecond. If the ADC count is 2, it means 2 milliseconds. If the ADC count is 3, it means 3
milliseconds.

842
And what is this delay going to do? It is going to turn a given digit ON for this amount of time.
And so, from 3 if I go down to highest value of ADC, let say 1023 that means each digit will be
on for 1023 milliseconds which is roughly 1 second. Now, if you see at the lower end of the
ADC count, you are going to refresh at 1 millisecond. That means the total refresh rate will be 1
kilohertz corresponding to 1 millisecond divided by 4 (because there are 4 digits). So, you are
doing 250 times a second for the entire display.

But the moment you increase the count to 2, the display rate changes drops drastically from 250
times a second to 125 times a second. And when you do 3 milliseconds, it is actually 3 into 4, 12
milliseconds. That means you are going roughly to about 80 times a second. And so, a very slight
variation of the potentiometer will quickly go through the entire combinations of a 250 hertz, 125
hertz and 80 hertz and so. And you see there is a big jump from 250 hertz you are suddenly
going to 125.

(Refer Slide Time: 32:18)

I would like to vary the refresh rate more gently by going from say 250 hertz to 220 hertz to 200
hertz and so on. So, one way would be to apply some non-linearity; some mapping of the ADC
values in a non-linear fashion, so that I can have a different amount of delay. And one method
could be as illustrated in this graph is that here is on this x-axis is the ADC value. And on the
y-axis, you have the delay time.

843
Now, if this was a linear relationship, you would actually see something like this. And of course,
the count here would be to 1023. But what we did was, we set, if the value of the ADC is less
than 500, then the new value is the actual value of delay is the value of the ADC into 10 percent
of that value.

So, a value of 1 will give you 1 millisecond. The value of 2 will be 1 plus difference that is now
1 into 10 percent. So, it is 0.1. So therefore, you will get a 1.1 millisecond delay. 3 will give you
1 plus 2 into point 10 percent of it; so, 0.2. So, you will now get a 1.2 millisecond delay and this
we this calculation we perform till the count is less than 500. The moment it becomes more than
500, we suddenly increase the that percentage amount. Instead of being 10 percent, we increase it
to 80 percent and now therefore, it is able to increase more rapidly.

Now, if you use this, you would see that when you use the potentiometer to change the refresh
rate that you can actually see the refreshing of the displays changing gently from one extreme
where all the 4 digits are ON at the same time, you are able to gently reduce the refreshing rate
and you will actually start seeing individual digits.

You will first see flicker and then the flicker will increase and then you will actually see each
digit being turned ON one after the other. This happens even when you are running this part of
the code that is the sequential style of programming; you will see that happening there also. But
it will be more prominent and more appreciable when you change the style of programming.

So, instead of sequential programming, you can do what is called an interrupt subroutine based
implementation. Now which means we can look at all the events that are happening. And what
are the events that we have? We have essentially 3 events: one is to read the ADC value and
based on the ADC value decide the duration of time for which each digit is going to be turned
ON. And for that we will invoke that function to convert from ADC value into delay value. The
second is to be able to read the switch. Whenever it is pressed, wait for it to be pressed. Then
wait for it to be released.

And of course, as you know, when you press a switch there is a potential of bounce. So, we have
to debounce it and we can debounce it either using a hardware method that is using a capacitor,
which I do not recommend at all or implement a delay function.

844
Now, the problem with implementing a delay function with a switch is that you cannot handle
the activity of switch press as a subroutine because as we have discussed in the past, interrupt
sub routines have to be kept very short. And you cannot include delay functions in interrupt
subroutines because then it would delay the interrupts subroutine to last that much longer.

And then it would deprive the other parallel activities parallel in, you know, in a different way.
In that the other contemporary activities would be deprived of the CPU attention. And so, we do
not recommend at all invoking delay functions in interrupts subroutine.

So, what options do we have? We can deal with the debouncing of the switch as part of the main
code. And we could relegate, we could offload the activity of refreshing of the display to an
interrupt subroutine and the reading of the ADC also to a subroutine. This way, we would be
able to implement a much smoother implementation, one in which even if you press the switch
as long as you wanted, it would not affect the refresh rate. The refreshing will continue to happen
as determined by the potentiometer.

845
(Refer Slide Time: 36:51)

And so, what we have done is we have in this program in this sequential style, let me go back.
This is the, this is the interrupt style. What we have done is we have divided the multiple tasks
into various ways that they will be handled. We have done switch. The switch as part of main
code. The display refresh as part of timer interrupt, timer ISR. Of course, the rate of the interrupt
generated by the timer is now not constant. The rate is now determined by a time which is
dictated by the potentiometer value. And so, we have a third; so, this is activity number 1, this is
activity number 2 and the activity number 3 is an ADC conversion.

An ADC conversion, once it is converted it implements that non-linearity that is it implements a


function to find out what should be the actual delay value and it stores it. It uses this resultant
value to program the timer. So, by changing the ADC, you are able to affect the interrupt rate
generated by the timer. And therefore, you would see that the multiplexing of the displays is
going from one digit ON which you can perceive to all the digits that appeared to be ON at the
same time. Of course, they are not ON at the same time but they are being turned ON and OFF
very fast for very short durations of time.

And while this is happening, in the background because they are being handled in the interrupt
subroutine, the main program can very happily read the switch, wait for it to be pressed, wait for
it to be released. While it is being pressed, it will debounce it. While it is being released it is
debounced and then only it will update the count. And this count will be as we have discussed,

846
this count is what is to be displayed on the digits. And so, this count must be a variable which is
of the type volatile.

(Refer Slide Time: 39:10)

And so, I strongly recommend to you that based on this discussion based on this description of
how the code is designed, I recommend to you to go through this code. The code has been nicely
partitioned into several subroutines and 2 interrupt subroutines and the main code in which the
switch is being looked at. And the count is incremented based on that.

And then the count is actually a memory location is being stored in the memory location, which
is of the type volatile so that the interrupts subroutines, especially the interrupt subroutine of the
timer interrupt will be able to pick the count.

And based on the value that has to be currently displayed, from that count it will be able to
display exactly that count on that digit and it will happen smoothly. And so, I strongly
recommend that based on this description that you go through this code, understand what we are
doing and implemented and you can try your ideas.

For example, would you like to implement the reading of the switch in the interrupt and doing
the display refresh in the main code? You try doing that and you will clearly see that if you did
not debounce the switch in the main subroutine in the interrupt code. And then if you applied a
capacitor it would lead to an increase in component count. If you did not apply a capacitor for

847
hardware debouncing and instead included delay subroutine in the interrupt ISR for the switch,
you would see how much delayed is the refresh rate.

So I recommend to you that you first implemented this code. As you have downloaded, build it
and download it into your lunchbox and see the performance, and then play with it. Do you want
to do the ADC conversion in the main loop and handle the display in interrupt and switch also in
another interrupt? That is also possible. Or you want to do switch and ADC in interrupt and you
want to handle display in the main program. All those permutation and combination exists.

And with experience you will realise that many of these things can be kept short and they can be
relegated or they can be performed as a part of an interrupt subroutine and that would lead to a
much better code implementation. That would lead to very crisp display where no count is being
lost. No switch being pressed is being lost. The displays are managed nicely. And with this
exercise we hope once you understand the code, you would become a better programmer.

848
(Refer Slide Time: 41:55)

There is one more aspect that I wanted to; I am not going to go through this code. Because by
this time you have become quite good with programming. We have just increased the level of
programming through this exercise. I want to discuss a little bit more here that when you write a
subroutine; there are actually couple of 2 methods of writing a subroutine. One, that we call as
blocking subroutine and the other that we call as non-blocking subroutine. Although we are not
explicitly discussed this in our lectures till now. But this is a good time to talk about it.

Now, in this the programming exercises that we covered here, the reading of the switch was in
the main program. But you could have as well offloaded it to a subroutine. And if you offload it
to a subroutine, you could write the subroutine in these 2 fashions. You could write the reading
of the switch as a blocking subroutine or you could write it as a non-blocking subroutine.

In the blocking subroutine what are you going to do? As the name suggests, it blocks; meaning
when you call this subroutine it is going to wait till that intended action happens. If the action
does not happen it is not going to go back. Which means, if this is my switch, alright? And this is
pulled up with a pull-up resistor and this is going to a particular port pin and I call a subroutine to
read the switch. Which means I want to return to the main program once the switch is pressed
and released, to indicate that the switch was pressed and released.

The subroutine would have only one return value. In this case that the switched is pressed. If on
the other hand, I do not press the switch. What is it going to do? It is never going to go back to

849
the main program. And so, in that way this subroutine is going to block the program in the main
code. Of course, if anything was happening at the interrupt level, interrupt will not be able to will
not be blocked. It will go, service the interrupt subroutine and come back into this blocking
subroutine.

On the other hand, if I program the same subroutine in the non-blocking format. What do I do? I
say call a subroutine to read the switch. Now because it is non-blocking, you are going for the
switch to be pressed for some time. If the switch is not pressed in the default time that you
defined, your subroutine is going to go back to the main program. But how would the main
program know what is the reason for the return from the subroutine?

So in the case of non-blocking subroutine there will be 2 return values. One will be TRUE or
FALSE and the other will be to tell you that the key was pressed, key pressed. Right? Now, in
the case of non-blocking subroutine if the key was not pressed. The first variable will be set to
FALSE; first return value would be set to FALSE. And, if the value if set to FALSE, you are not
going to look at the second variable. And in this case actually make sense.

If instead of a single switch there were many switches. And many switches mean one of the
switches is expected to be pressed. So, you would go back not only to say that the switch was
pressed but also which switch was pressed. So, you would return back with the code of the
switch that was pressed. And if there are say n switches, there will be n codes.

If this subroutine was written as a blocking subroutine, it will have only one return value which
is the value of the switch that was pressed. That is the code of the switch that was pressed. And if
subroutine is written in blocking format, it is going to block the rest of the execution of all
subroutines and main program.

If it on the other hand, it is written in non-blocking, now the return values are different now. You
have 2 return values. One which tells are you returning because some action happened or are you
returning because there was a timeout. Which means for each of such subroutines, you have to
also define a parameter called as a timeout period. Each timeout period will depend on the type
of subroutine, the type of activity you want to do in this.

And I would like to bring to your attention things that are in embedded applications where the
subroutines are written either in blocking mode or non-blocking subroutine format. Let us say, an

850
ATM. As we discussed earlier, ATM machine is a great example of an embedded application.
You as a user when you go and insert your card into the ATM machine, the ATM machine
responds by saying, “Please enter your pin”.

Now what if you did not enter your pin? What does; how does the ATM machine responds? If
the subroutine for reading the switch matrix which has number from 0 to 9 and so on. If
somebody had programmed that ATM machine to read the matrix of switches as a blocking
function, the machine would have blocked. Why?

It is asking you to enter the pin number and you are refusing to enter the pin. So, it is going to
block the operation. But what actually happens? If you have seen an ATM machine operation, if
you enter your insert your card and you do not enter the pin number for some time, the machine
simply ejects your card saying, “Timeout”. Which indicated to you that whoever, the embedded
designer who design ATM machine was a smart fellow.

He or she programmed the switch matrix and wrote a subroutine of a non-blocking function. So
if you did not pressed the pin withing a stipulated amount of time, it will go back to the main
program with the return value set to FALSE meaning there was timeout; nobody pressed the
switch and the main subroutine will not look at the second variable.

On the other hand, if you press the switch within the timeout period, the first variable written
value will be set to TRUE and the second variable will be set to the code of the switch of the key
that was pressed. And so please remember whenever you have an option, whenever you have a
freedom to write a subroutine you actually have 2 options. You can write the subroutine in
blocking format or you can write it in the non-blocking format.

With this we come to the end of this exercise. We come to the end of this lecture where we have
looked at various programming aspect with the view of making you a better embedded
programmer. I hope with all the sessions that we have had till now, you feel happy that you know
much about embedded system. You know so many features of embedded microcontrollers and
you are now able to program more efficiently.

And we would culminate, we would integrate all this knowledge that you have gained by having
a lecture later on and illustrate how this knowledge could be integrated together to implemented

851
a complete stand-alone project based on MSP430. So, I will see you very soon in the new
lecture. Thank you very much and bye-bye.

852
Introduction to Embedded System Design
Professor Dhananjay V. Gadre
Electronics and Communication Engineering
Netaji Subhas University of Technology
Badri Subudhi
Electrical Engineering Department
Indian Institute of Technology, Jammu
Lecture 36
Building an Electronics Project

Hello and welcome to a new lecture on an interesting topic which is slightly outside the realm of
embedded system design and you would recall that in one of the earlier lectures, in fact the first
lecture, when I was going through the course objectives. I had mentioned the immediate course
objectives for learning embedded system design.

But eventually I had said that I have a larger motive in offering this course and that is to enthuse
you budding engineer to fall in love with electronics, fall in love with this idea of creating
electronic circuits. And from electronic circuits to building complete electronic systems and
products and this lecture deals with those aspects.

So, I am going to talk about what does it take to plan and implement an electronics project, of
course today the electronics uses embedded computers, it uses programming, and so when I say
an electronics project it is not without programming. An embedded systems empowers engineers
like you to be able to build complete systems, because embedded systems provides the heart and
soul.

But it also requires a body, it requires a physical appearance and this project is about that, it talks
of all the issues required to be considered. So, that you can imagine a requirement based on a
problem that you may have perceived. How to plan for it? How to implement all the
intermediaries and eventually come to a working product, and support it in various forms I am
going to discuss in this lecture, all the related aspects.

So, while this is about building electronic projects, one should see it in a larger context of
planning to create an entire product. So, let us go ahead and so we are going to look at all the
issues that are required to be considered, when you are thinking of building an electronics

853
project, as a student you would be interested in building some circuit, as slightly advanced
student you might be thinking beyond circuit and you would be thinking in terms of system.

And if you are a graduate engineers and if not once you graduate and take up a professional job,
it would be your responsibility to be part of a larger organization to build complete systems. And
so this lecture is basically to sensitize you about all the aspects that one should consider from
start to finish.

And so when you think of building a electronics project and I could even replace this by saying
you want to build a complete project irrespective of whether it uses and the electronics circuit, or
not I think this discussion will still remain relevant and complete.

(Refer Slide Time:​ ​03:34)

So, you cannot think of building a project or pursuing a project unless you know the aims and
objectives. So, the first and foremost requirement of embarking on such an activity is to know
what is your role? What is it that you are looking at? And so we will see how we can think about
the aim that we have at hand. How to visualize it, and how to create a list of deliverables?

So, that you fulfill your responsibilities, as part of those deliverables one of the important things
that you would have to do is to visualize, what is it that has been put in your responsibility, what
has been is entrusted upon you. And so visualize the requirement and once you visualized it in
various ways that we will discuss shortly. Today no system works without electronics.

854
And when you talk of electronics it means creating a circuit and documenting it, building it,
testing it and so the second part, the third part of this activity will be to create a schematic and
implemented in some way. And one of the most common professional methods is to build a
create a printed circuit board. I am going to show you various options, once you have that, then
you would like to fabricate it. So, we are going to deal with various issues related to circuit
fabrication.

Now, let us assume that you have fabricated the circuit, you would come to a point where you
would want to power it, because without providing a source of power that electronic circuit is
quite useless. So, we look at power supplies issues, we have already dealt with those in one of
the previous lectures. So, I am going to revisit that topic and tell you what are the various
methods of testing, once you decide about that you may want to solder the circuit so that it can
take a physical form.

And a circuit is only a circuit, it has to connect to the physical world maybe your system is
bigger than just a circuit, maybe it has an enclosure, maybe some wires need to be connected. So,
you need to look at the possibilities of having to deal with wiring, and therefore we talked about
it in the system wiring component, once you integrate all these things you would not want to put
it out for others to use, or ship it unless you test it.

So, you need to think about a testing protocol, a testing mechanism and any system is incomplete
without being housed in a appropriate enclosure. So, we will see what are the various options for
enthuse for the electronic systems that you are building. And at the end of the day no system is
complete without documentation.

If when you buy any product it comes in a carton, or it comes in a external package and when
you open it, what you find is a piece of paper, which tells how to use it. This is one part of the
documentation, which is derived out of the system documentation that you as the system
designer will have to embark upon.

When some product goes wrong and you send it for repair, the people at the repairing center
refer to another set of document, which tells them if things go wrong, what all to test and that
part of the documentation that they refer comes from the complete documentation that you as a

855
engineer, you as a product designer will have to put together. And so we look at those aspects as
well.

So, these are the what I call as 10 commandments, that you as a budding engineer and a
professional engineer eventually must keep in mind when you embark upon this activity. So, let
us start and look at each of these aspects. Now, there is no point in moving forward unless you
know what you are doing, as they say that if you do not know where you are going, there is no
need to worry about what road you take. So, you have to be sure where you want to reach.

So, that you can take the right path, and so the aim of the project that you are doing, the aim of
the system that you are building must be very clear to you, maybe it is an iterative process you
can start off with some assumptions, proceed on that path and then you find that some of it is not
possible, you come back and revisit the initial expressions and refine them.

(Refer Slide Time:​ ​08:05)

And so that may take some iterations, so you must come up with the aim of the project, then you
must find out what is expected of you, is it just a prototype? Is it just a paper solution? Is it just a
proof-of-concept?

Is it going beyond the proof of concept of building a working prototype and then from the
working prototype into a you know marketable product, all these things you must consider in the

856
second aspect of this is what is it that is expected of you from the deliverables point of view.
What is the final form, physical form of the project? are you working on somebody else's work?

So, if that is the case are there existing prototypes that you could reference that you could build
upon. Is there a record of testing strategy and test data, or are you expected to create it? And then
once you are done with it you should be able to create a comprehensive report with suitable
photographs.

Today taking photographs is a child's play all of you, all of us are equipped with mobile phones,
smartphones and these smartphones offer great capability to take pictures. And you must use
those, if not you can take the help of professional support to take really good documentation
photographs. Now, in all this a concept called Gantt chart is very useful, a Gantt chart is nothing
but a two-axis representation, where on X axis you set time, and on the Y axis you put all the
activities that you have to do.

So, let us say you want to plan, so this I am going to take this much time to plan, then you say I
am going to start, you know initial ideas. I am going to you know read some literature and things
like that maybe it takes that time, maybe I can start prototyping, maybe while I am prototyping I
can do something else. So, I can have some overlap, so a Gantt chart is nothing but a 2-axis
representation of all the tasks, that need to be done in a serial, or a parallel fashion.

And each of these tasks is say take certain time. And so you can put all of that on a graph and
such a representation is Gantt chart, one may must make a reasonable X, X you know a
reasonable estimate of the time that it is going to take for each of these activities, maybe one can
give some margin for you know some missed opportunities, or some deadlines not being
followed up.

And so one should allow for that and based on these assumptions one should create a plan that
this is the time I am going to take to do this. Why is it also important? Is because if we go back
to my previous one of my previous lectures, where I talked of time to market, this Gantt chart
will be able to help you to estimate that the activity that you have embarked upon. How much
time is it going to take?

857
Are all the parts as I listed earlier those 10 commandments is it possible to achieve them in the
time frame that has been allotted to you? If not would do you need more help, maybe more
people involved in this activity would help you shrink some of the time. So, as to meet this time
to deliver, time to market as one of the important criteria.

So, the Gantt chart is is a tool to sort of visualize all the elements of your project, those 10 things
that I mentioned and then put them in a timely fashion, so that you finish. The next very-very
important aspect of this exercise is to visualize. What is it that you have building? And this
visualization usually starts in a mind, you start thinking this is what you want to do, based on
either self-motivation, or as part of a job that has been given to you.

But eventually you start thinking about it, but that thought is not enough, that thought has to be
translated in a form that you can work upon, that you can share with others that you can
brainstorm.

(Refer Slide Time:​ ​12:16)

And so visualizing your project is important, and one of the ways of doing that is to create
sketches. One need not be a great artist to use pen and paper, or any other tool to put all these
ideas that are floating in your mind onto a piece of paper, but drawing sketches is important.
However poor you may be at it, and I can assure you that with practice you will be able to do a
good job of it.

858
So, please practice using a notebook and a pen, in fact without a notebook and a pen you are not
even half an engineer. So, please carry a notebook and a pen with you all the time, so that not
only you can use it for drawing sketches, you can also capture the ideas that you that are coming
into your mind, and onto a piece of paper for you to revisit them at a later time.

Oftentimes once we have drawn you know raw sketches using paper and pen, it may be
imperative to translate them into more formal methods, which can be discussed at an engineering
level using CAD tools. And there are many CAD software, for example I use Eagle CAD, which
is actually a PCB schematic and PCB layout tool.

But I use it to create block diagrams, in fact many of the block diagrams that you have seen in
during this online course, they have all been created by me, or my students using this great tool.
It allows me to create block diagrams, to save them and then to export them in any format that
could be shared on through various mechanisms.

So, please consider using an appropriate CAD tool, for converting the idea in your mind into a
tangible form, which can be shared with others. This can also then be used in your
documentation, that you know this is how the idea evolved from a rough sketch and then you
from there you made this first iteration, and then you made another iteration, and so on and so
forth.

So, this will allow you to look back at how things changed in your mind. Once you visualize
what you need, eventually it is going to come down to implementing it in a circuit form. And the
first you know diktat in that direction is to actually create a schematic. And again as I mentioned
there are many methods you can start by creating a schematic on a piece of paper.

859
(Refer Slide Time:​ ​14:39)

But again that piece of paper schematic will be of not much value, because that piece of paper
schematic cannot be translated very easily in a form that can be prototyped and recreated and
tested. And therefore one of the standard methods of creating schematic or capturing the
schematic is using a PCB a schematic CAD.

And as I mentioned Eagle is a great software for that. It is it can be downloaded and used for free
in the evaluation version and you can even buy professional versions of that, if you are a student,
or involved in academia, Eagle allows you very low cost, or inexpensive, or zero cost version,
which has more features than a free version.

So,, I would recommend very strongly that you consider this software and here is an example of
capturing that schematic using this CAD tool. And I have basically illustrated two methods one
is a badly drawn schematic. Now, again it is like an intuitive method, that normally you would
say okay all my input start from my left-hand side and the signals progress through that sheet of
paper towards the right.

And here if you see on the left-hand side, the components have been very badly arranged and
you see the names of components are overlapping with the signals. And so it is not very
readable, the important idea of behind a schematic is that you should be able to understand it and
others who may be in your team should also be able to understand it. It is like coding, when you

860
write a program, how do you comment that program? You want that the program has a long life
beyond you. So, that somebody else can also read it and make sense of it.

Schematic falls in the similar category that you should draw a schematic, which is easily
understandable not only by you, now or a 6 months later, but also others who may not be any
who may not be at all aware of it, when they first look at it. And so here is an example of the
same schematic, which has been drawn in much better way.

As you see it has been labeled that this is the supply voltage here, this is the ground, this is a
collector we are going to use, this is the USB interface for connecting to the system and so on
and so forth. The components have been well labeled here is here are the annotations R1, R2 and
so on and so forth, on the left-hand side circuit you know they are very haphazard they are
merging with other components.

So, it is not a very readable circuit, so this will come by practice, you should draw these
schematics using this software, or any other software that you like and ensure that you can create
a schematic which is well understood. After you create that schematic, you should of course you
could you know simulate it using various simulation packages, such as spice and once you have
done that and you are you are confident, that your circuit is going to work, then comes a time
that you find out, what are the components that you are going to use.

Because there is no point in having a schematic and then building the circuit, trying to build a
circuit only to find that some of the components are missing.

861
(Refer Slide Time:​ ​18:17)

And many of these CAD tools give you this option and this facility too from this to start with the
schematic and get a list of components that we call as bill of materials. This bill of material is in
your control, but you get to have a look at it in a tabular form as you see here, that it tells me
what is the quantity of each of these components that I am going to use that you are going to use.

It tells me what is the value of these components, what is that device that we are using and in
physical form how does that device exist, you may want to verify and modify it, if you feel that
some of these components you are not able to get, or some of these components you cannot
prototype, because of the size of restrictions.

You can modify them by going back into the schematic, change the package of the components
that you are using and come back and look at the bill of materials again, take a printout of this
and use it as a reference that this is what you need before you take the next step. And what is the
next step?

862
(Refer Slide Time:​ ​19:12)

That you would want to create a PCB layout. Why PCB layout? Because that is the professional
way of doing things and a printed circuit board can be fabricated in many-many ways. This is a
very simple example of a circuit that I am going to eventually show you the entire working
prototype. This is a dual dice that I have actually demonstrated during the first couple of lectures.

This is the layout of this, the blue color represents the copper tracks on one side of the printed
circuit board and it is actually a single sided board. So, that is the only copper tracks that I have I
may need some wires to jump over some components, or wires the tracks, and so they are being
represented with these red wires. So, these red wires represent jumper wires, that you would
actually solder on your PCB.

So, you create a PCB layout and then you take go to the next point, where is you consider
wherein you consider, how are you going to prototype it, you did layout, are you going to build
that PC and prototype at that level, it turns out that there are many other alternatives. Instead of
coming to the PCB layout option, you could try to prototype in more simpler forms. There are
issues with those approaches, but it does not hurt to consider them.

863
(Refer Slide Time:​ ​20:32)

And the options are that you could use a breadboard, the nice thing about breadboard is that you
can quickly put wires on the breadboard, insert components and test your circuit. The
disadvantages are that the breadboards necessarily require that the components should have
enough spacing and that you cannot use certain types of components such as surface mount
devices, or components which are too small.

There are ways around, work around, around it work around, around this problem. But in general
breadboard should be resorted when you have no other option, or you want to quickly test some
circuit. There are other electrical issues that the tracks, the holes the in which you insert these
wires, they are like inductors.

And so there is mutual inductance between these tracks and they may modify, they may alter the
electrical characteristics of the circuit that you implement. So, you may not be very sure that if
your circuit is not working for some reason is it because the circuit is faulty to begin with, or is it
because the breadboard does not allow that circuit to operate at the in the region that you expect
it to work. So, you must consider that.

The other option is so this is the first option, option number one that you use a breadboard. The
second option is a general purpose zeroboard meaning a circuit board, in which there are holes

864
and under the circuit board there are pads, copper pads, on which you can solder things. We call
them zeroboard, again this is very similar to the breadboard.

And it may have issues for incorporating SMD components and there are workarounds around
that also. ​And then you could prototype, the third option is this is the one that you can prototype
by creating a printed circuit board in the lab. And in fact we have a dedicated session on how to
go about building a breadboard circuit, or how to build a general purpose zeroboard circuit, and
then how to prototype printed circuit board in the lab.

It is a quick and dirty method of creating a at least a single sided board and with some little more
effort you can even create a double sided board, that means a circuit board in which there are
copper tracks on both sides, that is the way most professional circuits are, in fact real profession
circuits have several layers. They are what are called as multi layered PCBs I will come to that.

And the most professional method is to you know create this layout and send it for fabrication
outside to a PCB fabrication house, which will create that prototypes for you and send it to you.
And then here you can order any complexity, meaning whether it is a single sided board, or
multi-layer board you can you know order it. It takes more money, it takes more time, but in
some, in some cases it may be the only option that you have.

(Refer Slide Time:​ ​23:26)

865
I am going to show you the 3 methods here, one is how to prototype it in the lab, and we have
seen these during our MSP430 lunch box experiments. You see here are these wires which are
being used to make connections here green and red, and it is good to use multicolored wires. So,
that you can reserve certain colors for certain signals, for example we use red and black wires
when we are dealing with power supply and current, and maybe a green wire to indicate other
signals.

And it is good to layout your circuit comfortably, you should not try to you know pack your
circuits very close together. Because they may create short circuits, which may you know
reflectan as circuit not working, but maybe the circuit is working it is the fabrication which is
creating problems. So, make sure that your circuit is well you know there is good spacing. So,
this is one method using the breadboard.

(Refer Slide Time: 24:37)

The second method is this is the zeroboard, and as you see if I zoom this up you see there are
holes in both the direction and the spacing of these holes is 0.1 ​inch in either direction, either
here, or in this direction. This spacing is uniform, this is the same spacing that you would get
even on a breadboard.

866
(Refer Slide Time: 24:54)

Here you see, these are all connected together, this is connected together and this separation
between these two tracks is 0.1 inch. And similarly you have this and this and so on and so each
of these holes are 0.1 inch apart. The nice thing about this is this is closer to the final prototype
and as I mentioned in you in some cases you may have SMD components and it may not be
possible to solder them on a zeroboard and certainly not possible on the breadboard.

(Refer Slide Time:​ ​25:35)

867
And so we use this approach called creating a circuit, which is able to where you are able to
solder a SMD component and bring the rest of the connections on pins which you can connect to
the rest of your circuit. I will this discuss these in more detail and then here is a example of a
prototype of a PCB which has been created in my lab.

This is a CPLD base based dice game, which actually I am going to go through in detail in a
lecture to be titled you know designing single board, single purpose computers.

(Refer Slide Time: 26:08)

They are being as you see here see this is the point I was making, this I see is far too you know it
has far too closely spaced components, closely spaced pins to be prototyped on this or the earlier
method. It is also difficult to solder this on a lab based PCB here. So, what we did was we
created a, we ordered professional PCB service to create what we call as BoB.

We call it BoB, BoB stands for breakout board, this breakout board allows us to solder, solder
commonly used SMD components. And bring out connections on the edges of the PCB, where
the spacing is comfortably possible to be used on a PCB, or on the breadboard or on the
zeroboard.

Because the spacing is all 0.1 inch apart, which is the standard for zeroboard and breadboard.
And then the same thing we can put on our own PCB and this is the result of such a exercise.
And we are now dealing with the power supply issues for the prototype.

868
(Refer Slide Time:​ ​27:48)

Now, in the lab you are going to prototype, you must have access to a general purpose power
supply, a power supply which satisfies the need for your powering requirement, and you could
have what they call as the bench top power supply. But these days you can have adaptors just
like your adapters for powering your charging your cell phone. And there are other adapters
which will give you varied voltages say 5 volts, or 9 volts, or 12 volts.

These are all SMPS based circuit adaptor, a power supply adapters, you must have access to that,
you must be able to measure voltage and current and therefore a digital multimeter is of great
help. It may not oftentimes be able to measure current. So, you must find out some alternative
method maybe attach a series resistance, low enough resistance.

So that you can measure the voltage drop across it across it to estimate the current that your
system is consuming and yes eventually your system must have its own power supply, because
you cannot ship a product without a power supply, you must integrate a power supply but to
begin with you need not worry about that the testing can happen with the commonly available
power supply sources.

869
(Refer Slide Time:​ ​28:54)

Now, having considered that you would want to solder your circuit, whether it is for the
zeroboard or for your lab made prototype, or for the final version, this does not apply to the
prototyping technique using a breadboard. But as I mentioned use that approach only for the very
simple circuits and for complex circuits you either take other methods.

And so you would want to solder and it is very important that once you solder you are able to
ensure that no wires have shorted or connections which ought to be soldered are not left open.
And so you should use appropriate tools for doing that maybe a magnifying glass, these days you
get glasses that you can wear and they have LED lights with the magnifying lenses in those
glasses.

So, that you can inspect if you can afford it, if you can afford even more you get microscopes
with where you can zoom in to a part of the circuit board just to inspect everything in detail you
must do that. The ordering of circuit board is very critical, because your circuit may be
consisting of SMD components which are really tiny circuit elements, and they occupy they are
very close to the PCB.

And so if you solder something which has height then reaching this PCB to solder circuit
elements, which are close to the PCB may be difficult to achieve. And so we always recommend

870
that you start by soldering your SMD components, or SMD resistors and ICS which are
providing a very low profile.

And once you do that then you can go to soldering through hole components, one should avoid
using a flux, flux is an important component. It is a necessary evil sometimes your components
may be oxidized and corroded and the flux allows you to remove that oxidized the surface clean
it up. So, that it is ready to be soldered, but leaving flux on your PCB is a recipe for disaster.

So, it is very important that if you have used flux you should be able to clean it up. And
incidentally the conventional soldering wires that you have they may look like a wire, but they
are actually hollow and they oftentimes contain some flux.

So, that when you melt the solder wire on the components the flux comes into picture and helps
in cleaning, which is why when you solder something you see fumes coming out, these fumes are
not from anywhere else, but is it is because you, you are melting flux and flux as I mentioned is
necessary evil.

It will help you in soldering well, but you should not leave flux on your circuit board, you must
use some mechanism to clean it up, one good method is to use various sorts of cleaning agents
and the properties are based on alcohol, various types of alcohols, using a brush and things like
that you must remove all traces of that flux. This will ensure that your circuit works correctly, if
other things are in place.

Once you have soldered your circuit you must perhaps connect it to the rest of the circuit boards
or rest of the intrusion and so on. So, you must find out what is the connection to the outside
world and how are you going to take these wires, which connect your circuit board to the outside
world.

Now, very simple physics comes into picture, that if you just connect a wire and bring it out and
somebody pulls that wire, it may break the connections, or it may you know short some
connections on your circuit board. So, you must anchor these wires before they go out of the
enclosure.

871
(Refer Slide Time: 32:18)

And one way to do that could be that suppose this is your circuit board and here is some
component and you are going to solder a wire and bring it out here like this. So, instead of just
bringing out like this, you should method of doing it is as follows, that you take a PCB, this is
your PCB and maybe it drill a hole here, maybe two holes and when you are taking a wire let me
use another color.

So, let us say you solder a wire here and you take it, put it through this and then take it out. And
so you anchor this wire in this hole. So, that when you if somehow this wire gets pulled here the

872
force will not be transmitted and conveyed to the solder joint, it will be stopped at this anchor.
And so your circuit will remain safe. And this is a good method of doing that you can open many
professional you know products and you see that is how they are doing it. And you must follow
that technique.

(Refer Slide Time:​ ​33:58)

Once you have soldered your circuit, you have connected it to external wires, or wires to other of
your system which maybe other circuit boards, it is time to test. And one good method is to not
use your actual PCB, or system power supply, but to apply power supply from other sources
without inserting any IC, you have soldered most of the components that you cannot do without
soldering.

But if there are any ICS which need to be inserted in sockets, you can start by not inserting those
IC and just applying power. And then use a multimeter to test the voltages at various points and
in that it is very helpful that while planning you allow for certain test points. These test points
can be you know jumper wires, or they could be you know pins that you solder and the purpose
is so that you can probe them, this is very important.

You should also consider how are you going to you know look at SMD versus DIP IC testing. If
you are using a DIP IC you can remove it. But if it is a SMD IC that you are going to be using in
the circuit board, you cannot do without soldering it. So, that is a compromise that you will have

873
to do, you must measure the supply voltages at various points, what is the operating point
voltages of the circuit? If you are using any circuits which have a timing relationship, that is they
provide certain timing parameters, you must be able to test it.

And you should be able to find out is are they producing the right frequency waveforms, right
frequency, correct frequency, correct time period by connecting a oscilloscope and testing it.
And if you are using in your op-amps, these op-amps have what are called as error voltages, you
should be able to estimate that before you insert them in the in your circuit.

If you are using any pulse width modulation signals you should be able to measure the frequency
of those PWM signals, because the frequency of the PWM signal is very important. These are
some suggestions that we have compiled together based on our not too much, but quite a bit of
experience that you should consider while testing.

(Refer Slide Time:​ ​35:40)

Now, suppose you are fortunate enough to have a working circuit, the power supply is working
and everything is working fine, what would be the next step to obviously put it in some form of
enclosure. So, that it can take the next step of looking like a professional product, and there are
many options you can use a ready-made enclosure.

I will show you some examples of that, you can even use PCB, which consists of copper on one
side and the non-conductive substrate on the other, you can actually solder them together to

874
create an enclosure, again this is good for prototyping. These days with the advent of 3D printing
mechanisms, you can actually 3D print enclosure for your prototyping ofcourse you cannot 3D
print mass numbers, because 3D printing is a slow process.

But it could it is very good for prototyping, once you are happy with your prototype, you can
make sure that large numbers could be already using conventional manufacturing methods. So,
3D printer could be very useful for prototyping you could use paper or cardboard, if you want to
take that approach.

This is good and then traditional materials like wood, or plastic could also be used to create
enclosures, you could use existing boxes. If you do not have ready-made enclosures these days,
there are lots of sizes of boxes that we use for you know carrying food, you could consider using
those. And once you have put your circuit inside these boxes, whichever approach you must put
identifier marks.

So, that you know if there is a terminal here, if there is a wire entering at this point, what is this
wire for? So, that if there is a jack maybe a connector that you have to connect, you should know
what that connector is for. So, that you do not by mistake insert a wrong connector, so putting
identifier marks on your enclosure is very important.

(Refer Slide Time:​ ​37:47)

875
Here are some examples on your left is a circuit which has been created in my lab using a CNC
machine. This is a sort of plastic and this was one of the projects that I showed you during the
demonstration, which is a LED hourglass, the box has been milled out of thick stock of plastic
and it has been snap fitted together to create the enclosure.

This is 3D printed enclosure for a color mixer, in the center is actually underneath this is RGB
LED, as I showed you again and this white thing is not 3D printed, actually this is a table tennis
ball, a ping-pong ball which has been cut in half. So, as to diffuse the LED light underneath it,
and this has been created using a 3D printer that we have in our lab.

(Refer Slide Time:​ ​38:43)

What are other options? You can also create acrylic, you can use acrylic boards and you can cut
them using a you know hacksaw, or if you have access to a CNC machine as you see here it has
been nicely cut, you see these edges are designed specifically and they have been put together.
This is the lab made PCB here and it is sandwiched over top and bottom acrylic sheet, which has
been drilled holed.

This is the speaker here and so to allow for the sound to come out of the speaker, here are holes
that have been drilled into it. And this example here is a ready-made, this is a ready-made
enclosure and you get these enclosures of various shapes and sizes and dimensions and you
could have a variety of them available at hand.

876
So, that you can select a particular enclosure for your application and at the last point I
mentioned that you must you know mark your enclosure, this is what has been done these two
are voltage controls. So, as you see it has been listed that this will vary the voltage in the fine
form and this is the coarse control, this is the LED for on-off and this is the title of this project
that this is a precision voltage regulator for a particular application.

So, this is a good approach of prototyping of course this may not be the final form of your
product, but the prototype must be well made in this form. So, that this can act as a reference for
the actual product.

(Refer Slide Time:​ ​40:22)

At the end of it in your after your prototyping or while you are prototyping, a documentation is
one of the most important elements of any system design. Because this documentation will be a
guide to various levels of you know debugging, or trying to fix things, or to create you know
papers out of it as in you want to publish something, or you want to share with the rest of the
world.

This documentation in great detail you must you know create it and the documentation must
follow certain process, procedure, that it must have a title it should also have why did you do
this, the motivation, why are you documenting it? What are the technical details of this project in
terms of block diagrams, in terms of circuit diagrams, PCB layout? If it is using some embedded

877
controller or computer then what is the kind of flow chart that was used to create the system,
may be a record of the code.

And pictures and pictures not just in the final form, but as the project was being was evolving at
various stages you should take pictures. And what are the reference that he used was it
everything from your own thought process, or did you use any books, or did you use any you
know internet websites, all those must be in incorporated in the reference.

This would be helpful to go back and revisit if some things do not work, then you can go and
look at those references to find out what was the thought process at the time that you looked at
those references. And it would help these days it is very much possible to be able to create a
video record of the project in operation. This you could again share it on social media on
YouTube, or you could save it archive it for future reference.

(Refer Slide Time:​ ​42:16)

Here is an example of a project built from scratch and you see here the PCB, this side is the this
is the dual dice PCB, it has been fabricated in the lab. The other side here, this was fabricated in
the lab, but it is basically nothing but a couple of electrolytic capacitors for storing the voltage.
And at the center here this is the Faraday based energy converter from mechanical energy into
electrical energy.

878
And this is basically an acrylic tube, the ends of these are sealed with the hot glue ofcourse this is
a prototype, and this is not something that you would ship out as a product. But for prototyping it
is good. So, that the magnets that you are enclosing do not fly off as you shake it. So, you must
have access to all these prototyping tools and techniques. So, that you can create a prototype that
works reliably and you know passes before it can converge into a product, if that is your idea.

I thank you for listening to me and I hope all these 10 points that I discussed here would be of
help to you, as you take may take great strides from being a student to professional engineers. I
hope that you use these techniques in your work, various levels of prototyping as simple circuits
going on to projects and products maybe you participate in various competitions, where it may
be expected of you to build prototypes.

I hope these points you would consider and use whenever such a such an opportunity arises. I
thank you again and I wish you all the best in using these skills and experiencing them in real life
thank you.

879
]Introduction to Embedded System Design
Professor Dhananjay V. Gadre
Electronics and Communication Engineering
Netaji Subhas University of Technology
Badri Subudhi
Electrical Engineering Department
Indian Institute of Technology, Jammu
Lecture 37
Circuit Prototyping Techniques

Professor Dhananjay Gadre: Hello and welcome to a new session for this online course on
Introduction to Embedded System Design. As usual, I am your instructor Dhananjay Gadre
and today I am joined here by Dr. Badri Subudhi​.

Professor Dr. Badri Subudhi: Hello everyone, myself Dr. Badri Subudhi, I am a faculty at
electrical engineering department, IIT Jammu.

Professor Dhananjay Gadre: Today we are going to look at a new topic which is about circuit
prototyping techniques. In an earlier lecture we covered how to design a complete system
including wiring and other issues, but today we are going to look at specific part of that
whole project fabrication and the specific part being how to prototype an electronic circuit,
what are the various methods, which one is better than others and so on.

(Refer Slide Time 01:18)

Professor Dr. Badri Subudhi: So there are 4 type of circuit prototyping methods are there,
first one is breadboard, second one is zeroboard, third one is Manhattan style and fourth one
is custom printed circuit boards.

880
Professor Dhananjay Gadre: Now, you see these 4 methods have their own advantages and
disadvantages. The breadboard style method is something which is often called quick and
dirty method because it allows you to quickly put together a circuit that you have in mind and
test it. Ofcourse the issue is that the breadboard is not very conducive for testing high speed
or high frequency circuits.

The second method is closer to the actual final professional implementation and that is called
using a zeroboard. zeroboard is nothing but a general purpose printed circuit board which has
holes at regular intervals where you can insert your components and solder them. Ofcourse,
this is not as close as the as having a custom printed circuit board, because you had to make
do with whatever holes that are available and you have to fit your components.

It also has some disadvantages compared to the custom printed circuit board method. And
that means soldering surface mount devices can be a little bit of challenge, although we will
discuss how that can also be resolved, how that can also be accommodated in your zeroboard
fabrication technique.

Another very interesting style of circuit prototyping is what is called as Manhattan style. The
reason why the word Manhattan comes is because in New York in Manhattan, you have high
rises, very tall buildings. And once you solder your circuit board using this technique, you
will realize that with all the components rising up, it looks like Manhattan skyline.

And the fourth method of course, is that you create your own custom printed circuit board,
which is of course takes a lot of time to design, fabricate, solder and test. However, one must
evaluate which technique is best for a given situation. Oftentimes, one starts with some
breadboard testing, maybe if breadboard is not suitable for the job one may do a zeroboard
testing and eventually if you want to do real professional job you would get into the area of
creating a custom printed circuit board, so let us see all these 4 methods.

881
(Refer Slide Time 03:47)

Professor Dr Badri Subudhi: So first method is circuit on breadboard. So you can see a
breadboard where the horizontal line in the top are connected together. Similarly the vertical
lines are connected together. So, this is a simple example of circuit when one IC is there, few
single stranded wires are there, few registers are there, one LED is there and few capacitors
are there.

(Refer Slide Time 04:14)

So, the second example you can see there is a 7-segment display is there, which is connected
through some wires where the each register is connected with one wire and the LED
7-segment LED display is connected to these wires.

882
(Refer Slide Time 04:32)

Professor Dhananjay Gadre: So, the third example of a breadboard circuit is as you can see, it
has a liquid crystal display LCD. And since the size of the LCD is slightly bigger than the
previous two examples as you see here, therefore a larger breadboard is being used. And
because it probably uses more connections, you see more number of single strand wires to
make connections.

(Refer Slide Time 05:00)

Here is an example of a breadboard, breadboard without any components. And as you see, it
has a lot of holes, these holes have a certain pitch, pitch means the distance between two
nearest holes. The distance between any two nearest holes here if I say this line and this line,
this distance is 0.1 inch.

883
Similarly, if you see the holes in these lines, this is also 0.1 inch. The reason for this peculiar
choice of pitch is that in the olden times all the ICs were made such that the distance between
the two neighbouring pins of an IC was 0.1 inch and the distance between two rows of ICs
was in multiples of 0.1 inch, usually it was 0.3 inches or 0.6 inches.

Therefore, a breadboard was designed in a way so that ICs could also be inserted, ofcourse,
discrete components can be inserted at whatever pitch, the holes might be arranged that but to
accommodate the integrated circuits, the breadboards were created so that the pitch of the
holes is 0.1 inch.

(Refer Slide Time: 06:19)

As my colleague mentioned, here, you see this is labelled plus and minus, there is nothing
hard and fast about this plus and minus, it is a suggestion that you could use the top line here,
which I am marking here, maybe I will use a different colour so that it is more obvious. So,
let me use a red wire.

884
(Refer Slide Time: 06:39)

885
So you see this line is all connected together. Similarly, this line is connected together. And
it is suggested that the red line should be plus and the blue line should be minus. It is again a
suggestion you are free to utilize those interconnections in any which way you want.
Similarly, the horizontal wires, horizontal holes on the bottom line are like that here you have
these wires are all, these holes are all interconnected internally.

Similarly the row of line above that is also interconnected. Now here the connections are in
the horizontal direction, whereas the rest of the holes they are connected in this vertical
fashion which means all the holes in column 30 or 29 if I zoom this you may be able to see
this, all the holes in these columns 30, 29 are all interconnected.

However, this separation big separation here if I draw it here, this is this disconnects the holes
on this side and this side, they are disconnected. This allows you to put integrated circuits say
somewhere say something like this. I could put a circuit here and it would occupy holes like
this on both sides.

And therefore it will not short opposite pins on opposite sides of the two rows of an IC and it
would allow the user for example, make connections from here and so on, similarly here and
so on. So this is the general structure of a breadboard. This is a small size breadboard and you
get larger size breadboards also. To discover what is underneath this top layer of plastic with
holes. What we did was we took a breadboard and we milled one part of it.

886
(Refer Slide Time 08:45)

And as you see here, you see these are metal contacts. It is an entire column of contacts.
Similarly, you see column of contacts here horizontally. So this is what lies underneath the
holes in a plastic insulating form here underneath, this is nothing but rows of copper
connections which make connections in the vertical as well as in the horizontal holes.

So this is the structure of a breadboard and this makes it very convenient to quickly prototype
a circuit, you do not need to wait for any PCB inserting a component and making connection
does not take much time compared to soldering and therefore this is a much preferred
approach of prototyping circuits.

But because of the nature of these wires, there is a lot of mutual inductance and is not very
suitable for high frequency circuits. What all is needed to prototype such a circuit?

887
(Refer Slide Time 09:44)

Professor Dr. Badri Subudhi: So you may need a few tools for prototyping on breadboard. So
you can see few examples of prototyping breadboard tools. So first one is you can see on the
screen is a couple of single stranded wires, the second one you can see is a wire clipper, the
third one you can see is a nose plier.

Fourth one you can see is a pusher or a tweezer and fifth one you can see is a wire cutter. So
these are the following tools you may need for prototyping a breadboard.

(Refer Slide Time: 10:21)

Professor Dhananjay Gadre: Let me explain the types of wires. It is very important that we
use only single strand wires, because by the way wires come in two types; one is what is

888
called as a multi strand wire which means tiny strands of copper wire are bunched together so
they are all shorts. Apart from multi-strand wires you also get what are called a single strand
wires which means that inside an insulation like here you see this is green insulation, this is
red insulation and this is black insulation, you have a single strand of copper wire.

(Refer Slide Time: 10:57)

This may not appear like copper and that is because it is covered with tin that protects it from
oxidation. So these are the kind of wires that we recommend you to use. Why? Because it is
very easy to insert it, if you have instead of a single strand wire, if you have a multi strand
wire, then it will not have the physical strength to be inserted in those holes and it will not go
in those holes.

889
So it is very important that one uses single strand wires, you can get an entire roll of single
strand wires with different colours of plastic insulation. Here it is a black insulation and you
can have a bunch of that. What is important to note is what is the size of, what is the gauge of
these wires and we recommend that you use something like 24 to 26 swg, this will go nicely
into the breadboard holes and it will also make good contacts.

If your wire is too thick, it will not go, you will have to force the wire inside. If it is too thin it
may go in but may not make solid electrical connection with the wires within the breadboard
and therefore thin wires are not recommended thick wires may have physical difficulty of
insertion so we do not recommend those kind of wires.

(Refer Slide Time: 12:16)

So, what we what you should have is access to single strand wires of such a dimension such
gauge and with different insulations. On insulation let me also make a point that the typical
insulation that you would get in the market is plastic insulation.

However, apart from plastic insulation, you also get such insulated wires with Teflon
insulation and it is not recommended to use Teflon insulation for bread boarding purpose
because removing a Teflon insulation is a very-very tough and tricky job and you need a very
specialized wire removing tool and we do not recommend using that for breadboard purposes,
using a normal plastic insulation copper wire of 24 to 26 standard wire gauge is quite
suitable.

890
(Refer Slide Time 13:09)

Here is a second example. So breadboard as we mentioned is a good way in fact you have
seen the use of breadboard circuits in many of our experiments in the past. Here is a second
example of how to prototype a board and that we call a zeroboard. This is a name we have
chosen and it is commonly used.

There are other names you could call this a general purpose printed circuit board because it is
for general applications you can use this PCB for any kind of circuit and again here it has
similar feature and characteristics that the holes here the pitch of the holes whether in the
horizontal or vertical direction, here is constant of 0.1 inch.

891
Why? Again because it allows easy insertion of ICs and other components. And the difficulty
is that it is difficult to use it with surface mount devices and I will show an alternative to that.

(Refer Slide Time: 14:14)

Here you see a PCB, a zeroboard that we ordered in bulk, which is why it also has a name of
my lab, but you can get it in the market very easily of various dimensions. The material of the
PCB is very important, this is called FR4 stands for fire resistant type 4 substrate that is the
insulating material on which copper tracks or copper pads in this case are pasted.

You can insert components from this side and they are soldered on the other side. So, this is
the top side of the zeroboard or general purpose board.

(Refer Slide Time: 14:58)

892
In the next slide you see here is the bottom side of the same circuit. As you see here, it
consists of these are the copper pads. They do not appear like copper as I mentioned copper if
left without any coating will lead to oxidation and therefore usually it is coated with tin. Tin
does not oxidize as easily as copper and it also helps in soldering. As you see, we have used a
couple of types of wires, you already recognize this wire, this is the same plastic insulation
wire, single stranded plastic insulation wire.

But when we know that the wiring is not going to be creating any shorts with anything else
then you can also use this is called hook-up wire. This also is in the same, it is a copper wire
with tin coating and this also is available in different dimensions. As I mentioned earlier, we
use a standard size of 24 to 26 swg for such purpose.

(Refer Slide Time: 16:01)

893
And here you see the circuit has been soldered. And you see this is very important, these are
all mounting holes, because at the end of the day this PCB will rest on some surface and if the
surface is conductive, then it might short the connections on the bottom side therefore, as you
see here, these are the mounting holes mounting screws, which we have, which allows us to
have the PCB little bit (up) away from the surface. So, you should plan your circuit to be
soldered in a way. And then this is a good method for prototyping and testing a small circuit.

(Refer Slide Time: 16:40)

Professor Dr. Badri Subudhi: So as like, we have used different tools for breadboard, there
are some tools we may need for prototyping zeroboard also, so part of these components is
soldering wires, so you can see in the left side of the display, so this is the soldiering. So

894
these wires are made up of 60 percent tin and 40 percent lead and right side you can see these
are forceps of different size or tweezer of different sizes.

895
(Refer Slide Time: 17:19)

Similarly, you may need a wire cutter so as previously we have used a wire cutter similarly,
you can use the same type of wire cutter here also. In spite of that you may need a soldering
station. So, you can see the example in the right side this is a whaler soldering station, but it
is not necessary to use a soldering station in place of soldering station, you can use a
soldering iron which is easily available in the market.

Professor Dhananjay Gadre: Now, as I mentioned earlier, often times, you may need to use a
surface mount device. And the issue with surface mount device is the distance between the
pins of an IC or a component, the distance has been reduced significantly. And the other
problem is that there is no uniformity, there is no standard like you have your normal DIP,
the distance between pins is 0.1 inch, but surface mount devices have a variety of pitch.

896
(Refer Slide Time: 18:21)

In this case, the distance between these two wires is relatively large for SMD. And there are
other SMDs where the pitch of the pins is even narrower. And if that is the situation and in
fact increasingly, the integrated circuits that are available these days are being fabricated are
being made available only in SMD versions.

And therefore it raises a very important question and a doubt as to how could we prototype
using the zeroboard technique involving circuit components which are primarily surface
mount devices. So the solution is to use what is called as a breakout board. In this example,
we have a breakout board in fact, we call it a universal breakout board.

897
(Refer Slide Time: 19:08)

I will explain briefly why we call it universal BOB. The reason is, you see each IC would
have its own characteristics, some pin would be connected, would be used for connecting the
supply voltage, some maybe input pins, some maybe output pins, and if you have certain pins
which are ground and on SMD IC oftentimes multiple pins are available for connecting to the
ground.

So if you dedicate a breakout board for a given IC, then you would be stuck to using that
breakout board only for that IC. So we wanted to create something of a universal breakout
board meaning for a given size of the IC. Irrespective of the type of the IC, I should be able to
use the same breakout board and here is an example. This is a 44 pin universal breakout
board.

898
Here it does not matter, in this case, this is a Xilinx CPLD which we used and we will use for
displaying or demonstrating the single purpose computer during that lecture. And you see we
have soldered it here, but we can solder other types of ICs as long as they are available in 44
pin TQFP footprint. Now, how do you make a universal breakout board?

Now, you see from each of the pads, you have a copper wire as you see here, this is a copper
wire. This is from this pin this copper wire is going here sorry it is going to the next pin, if I
erase this, so you see from this wire, this pad, the wire copper track is going here.

These holes are placed at a pitch of 0.1 inch which as we mentioned earlier, the zeroboard
allows you to insert components which have a pitch of 0.1 inch so, this solves that problem.
Now, the second problem how do we make this universal?

(Refer Slide Time: 21:20)

899
For that we must look underneath the other side of this PCB, you see all these pins have two
pads, this is a pad here connected to this pin and here is a pad which is connected to an entire
what we call as the ground plane that is this entire green portion is actually copper. Now, if
we decide, if we know that this particular IC has say this pin to be grounded, then we will
simply short it with a wire as you see here.

You see this wire shorts this pin to the ground plane, any other wire you see here? Here you
see this is shorted together. So, all the ground pins of that IC can be shorted without being
committed to a particular type of IC, then some of the pins will be power supply pins and as
is well known that whenever you have a power supply pin in an electronic circuit, you must
connect a decoupling capacitor.

900
Typical value of the decoupling capacitor is 0.1 micro farad or it can also be point 0.01 micro
farad. And here what we see is the neighbouring pin is actually a Vcc that is a supply voltage
pin and we have soldered a 0.1 micro farad ceramic SMD capacitor.

(Refer Slide Time: 22:43)

So, what these pads serve the purpose of either connecting a particular pin to ground plane
and therefore connecting all the ground pins together or if that particular pin is a Vcc supply
pin then it allows us to connect a capacitor between the supply pin and the ground pin, rest of
the pins which are neither supply pins nor ground pins, they are left unconnected.

And these are jumper pins, which are soldered on the breakout board so that this can be
inserted in the zeroboard. So, this technique allows one to solder or utilize surface mount
device components even in the prototyping technique using the zeroboard or the general
purpose board.

So, this is a very important facility that using a breakout board you can mix surface mount
device components as well as normal leaded components as they are called in a mixed design
and yet still be able to prototype using the general purpose PCB method.

901
(Refer Slide Time: 23:58)

This next style as I mentioned earlier is called the Manhattan style of prototyping. Now, here
is an example, here is a simple circuit that we want to prototype, this is popularly called Joule
thief, because it is actually a sort of a DC to DC converter. This is basically an oscillator with
these two inductors which are coupled with each other and general purpose NPN transistor
such as BC547 and the supply voltage here is nothing but a simple (I am going to erase all
this).

(Refer Slide Time: 24:40)

So the supply voltage for such a circuit is a single 1.5 volt battery, I am going to ground it to
show 1.5 volt AA or AAA battery you can use, and this is a white LED, this LED is a white
LED in this circuit. Now, as we have discussed it earlier white LED cannot be turned on or

902
cannot be controlled with a 1.5 volt supply voltage, you need much higher voltage closer to
3-3.5 volts to be able to turn on a white LED.

But this circuit allows you to do exactly that by using sort of a DC to DC very cheap DC to
DC converter configuration, which uses one transistor and these two inductors, they form an
oscillator. And with that you get roughly 8 to 10 volts in spiked form, meaning it is not a
continuous 10 volts, the output is more like something like this.

And this peak could be 5 to 10 volts and this is sufficient to drive a white LED. This sort of
circuit is called Joule thief because it sort of robs or rather extracts the voltage from a small
1.5 volt battery and yet drives a white LED, this is a popular circuit you will find on the
internet very commonly.

Now, we wanted to show how such a circuit can be fabricated using this Manhattan style
circuit board. So, for that, we first created a layout meaning given this circuit, how would our
components be arranged and here you see, this would be our, this dimension is our printed
circuit board.

Actually it is not the PCB, it is a raw copper clad board, meaning the board that you would
get in the market with the substrate of various sorts pasted with very thin sheet of copper,
typically the thickness of the copper that is available that is pasted on substrates is roughly 35
micron thick. And this is the raw form of the copper clad board that you would get.

These tracks that you see these black things is basically used to cut and separate various
segments of the copper to form small islands. And once these islands are formed then you can
solder components as listed here you see a diode, this is actually the LED, this is a resistor
this one, here is another resistor which is this base resistor. This is the transistor here in
between and what else we have?

We have an inductor, this inductor is here and on-off switch is not shown here, but this is the
on-off switch and you need a 1.5 volt battery, this is the battery holder, these are the two
connections as you see the plus and minus are separated because the copper layer has been
removed from these two parts so let us see how it looks like.

903
(Refer Slide Time: 27:40)

Once you have laid it out, you have to have some practice of laying out layout on piece of
paper and then you cut a raw copper clad board of suitable dimension and then using a file, a
thin file or you can even use the sharp edge of a knife or sharp edge of forceps to remove the
copper. You see this, there is no copper here and so, islands have been created.

(Refer Slide Time: 28:15)

And then once you have this is another view of the same PCB, different islands of copper
have been created which means now instead of a contiguous layer of copper it is partitioned
in small islands and now you can solder your components.

904
(Refer Slide Time: 28:31)

And this is what a soldered Manhattan style PCB looks like, here is the white LED, here is
the resistor in series with the LED, here is our BC 547 transistor, here is the base resistor for
the transistor, here is an inductor. And you see a battery holder has been soldered here and an
on off switch is soldered here.

905
(Refer Slide Time: 28:55)

Here is another view. Now you see as you see here, you see these components are rising up in
the air and this is a very simple circuit, but imagine that there are 50-100 components like this
you will suddenly see these components as tall buildings. And so this is the reason why this
technique of prototyping a circuit is called Manhattan style, this is very popular whenever
you use high frequency circuits.

(Refer Slide Time: 29:23)

Now, in this particular case we used a single sided board meaning that copper was available
only on one side of the PCB, the other side was blank. But you also get such PCBs of the
type called double sided PCBs which means, you have copper on both sides. So, you could

906
utilize one side force soldering your circuit and the other side of the copper could be
connected to ground to create what is called as ground plane.

And having ground plane is very helpful whenever you are testing and prototyping high
frequency circuits. So, in fact this is very popular with the ham radio community who build
radio circuits of very high frequency this is a very popular method, quick method of creating
your own circuit implementation. And in this what all you need apart from soldiering wire
and soldering iron, you need a cutter for cutting the components to appropriate size.

907
(Refer Slide Time 30:32)

And ofcourse, you need a file what is called as a watchmaker's file, which is a very thin file
for removing unwanted copper to create these islands, apart from that, you need a hacksaw to
cut a PCB of appropriate dimension. Other than that, no specialized tools are required for
prototyping a circuit using this Manhattan style PCB.

(Refer Slide Time: 30:56)

At this point, we now come to the most common and most comprehensive method of creating
professional and custom made circuits and that is the using custom PCB fabrication
techniques.

908
(Refer Slide Time 31:00)

Professor Dr. Badri Subudhi: So first of them, you have to use a toner transfer method, so in
toner transfer method, initially copper clad cutting will be there. So, after that sandpaper can
be used for sanding the surface for surface preparation then a layout will be placed so it is
called as placing the layout.

After that paper will be removed so paper removal, then removing unwanted paper with a
needle, then etching then scrubbing then acrylic spray then drilling and soldering. So, these
10 stages are mainly required for toner transfer method.

909
(Refer Slide Time: 31:35)

Professor Dhananjay Gadre: So, let us start with the first step. Now to be able to create a
circuit board a custom circuit board you definitely need a schematic. Here is an example of a
schematic, circuit schematic and as I mentioned in the very first lecture, that it would be
helpful if you knew how to use some schematic capture and PCB layout software.

We recommend using Eagle CAD. And this schematic was drawn using Eagle CAD, it allows
you to create a schematic and from the schematic it allows you to create a layout, I will
explain both of them here. Here is a circuit diagram, which is basically a oscillator using a
555, as you see here a 555 IC, it has a bunch of components. It is an Astable multi-vibrator
and you create that layout, you create the schematic, from the schematic you create a layout.

910
(Refer Slide Time: 32:32)

Here is an example of the board layout. Now, you see many of the things you see here, it
appears to be mirror image. And it is not by mistake, it is by design and desire that once you
create a layout, you can print it out on a piece of paper and you can choose to have the true
version or the mirrored version.

And for the toner transfer method, we have to have the mirror version which I will explain
briefly shortly why a mirror version is required. Also, this is a board layout which means this
is what it would look like on the screen of your laptop or desktop PC that you are using to
create this layout.

The thick black tracks, these are going to be our copper tracks which will connect various
components as you know mentioned or as listed here or as designed here. So, they will
translate into this, ofcourse this is not done automatically, you have to place the components
that are shown in the schematic diagram onto your board and then you have to make the
connections.

You can choose to use the auto routing feature of the software. But in this case this was done
manually. Once you have laid out your components and you have interconnected them then
you see since this is just a view on the laptop or the screen, you see it shows where all which
components are going to be placed.

The actual layout will not have this information, you do not want because otherwise what will
happen is this track here and this track here are going to get shorted because of the outline

911
here which is off a buzzer. So, this is only a view that you see on the screen of the PC, but
this is important, once you have this then you have to print it out.

(Refer Slide Time: 34:27)

Now, to prepare for the process, you need a copper clad board and you had to cut that copper
clad board to be slightly bigger or equal to the dimension, this is the dimension of my PCB
that I wish to fabricate and therefore you must make a appropriately sized, you must cut a
appropriately sized piece of copper clad board from a larger stock that you may have.

For that you can use a hacksaw, you can mount the raw copper clad board onto your table in a
vice and then using a hacksaw you can cut it. Or if you have access to a Computer Numerical
Control machine called as CNC machine then you can program it to cut it off exactly the
same dimension as you want.

You can also have that CNC machine drill holes, especially the mounting holes or other holes
also and this method is very good if you want to fabricate several, say 20 PCBs you want to
make, using the hacksaw method will be manually taxing and may take more effort. But if
you do not have a CNC machine then it certainly can be used. So you first cut a copper clad
board of appropriate size.

912
(Refer Slide Time: 35:46)

This is by the way, an example or view of a CNC machine that I have in my lab and we use it
often to cut as you see here. This is the raw big size copper clad board that has been mounted
on the table of the CNC machine and here is the spindle onto which a cutting bit has been
installed and it can cut in whatever arbitrary shapes as you see, circular PCBs have been cut
so on and so forth.

Anyway, once you have the raw copper clad board and you cut it to size, the surface of the
copper clad board will often be dirty and may have some scratches. And having making a
PCB on such a dirty surface will not result in a good quality PCB. And therefore, the first
important step to follow is to smoothen the surface and to remove all residue of oil or grease
or dirt that may have accumulated.

913
Even oxidized copper would not allow a good PCB to be made and therefore, it is strongly
recommended that you first prepare this surface of the raw PCB, and for that the best method
is to use a sand paper. Before that, let me also mention that the PCB itself is of various types,
you get very cheap PCBs.

(Refer Slide Time: 37:12)

You may have seen brown coloured PCBs, they are made out of material called phenolic
material phenolic PCB, and I we do not recommend using such a type of PCB, the good
quality sturdy PCB is called FR4 and this is made out of fibre glass. This is the substrate, this
is a non-conductive surface on which a thin layer of copper has been pasted. And this is an
example of a FR4 type of raw PCB.

914
(Refer Slide Time: 37:47)

Once you have cut it, then you start scrubbing it, you start using a sandpaper, again sandpaper
is available in various types. The grid that is the size of the sand particles which are stuck on
the sandpaper is very important because we do not want to scratch the surface, we want to
smoothen it.

Therefore it is very important that you choose a fine pitch fine grade sandpaper. In our lab we
use 320 grade sandpaper, you can choose any grade above 320, 400 so on and so forth. If you
choose 100 grade sandpaper it will leave visible marks on the PCB so we do not recommend
that.

915
(Refer Slide Time: 38:35)

And here is an example, here is the raw copper clad board as you can see, it is very dirty and
then you use a sandpaper to clean it and once you have rubbed it, you see it is much more
smoother and uniform and devoid of any oxide. So these are the three stages of sanding,
sandpapering the PCB. Once you have you have this prepared copper clad board, you are
ready for the next stage. What is the next stage?

916
(Refer Slide Time: 39:02)

Then you take your layout, now you see this, you print the layout on a photo paper, you do
not print it on a normal paper, what is recommended is a photo paper. Photo paper is
available these days on various internet sites as well as regular stationers, this photo paper is
the same paper that is used to print photographs.

Because these days people can print photograph using home printers inkjet printer, so similar
photo paper is used. This photo paper is used on a laser printer, you cannot use the inkjet
printer for printing the layout of the PCB that you want to make. So two important things one
of photo paper, two a laser printer. This is very-very important.

Now once you print the layout on a photo paper, you cut it slightly bigger than the dimension
that you want. Now you see this printout is different from the layout that we saw earlier let
me show it to you.

917
(Refer Slide Time: 40:02)

Because here, the references of the components and their names and where they are going to
be placed they have been removed, while printing we make sure that we want to print only
the layout as well as any text on the copper side of the board that you may want as you see
here, I have the holes, the components, this is where IC will go, this is where a switch will go
and so on.

And I also have this printed here, this is the name of my lab and this is a CPO that stands for
code practice oscillator, you can print other relevant information as to who made it, when it
was made left up to you. So once you print it out, this is the outside limit layout of the PCB
and these are the four mounting holes.

918
Now what you do is, you flip this and place it on the copper side of the cut PCB that you just
prepared, which you use the sandpaper to shine. You flip this layout, the print side, place it
on the copper side of the PCB.

(Refer Slide Time: 41:12)

And then use a normal regular home iron for ironing clothes, we use a similar iron about
1000 watts and we firmly press the hot iron on the on the paper. So, that the idea is that the
print which is there the laser print gets stuck to the copper. So, you may need some practice
but roughly five minutes of intense pressing is required so that the entire paper gets stuck to
the PCB.

919
Here you see the pressing is in progress and after it has been pressed, this is what it looks
like. You see, because of the heat you see a little bit of blackening here. This blackening is
nothing to worry about, it is basically the rubbing action of the iron which appears to have
made the paper black, no issues. Make sure that you do not hurt yourself in this process. Once
you have pressed the board, you are ready for the next stage, what do you do in the next
stage?

Now this paper was a necessary evil, we do not want the paper, what we want is the layout
and we want the layout to be transferred on the copper surface of the PCB.

(Refer Slide Time: 42:19)

And so we will remove this paper and that is very easy. All you do is dunk this PCB with the
paper stuck on the surface into cold water in a plate or some in a little container and gently,
gently, it is like you are giving a massage to the paper stuck on the PCB. And the idea is
basically the paper will get dissolved or will get wet and you can gently ease it off. And once
you do that, this is what you will see.

920
(Refer Slide Time: 42:51)

Now you see, you remember I mentioned that we need to print the mirror image of the layout
so that when we press it automatically mirrors the mirror and we get the original. So you see,
everything you see here is in the correct orientation that we want. This is you can it is
readable English, on the layout, it did not appear to be readable and that is the test to see
whether this is the correct printer you have made or not.

And now, you see the copper, you see all these tracks which have been which is nothing but
the laser print which has been transferred on the PCB. You also see there are white patches
here, this hole is not open, that is nothing but paper which has not been removed from the
copper.

And so the next stage will involve removing this paper so that you are left with only these
print tracks, holes and copper and nothing else, there should not be any leftover paper on the
PCB that that is what we need to do in the next stage.

921
(Refer Slide Time: 44:00)

And here we are going to use a small needle to manually remove what appears to be paper.
And once you do that, this is what your PCB will look like. Now, it is ready to be etched,
what you have achieved is, you have achieved the print which was from the laser printer on
the photo paper to be transferred on to the copper surface of a PCB.

This print will resist any acidic reaction from chemical that we are going to use. And so, it
will protect the copper underneath the black tracks or black print that you see the copper
underneath will be protected. For that we need to put it in a solution, in a chemical which will
react with copper.

922
(Refer Slide Time: 44:52)

And the most common form of etching process is to use ferric chloride. Ferric chloride may
be available in liquid form or you may by crystals and using distilled water, you can create
ferric chloride solution. If you have access to a chemical laboratory in your college, they may
offer you the best advice.

Always use a plastic container for etching because you cannot use any metal because the
ferric chloride will react with the metal. So here we see, dust bin actually is being used for
etching the PCB. We also have a rubber glove. This is an important you do not want to
interact you do not want the ferric chloride to come in contact with your skin.

Although it is not very harmful you can always wash it off, but if it can be avoided, why not.
So you see copper glove is used to handle the PCB as you put it in the etching solution.

923
(Refer Slide Time: 45:50)

Once you have put it in the etching solution, you have to vigorously agitate the container and
this basically will accelerate the reaction. Another method to accelerate the reaction is to
increase the temperature of the etching solution and you could use a heater or something like
that, but one has to be very careful not to melt the container.

Even if you do not heat it up, it will take about 15-20 minutes of vigorous shaking the
container and this is what once you take the PCB out of the solution, you see the copper is
gone. Only black tracks are left and the substrate of the PCB, which is the fibre glass material
is left.

924
(Refer Slide Time: 46:36)

Here is the here is what it looks like. And it has just been placed on a tissue paper so that
additional ferric chloride is absorbed.

(Refer Slide Time: 46:49)

Now you need to go to the next stage which will involve washing and scrubbing the PCB. So
it should be thoroughly rinsed in flowing water and so you could use soap also to clean it.
And then what you do is, you use any method to scrub and remove this print that you got
from the laser printer, you have to remove that.

You could use a sandpaper but use it gently, you do not want to sand off the copper tracks,
you just need to remove the print.

925
(Refer Slide Time: 47:22)

Once you do that, here is your beautiful looking PCB, and you can match it with your layout
to ensure that no tracks are cut. For that you may use some inspection mechanism like
magnifying glass or something like that. Make sure that no tracks are broken. And now you
are ready to drill holes into this. Once you drill holes, this is what you this.

Okay, before you drill holes, you need to now as I mentioned, copper will oxidize quite
quickly. And if you do not protect the copper from oxidation, in a day or two, it is suddenly
start looking brown in colour.

926
(Refer Slide Time: 48:21)

And so what we do is we use an acrylic spray. It is called conformal coating, this is available
in many electronics markets, we spray a very thin layer of this acrylic material onto the PCB
and in about half an hour's time it dries off and you are left with a beautiful PCB which has
been coated with the acrylic material and it protects the copper tracks, now you are ready to
drill holes.

927
(Refer Slide Time: 48:31)

The first thing you must drill is the mounting holes which are usually we use a 3 mm drilling
bit for that. Once you have drilled the mounting holes, you can use a thinner drilling bit. In
this case we choose either 0.7 mm or sometimes for thicker components that is components
with thicker leads, we use 1.0 mm drill bit to drill holes.

928
(Refer Slide Time: 49:10)

Once they are drilled, this is what the completed PCB looks like and as you can see the
copper, the paper underneath the PCB. And you can see that they have been neatly drilled.
Now you are ready to go to the next stage which is to refer to the layout, refer to a bill of
material which will tell you what should be the value of various components that you must
solder. And so you must bring all these things together.

(Refer Slide Time: 49:39)

Here it is being shown in the soldering setup. So not only do I have the soldering iron with
me, I have the other material which is very important while you are sorting because you do
not want to insert the wrong component in some hole, only to have to de-solder it. So it is

929
better to take preventive measures, make sure that you are sure that this is the component to
be soldered in given holes.

(Refer Slide Time: 50:02)

And so we have a layout printed a print layout, we also have a bill of material which tells me
which component, what is the value, where it is to go and so on. Once we have that then the
rest of the components, rest of the implements and tools are very similar to what we used in
the past.

930
(Refer Slide Time: 50:17)

Here is a cutter, once we insert the component in the holes, we have soldered it we need to
cut off the unwanted length of the wires for that we need this cutter. This tweezer will be
used to bend the components nicely so that they go right into the holes where they are
supposed to go so tweezer is meant for that.

On this side we have the soldering station here. This is the soldier wire, spool of soldier wire.
We choose the thin size of the diameter of the soldier wire, it is often you may have to find it
in the market. We use a 26 swg for that again for the solder wire.

By the way, the solder wire is not solid, it is hollow, it contains flux and the proof of that is
when you melt a solder wire on a solder iron or a solder station you see vapours and those
vapours are because of the chemical flux. This chemical flux helps to cleanse the surface
when you are soldering any electronic components, it cleanses at nano, micro level which you
cannot clean otherwise.

And here you also have a spool of what we call as jumper wire or we call as hook-up wire,
which is a conductive wire, there is no insulation on it, it is tinned copper wire again, 26 or 24
swg, this would be used to create jumpers because we are making a single sided board. So
you need all these things on your table. Your table needs to be very clean and once you have
that, then you insert components.

931
(Refer Slide Time: 51:57)

The way to insert soldering components is that you must solder components with smallest or
lower profile first, which means you solder registers and SMD components first, then you can
solder IC bases or LEDs. And as the height of the components increase, you should solder
them later. Once you have done that, you can snip off extra leads of the components with this
cutter as you see here.

(Refer Slide Time: 52:25)

And once you do that, you are left with a beautiful PCB where all the components have been
inserted rightly as you see here, the resistors have been nicely bent at 90 degrees so that they
are easily inserted in the given holes. Here is a LED, it is powered with a battery, here is a

932
buzzer this is the 555 IC, here are two capacitors one of them is a electrolytic capacitor, the
other is a ceramic capacitor.

And these four mounting holes with screws there allows you to put it on any surface without
a danger of making unwanted connections because the surface might be conductive. Now,
this is an example of a custom made PCB, which is very good for prototyping. Ofcourse, if
somebody says we want to have 10000 pieces of this circuit, it would be very difficult to do
all these manually.

What you would do at that point is the layout that you created, instead of making the PCBs
yourself you can order this PCB to be made by professional PCB fabrication companies and
they would give you a large volume in small amount of time. You could choose to solder it
manually or even the soldering process can be done in the automatic way.

This is an example of a single sided board meaning that the copper tracks are only on one
side, but using this technique in a lab, you can create a double sided board also for that you
need instead, by the way I forgot to mention the thickness of typical copper clad board that
you get in the market is 1.6 mm, but you also get a 0.8 mm thick PCB.

And when you want to make a double sided board, we choose to use 2.8 mm thick PCBs.
Each PCB will make one side of the layout, and then we align them and glue them together
and put wires through holes so that the two PCBs join up and make like a 1.6 mm PCB. So it
is possible to prototype a double sided layout also in the lab.

If your circuit is complex enough to merit a multi-layer board, beyond single sided you have
double sided, you also have 4-sided, 4-layered, it is not 4-sided, 4-layered or 8-layered or
6-layered, 20-layered PCBs also you can have, for that it will be difficult to prototype in the
lab and the best way is to send out your layout to a PCB fabrication facility which has
capability to fabricate PCBs of the type of the number of layers that you wish.

Once you do that, you get the PCB back then you can solder manually as I mentioned. In the
activities related to this course, in the introductory kind of projects that you may want to
prototype, single sided as well as double sided PCBs might be sufficient for a large number
of cases.

Ofcourse, I am not saying that only single and double sided boards would suffice. In some
cases, you may need multi-layer PCBs, where the only option you may have is to get even a

933
prototype PCB fabricated outside. But you must be aware of all these methods of testing a
circuit before committing for a final version. And with this lecture, we hope that we have
introduced you to all the common methods of prototyping and we hope that you would use
these techniques to chart your own project whenever you are ready with an idea, and you
want to actually build it in a way that a professional would build.

And as we discussed in an earlier lecture that PCB is only one part of a system, you would
need an enclosure, you would need if there are multiple PCBs you will need to wire them
together. I have already covered that in a previous lecture,

And I hope using both these lectures together, you will be able to plan and go onto the path of
creating a professional looking PCB, which will give you a good confidence that your final
project will work successfully. I hope you find our lecture here very useful. Thank you for
listening to us and we will see you soon in a new lecture. Bye, bye, Thank you.

934
Introduction to Embedded System Design
Professor. Dhananjay V. Gadre
Netaji Subhas University of Technology
Professor. Badri Subudhi
Indian Institute of Technology, Jammu
Module 12
Lecture 38
Single Purpose Computers

Hello and welcome to a new session for this online course on Introduction to Embedded
System Design. I am your instructor Dhananjay Gadre. Today we are going to look at a very
different topic. Although we mentioned this topic in the first lecture, where we were talking
about various ways of implementing the embedded computers and to revise that or to mention
what we had repeat what we had mentioned, we had said that there are 3 ways of
implementing an embedded computer.

(Refer Slide Time:​ ​0:57)

The first method is using a general general purpose computer plus processor, the second is to
use an application application specific processor. For the first approach you might be using
commonly available microprocessor such as 8086, 68000 and so on. For the second approach,
we will be using a microcontroller which is what we are doing in this course. But we had
mentioned a third approach and this is this was called single purpose computers, which
means computers which are designed with only one objective in mind which is to solve the
current problem at hand, it cannot do anything else. If you want to modify it, you will have to
redesign everything.

935
Usually the single purpose computers are implemented using digital logic. And it follows
paradigm which we also showed how that paradigm of looking at the computational model
applies to the general purpose processor, as well as the application specific processor. That
paradigm included 2 building blocks. One was called the sequencer or the controller, and the
second was called the data path.

The sequencer decided which elements of the data path to be used for what computational
tasks, the elements of data path would perform their tasks, process data as they are capable
of, and convey the result or parts of the result to the sequencer to decide the next course of
action.

In this lecture here, I am going to show you a sample project implemented using such an
approach. The heart of a single purpose computer is the finite state machine. This finite state
machine is a computational model with which you can create sequences. It uses a concept
called states and outputs and conditions of transition.

(Refer Slide Time: 3:28)

When a certain machine has characteristics of switching into other states in accordance with
its inputs, past status, clock signals, these class of machines are called finite state machines,
they are known by other terms also such as finite automata sequencer as we will be using that
term often in this lecture or control path.

936
(Refer Slide Time: 3:52)

Now broadly, there are 2 types of finite state machines. One is called the MOORE machine
here. The characteristics of this MOORE machine is that the machine output depends only on
the current state. So, the representation of the states, outputs and the transition conditions are
illustrated using a diagram called state diagram.

So, here in this machine, there are 2 states, one is we could we could call it S0, state 0 and
another is state 1. And if you are in state 1, state 0, then it would produce certain outputs
which you can define here. We are just given a label output, but you can mention what all
outputs you have, what is the values of those outputs 0, 1 whatever.

And then when a certain condition is true, here, it should be that if the condition is say not
true, then it will remain in the state but if the condition becomes true, it will transition to S1.
Similarly, we could make it that if the condition is true, it remains in the state, but if the
condition becomes false, so I have used a condition bar, it will transition from S1 to S0. This
is the complete description of a MOORE state MOORE type of finite state machine. There is
another method of modelling state machines and that is called Mealy machine.

937
(Refer Slide Time: 5:28)

In Mealy machine, we have the states are still the same, but now, the outputs have moved
from within these states, these circles which represent the state on the edges which represents
the condition and again I will have to correct this, here is the condition bar and if there is
condition, then say I can say output 1, this is output 2, if it is condition you remain in so, this
is state S0, this is state S1 and for condition 1 and you could have output 2 here, it continues
to produce output 2. And if it goes back here it could be output 1 again and it goes back into
state S0.

This is the graphical representation of any finite state machine. As you can see, it uses 2
symbols, one is a circle to represent the state and one is these arrows which represent the
transition conditions. These transition conditions are basically inputs, which when they
change, they transition from one state to another state.

However, one must also keep in mind that if these finite state machines are implemented
using a synchronous logic, then the transition happens on 2 conditions. One is this condition
being checked, but also at the rising or falling edge of the clock whichever may be the case in
your implementation. So, it requires 2 conditions to be true, the physical condition that is the
input to have a certain value and the transition of a clock from 0 to 1, then only it will
transition from state S0 to S1, this must be kept in mind. It is not mentioned here, but this is
what is the assumption.

938
(Refer Slide Time: 7:27)

The physical representation of such a state machine can be done by using 3 building blocks.
One of them is the memory as you see here, this is the memory, this is the combinational
logic and this also is so this I would say combinational logic 1 and this is combinational logic
2. The combinational logic receives the inputs, these inputs are external inputs, which means
we call them asynchronous inputs, which means they are coming from an outside world
outside of this system.

And therefore, they can change whenever they wish to. They are applied to this
combinational logic block. This combinational logic block produces an output, which
becomes the input of the memory. And so since this is the value that is currently known, this
is called next state I will come to that in a moment.

The output of the sequential logic which is which could be implemented with D type flip
flops is passed through another combinational logic block and that produces the output. And
since we said in the Moore machine, the outputs are dependent only on the present state. So,
this is your present state. The combinational logic does not change the state, it simply
transforms these present state values into expected output.

And these are the outputs that you mentioned in the circles that represented each of these
states. These present state values also are fed back into the first combinational block and
together with the inputs they decide the next course of action that is, it provides next state
inputs.

939
And as you see, the memory is clocked and this clock is locally generated and the rate of this
clock will decide how quickly the state machine can transition. All of this can be
implemented using logic circuit, this is combinational logic, this is memory that is flip flops
and this is another set of combinational logic.

Now, in this block diagram, if you want to represent a Mealy machine, all you have to do is
the inputs now are able to affect the outputs, not only the outputs are affected by the current
state, but current inputs may also modify the outputs.

(Refer Slide Time: 9:53)

And this is represented in this second diagram here. And you see, the rest of everything
remains the same, this is my next state. This is my present state, that present state is being fed
back into the combinational logic, but some of some or all the inputs are being fed into the
output combinational logic and therefore, these outputs are dependent not only on the present
state, but also on the present inputs.

And these are two alternative methods of implementing the finite state machine using the
Mealy model or the MOORE model. Now, when you probably would study this as part of
digital circuits and systems, and they would talk about various examples, and I want to take
one example, what are simple examples that you already know?

A counter is an example of a finite state machines, it has finite number of states, which can be
limited by the will be limited by the maximum number of flip flops being used in that
counter. And so, the state diagram can be drawn to represent the transition of the states that is

940
how the counter is working? Is it counting up or is it counting down? Or is there any
sequence, up or down sequence or you want to change that sequence, you can create a
counter with arbitrary outputs also. Outputs that do not seem to have a pattern of being
increasing or decreasing, you can choose that.

(Refer Slide Time: 11:22)

And let me show you an example of a finite state machine. Essentially, it is a counter except
with the little addition that I have added an enable signal. If the enable signal is 1, it transition
from one state to the other. If the enable signal is held to 0, it will retain the current state, and
if it retains the current state, it will keep on producing the outputs as mentioned in the state
circle in the symbol that represents the state.

Now, how do you implement such a finite state machine? How do you implement that
counter? Now you can actually draw from the state diagram you can create a state table, in
the state table you will create a table, let me show you what that table would look like.

941
(Refer Slide Time: 12:10)

In the table you will create what is your present state, we call it PS, what is your next state
and what are the outputs. And if it is a MOORE machine, then the outputs will can be
mentioned as a function of the states only. So, if I know my present state S0, I know my
output so maybe output 1 and my next state could be S 1 and if my present state is S1, this the
next state is S2 and you can have output 2 and so on, and eventually it will somewhere it will
say let us say S7 and I want to go to S0 and output will be OP7.

Now with this table I have actually represented a counter with no enable signal, why?
Because whenever you are in state S0, the clock will take you to S1 if you are in S1 it will
take to S2, there is no condition to hold the current state. If we want to modify it to be
representative, this is the state diagram. This is the state table from the state diagram we drew
earlier, if you want to create the state table for the earlier state diagram, then it will have to
have the following representation.

942
(Refer Slide Time: 13:41)

So, this is a state table, here you will write present state and if the input is enabled, if it is 0
and if it is 1 because there is only one input what will be the next state, and here is your
output. So if the present state is S0, if the enable signal is 0 is the next state will be S0.
However, if the enable signal is 1, the next state will be S1, but if you know as 0, you can say
I want the output to be 000. If the present state is S1 and if enable signal is 0, it will retain
that state and if it is 1, it will go to the next state and I can have my output 001 and so on and
so forth.

Now once you create the state table, you know the relationship between the inputs and
outputs of your first combinational block, the relationship between inputs and outputs of your
second combinational block and the middle block is just few flip flops and we can decide
how many flip flops to use. One method is for the total number of states that we have, we
take log 2. So like we have 8 states, we take log 2, you get 3. So, all you have to do is use 3
flip flops, this is the encoded method of representing the states.

The other option is for all the states you have one flip flop, and that is called one hot method
of encoding representing the state, we are not going to go there, it may appear that one hot
encoding uses more memory. But the advantage of that oftentimes is that when you use more
memory, your decode logic that is the first block of combinational circuit, maybe even the
second block of combinational circuit, the complexity of that circuit will simplify.

So, it is a trade off. If you use the encoded method that is used less number of flip flops, your
combination circuit might increase. And so you decide whether you want to use the encoded

943
method of State representation or the one hot method. Anyway, this can be manually
implemented meaning you could create a table which which implements the relationship here
between inputs.

(Refer Slide Time:​ ​16:17)

Now, your input here is enable as well as the present states and you are producing next state.
So, if I use the encoded method, the number of flip flops will be 3 therefore, you have to deal
with 3 D type inputs to the flip flops, we can label them D0, D1 and D2. The outputs of these
flip flops will be Q0, Q1 and Q2 and these outputs here they go into the combinational circuit
including the signal enable.

(Refer Slide Time: 16:57)

944
So, you have to create a table which has Q2, Q1, Q0 and enable to produce outputs which is
D2, D1 and D0. Which means it is a matter of implementing 4 combinational circuits with 16
states here, these 16 states will produce one output the same 16 states will also produce
another output and the third output and that resultant combination logic circuit will go in the
first combinational block one. So, here you are putting en enable, we are also putting Q2, and
it is producing D2, D1 and D0.

So, implementing finite state machine is an exercise in starting from creating the state
diagram from there to create the state table. That state table will give you the relationship
between inputs of the combinational circuit and the outputs, it will also give you another
relationship for the second building block combinational circuit 2. The inputs to this will be
Q2, Q1 and Q0 and the outputs will be say O2, O1 and O0.

So, you solve this combinational circuit using minimization techniques that you are aware of,
you solve this combinational circuit using the same approach and the middle path is just
sufficient number of D type flip flops. So you see, solving implementing a finite state
machine is all about implementing a couple of combinational circuits. Now, this is possible
manually using a pen and paper method.

If the number of inputs on your combination circuit are few meaning 4 or 5 or 6, because
with four inputs you can draw a K map, but as the number of inputs increase, then you may
have to resort to other methods. And in the contemporary world, this is only for learning
purpose, real implementation is done with the help of representing the requirements of this
state machine as a hardware description language code. So, I am going to show you that for
this counter what kind of VHDL code is implemented.

945
(Refer Slide Time: 19:41)

Here is the VHDL code here, as you are aware VHDL code consists of 2 parts; the entity
declaration here, which defines the relationship of this circuit with the outside world. So, in
this case the entity will have all those signals which enter the circuit and which exit the
circuit. In our case, we have a clock and enable signal and the outputs are these actual outputs
which are the output of the counter.

And then the second part of a VHDL code is the architectural description architectural block
which decides the relationship between these input signals and the output signal. And you can
express that in various ways various methods of writing your code, one of a common popular
method is called behavioural style of modelling.

In this you have represented your code and once this code is compiled, it will give you a net
list of components or digital logic building blocks which when connected, as the net list
suggests, it will implement a 3 bit counter. Now, what can I do with that counter? Let me
show you an interesting variation to that counter. We have a counter with 3 outputs and it
uses all the possible states that is going from 000 to 7. So, essentially what was implemented
was an up counter with an enable signal, whenever enable is 1 it will transition to the next
state, if the enable is held to 0, it will hold that current state.

Let me say that I modify that ​counter to not have 8 states but have only 6 states say
1,2,3,4,5 and 6. Which means it will still require 3 D type flip flops, because the number of
states is more than 4 and less than 8. What would I use that for? I could use this circuit to
actually implement a dice, how?

946
(Refer Slide Time: 21:44)

So, it is like this that I have created a counter. The counter requires a clock. Yes, it can be
high frequency clock, but now I have a enabled signal in the following form, I have VCC, I
have a switch, and I have a pull down resistor. And this is going into the enable signal of the
counter. Now since this is 0, it is going to hold the state, this 3 bit, we will call it 3 bit dice
counter. The outputs are, let us say, y2, y1 and y0, so there are three outputs. And the state
diagram for this is as follows. You have 1, 2, 3, 4, 5 and 6 states, if the enable signal is 0, so
enable bar is going to remain in that state this is S0.

Now instead, I can choose whatever outputs I want in those states, and I want because the
dice will give you random numbers between 1 and 6. I want the first state to give me 1, 2, 3,
4, 5 and 6, and if the enable signal is 1, it goes to the next. Here again, en bar so it is S1, en,
here en bar. Again, this is S2, S3, S4, S5, en, this is going to stay here for en bar, en, e bar,
en, and I am going to stay here for en bar. Now, basically what I have done is I have
repurposed that counter to become a dice. The only condition is that the clock frequency
should be very high.

Now, when the user presses the switch, the counter will start working, it will go transition
through all the states and when I remove the switch press, when I release the switch, the
enable signal will become 0 and it will hold a state where it had reached and those outputs
will become stable. Now, these 3 bits can be decoded passed through another combinational
circuit and can be represented on a 7 segment display if you like.

947
And so, what you have done is started with a simple finite state machine and convert it into a
useful piece of equipment or gadget. However, please understand that this is not really what
full computer would do. This does serve a purpose but this is a very simple applications. In
real applications, the finite state machine is only a sequencer which means it tells somebody
what to do and that somebody has to actually perform those operations.

In this simple application, the sequence itself could be converted into numbers, but nothing
more. And so, what we are going to look at is a bigger model where we are able to not only
decide the sequence, we can program what sequence we want by implementing the state
machine and we have other elements of data processing, which are under the control of the
outputs from the state machine to perform useful computational operations. And that
approach involves a building block which we call as the data path.

(Refer Slide Time: 25:42)

So, data path nothing is nothing but it represents all the functional elements which process
data which are under the control of the finite state machine. And when you glue these 2
building blocks together, one which consists of the sequencer or the control path and the
other which consists of data path elements, then you are able to implement a single purpose
computer.

948
(Refer Slide Time: 26:23)

And that is represented or that is called FSMD that is Finite State Machine with Data Path. A
finite state machine sequences operations into data path through signals called control
signals, the data path elements under the control of these control signals perform certain
useful operations, they may give the feedback back to the sequencer using what we call as
status signals. And the happy marriage of these 2 elements will be used to implement a single
purpose computer.

(Refer Slide Time: 26:47)

So, we need to send control signals to the data path from the sequencer, and the data path will
need to perform useful operations and give feedback to the sequencer to show that the
sequencer can decide what is the next course of action. Here is a block diagram

949
(Refer Slide Time: 27:12)

I this is a repeat of what I had shown earlier that we have a sequencer, which is nothing but a
state machine. And the state machine produces control signals and feeds various elements of
data processing elements. And here is a list, I will show you a bigger list, these elements will
operate on that data which may be coming from outside or may be provided by the sequencer
and it will give a feedback to the state machine.

State machine can also provide some outputs or these data processing elements will provide
outputs either stored them in memory or provided in the outside world. Let me draw a
representation of FSM-D which is useful for implementing single purpose computers.

(Refer Slide Time:​ ​27:59)

950
So, here is my sequencer, here are inputs and these might be these would turn out to be
asynchronous inputs, I would need a clock signal, this is my clock, here is my elements of
data path data path, these data path elements will get control signals from the sequencer. So,
these are control, the data path elements will perform certain operations for which it may
have some inputs from the same inputs which are going to the sequencer, or it may have
certain other inputs, it will provide feedback and we call this status.

The data path may produce certain outputs for global consumption that is for the outside
world. The sequencer may also produce some outputs if it so wishes, and these 2 outputs are
your global outputs or user outputs. So, this is the block diagram that we are going to use in
this lecture and we will implement a useful single purpose computer.

(Refer Slide Time: 29:28)

What are the elements of data path? This is not this is not the only 10 elements, this is just a
sample of such data processing elements. Usually data path elements are elements of
combinational circuit, you can implement elements of data path using simple combinational
logic, but that is not necessary. Sometimes you may have to store some information for
further processing. So, for that you may require latch and flip flops. Sometimes you want a
flip flop with the enable signal so that you only capture the data whenever the enable signal
allows you to.

You may use tri state buffers, you may use comparators for comparing 2 numbers, you may
use encoder and decoder, you may use multiplexers and demultiplexers and counters and you
can use adders and subtractors or you could make generic building block and arithmetic

951
logical logic unit which would not only perform mathematical operations, but may also
perform logical operations. You could also divide the clock for use in certain parts of the data
path. And this is just a sample of some of the data path building blocks.

(Refer Slide Time: 30:46)

So, here is the representation of a flip flop. And, like I mentioned, we do not manually
connect all the building blocks such as flip flops or gates, but we write VHDL code to model
them. So for our flip flop here, it is a rising edge flip flop as this clock indicates here, this is
the rising edge. And so it is going to capture whatever data here on every rising edge and
present it to the output.

(Refer Slide Time: 31:15)

952
Here is a VHDL code to represent that. I am not going to go in detail and I strongly urge you
and encourage you to learn VHDL or other hardware description language such as Verilog
and there are many, many software programs available which you can which you can use to
practice and develop logic systems.

(Refer Slide Time: 31:45)

Here is a controlled latch which means it is going to capture information at the rising edge
but only when enable is 1, let me show you what does it mean?

(Refer Slide Time:​ ​31:56)

It means if enable is equal to 1, then Q gets the value of D on clock rising edge, else if enable
is equal to 0, Q gets the value of the previous value, so I will call it Q previous which means

953
it does not capture the input. Now, how does it how does it use a normal D type flip flop, how
does a normal D type flip flop get modified to implement such a such a requirement? Well,
this can be implemented as a finite state machine by itself.

And you could draw the state diagram for this final state machine and implement it, and the
implementation will look something like this that it does use a D type flip flop, but it uses an
additional component which in this case is a 2 input multiplexer; 0 and 1 are the inputs, the
output of the multiplexer provides the connection to the D input of the D type flip flop.

Here is the Q which will go to the outside, but it will also be fed back into the 0 input of the
multiplexer. The one input of the multiplexer is actually the D in, which you want to capture
here so D in. The clock will be applied to the clock input and the control signal of the select
line of the multiplexer will become the enable signal.

Now, let us go through this circuit to understand that it actually implements this requirement.
Now, if enable is equal to 0, the 0th input gets connected here. And the 0th input is nothing
but the current value of Q. So on every rising edge, it is going to just capture D and transfer it
to Q which means Q value is not going to change, but the moment enable signal becomes 1.
Now it is going to route the D in input to the Q and now on every rising edge every rising
edge it is going to capture this value and put it at the output, this is exactly what we wanted.

And so, this is the method of implementing a latch with enable signal. Similarly, you can add
more signals to this by saying that I want a reset signal that is if reset is one, then irrespective
of the state of the rest of the input signals, the output should be 0 and so on and so forth. And
you can implement VHDL code to implement whatever functionality that you wish, here this
is the code for control the flip flop that is a flip flop where there is a enable signal, then one
important building block is the tri state buffer.

954
(Refer Slide Time: 34:58)

Here output becomes gets the value of input provided select line is equal 1, but if select line
is 0, then the output becomes high impedance.

(Refer Slide Time: 35:09)

Here is a VHDL code for that, this is Z here represents indicates the high impedance.

955
(Refer Slide Time: 35:16)

Then you would require comparators to compare digital numbers. Here in this example, two 3
bit numbers A and B are being compared. And a comparator typically has three outputs, A is
greater than B, A is equal to B and A is less than B. Whenever, any of these three conditions
is true, that particular output becomes 1 and the others are 0.

So if numerical value of A those three bits as a number is more than the numerical value of B,
AGT will be 1 and the rest of the 2 outputs will be 0. If the numerical value of A is equal to
B, AGT will be 0, A equal to B will become 1 and A less than B will also remain 0.

(Refer Slide Time: 36:06)

956
Likewise, this is the VHDL code for implementing such a three bit comparator and you can
increase the size by having n bits on the 2 inputs.

(Refer Slide Time: 36:17)

Similarly, this is an encoder which encodes the value here depending upon the combination
here of 0s and 1s, it provides an output and you could make a priority encoder meaning if this
is 1, then the value of this will indicate that In2 is 1 and so on.

(Refer Slide Time: 36:40)

Here is the code for the encoder.

957
(Refer Slide Time: 36:46)

This is the opposite of encoder, this is a decoder. In this case is a 4 to 16 decoder and again
VHDL representation for such a decoder.

958
(Refer Slide Time: 36:58)

Then we have a multiplexer, this is an eight input multiplexer, each of the inputs is single bits
and the select lines here will decide which of the inputs get routed to the output, we use such
a multiplexer 2 input multiplexer in a previous example, and multiplexers are very, very
useful building blocks and we are going to see their use in our implementation.

(Refer Slide Time: 37:20)

This is the VHDL representation.

959
(Refer Slide Time: 37:23)

Again, this is a counter and in this case the counter has a clock and a clear signal which
means if there is 1, all output bits of the counter will become 0, else it will count. Now, this
does not indicate whether it is going to count up or count down or may have a different
counting sequence that will be decided by the kind of VHDL we have.

(Refer Slide Time: 37:46)

And as we see here the count is being incremented on each clock edge. Therefore, this is a up
counter, VHDL code for up counter.

960
(Refer Slide Time: 38:01)

This is a arithmetic and logical unit and there are 2 operands, operand 1 and operand 0, and
the opcode that is the bits here will decide what operation it performs and it will depend on
you, if you want to do add, subtract, and to the bits of operands 1 and 0, it will depend on all
of you.

(Refer Slide Time: 38:20)

As you can see here, a lot of functions are being performed, here you are ANDing you are
ORing, you are adding subtracting you are incrementing, you are decrementing and so on. So,
you can implement a wide variety of functions using a ALU.

961
(Refer Slide Time: 38:39)

Clock divider is used to divide the clock frequency from a higher value to a lower value and
it is often useful in FSM-D applications.

(Refer Slide Time: 38:50)

Now what we are going to do this is the VHDL code for a clock divider.

962
(Refer Slide Time: 38:54)

What we are going to do is, in our next lecture, we are going to implement a single purpose
computer to implement a particular requirement and that is to implement a dual dice game.
That is a game in which there are 2 dice outputs and the rules of the game will be mentioned
and we will see how these are implemented very easily using the finite state machine with
data path approach. So, I will see you soon in the next lecture.

963
Introduction to Embedded System Design
Professor. Dhananjay V. Gadre
Netaji Subhas University of Technology
Professor. Badri Subudhi
Indian Institute of Technology, Jammu
Module 12
Lecture No. 39
Single Purpose Computers- Continued

Hello, and welcome back to a new session and we are going to continue our discussions on
Implementing Single Purpose Computers. I am your instructor Dhananjay Gadre. In the last
lecture, we were we covered some ground to understand the components of a single purpose
computer namely, we need a Sequencer and we need Data Path. The sequencer is nothing but
a finite state machine, that finite state machine could be implemented either as a Moore
machine or a mealy type of finite state machine it does not matter.

The data path elements will be determine by the requirements of the single purpose computer.
So, to illustrate this idea I am going to present to you a single purpose computer which will
play a game, which we call a Dual Dice Game. Before we start implementing the game as we
always do whenever we have to implement something the first and foremost task is set down
on a piece of paper the requirements unless you know what you require expect out of that
implementation things will not move forward and so, here is the problem statement.

(Refer Slide Time: 1:33)

We are having, a game where there is a there are two dice that we roll now, when we roll a
dice the number is between 1 and 6, when we roll two dice the purpose is actually to sum the

964
output of these two dice and therefore, this dice will produce a numbers between 2 and 12.
Based on this sum, we will take certain actions. So, when we roll the dice, the two dice the
number will be displayed, the sum of these two dice will be displayed.

If, the sum is a value is 3, 6 or 9 that is the sum of two dice is 3, 6 or 9 the player wins and
the game terminate there. If the sum is 2, 8 or 11, then the player losses and game ends again.
In case, the number is anything other than these which means if it is 4 or 5 or 7 or 10 or 12,
then the game proceeds to second stage, and before proceeding to second stage it stores the
current number that was received which means, that number had to be one of these numbers.

In the second stage, the user is prompted to roll the dice again and the new number is
displayed on the 7 segment display together with the old number you would like to know
what your previous number was because the in the second stage you are going to take some
decision based on the previous value of that number also and so, if the new number matches
with the old number you win.

On the other hand if, the new number is 3, 6 or 9 then you lose else, you the current value of
new number that you got becomes the old number you store it and prompt the user to roll the
dice again and you stay in stage two till a decision comes out. Let me draw for end user what
would the game look like.

(Refer Slide Time:​ ​3:34)

So, we want a system which has mechanism to roll the dice and we do not have a physical
mechanism where, we are shaking it and instead we have a switch with which we can
simulate the act of rolling the dice. So, when I when I press the switch it is like I am rolling

965
the dice. So, dice is being I am shaking the dice and when I realize the switch it means, that I
have thrown the dice and you see the two numbers that come out and so, I would like to
display them I need 4 7 segment because I have a number which can be more than 10 and I
have to display 2 such numbers or the current stage and may be if, happen you go to the
second stage.

So, I have four 7 segments displays here. Now, how does the user know that the game I have
won or I have been lost or the game has gone to the second stage? So, we have to use some
indicators to indicate. So, let us say that use a LED which is appropriately labeled so, this
could be win, another LED could be to indicate that the user has lost lose, a third LED in case
neither win nor lose then it must indicate that now the user has to press the switch again so,
we call it play again or PA play again.

You could also, have a buzzer to sort of you know to indicate some result you may also have
some LEDs to indicate are you in stage 1 or are you have gone to stage 2 so on and of course,
these numbers could be old numbers and these could be new numbers this is the user
interface to the system. Now, we have to design everything that goes with here with the help
of logic circuits which will be portioned into two halves, one will be called the sequencer,
what will be the sequencer do? It will essentially follow the rules of the game, it will prompt
the user to press a switch.

When, the switch is pressed will de-bounce the switch and then it will roll the dice when the
switch is realized again it will de-bounce the switch and then it will stop the dice look at the
numbers and there are many ways of processing that information may be, you have two dice
and then use a arithmetic number adder to add the two numbers or you can take a alternative
approach by saying let us make a counter, a single counter which counts from 2 to 12 so, it
goes from 2, 3, up to 12 and go back to 2.

Now, of course there is a difference in the way these number will appear in this two
approaches. If you use two counters which have a number between 1 and 6 for both of them
and use adder to add these numbers the probability of some of the numbers will be more than
the probability of other numbers.

In this case compare to a solution you can choose that you have a single counter which has a
number between 2 and 12 because in this case the probability of each number is same where
as in the earlier case of using two counters some numbers will have higher priority and there

966
are again various methods of you know, improving the probability of certain numbers even in
the single counter method.

So, this is the over-all block diagram. Let us look at what are the kind of elements of data
path that we may require.

(Refer Slide Time: 7:31)

We would require, the de-bounce circuit because, there is a switch which mechanical switch
in nature and when the user will press and realize they will produce switch bounce we need
some counters to implement the random number generator as I mentioned it could a single
counter to go from 2 to 12 or it could be two counters each of which have a number from 1 to
6 but, you will require another logic block to add these two numbers.

You may require comparators why because now you have to decide what is my number, what
is the result of that rolling of the dice, is it 3 you will win, or if it 6 you win if, it is 2 you lose
and so on. So, that is best done using comparators so you know what is the result of that.
Then you may want if you in the stage one you do not win or lose either then you have to go
to stage 2 you have to store the current number which will do using the latch with enable
signal and of course you will require decoders to display the numbers on 7 segment displays.

So, broadly these are the building blocks the data path building blocks that you have require
and let us look at the representation of these blocks with the interconnection to show, to
evolve from our single block diagram user level block diagram to a more detailed interaction
between the circuit elements.

967
(Refer Slide Time: 8:59)

Here is the complete block diagram which involves the elements of the data path as well as
single block which will represent our finite state machine. So, I am go to zoom on this part of
the circuit to first talk about the finite state machine. So, here as you see the finite state
machine produces two types of outputs if, you remember that let me draw for your easy
reference.

968
(Refer Slide Time: 9:29)

That a state machine will produce two sorts of outputs, two types of outputs, one which could
be for global outputs so, these are global outputs and it could produce outputs which are
control signals to the data path elements. So, these are control and it does that with the help of
asynchronous inputs together with inputs coming from the data path elements and so, these
are status inputs.

So, you have to design a finite state machine were the inputs are the the asynchronous inputs
as well as the status inputs and the output such state machine will be two sets of outputs, one
is the global outputs and the other will be control outputs which go to the data path and so,
we must see the both sets of outputs together and this what is being done here if, you see if
you look at this signal win, lose, play again and buzzer these are global outputs.

You also have, stage LED 1 and stage LED 2 this indicates whether you are in stage 1 or
stage 2 and you have other control signals which is to display you want to enable or disable
the display or you want to enable the latch and you have another signal which is the control
signal for the counter, these are the global and intermediate outputs and then you have some
inputs coming from the state data path and these are when the values are equal previous and
new values are equal or if, the current value is equal to 2, 8 or 11 we have labelled it as single
signal EQ2811.

And another signal which indicates whether the sum is 3, 6 or 9 and the other asynchronous
input is the reset to reset the circuit to begin from scratch and the switch which is the actual
switch used to interact with the game.

969
(Refer Slide Time: 11:48)

Now, let us zoom this part of the circuit to see how the various data path elements are
required and what functions they serve. So, the first element of the data path is a counter
which produces is a 4-bit counter, it produces numbers between 2 and12 this go into the 7
segment display control circuit it is a 4-bit binary number and it is converted into decimal
number which could be anywhere between 2 and 12, and we displayed either these two digits
or these two digits.

Then, in case you do not win or you lose it will go into stage 2 for before that you do that you
have to store that number and it stored into the latch, it is a 4-bit latch enable signal and then
if the number you have to find out whenever you rolled the dice is a number equal to 3 that
you do with this comparator or if the number is 6 you do it with this comparator, two inputs
of this comparator are 1 which is coming from this counter and the other which is fixed value
of 3 here, 6 here and 9 here and these 3 outputs are ORed together to create single signal
called EQ369.

So, if ​EQ369 is 1 that means your sum was either 3 or 6 or 9 and the state machine can take
an appropriate action that is to declare either win if you are in stage 1 or you lose in stage
2. Similarly, the same number is going to 3 comparators here, one where the input is 11,
second where one of the input is 8 and the third in which input is 2 and it is being compared
with the current output of the counter and if, this output which is a OR of these three
comparators, if it is 1 it indicates that your number will either 2, 8 or 11 and again this signal
is going to the finite state machine to indicate to the finite state machine the result of your of
this roll of dice and to for it to take appropriate action.

970
In case, in stage one you neither win nor lose the finite state machine will generate a control
signal to capture this input and it will be available at this point and it will be compared with
current value when you rolled the dice again this current value is available here also and if
these two numbers match then it is called EQ previous and this goes here again to the state
machine as status signal and the state machine will decide what to do with that number.

Apart from that, here are 3 LEDs for win, lose or play again, here are 2 LEDs to indicate
stage 1 or the stage 2 of the game, a buzzer to beep whenever certain action is taken. So, this
is the representation. Now, we are still not anywhere in the completion we have to now
decide what are the states required in the finite state machine. So, let us have a look on that
here is the finite state machine.

(Refer Slide Time: 15:12)

You start with S0 that is your reset state, you wait for a button if, the button is pressed you
going to S1 if, the button is not pressed you remain in this state not mentioned here but, that
is what is being done if, the button is not pressed you remain S0, if the button is pressed you
go to S1.

In S1 now in each of the state certain outputs are being produced and I will show you the next
slide where we have made a list of these outputs and we know these outputs, what are these
outputs?

971
(Refer Slide Time: 15:45)

These outputs various values as well as which consists of control signals to the data path and
3 global signals which is win, play and lose and 2 more global signals which is to indicate
whether you are in stage 1 or stage 2. So, all these outputs from the state diagram state
machine are mentioned in each of the state S0 or S1. Now, these outputs are either 0 or 1 but,
in some cases it is x means we does not matter which means it says do not care which would
mean that is ok if it 0 or it is ok if it is 1 may be the previous state would decide if it will
remain 0 in the state and so on.

So, those state are mentioned x, x here so, you go from are in state 0 waiting for button is
pressed you come in state S1 that you start counter that will see when we look at these
numbers here, you wait till the button is not realized when the button is realized it will going
to S2 here, numbers are ready and they will be displayed if, the number is EQ2811 and not
EQ369 you are go in the state as four which actually to indicate that you lost.

On other hand, if EQ369 is 1 I should not put a bar on it if, the state 369 is 1 and EQ2811 is 0
it means you are wining and state and appropriate output will indicate whether it win or lose
and form there you will go into this waiting for button to be pressed else, if neither win nor
lose you are going to state where you are request the user to press the button again by the
help of LED called play again and once it is pressed you are going to the state here you are
going to start the counter.

The counter, to produce second number wait for the button to be realized and then once the
number is generated you are going to compare it with the previous number here if, it is equal

972
to previous and not anything else you are going to win state, this is your win state, this is your
lose state, this is your state to indicate your stage two if, the numbers are not equal then you
go back if the number is equal to 369 then you lose else you go back and ask the user to press
the switch again you will still in stage 2.

(Refer Slide Time: 18:31)

Now, to know what outputs are produced here is the table, here is the table which indicates
the outputs required stage 2, stage 1, display enable, win, play again , lose and latch enable.
This latch enable signal is to generate the is to enable the latch to capture that number. In
state S0, you want the play again since LEDs are connected in Active low mode which means
the LED will light-up when the output is 0, you are only lighting the play again LED, you
have disabled the latch you do want to capture the number and rest everything does not
matter, the counter is free running so, it is going to keep on running.

In S1, you are indicating that you are in stage 2, stage 1 because again its active low LED,
you have enabled the display you are indicating that it is neither win nor lose nor play again
and you have enabled the latch and from here you see each of the stages have indicated kind
of outputs that will be produced some of the outputs go to the outside world in the form of
win, play again or lose or stage 1 and stage 2.

The rest of the outputs go into the data path controlling those data path which we name is the
counter and the latch and the display control circuit. In this table it is required. It will list all
the states and the expected outputs and these numbers you see here x , x, x, 0, x, 0 will

973
exactly be here x, x, x, 0, x, 0 and like-wise you see in each of the states we have mentioned
what numbers what outputs are produced what state of those outputs.

Once, you decide this as I mentioned this is this finite state machine it can be implemented as
a piece of VHDL code all the elements of the data path whether it is counter or 7 segment
display or these comparators can be again represented as the VHDL code. So, now you create
the single VHDL code where you write down the code for each of these building blocks,
finite state machine, the counter, the latch, and these comparators and so on and when you
compile that you will get a net list which you can implement in any form.

Now, what are the options we have? So, we can implement this net list at various in various
ways.

(Refer Slide Time: 21:21)

One common method is to use a Programmable Logic Device which are primarily of two
types you either have a simpler, smaller device called Complex Programmable Logic Device
or you have much more denser in terms of the number of gates you have a Field
Programmable Gate Array. There are many manufacturers which make a CPLD and FPGA
devices one very popular manufacturer is Xilinx.

They also provides a software for modelling codes and then targeting there products with
they makes CPLD as well as FPGA they have they have a software called ISE which allows
you to write and test, compile and download the VHDL or verilog code into the IC which
could be CPLD or the FPGA so, this is one approach.

974
So, second approach could be that given the net list you can get application specific
integrated circuits that being made that is another possibility. Now, what we are going to
show is to how to take the code that we have written compiled it by using an appropriate
compiler in this the Xilinx ISE and we show implementation using the CPLD.

(Refer Slide Time: 22:58)

This is the block diagram of the implementation as you see here, here is the Xilinx CPLD
XC9572. It has two switches reset and the button which is used by the user to interact it needs
a power supply I am to going to come to that here is the display which indicates the new
number here, and the old number here, these are the three status LED which indicates win,
play again and lose, two LEDs which is stage one and stage two and a buzzer.

Now, exactly like we talked about the Eco-system for a Microcontroller and we mentioned 4
elements of eco-system.

(Refer Slide Time: 23:43)

975
Namely 1 was clock, 2 was reset, 3 was power supply and 4 was program download
capability, these four eco-system elements that are required essential elements that are
required by an Embedded Computer such as the microcontroller also required by
programmable logic device such as the CPLD or FPGA and this previous logic diagram
indicates that.

Here, is the power supply from the data sheet of this CPLD we found that the power supply
required is 3. 3 volts it also mentioned the data sheet how much the current it will consume.
So, the power supply has to be appropriately design so, that can provide that power, the
source of the power supply important in this case implemented using USB input which is 5
volts you will require a clock.

So, power supply and clock and this case the clock was implemented using a triple 555
astable multi-vibrator because, the requirement was at very high frequency otherwise we
could use other approaches and off course it requires a reset so, this is your reset switch.

So, in this case there is only 1 reset which is the user reset and power supply and the clock
generator how do I download code into this? Most CPLDs and FPGAs are require JTAG,
require a JTAG interface and so, whenever you want to download the code into your CPLD
and FPGA you need a mechanism such as, JTAG correctors, JTAG interface to download the
bit file.

Basically, when you compile the code, the compiler will produce what we called it as a fuse
bit file meaning the fuses in your programmable logic device set on or off to create the circuit

976
that what you want and this output of a compiler VHDL fuse bit file that needs to be
downloaded into the target device and for that JTAG is used.

So, what we did was tested the circuit first in a evaluation kit like we have evaluation kits for
microcontrollers, there are evaluation kits for programmable logic devices also and once the
code was found to be working, then an entire Stand-alone implementation was created and let
me show you that this is the systematic diagram of the CPLD.

977
(Refer Slide Time: 26:35)

CPLD based dual dice game here is the power supply as you see the input is 5 volt source it
produces VCC which is in this case 3.3 volts it use as the voltage regulator called triple 1117.

(Refer Slide Time:​ ​26:51)

The clock generator is based on a 7555 astable multi-vibrator produces about few kilo hertz
of clock we do not need very high frequency clock.

978
(Refer Slide Time:​ ​27:04)

Here is the CPLD which is a XC9572 various outputs of the CPLD are connected to various
peripheral devices such as displays, and buzzers and LEDs and here is that JTAG collector
which is TDI, TMS, TCK, and TDO this is an external collector external interface.

(Refer Slide Time: 27:26)

Here, is the display which is a four digits 7 segment display.

979
(Refer Slide Time: 27:30)

Here is the buzzer. These are the output LEDs for win, play again and lose and also stage 1
and stage 2.

980
(Refer Slide Time: 27:42)

And these are the two switches for playing you the user button and the reset switch this is
what we have, here is the broad layout.

(Refer Slide Time: 27:52)

This was fabricated in my lab on a single sided broad. Now, the CPLD itself is consist of
SMD IC which has very fine pins and it is impossible to fabricate a circuit to accommodate
such a fine pin IC an interesting approach as I mentioned earlier was taken to create a
break-out broad.

981
(Refer Slide Time: 28:19)

This is the break-out broad, this was fabricated using outside fabrications facilities and on
that this is actually a 44 pin Universal BoB which means any 44 pin IC can be ​soldered ​it
onto this and at the bottom appropriate grounds planes this is going to be ground plane, this is
ground plane.

So, appropriate depending upon which pins of IC that you are soldering it to be grounded
here, here, here and somewhere here, some of the pins are VCC so, they need capacitor to be
connected to the ground you see a capacitor here, you see a capacitor here, and you see a
capacitor here, thess this pin must be VCC, VCC, and VCC and this is what its looks like at
the top and the bottom.

(Refer Slide Time: 29:14)

982
This is the actual implementation. This is the top layer, here are the win, play again, and lose
LED, this indicates the stage you are in, this is old number, this is new number, this is the
clock generator, this is reset switch, and this is the user switch which you press, these are the
rules which the game are mentioned.

(Refer Slide Time: 29:34)

So, this is the bottom layer of the PCB which has the power supply regulator, this is the USB
connector and labels have been labels have been put to indicates it is, who implemented this
is name of my student who implemented this, it is your provocative what you want to print.

The PCB technique, offers you that flexibility and I hope you enjoyed this lecture. It gave
you inside how to design and implement single broad computers on programmable logic
devices. A CPLD is typically, has much less resources and so, you have to really struggle

983
with the logic to optimize it if, you have access to FPGA which have 10 of thousands and
lakhs of gates.

You will be able, to implement larger designs but, the approach still will be same, it is an
approach which has a sequencer, it has data path elements and it is left to you to decide what
elements of data path are required, how are they controlled by the sequencer, what outputs do
they produced, what kind of global outputs they produced, what kind of status outputs they
produced, once you integrate two building blocks and you model it using the VHDL in a
single program file to integrate everything, you will be able to implement your own single
purpose computers.

I hope you found it very useful to, I hope you will be able to learn from it and implement
your own single board computers. Thank you, I will see you very soon.

984
Introduction to Embedded System Design
Professor. Dhananjay V. Gadre
Netaji Subhas University of Technology
Professor. Badri Subudhi
Indian Institute of Technology, Jammu
Module 12
Lecture 40
Recap of Course Coverage and Project Demonstration from Concept to Final

Hello and welcome to this last session of this online course on introduction to embedded system
design. I am your instructor Dhananjay Gadre. In this session, we are going to go through all the
topics that we covered. And then terminate this session with a project description which will help
you to visualize to plan and to implement a MSP430 or end for that matter any microcontroller
based project. We have already seen some implementation issues, which will discuss shortly. So
let us start. So let let us go through all the topics that we have covered from the first lecture as
you know, we have covered more than 40 lectures.

(Refer Slide Time: 01:06)

At the beginning we had a course on lecture on embedded system characteristics. We followed it


up with a project demonstration. Then we saw how the embedded computer could be
implemented many ways of implementing the embedded computers namely using a
microprocessor or application specific controller and a single purpose computer. Then we saw

985
how the microcontroller which is a very common and useful application specific device could be
used for embedded system applications.

We also saw how we could implement embedded computer, embedded system using a single
purpose computer here. Then we looked at the salient feature since our target was to use
microcontrollers for implementing embedded systems. We started concentrating on various
issues of microcontrollers.

We looked at the various salient features of modern microcontrollers. This was like a collection
of all the good features of contemporary microcontrollers some or more may be available in the
microcontroller that you may have chosen, then how do you choose the right controller for your
application.

And we looked at not only the technical aspects but also other aspects which would impact the
time to market and the economics of your project. After we did that, we looked at the ecosystem
elements of a microcontroller. A micro controller requires four essential elements for survival for
thriving in an embedded system application and they are power supply, reset, clock and the
ability to download program from your development host into the memory of the
microcontroller.

So, we looked at all those issues. Once we got done with this then we said, all right, let us now
try to visualize an embedded system using a six box model in these six boxes we looked at the
input boxes which has sensors and human input devices the controller box, then the output box
with which the controller can interact with the outside world by controlling output devices such
as motors and relays and LED’s and LCD’s and so on, then we looked at host and storage, what
is meant by that for storing lot of data that you your application may be generating.

Then we looked at a box which allows you to which allows the embedded system to
communicate with the outside world and last but not the least, we looked at the power supply
block. Now, after having seen all these blocks.

986
(Refer Slide Time: 03:58)

We also had some idea about what is this idea of electronic Glue, the electronic circuits which
binds all these individual six boxes. We looked at those aspects briefly. Then we had a dedicated
session on the design of a power supply. The design of power supply is very important. It is in
my opinion a very neglected topic and I strongly recommend to you to focus more on
understanding the design of power supplies. It will be a good skill to have. Once we were done
with this, we started looking at the architecture of MSP430. We looked at the CPU, the register
arrangement, the memory arrangement, the flash and so on and so forth.

After that, we had a session on how to install the code composer studio and the GIT software
which allows you to maintain a repository of all the versions of programs that you would end up
writing for a given application for a given project. And so having such a mechanism is very
useful. After that, we had a session on embedded C programming, where we went through
specifics of C programming language in the context of embedded applications.

Once we were done with that we started looking at the input output features of MSP430
microcontroller and we covered the digital input and output devices. We did some experiments
to connect outside LED’s and switches and control those LEDs and switches. Then we looked at
the specific aspects of the microcontroller ecosystem in the context of MSP430, namely the
clocking mechanisms, what all the options of clocks you have on MSP430 and to recap here
MSP430 as a very rich mechanism very rich source of clock sources, which could be

987
manipulated and navigated to various CPU and other sub system blocks inside the MSP430
microcontroller.

There is the low frequency crystal oscillator. There is a very low frequency oscillator, which is
RC based within the chip and then there is the DCO. And the three signals clock signals are
namely A clock, the SM clock and the M clock. Then we looked at how many ways can be reset
MSP430 microcontroller.

And the various low power modes that are available how you can enter those modes to conserve
power and once having entered how do you exit those modes, so that you could resume the
normal operation. When we were looking at the clock. We also saw how the clock frequency
could be dynamically changed and this would allow an embedded application to conserve power
in case you do not want to operate at a very high frequency because the current requirement at
the time does not need you to you can reduce the clock frequency. So as to conserve power.

Then we started looking at some theoretical aspects as to how to drive output devices in the form
of LED’s and relays and motors and how to design the electronic circuit namely these are the
aspects of electronic glue, how to design the drivers for for such devices? We also looked at
various ways of reading inputs such as keypad or things like that switches. Then we saw
specifically, how do we send information out from the microcontroller for human interaction
namely through the seven segment displays and an LCD display.

And let me mention here that although we used character LCD, what is called as character in
LCD, you can also try to experiment with graphics LCDs. There are many many graphics LCDs
available. In fact, the graphics LCDs have the advantage that they conserve they consume much
less power than the character LCD that the 16X2 or 16X4 character LCDs that are available in a
market. These graphics LCDs also operate at 3.3 volts.

So that is a very natural, amalgamation or marriage between the MSP430 ecosystem and the
LCD. Because you do not need to worry about having to get additional power supply and that is
a very important could be an important consideration. Then we looked at the a very important
aspect of embedded systems and microcontrollers. That is the interrupts.

We had several examples, how these interrupts could be utilized. So, as to perform the required
tasks in a equitable fashion. When there are multiple things to be done. You cannot round robin

988
and you cannot do polling and implement everything that you want. And so one of the methods
of overcoming that obstacle is to use interrupts.

(Refer Slide Time: 08:40)

Then we looked at another important feature of a microcontroller and embedded system, which
is the mechanism to count time and count events. And for that we looked at the MSP430 timer in
the compare and capture mode. Also how we could use the timer for PWM pulse width
modulation. Although we also looked at the mechanism to generate pulse width modulation
signal using a software code only without the requirement without the implication or without the
intervention of a timer.

Then we looked at MSP430 ADC, how we could use the ADC for so many applications not only
reading external analog sensors, but also using it as a seed to feed into our LFSR based random
number generators. We looked at various ADC interfacing issues, how to connect them to
sensors. We looked at how to generate random numbers. And then how do we convert analog
voltages from the microcontroller. Although one of the methods is using PWM, but we looked at
how additional mechanisms such as R2R ladder networks could be used for generating analog
voltages.

Then we looked we had a lecture on MSP430 serial communication. We looked at UART in


great detail. We also brief briefly covered I square C and SPI. And then once we had done this

989
this basically covered a lot of physical issues of the modules that are available the functional
blocks that are available inside a microcontroller.

Now, was the time was improve our C programming skills and we looked at we looked at
mechanism to interface four digit seven segment display in a multiplex fashion how that would
improve the performance of that display would be improved. If you went from sequential
mechanism to refresh the display to an interrupt based display.

And then we had a lecture on how to plan for a project and here there was no specific dimension
that the project has to be necessarily microcontroller based. It was a general discussion that you
start with the visualization and then start with the objectives. Then you have a visualization and
then you plan for the electronic parts and then the enclosures and how the wiring and have to has
to be in place and documentation.

This was very general topic. It could be non-microcontroller based project also and then we
looked at various methods of prototyping circuits. This would be very useful. If you are going to
play with microcontrollers or any other circuit in future. And now once we have covered all
these topics now is a time to sort of pull build all of them bring all of them together in one last,
like they say the topping on the cake to integrate all these issues and illustrate it with the sample
project based on MSP430.

That has been specifically implemented for this course. In the beginning, I showed you so many
projects that has been that have been implemented in my lab. But this specific project that is here
with me right next to me was implemented during the course of the recording of these videos by
one of my students. And I am going to go through the entire process from visualization to from
the objectives to visualization and how it was implemented in this lecture.

So instead of saying we want to implement a project and that project could be any project. We
are saying we want to implement a MSP430 based project. This course has been about
implementing an embedded system specifically using micro controllers and even more
specifically using the MSP430 microcontroller. So, it makes a lot of sense to actually illustrate
how you can plan test and implement a MSP430 microcontroller project. And so this rest of this
lecture is about that.

990
(Refer Slide Time: 12:52)

So, as as we discussed earlier in any in any such activity, you must start with an object. What do
you want to implement unless you know specifically what do you want to implement, what can,
how can you plan for it? And so objective setting down the objective in black and white is very
important. Just discussing that you want to do this is not good enough.

Because when you actually come to implementing it you may forget what you actually wanted to
implement or new ideas may creep in and that would make the implementation near impossible.
And so not only thinking about the objective, but also to put it in black and white on a piece of
paper is very important.

Once you have done that then you start visualizing that, all right, I want to implement this. What
would it look like or what would I want it to look like that is very important. Then you start
planning based on that visualization and obviously instead of implementing the project from
scratch. You like to test some parts of it. So that you can ascertain the the feasibility of your
project.

Because if at this point of time you find that some of the aspects that you visualized about or you
put in in the objectives, if they are, you are not able to achieve then there is no point in
proceeding with the project. Then you better resolve that issue. So, testing if you have access to
certain modules, or you can test it in some way some aspects of your implementation. It is a good
idea.

991
Once you are once you have done that testing which will give you a good confidence that till
now the progress that you have made will lead to success. Then you can start planning on
creating this schematic from the schematic to create a printed circuit board layout. If if you have
the necessary ecosystem support to actually fabricate it. And in this case, we have actually done
that, then you start prototyping. Meaning you put put all the components together, circuit
fabrication and then you start implementing it, maybe download the code and test parts of it and
then eventually once everything is done you document it.

(Refer Slide Time: 15:02)

So I am going to show you that. So what happened was a couple of years ago. I was coming to
my institute and I saw a roadside vendor selling these very nice glass fish fish tanks, fish bowls,
and I was intrigued they look very interesting although the reason why they looked interesting is
because he put coloured water in some of these bowls.

Anyway, I like them enough to take a picture. And so I wanted to see could I use this fishbowl to
implement some project. I like to implement use electronics to create artistic projects. And so
this sort of caught my imagination. And so I said, maybe I would put a circuit inside the fishbowl
and see if I can power that circuit in some way which does not require me to drill hole into a
glass bowl, which is very difficult.

But then, how do I provide power to the circuit inside the glass ball? One solution could be that I
put a battery. But the moment I put a battery the problem is that once the battery is discharged, I

992
had to replace it. If it is a chargeable battery then again, I had to take it out and charge it. But that
is when an idea came to my mind.

Especially because in these in this age, we are talking about mobile phones, which have a
wireless charging mechanism that you get certain mobile phones with a charging mat and you
simply put your mobile phone on that mat and it gets charged. So I thought why not use such a
mechanism into our system.

(Refer Slide Time: 16:31)

So this was the, so once I started thinking about it, I created a sketch. Which helped me visualize
this project and if you see this sketch here and you see the implementation. I hope you agree that
this is more or less than a hundred percent reproduction of the visualization. The actual
implementation is almost hundred percent same as visualize. So what do we have here, that we a
few candles inside and we have these string of LED’s. And the reason why I thought of this
string of LED’s was also, because you may have seen in the in these last couple of years on
traffic junctions, these kids sell balloons, which have beautiful LED strings strung on those
balloons.

And in fact, I had bought some of them and I found that these the LED string was unique. It was
unlike I had other LEDs strings that I had seen and in fact we the the LED string that is in used
here is exactly from that source is actually two very thin wires and the LED is contained in some
glue.

993
And these two wires are actually turning those LEDs on and off. And these are not addressable
LEDs meaning I cannot individually turn each LED on or off or I can control it individually I can
control all of them together. And so if I apply a voltage to the two wires, the LEDs will glow I
can apply less and more voltage and then it will its intensity will change. So, that is how these
LED balloons that I saw last year and the year before last. So I thought I should integrate that in
the in this project. So this was the visualization and then we started with the implementation.

(Refer Slide Time: 18:25)

So the first part was since we, so the objective is now to create a wirelessly powered art
installation. This could very well I could put it in my office here or I could take it home and set it
out in my drawing room and it would be a great piece of art sort of a conversation starter if he
guest come come home and so on and so forth.

So, question is there are two important parts in this one is how do I supply power to this micro
controller circuit and then the micro controller circuit itself. What all do I want to do it. As you
see in this visualization, there are four candles looking candle like structures. They are not
candles they are implemented out of LEDs, but they behave like candles. So they need to flicker.

So, the part was that part was about this microcontroller circuit. So the first aspect was spent on
the first activity was spent on getting the wireless power supply working. And for that what we
did was we read through the available literature and then it turns out that the mechanism of
wireless power transfer is the transmission of energy without wires. As is very obvious from the

994
from the the term. And what it involves is that you apply a time varying electromagnetic field
and launched it in some way over space and then on the other side, you must have some
mechanism to receive this power to extract this from the space.

(Refer Slide Time: 20:09)

It turns out that wireless power transfers are largely of two categories one is called near field
non-radiative. And the second is far field in the near field non radiative method again there are
two sub methods one is one uses magnetic field and uses inductive coupling using coils. And the
second one is uses electric fields and uses capacitive coupling and for capacity coupling it uses
plate’s electrodes.

The second method is far field the technique here uses microwave radiation. And in fact people
have done projects that normal transmissions of telephone towers, you could actually receive
energy from these if you put a create a receiving antenna, in fact that method is called Rect Ant
meaning a receiving rectifying antenna. Please search for this term and you would get to know
what I mean here. So that method is far field using a radiative method. The more common ones
are near field which means you put the transmitter of the power and the receiver close to each
other.

995
(Refer Slide Time: 21:03)

And sure enough you can actually create such a mechanism very very easily. In fact, we have
these in our lab for demonstration for school kids and it requires just a handful of components if
you see this is nothing but a couple of a feet or so of wire of certain gauge. We in this case we
use 28 SWG to create a 10 turns, 10 turns of coil.

We simple lab NPN transistor like 2N2222 and 1 kilo ohm resistor here in series at the base. And
you can use a simple 1.5 volt, alkaline battery to power this. And on the other side you just
double the number of turns from 10, you make a single coil of 20 turns and you put a resistor if
you want or if you like you do not need to put a resistor either. And when you bring the second
coil, which is powering the LED close to the the first coil here, you would you would find that
the because of inductive coupling you are basically able to turn the white LED on.

996
(Refer Slide Time: 22:22)

Here is a simple implementation that we have in the lab. This is this is the transmitter as you see
this is the NPN transistor. This is the coil in two parts. That is the centre tap which connects to
the VCC. This you can apply here 1.5, 1.5 volt cell here like this here. Once you do that then this
fellow, this call will start radiating. And if you put the second coil now this has double the
number of turns or rather the sum total of these terms the sum total of these turns are also here
and I just put two LED’s back to back and if you put one this coil on top of the the transmitting
coil, you will see that these LED’s light up.

And so this is basically wireless power transfer. The only issue is the amount of power being
transmitted from here to here is very very small. It hardly it just turn these LEDs on quite
brightly though, but not enough to power several LEDs and the micro controller circuit to. And
so the way to go about it was to scale the power being handled at the transmitter.

And one way to scale that was to increase the voltage. But when you increase the voltage, it turns
out that this transistor should be capable of handling there large power dissipation. And if you
experiment with such a small transistor will find that soon enough as you start increasing the
voltage the transfer will simply not be able to handle the increase power dissipation and will
simply burn off.

997
(Refer Slide Time: 24:06)

And so we replace this transistor with the more powerful transistor and the more powerful
transistor in our case what we did was we used a TIP3055. This is a very hefty power transistor,
which has a VCE max of I think about 60 volts, but that is not as much important as that the IC
the collector current maximum that you can have on this is 15 amperes.

And that is the important 15 amperes. So that is the important part the part necessary for our
requirement. And so this transistor was chosen at the as we start increasing the supply voltage
the transistor becomes extremely hot and the only way to handle that is to attach it to a heat sink.
Heat sink does nothing but increases the power dissipation capability of the transistor, it
increases the metal surface through which the transistor can dissipate that heat.

And so we did that and we did some testing and we found that if we applied 6 volt at the primary
that means 6 volt in the energy the the transmitter part on the secondary side, you could easily
get 4.5 volts and you could get up to a 100 milliamperes of current of course at that time the
source was consuming much more.

It was consuming about 1 and the half 2 amperes of current. So, the efficiency of the system is
extremely poor and that it is not normally the case because the your wireless phone chargers and
increasingly, vehicles are being charged using this method. It does use near field non radiative
technique, but there is a further specialization in that it uses resonance.

998
So, it uses a resonant circuit where the efficiency is very high. And so but the complexity of such
a circuit increases we have chosen to keep it simply because the idea was to illustrate this
process from visualization to implementation. And therefore we have kept a non-resonant
mechanism, which of course consumes waste more power, but it serves our purpose. Now, once
we have once we were able we are confident about the power supply part.

The second part was to concentrate on the micro controller circuit and for doing that instead of
creating a custom circuit our lunch box comes into picture and we use that to connect several
LED’s on the pins and wrote program to be the linear feedback shift register to generate random
numbers and for making one candle one candle one candle, we you be used 2 LED’s.

(Refer Slide Time: 26:50)

So, it could be something like this one LED here one more LED and then limiting resistor. This
is your VCC and this goes to 2 pins of the microcontroller and they were control together with
random bits being thrown at both these LEDs. And so what you end up getting is a flickering
effect, and once we tested that we were confident that we would be able to control these candles.

And then since the the LED string we wanted to blink the LED is on that string. We wanted to
increase and decrease the intensity. So, we connected it to an appropriate pin of the
microcontroller which had a PWM output. So, that we could ramp up the LED intensity make it
go down and so on so forth. So, this was tested using the lunch box. And once that was there
then we started creating the schematic and from the schematic the board layout.

999
(Refer Slide Time: 27:53)

And so let me show you the schematic. So, this is the schematic diagram for this MSP430 based
wireless power transfer project. Let us go through all the parts of this schematic. This is the
power supply part. So, on this on these two terminals you would be able to collect a coil. Like
this here, and then this would generate AC. It would receive the voltage in AC form. And so you
are going to have rectifiers. This is the bridge rectifier.

These you see if you notice these are not normal rectifier diodes. They are ​schottky diodes and
the reason by ​schottky ​diodes where used is that the ​schottky diode voltage drop is much less
than the drop that you would get with a silicon diode. And because we want to extract as much
power from the system as possible. We did not want to waste the voltage over a silicon diode, so
schottky ​diodes were used.

And then it was filtered out using this 4700 microfarad capacitor as you see here. So, this was the
part of the power supply. Now this would this as I mentioned in our test this would provide us
about 4.5 volts. Now, of course MSP430, now when you start designing the system you would
put the requirements for the microcontroller and as I mentioned you have to look at four aspects,
how do I provide the power supply for the microcontroller.

When you decide that you want to implement it with MSP430, you have to worry about
providing about 3.3 volts. You can go maximum up to 3.6 volts. You can look up the data sheet.
It can go down to 1.8 volts. But of course at 1.8 volts the LED’s is will not light up all the LEDs

1000
all the coloured LEDs. And so you have to up if we choose the supply voltage to be 3.3 volts.
You have to worry about getting 3.3 volts from this 4.5 volt raw voltage. So, we come to that
briefly. Then once we have the power supply available. Every project must indicate that the
circuit is working. The system is working and though so we had we have provided a power all
LED.

Please remember that whenever you make any project provide for a power on LED. Otherwise if
the system is not working you would wonder why did not working. It could be that the power
supply itself is not available or if the power supply is available, then you know, the power supply
is not an issue. You should look at other aspects. So, providing a power on LED is very
important. That is what this second box does for you.

Now as I mentioned we wanted 3.3 volts our source was 4.5 volts. So, we could use a regulator.
And again, we have seen various regulatory options. We could use a switching regulator. But
again the there no need because we are getting 4.5 volt raw voltage and we could choose LDO
low dropout voltage regulator.

(Refer Slide Time: 30:50)

And so we use this LP2950 with 3.3 volt output. It works very well with the differential voltage
here. In this case up to 1.2 volts it this regulator works very well. And so this was chosen to
power the MSP430. The expected current for the MSP430 itself. If you are going to use the

1001
internal DCO clock the default clock or 1.1 megahertz, you know that the current is of the less
than a ​milliampere​.

And so this this regulator is quite happy to provide that current. And all circuits require
decoupling capacitors. And usually we should do 10 microfarad electrolytic and 0.1 micro farad
ceramic and connect it to the output of the supply voltage near to the nearer the pins of the
microcontroller. So, this was the bypass capacitors.

(Refer Slide Time: 31:44)

Here is the MSP430 circuit here as you see. This pin is the reset since we are not doing anything.
We are not resetting it manually we have pulled it up with this resistor. So, that the only way to
reset the system is to turn the power off and turn it on again. And then all the rest of the pins here
is the supply voltage connected here. Here is the ground and these are so these these two these
two these two and these two they are driving two LEDs in the output low mode meaning when
these outputs are low, the LEDs will be on.

And then this P2.1 was chosen to drive the string because on P2.1 you can have a PWM output.
And rest of the pins since they were not being used. They have been left unconnected.

1002
(Refer Slide Time: 32:36)

Let us go here. Now, I have 4.5 volts available. I am going to use white LEDs. In fact, I would
choose what is called as a warm white shade. Because warm white would mimic a candle much
better than, cool white would do. So, warm white but a warm white LED requires more than 3.5
volts for operation. I supply voltage of the MSP430 power supplies only 3.3. So, instead of
directly driving what we choose to do was as follows.

(Refer Slide Time: 33:09)

1003
We took the MSP output here and we could have a low side driver as we have already,
understand that term and then we could have a LED like this. So, this is the raw voltage raw
VCC of 4.5 volts and this is the 3.3 volts MSP430 power supply. And if you wanted to drive the
LEDs with 4.5 volts, the only way to do that would be to isolate the supply voltage using this
NPN transistor as a switch that is a low side switch.

And so in we would need 8 of these switches 8 of these transistors instead of using individual 8
transistor what we choose to do was use this NPN driver called ULN2803. It has 8 NPN type of
low side drivers. And then so this was connected to the output these inputs of the driver were
connected to the MSP430 pins. And these outputs were connected to LED’s. These are the
current limiting resistors.

(Refer Slide Time: 34:22)

Now we are left with only the mechanism to drive the string of LED’s and for that we took
another transistor and connected the string here. So, this is the raw supply VCC here is raw
supply voltage and the string was connected between this point and this point like this. And a
connector has been provided so that you can remove it if you like.

And then these are the 4 connectors for 4 candles. Each of them would have two LEDs like this
and this and this is the supply voltage. So, as I discussed it will be in the low side switch mode
that is the anode will be connected to VCC and the cathodes will be connected will be controlled
by the microcontroller. So, this completes the schematic of the project. Here is the board layout.

1004
(Refer Slide Time: 35:03)

This was implemented like on a single sided PCB. The blue wires indicate tracks and the red bars
indicate jumpers. Because the signals have to cross so you bring them up on jumper wires and
then put them bring them back in. So, as you see it only uses about 1, 2, 3, 4, 5, 6 jumpers.

And now cutting a circular PCB is a challenge, although in my lab, I do have a CNC machine
and I can cut a PCB in any shape. I wanted it to be cut in a way that anybody with access to basic
tools could do it. So, we decided not to although the, you see a circle here. We did not implement
a circle. What we did was we cut a square which could inscribe this circle and then we cut out
these parts of the square here. So, ended up making a octagon. So, let us see how is this was
implemented.

1005
(Refer Slide Time: 35:56)

So, the PCB was cut as you see there is a circle, marking inside, but it was actually cut like a
square and then the corners were cut off using a hacksaw. So, all this whole this whole stuff was
done using a normal hacksaw. And the, we have already seen the PCB fabrication method all that
was done the layout was stuck here. And then the board was put in ferric chloride. The raw PCB
board was put in ferric chloride etched and then once that etching was complete the ink from the
laser printer was removed using this scrubber. And then it was drilled and sprayed with that
acrylic spray. And then we started soldering.

(Refer Slide Time: 36:39)

1006
Here is the coil at the bottom. And on the top you would see here is the, this is the top side as
you see the top side has been printed with the what what is called as identification layer. So, this
PCB actually went through two processes of transferring the layout. The bottom layer was the
tracks and the top layer was the the identification layer. So, that we know where each of these
components are going to be put and this can be easily done.

And then once all the things where solder, drilled and all. These components where solder and
these plastic things are nothing but thick straws and they were glued on the base with hot glue
and inside you see these two white LEDs and in this the current implementation, I have covered
these these LEDs with the hot glue. So that it can diffuse that light even better. And as you see
this is the string of LEDs you see this is the string of LED’s and this bubble that you see here
little drop here droplet that contains a LED of various colours. So, this was all soldered together.

(Refer Slide Time: 37:48)

And then the power supply part. So, a wooden base was taken at the centre of it, hole was drilled
large enough for this coil the transmitting coil to be installed and then on the bottom side, this is
the Hefty transistor that I mentioned and this is the heat sink. This is the heat sink. And the
transistor was mounted.

You may see some white paste kind of thing that is not paste that is what is called as heat sink
compound. It removes any air gaps between the metal surface of the transistor and the heat sink
and provides better conductivity for the heat. This is this was done on the general purpose PCB.

1007
And because when we put it other way around it, this would not allow the base to be horizontal.
So, 4 mounting screws were installed on the wooden base and this is the close up of the the
transistor.

(Refer Slide Time: 38:47)

Anyway, this is the final implementation as you see here the fish bowl containing the the the art
installation and at the bottom. This is the power supply part.

(Refer Slide Time: 39:00)

1008
And I have this whole thing here, but let let us go through the code first and then I will
demonstrate this project to you. The code is very simple. You have the LED strip on P2.1. This is
our PWM output. Then there are some constants to find for increasing and decreasing the
brightness and for blinking LEDs, this is the register setting for timer one, the timer one has been
programmed for the PWM output here. Then these are variables declared here. These are all
declared as volatile because some interrupt is happening.

(Refer Slide Time: 39:39)

This is the whenever the timer interrupt happens. It goes into it. And in this at some point, it will
blink the LED and at some point after sometime it will do PWM on on those LEDs. So, this is
the timer code which control that string of LEDs.

(Refer Slide Time: 39:59)

1009
And this is the simple mean code where we have defined the P1 port 1 as all outputs. This is the
seed for LFSR a 32 bit LFSR was chosen and this are seed for that LFSR, although it means that
every time you turn the system off and on it will always start with the same pattern and one way
to overcome that would be as we have discussed we could use ADC a spare ADC channel
without connecting it to any source just read it and you will get a random number and use that to
feed into the linear feedback shift register for subsequent random numbers.

And then we stopped the watchdog timer here. We call the function to program the timer 1 and
then we set the bits in the SR register to enable the interrupts and then enter a infinite loop where
we are simply outputting the LFSR bits on all the 8 pins of port 1 that is what we are doing with
some delay. This delay was experimentally ascertained for this value.

So that it gives you flickering effect. If it is too slow. You will not see, if it is too fast again you
will not see. So, this was inferred experimentally and once this code is compiled. Now the
problem is how do you put the microcontroller, till now we have been downloading our code into
the lunch box. So that is last aspect that I want to discuss. You can do your experiments on lunch
box.

(Refer Slide Time: 41:32)

1010
And there are similar evaluation kits available such as Texas Instruments very own TI’s, what is
called as MSP430 launch pad. This is a very very worthy evaluation kit. It allows you to debug
the code also and it has a mechanism that the pins which are used for programming the target
microcontroller. There are jumpers, you could remove the jumper and connect it to your target
board. But for this present case what we decided to do was we tested everything on the lunchbox,
program the IC in the lunch box and then simply took it out and insert it into the PCB of the
system here.

(Refer Slide Time: 42:22)

1011
And you may need to do some iterations. If it does not work the way you want it to work. You
can always put it back reprogramming and put it in there are some dangers that the pins of the
microcontroller will get bent and so on so forth, but for a simple project, that should not be a
worry.

So, but when you are developing your own projects, you have to be aware of the need for
appropriate programmer so that you can download the code from the desktop into the memory of
the microcontroller and in this present case we use the MSP430 lunch box. I hope that you would
continue using the lunch box.

You can get more MSP430 microcontroller from the open market or you could even send request
mails to TI, they are happy to offer free IC’s provided you make that request from your official
student email address you could request them and then you could use those IC’s in your projects.
And if these IC’s are MSP430G2553 you could continue to use the existing lunch box that you
have.

So, this is this is all for this project. I hope we were able to illustrate how all the skills that we
have acquired over the course of this lectures series of lectures that all of these could be
integrated at the end to implement a MSP430 based project. Let me show how it works. So as
you see this is blinking here.

(Refer Slide Time: 43:53)

1012
I can remove it and it stops working by because there is no source of power. Let me also take it
out of the fishbowl to show you the circuit here. Now, I could put it back on top of it and it starts
working again why because here is the the receiving coil and in this there is the transmitting coil,
I put it on top of it it starts working.

And I can remove it put it back into my fish bowl. And then transfer it over here and you see it
starts working again. So, this is how it works. I hope you enjoyed this course. I hope it enthused
you to fall in love with electronics in general and microcontroller circuits in particular. I hope
that you will continue to build more and more projects not only in your student life, but when

1013
you enter the professional life, and I would be very happy to hear from you. Should you want to
share your success stories with me. Thank you very much. See you soon.

1014
THIS BOOK IS
NOT FOR SALE
NOR COMMERCIAL USE

(044) 2257 5905/08 nptel.ac.in swayam.gov.in

You might also like