Electronics Engineering Herald ADVT
Home | News | New Products | India Specific | Design Guide | Sourcing database | Student Section | About us | Contact us | What's New
Processor / MCU / DSP
Memory
Analog
Logic and Interface
PLD / FPGA
Power-supply and Industrial ICs
Automotive ICs
Cellphone ICs
Consumer ICs
Computer ICs
Communication ICs (Data & Analog)
RF / Microwave
Subsystems / Boards
Reference Design
Software / Development kits
Test and Measurement
Discrete
Opto
Passives
Interconnect
Sensors
Batteries
Others

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


Online course on Embedded Systems

 

MODULE -2 (Microcontroller and programming)
   

   Microprocessor, Microcontroller and System on Chip

Microprocessor:
Microprocessor is the Central Processing Unit (CPU) of embedded system. It does arithmetic and logic operations of the digital binary data.Very old embedded systems circuit/board was generally made up of separate microprocessor (8085), I/P interface, O/P interface, memory, clock and timing devices, power supply devices, and analog/linear devices.

Microcontroller:
In the early days of embedded systems, engineers have built embedded systems with separate set of devices connected on a printed circuit board. The complexity involved in manufacturing and re-engineering was very high with many Integrated Circuits and other components on-board. Also the advance in technology has enabled processor manufacturers to add one device after one into single IC. It started with adding I/O interface and memory, now we see lot more functions inside the processor chip. These microprocessors with all the additional support built-in are called microcontrollers.

To define, Microcontroller is an Integrated Circuit device with CPU, memory, I/O interface and any other logic and analog function on a single chip.

System On Chip (SOC)

Even though MCU holds most of the functions, it still lacks in few special analog functions and application specific functions. The idea of putting entire system (all the semiconductor IC functions) on a single chip is called System on chip. On a printed circuit board, you see a single IC accompanied with few discrete and passive components.

If we look at the recent microcontrollers released in the market, most of them are very close to System On Chip. The concept of SOC is well ticking in the market.

SOC is a common sense solution, that means, why we have to go for a complex board when we can put everything into a single IC. SOC saves board space, ease manufacturing, and score higher in reliability over non-SOC solutions. It's drawback is, the manufacturer profits from this product only if it's used in millions. Also it steals some design flexibility for the design engineer.

Processor Architecture

The two most popular architectures used in embedded world are Harvard and Van Neumann. Read this separate article describing the differences between these two architectures.

The Van Neumann V/S harvard processor architecture.

The popular microcontrollers and companies

There are plenty of microcontroller manufacturers all around the world. We in India don't have a LOCAL IC manufacturer who can supply microcontroller chips. However all the major microcontroller vendors in the world have support offices in all our metros. To learn about latest trends in microcontrollers read this report.

Market and technology trends of microcontrollers in the year 2008

Programming: machine language, assembly language, and C programming

Assembly and machine language

Now let's start embedding! We will begin training you in programming now, and in coming modules we will be covering on details of functional blocks available on a microcontroller.

The microcontroller is the one, which decides what need to be done, what need not be done, and how to be done. Basic rule we need to keep in mind while "instructing" the microcontroller is - microcontroller is like a very intelligent child. The child (controller) would do exactly what was told it to do - nothing more nothing less. If the instruction is ambiguous then the behavior of the microcontroller would go haywire.

Example: In a bread toaster, the sequence of operations is,

a) Turn on the heater
b) Check whether the bread is properly roasted or not (by checking the temperature or set time)
c) If bread is not yet completely toasted properly again go to step (b)
d) Stop the heater as the bread is toasted properly.


Now how do you tell this sequence to a microcontroller inside a bread toaster? You should tell it (microcontroller) in a way it understands. It is like speaking to a person who knows some language, which you can't speak. The instant option left to you to speak to such person is to catch hold of a translator, who knows both the languages and translate/convert your language to other's language.

The language what all microcontrollers understand is called machine language. Here is just a few lines of machine language for Freescale's 6812 microcontroller.

CF0C00180B8000024D008018030FA008009600847FB1F033260EFE080009
7E080026EE4C008020E918030FA008004D008020DE23F000

Does this jumble of hexadecimal codes dismay you? Obviously you should be! Any way don't get disheartened by this magic series of numbers. But make it very clear this (machine language) is the native language of all the microcontrollers and you should "instruct" them only in their language. Also this machine language is different for each microcontroller families (8051, PIC, ARM etc..).

In the very early stages itself computer scientists/ chip designers noted this problem instantaneously and came out with a solution. For each of the operation that microcontroller can do (execute) they assigned an "English like" word so that programmer/ designer can easily instruct the microcontroller. This is called assembly language.

Here below is table of assembly languages instructions for popular PIC16xx microcontroller. In total it has only 35 instructions.


pic instructions

In this above table, the English type words in the first column are assembly language instructions and the binary codes in the fourth column are machine language instructions.


With this background let us do a small exercise. Let us try to add two numbers, say 3 and 4.

Again remember this,
[Microcontroller is like a very intelligent child. The child (microcontroller) would do exactly what was told it to do - nothing more nothing less. If the instruction is ambiguous then the behavior of the microcontroller would go haywire.]

MOVLW #3; Move value 3 into register W (working register).

What is register?

Register in the context of microcontrollers: Register is some temporary space which it can be used to keep some value temporarily. Generally every microcontroller will have some registers. Some registers have special purpose capability. In this context the register we are using is called "W" register or working register.

ADDLW #4; Now the working register content is added with another value 4.

So now the result 7 is in Working register and it can be used by programmer in any way he/she wants (like display/ store it future arithmetic operations etc)


Basically assembly level language is all about knowing what all the instructions are available with particular microcontroller and write the program (code) according to requirement using the list of available assembly instructions. So by now we know little bit of knowledge on how to speak to microcontroller in their own language.

Now the questions arise. We the programmers use the assembly language as the instructions to "instruct" the microcontroller. But it is already mentioned that microcontrollers only understand machine language as machine language is the native language of all the microcontrollers and we should "instruct" them only in their language.
How does the assembly language become machine language?

Here comes the "Assembler" (You language translator friend): Assembler is a program, which converts assembly instructions to machine language. It is like a translator (dhubashi) who would be used when two persons are communicating in completely different languages.

The C language - very essential

Now we know some basics of machine and assembly language, so that we can instruct microcontrollers in their own language.

Now let us C!

The assembly language programming would work only for simple embedded applications, as you develop bigger and complex applications the assembly language code will be very difficult to manage and the time and effort required to program and debug (fixing errors) rises exponentially with the total code size.

Assembly can still be used for simple programs, only if you wish to experiment. Otherwise C language is the only practical and efficient solution. The thumb rule to decide whether the program is simple or complex is, less than 1000 lines of assembly code than it's simple, greater than 1000 lines of assembly code; better call it complex.

Here few examples of some of the assembly instruction set of few popular microcontrollers.

680x0 based microcontrollers (680x0 are popular 16 bit series of microprocessor/ micro microcontrollers from Motorola)
BRA - Branch;
JNOV - Jump on No Overflow;
DBcc - Test Condition, Decrement, and Branch;
STJ - Store jump-register;

Some of the PIC based assembly instructions.
DECFSZ f,d - Decrement f, Skip if 0
BTFSS - Bit Test f, Skip if Set
IORWF f,d - Inclusive OR W with f
RETLW k - Return with literal in W

Some of the 8051 instruction set
DJNZ - Decrement Register and Jump if Not Zero
JBC - Jump if Bit Set and Clear Bit
LCALL - Long Call
LJMP - Long Jump
XCHD - Exchange Digits

What do you think of these instructions? Seems like some combination of English alphabets isn't it? We immediately feel intimidated by seeing them in the code. How much ever comments/ explanation is provided, it would be very difficult for "new" guy to understand the logic. (New guy is just an acronym here - if you see the code you have written in assembly after 6 months - you will be the "new" guy - In the beginning of my career(author) I have become "new guy" several times and left the difficult portion of the code - simply re-wrote the module - which saved my time and effort). So first problem is its readability. No matter what ever the clarity in description in the form of comments/explanation would make a new guy to feel uncomfortable with the code. So imagine a case of complex embedded application written by multiple developers. Simply it is hell.

Next problem is its (assembly languages) compatibility. Assume with great difficulty the embedded application is developed in assembly language and is fairly working well. Now suddenly market scenario changes and instead of microcontroller-X(which is used by you) microcontroller-Y is cheaper/ affordable (We have seen cases where the microcontroller (and its associated hardware design) changed overnight as another microcontroller was available for 10 cents less). Now in no way you can complete the project as,
--> You need to completely unlearn the assembly language of microcontroller-X and learn that of        microcontroller-Y
-->  Logically design the flow and implement the code using new assembly language
-->  Test the entire setup again.

Here comes the silver bullet - C language. Basically C language is universally known and any "new guy" can learn the basics of C in couple of weeks and understand the design / flow. Also if the hardware (controller) is changed/ redesigned all you need to do is re-compile your program for the new microcontroller :) Life is very easy.

Again - let us remember our postulate. Microcontrollers only understand machine language as machine language is the native language of all the microcontrollers and we should "instruct" them only in their language. So how does the C language code become machine language?

Here comes the "Compiler", compiler is a program which converts C language to machine language. It is like another (high level) translator

But bear in mind - Assembly language (or machine language) is the one which gives fastest and compact code. Basically assembly language is used in these two things.

The first is for when you need to access hardware. Writing routines to interact with the hardware can be easier and cleaner than the equivalent operation in C. It is not difficult to export the assembly routines to make them callable from C or some other language, so you can get the advantage of having precise control over the hardware without having to write your entire program in assembly.

The other thing assembly is good for is optimizing certain parts of a program. If you have an extremely time critical routine that is called a lot, then it makes sense to go through it with a fine toothed comb and choke every possible cycle out of it. You have to look at the speed gain and compare it to the time you spent optimizing the code. If you spent three hours optimizing a routine, and you only get a 2 microsecond speed gain, then you have to call that routine billions of times to make it worthwhile. In most cases, it's simply not worth the effort. Embedded applications and DSP are areas where hand optimization might make a significant difference, but unless you doing some extreme number crunching on a PC, it's probably not worth it.

Other than these two things assembly language does not play much role in embedded systems. There are some extreme cases where the complete windows programming is done in assembly. This just shows how much complexity a person can handle and remember this can not be done by next (other) guy.

Ok now we are little bit into the embedded systems. At this point it would be ideal to have some hardware/ assembler/ compiler to play with. We would provide some of the example hardware which we would be using (it would be better if you have them and keep trying the next modules/sections with examples). Otherwise it will be like hearing a nice story and forgetting everything.


Kits to buy to practice this course:

From this module onwards this course gets more practical. If you own a personal computer at home, you can establish your own lab to practice this course. You got to do little shopping to establish an embedded lab.

You need microcontroller development board/kit and developement software called Integrated Design/Development Environment/platform (IDE). We are providing multiple choices of embedded development boards/kits from leading vendors which are available in many parts of the world and also in India.

The kit we have used and also suggest you to buy are:

1. Kit Name: Low-cost development platform Discovery from ST MIcroelectronics

To buy this kit or to learn more visit ST website at http://www.st.com/internet/evalboard/product/250863.jsp

The cost of this kit not more than 9.9 US$

Installation, programming and sample-code details of this kit available at: http://www.eeherald.com/section/design-guide/esmod3b.html

Other course modules for STM32 Discovery kit are listed in the table(module-table) down below with the column title: stream-discovery.

If you not able to procure this kit, we are providing one more option to buy similar kit from NXP Semiconductor, detalis of NXP kit is provided below:


2. Kit Name: Low-cost development platform LPCXpresso from NXP Semiconductors

To buy this kit or to learn more visit NXP website http://ics.nxp.com/lpcxpresso/

The cost of the kit is around less than US$40.

Installation, programming and sample-code details of this kit available at: http://www.eeherald.com/section/design-guide/esmod3a.html
Other course modules for LPCXpresso kit are listed in the table(module-table) down below with the column title: stream-LPCXpresso.

Our earlier board was ARM 7TDMI based AME-51 lite (ML67Q4050) from OKI Semiconductor. This board is now obsolete so we don't recommend to use AME-51 lite practice material put on this website. However the old course modules for AME-51 are still available with links listed in the table (module-table)down-below for your reference under column title: stream-AME-51.

If you don't have PC or not interested in buying the kit, you still can continue to learn from this course without buying kit except you miss practical exposure. If in case you wish to write few sample code by yourself (after completing reading of few more modules), you can send us your code/program to get it vaidated. We can publish and reward good programs (both C and assembly langauge).

You can intrepret this course material to any other ARM Cortex M0 kit you have.

Books to buy for learning more on embedded systems:

If you feel you need some more reference material in the form of books for your embedded systems learning. We refer these below books. But they are not must for this course:
The books are,

1) Embedded Systems Building Blocks, by Jean LaBrosse
2) An Embedded Software Primer, by David Simon
3) The Art of Designing Embedded Systems, by Jack Ganssle
4) Fundamentals of Embedded software by Daniel Lewis
5) Let Us C, by Yashwant Kanetkar

Click below to visit next module from the stream of your choice:

Module-Table:

Stream-Discovery Stream-LPCXpresso Stream-AME-51

Module 3b: Installation of ARM Cortex M0 based STM32F0 kit from ST Microelectronics and sample code

Module 4: Sample programs -1 for ARM Cortex M0 based on STM32F0

Module 5b: ARM Cortex M0 Architecture

Module 6b: Sample program-2 (interfacing keypad)

Module 7: Serial communication concepts -1

Module 8: RS-232 Basics

Module 9: Controller Area Networking (CAN)

Module 10: LIN

Module 11: I2C Bus Interface

Module 12: SPI Bus Interface

Module14: USB Interface

Module15: SRAM memory interface

Module16: Flash memory interface

Module17: LCD display panel interface

Module18: Touch pane interface

Module19: Audio/video interface

Module 3a: Installation of ARM Cortex M0 based LPCXpresso kit from NXP Semiconductor and sample code

Module 4: Sample programs -1 for ARM Cortex M0 based LPCXpress

Module 5a: ARM Cortex M0 Architecture

Module 6a: Sample program-2 (interfacing keypad)

Module 7: Serial communication concepts -1

Module 8: RS-232 Basics

Module 9: Controller Area Networking (CAN)

Module 10: LIN

Module 11: I2C Bus Interface

Module 12: SPI Bus Interface

Module14: USB Interface

Module15: SRAM memory interface

Module16: Flash memory interface

Module17: LCD display panel interface

Module18: Touch pane interface

Module19: Audio/video interface

Module 3: Installation of OKI's ARM7 KIT(old module, suggest to skip this module)

Module 4: Sample programs -1 for ARM7 TDMI MCU

Module 5: OKI ARM Processor Architecture.

Module 6: Sample programs -2 for ARM7 TDMI MCU

Module 7: Serial communication concepts -1

Module 8: RS-232 Basics

Module 9: Controller Area Networking (CAN)

Module 10: LIN

Module 11: I2C Bus Interface

Module 12: SPI Bus Interface

Module14: USB Interface

Module15: SRAM memory interface

Module16: Flash memory interface

Module17: LCD display panel interface

Module18: Touch pane interface

Module19: Audio/video interface

 

Previous common modules


Module 1: Introduction to Embedded Systems: Definition, application and future.

Module 2: Microprocessor, Microcontroller, MCU Manufacturers, introduction to programming.

ABOUT THIS COURSE:

Totally EEHerald brings 20+ modules. You can be assured of completing basic course in Embedded Systems after studying and practicing exercises in all the modules. We will give priority to programming and serial communications (SPI, USB, CAN etc..) part..

This free tutorials on embedded systems is prepared by embedded professionals with more than10 years of industrial experience, however we want your feedback on this course content; please email your questions, suggestions and comments to editor@eeherald.com. Your questions on present modules will be answered in the revised modules. We may change the course content based on the majority of your requests and feedbacks.

Please let your friends know about this course, we request you to email this link to your friends and colleagues who are interested in embedded system.

Events
Advertise
Send News
Send Article
Feedback
eeherald.com
India Search
Electronics Design Business
Home | News | New Products | India Specific | Design Guide | Sourcing database | Student Section | About us | Contact us | What's New
©2006 Electronics Engineering Herald