You are on page 1of 28

ROBOTICS And EMBEDDED SYSTEMS

Embedded systems are combination of computer hardware and software, and perhaps additional mechanical or other parts, which are designed to perform a dedicated function. An embedded system is a special purpose computer that is used inside of a device. For developing embedded application we are having two options. 1. Assembler 2. C Compiler

Assembler
Using assembler can reduce them memory used abundantly. We can have a good control over the code. When we use assembly language we are directly programming the microcontroller. he process time can be easily calculated. !ut ma"ing a application in assembly language will ta"e many man hours. #orting is not at all possible in assembly language. $ven to port the code into another derivative we need to twea" a lot. %ebugging is really tough. A simple applications code may range from &'' to ('' lines. )t is really tough to map the mista"e and rectify it.

C Compiler
he application can be rapidly developed in C Compiler. he code can be ported into other microcontroller *ust li"e that. %ebugging is really easy in C. +n the other hand when we use C we don,t have the control over the code. he C Compilers are memory hungry. We can still use C Compiler because we can ma"e the applications rapidly. We don,t want to learn another new language. he -'(1 has only 12. bytes of ram. he enhanced version -'(2 even has only 2(/ bytes of ram. 0o while programming microcontroller we should ta"e care a lot in the usage of the variables.

Different microcontrollers in market


PIC One of the famous microcontrollers used in the industries. )t is based on 1)0C 2 Architecture which ma"es the microcontroller process faster than other microcontroller. I!TE" T#ese are the first to manufacture microcontrollers. hese are not as sophisticated other microcontrollers but still the easiest one to learn. ATME" Atmel,s A31 microcontrollers are one of the most powerful in the embedded industry. his is the only microcontroller having 1"b of ram even the entry stage.

Microprocessor and Microcontroller$


A microprocessor is an integrated circuit that has all the functions of a computer, e4cept memory5 input6output systems. he )C thus includes the instruction, A7U, registers 5 control functions. A microcontroller is differed from microprocessor in many ways. A microcontroller is a highly integrated chip that contains all components comprising a controller. ypically, this includes a C#U, 1A8, some form of 1+8, )6+ ports, 5 timers. A microcontroller is designed for a very specific tas"2to control a particular system. 8icrocontrollers are sometimes are called embedded microcontrollers, which means that they are part of an embedded system. Applications 8icrocontrollers are well suited for systems that re9uire a small component count. Applications are relatively small and suited to very precise tas"s. 1elatively simple )6+ control. Comparin% Microprocessor and Microcontroller 8icroprocessor: hey are processing intensive wor" with large 9uantities of data. )nstruction sets are tailored to nibble byte and word manipulation. Addressing provides access to large arrays of data. 8icrocontroller: )nstruction 0et catered to )6+, including bit manipulation set, clear, logical operations. )nstructions are compact, many 1 byte Computer has a large 1A8 to 1+8 ratio for +60, applications and data. uCs have a large 1+8 to 1A8 ratio since programs are stored on 1+8 and very little data storage is typical.

CISC and RISC


C)0C is Comple4 )nstruction 0et Computer. A design philosophy for computers whereby the processor is designed to e4ecute a relatively large number of different instructions, each ta"ing a different amount of time to e4ecute ;depending on the comple4ity of the instruction<. A Comple4 )nstruction 0et Computer ;C)0C< is an instruction set architecture ;)0A< in which each instruction can indicate several low2level operations, such as a load from memory, an arithmetic operation, and a memory store, all in a single instruction. ypically C)0C chips have a large amount of different and comple4 instructions. he philosophy behind it is that hardware is always faster than software, therefore one should ma"e a powerful instruction set, which provides programmers with assembly instructions to do a lot with short programs. RISC, or 1educed )nstruction 0et Computer. is a type of microprocessor architecture that utili=es a small, highly2optimi=ed set of instructions, rather than a more speciali=ed set of instructions often found in other types of architectures. Certain design features have been characteristic of most 1)0C processors: one cycle e&ec'tion time$ 1)0C processors have a C#) ;cloc" per instruction< of one cycle. his is due to the optimi=ation of each instruction on the C#U and pipelining. pipelinin%$ a techni9ue that allows for simultaneous e4ecution of parts, or stages, of instructions to more efficiently process instructions> lar%e n'mber of re%isters: the 1)0C design philosophy generally incorporates a larger number of registers to prevent in large amounts of interactions with memory. )n practice, however, 1)0C processors operate at more than one cycle per instruction. he #rocessor might occasionally stall a a result of data dependencies and branch instructions. A data dependency occurs when an instruction depends on the results of a previous )nstruction. T#e Performance E('ation he following e9uation is commonly used for e4pressing a computer?s performance ability:

he C)0C approach attempts to minimi=e the number of instructions per program, sacrificing the number of cycles per instruction. 1)0C does the opposite, reducing the cycles per instruction at the cost of the number of instructions per program.

)*+, Microcontroller
)ntel -'(1 is C)0C architecture which is easy to program in assembly language and also has a good support for @igh level languages. he memory of the microcontroller can be e4tended up to /&". his microcontroller is one of the easiest microcontrollers to learn. he -'(1 microcontroller is in the field for more than 2' years. here are lots of boo"s and study materials readily available for -'(1. P#ilips he #hilips -'(1 derivatives has more number of features than in any microcontroller. he costs of the #hilips microcontrollers are higher than the Atmel which ma"es us to choose Atmel more often than #hilips.

Dallas %allas has made many revolutions in the semiconductor mar"et. %allas -'(1 derivative is the fastest one in the mar"et. )t wor"s A times as fast as a -'(1 can process. !ut we are unable to get more in )ndia. Atmel hese people were the one to master the flash devices. hey are the cheapest microcontroller available in the mar"et. Atmel even introduced a 2'pin variant of -'(1 named 2'(1. he Atmel -'(1 derivatives can be got in )ndia less than .' rupees.

Arc#itect're of )*+,

he features of the -'(1 are:


1. &B !ytes of Flash 8emory 2. 12- 4 -2!it )nternal 1A8 A. Fully 0tatic +peration: 1 8@= to 2& 8@= &. A2 #rogrammable )6+ 7ines (. wo 1/2!it imer6Counters /. 0i4 )nterrupt 0ources ;( 3ectored< .. #rogrammable 0erial Channel -. 7ow #ower )dle and #ower %own 8odes he -'(1 has a -2!it C#U that means it is able to process - bit of data at a time. -'(1 has 2A( instructions.

Some of t#e important re%isters and t#eir f'nctions are

$very microprocessor 5 microcontroller uses cloc" signals. he cloc" signals are used to synchroni=e C#U with other peripherals in the C#U. Cloc" signals are very much important for a time critical *obs.

Pin dia%ram

Po-er s'pply -'(1 can handle power supply of A.( volts to . volts with no problem. Always use a %ecoupling Capacitor between the #ower supply and the Cround. %ecoupling capacitors are used to avoid the spi"es. #in &' is for 3CC and #in 2' is for Cnd. Reset Circ'itry As soon as we give the power supply the -'(1 doesn,t start. We need to restart for the microcontroller to start. 1estarting the microcontroller is nothing but giving a 7ogic 1 to the reset pin at least for the 2 cloc" pulses. 0o it is good to go for a small circuit which can provide the 2 cloc" pulses as soon as the microcontroller is powered. his is not a big circuit we are *ust using a capacitor to charge the microcontroller and again discharging via resistor. Crystals Crystals provide the synchroni=ation of the internal function and to the peripherals. Whenever ever we are using crystals we need to put the capacitor behind it to ma"e it free from noises. We can also resonators instead of costly crystal which are low cost and e4ternal capacitor can be avoided. !ut the fre9uency of the resonators varies a lot. And it is strictly not advised when used for communications pro*ects. he -'(1 operates based on an e4ternal crystal. his is an electrical device which, when energy is applied, emits pulses at a fi4ed fre9uency. Types of Memories in )*+, he -'(1 has three very general types of memory. o effectively program the -'(1 it is necessary to have a basic understanding of these memory types. hey are: +n2Chip 8emory, $4ternal Code 8emory and $4ternal 1A8. On C#ip Memory refers to any memory ;Code, 1A8, or other< that physically e4ists on the microcontroller itself. E&ternal Code Memory is code ;or program< memory that resides off2chip. his is often in the form of an e4ternal $#1+8. E&ternal RAM is 1A8 memory that resides off2chip. his is often in the form of standard static 1A8 or flash 1A8. Code memory Code memory is the memory that holds the actual -'(1 program that is to be run. his memory is limited to /&B and comes in many shapes and si=es: Code memory may be found on-chip, either burned into the microcontroller as 1+8 or $#1+8. Code may also be stored completely off-chip in an e4ternal 1+8 or, more commonly, an e4ternal

$#1+8. Flash 1A8 is also another popular method of storing a program. 3arious combinations of these memory types may also be used22that is to say, it is possible to have &B of code memory on-chip and /&" of code memory off-chip in an $#1+8. E&ternal RAM $4ternal 1A8 is any random access memory which is found offchip. 0ince the memory is off2chip it is not as fle4ible in terms of accessing, and is also slower. For e4ample, to increment an )nternal 1A8 location by 1 re9uires only 1 instruction and 1 instruction cycle. o increment a 12byte value stored in $4ternal 1A8 re9uires & instructions and . instruction cycles. On C#ip Memory he -'(1 includes a certain amount of on2chip memory. +n2chip memory is really one of two types: )nternal 1A8 and 0pecial Function 1egister ;0F1< memory. Re%ister Banks he -'(1 uses - D1D registers which are used in many of its instructions. hese D1D registers are numbered from ' through . ;1', 11, 12, 1A, 1&, 1(, 1/, and 1.<. hese registers are generally used to assist in manipulating values and moving data from one memory location to another. For e4ample, to add the value of 1& to the Accumulator, we would e4ecute the following instruction: ADD A.R/ Special 0'nction Re%ister 1S0R2 Memory 0pecial Function 1egisters ;0F1s< are areas of memory that control specific functionality of the -'(1 processor. For e4ample, four 0F1s permit access to the -'(1Es A2 input6output lines. Another 0F1 allows a program to read or write to the -'(1Es serial port. +ther 0F1s allow the user to set the serial baud rate, control and access timers, and configure the -'(1Es interrupt system. S0R Descriptions P* 1Port *. Address )*#. Bit Addressable2 his is input6output port '. $ach bit of this 0F1 corresponds to one of the pins on the microcontroller. For e4ample, bit ' of port ' is pin #'.', bit . is pin #'... Writing a value of 1 to a bit of this 0F1 will send a high level on the corresponding )6+ pin whereas a value of ' will bring it to a low level.

SP 1Stack Pointer. Address ),#2 his is the stac" pointer of the microcontroller. his 0F1 indicates where the ne4t value to be ta"en from the stac" will be read from in )nternal 1A8. )f we push a value onto the stac", the value will be written to the address of 0# F 1. hat is to say, if 0# holds the value '.h, a #U0@ instruction will push the value onto the stac" at address '-h. his 0F1 is modified by all instructions which modify the stac", such as #U0@, #+#, 7CA77, 1$ , 1$ ), and whenever interrupts are provo"ed by the microcontroller. DP"3DP4 1Data Pointer "o-34i%#. Addresses )5#3)6#2 he 0F1s %#7 and %#@ wor" together to represent a 1/2bit value called the Data Pointer. he data pointer is used in operations regarding e4ternal 1A8 and some instructions involving code memory. 0ince it is an unsigned two2byte integer value, it can represent values from ''''h to FFFFh ;' through /(,(A( decimal<. PCO! 1Po-er Control. Addresses )7#2 he #ower Control 0F1 is used to control the -'(1?s power control modes. Certain operation modes of the -'(1 allow the -'(1 to go into a type of DsleepD mode which re9uires much less power. hese modes of operation are controlled through #C+G. Additionally, one of the bits in #C+G is used to double the effective baud rate of the -'(1?s serial port. TCO! 1Timer Control. Addresses ))#. Bit Addressable2 he imer Control 0F1 is used to configure and modify the way in which the -'(1?s two timers operate. his 0F1 controls whether each of the two timers is running or stopped and contains a flag to indicate that each timer has overflowed. 0ome non timer related bits are located in the C+G 0F1. hese bits are used to configure the way in which the e4ternal interrupts are activated and also contain the e4ternal interrupt flags which are set when an e4ternal interrupt has occurred.

TMOD 1Timer Mode. Addresses )8#2 he imer 8ode 0F1 is used to configure the mode of operation of each of the two timers .Using this 0F1 your program may configure each timer to be a 1/2bit timer, an -2 bit auto reload timer, a 1A2bit timer, or two separate timers. Additionally, you may configure the timers to only count when an e4ternal pin is activated or to count DeventsD that are indicated on an e4ternal pin.

T"*3T4* 1Timer * "o-34i%#. Addresses )A#3)C#2 hese two 0F1s, ta"en together, represent timer '. heir e4act behavior depends on how the timer is configured in the 8+% 0F1> however, these timers always count up. What is configurable is how and when they increment in value. T",3T4, 1Timer , "o-34i%#. Addresses )B#3)D#2 hese two 0F1s, ta"en together, represent timer 1. heir e4act behavior depends on how the timer is configured in the 8+% 0F1> however, these timers always count up. What is configurable is how and when they increment in value. P, 1Port ,. Address 8*#. Bit Addressable2 his is input6output port 1. $ach bit of this 0F1 corresponds to one of the pins on the microcontroller. For e4ample, bit ' of port 1 is pin #1.', bit . is pin #1... Writing a value of 1 to a bit of this 0F1 will send a high level on the corresponding )6+ pin whereas a value of ' will bring it to a low level. SCO! 1Serial Control. Addresses 8)#. Bit Addressable2 he 0erial Control 0F1 is used to configure the behavior of the -'(1?s on2board serial port. his 0F1 controls the baud rate of the serial port, whether the serial port is activated to receive data, and also contains flags that are set when a byte is successfully sent or received. SB90 1Serial Control. Addresses 88#2 he 0erial !uffer 0F1 is used to send and receive data via the on2board serial port. Any value written to 0!UF will be sent out the serial port?s H% pin. 7i"ewise, any value which the -'(1 receives via the serial port?s 1H% pin will be delivered to the user program via 0!UF. )n other words, 0!UF serves as the output port when written to and as an input port when read from. P5 1Port 5. Address A*#. Bit Addressable2 his is input6output port 2. $ach bit of this 0F1 corresponds to one of the pins on the microcontroller. For e4ample, bit ' of port 2 is pin #2.', bit . is pin #2... Writing a value +f 1 to a bit of this 0F1 will send a high level on the corresponding )6+ pin whereas a value of ' will bring it to a low level. IE 1Interr'pt Enable. Addresses A)#2 he )nterrupt $nable 0F1 is used to enable and disable specific interrupts. he low . bits of the 0F1 are used to enable6disable the specific interrupts, where as the highest bit is used to enable or disable A77 interrupts. hus, if the high bit of )$ is ' all interrupts are disabled regardless of whether an individual interrupt is enabled by setting a lower bit.

P6 1Port 6. Address B*#. Bit Addressable2 his is input6output port A. $ach bit of this 0F1 corresponds to one of the pins on the microcontroller. For e4ample, bit ' of port A is pin #A.', bit . is pin #A... Writing a value of 1 to a bit of this 0F1 will send a high level on the corresponding )6+ pin whereas a value of ' will bring it to a low level. IP 1Interr'pt Priority. Addresses B)#. Bit Addressable2 he )nterrupt #riority 0F1 is used to specify the relative priority of each interrupt. +n the -'(1, an interrupt may either be of low ;'< priority or high ;1< priority. An interrupt may only interrupt interrupts of lower priority. For e4ample, if we configure the -'(1 so that all interrupts are of low priority e4cept the serial interrupt, the serial interrupt will always be able to interrupt the system, even if another interrupt is currently e4ecuting. @owever, if a serial interrupt is e4ecuting no other interrupt will be able to interrupt the serial interrupt routine since the serial interrupt routine has the highest priority. PS: 1Pro%ram Stat's :ord. Addresses D*#. Bit Addressable2 he #rogram 0tatus Word is used to store a number of important bits that are set and cleared by -'(1 instructions. he #0W 0F1 contains the carry flag, the au4iliary carry flag, the overflow flag, and the parity flag. Additionally, the #0W register contains the register ban" select flags which are used to select which of the D1D register ban"s are currently selected. ACC 1Acc'm'lator. Addresses E*#. Bit Addressable2 he Accumulator is one of the most2used 0F1s on the -'(1 since it is involved in so many instructions. he Accumulator resides as an 0F1 at $'h, which means the instruction MO; A.<5*# is really the same as MO; E*#.<5*#. @owever, it is a good idea to use the first method since it only re9uires two bytes whereas the second option re9uires three bytes. B 1B Re%ister. Addresses 0*#. Bit Addressable2 he D!D register is used in two instructions: the multiply and divide operations. he ! register is also commonly used by programmers as an au4iliary register to temporarily store values.

ADDRESSI!= MODES
An Daddressing modeD refers to how you are addressing a given memory location. Immediate Addressin% )mmediate addressing is so2named because the value to be stored in memory immediately follows the operation code in memory. hat is to say, the instruction itself dictates what value will be stored in memory. For e4ample, the instruction:

MO; A.<5*# Direct Addressin% %irect addressing is so2named because the value to be stored in memory is obtained by directly retrieving it from another memory location. For e4ample: MO; A.6*# his instruction will read the data out of )nternal 1A8 address A' ;he4idecimal< and store it in the Accumulator. Indirect Addressin% )ndirect addressing is a very powerful addressing mode which in many cases provides an e4ceptional level of fle4ibility. )ndirect addressing is also the only way to access the e4tra 12- bytes of )nternal 1A8 found on an -'(2. )ndirect addressing appears as follows: MO; A.>R* his instruction causes the -'(2 to analy=e the value of the 1' register. he -'(2will then load the accumulator with the value from )nternal 1A8 which is found at the address indicated by 1'. E&ternal Direct $4ternal 8emory is accessed using a suite of instructions which use what ) call D$4ternal %irectD addressing. ) call it this because it appears to be direct addressing, but it is used to access e4ternal memory rather than internal memory. here are only two commands that use $4ternal %irect addressing mode: MO;? A.>DPTR MO;? >DPTR.A E&ternal Indirect $4ternal memory can also be accessed using a form of indirect addressing which ) call $4ternal )ndirect addressing. his form of addressing is usually only used in relatively small pro*ects that have a very small amount of e4ternal 1A8. An e4ample of this addressing mode is: MO;? >R*.A

Makin% a line follo-er on bread board

Makin% of a Infra Red Sensor

Setting up a Microcontroller

Settin% 'p a Motor Control Circ'it

T#e complete circ'it dia%ram of a "ine 0ollo-in% Robot

T#e iBOT

T#e iBot Controller Board


he i!ot Controller !oard is based around the #hilips -I3(11%2 microcontroller. 0eat'res$ !uilt around the popular -I3(11%2 microcontroller with ample of program memory ;/&Bb< - channels of motor control, capable of driving & dc motors or 2 stepper motors at a time. +nboard detachable 1/42 7C% for enhanced interaction. - digital input channels for sensor interfacing. +nboard 102A2 level shifter for direct communication with a computer. & general purpose 7$%s and 0witches.

Parts identification$ Po-er On S-itc#: )t,s a basic push to on 2 push to off type switch IC 7)*+: )t,s a three terminal linear ( volt regulator used to supply the microcontroller and other peripherals. Motor Enable s-itc#: his switch is used to enable6disable the motor driver chips hence in turn enabling6disabling the motors. Reset S-itc#: his switch is used to reset the microcontroller. IC +++: his general purpose timer is used in the mono2stable mode to automatically 1eset the microcontroller during programming. MA? 565: his chip ta"es care of the voltage conversions needed to communicate with the #C,s RS565 1Serial3 COM2 port@ 72IA%: )t is a & channel motor driver with /''mA of current per channel and has inbuilt clamp diodes. he board contains two such chips. Potentiometer 1Pot<: he potentiometer is used to vary the contrast of the 7C%. Sensor port: At a time, - individual sensor modules can be connected to this port. he port also provides a (3 supply needed drive the sensors. DB 8 connector: his is a I pin connector used to connect to the #C,s C+8 port during programming or for general UA1 communications. S-itc# array: Four general purpose switches are connected in the active2low configuration. Crystal$ he crystal sets the microcontroller,s cloc" fre9uency to 11.'(I2 8@=. Beeper: Connected in the active low mode, the beeper can easily be used to get audible feedbac"s from the controller.

T#e line sensin% mod'le

he line sensing module is designed to detect a white line on a blac" surface from an ideal distance of 1'mm to 2'mm. he module detects the line by measuring the intensity of reflected )nfrared ;)1< light. he sensor can be tuned to detect various contrasts, say white line on a green surface or a white line on a blac" surface. he red indicator led lights up whenever in encounters a reflecting surface ;white line< T'nin% t#e line sensin% mod'le$ Jou need the power supply6battery, controller board, sensor module and a screw driver. 0tep 1: Connect you module to one of the sensor port on the i!ot controller. 1efer the ad*oining figure for reference. 0tep 2: urn on the power supply of your i!ot controller. 0tep A: #lace your sensor at a distance of appro4imately 2cm above the surface that you Kdon,tL want to detect, eg., a blac" surface. 0tep &: Using the screw driver, turn the potentiometer in either direction. Jou will notice that the indicator 7$% lights up at a particular point and goes off at another point. Gow, in order to properly tune to the sensor, you need to turn the pot to such a point that the 7$% *ust turns off. 0tep (: Gow when you place you sensor on a reflective surface ;such as white< you,ll see the indicator 7$% glows. hat,s itM We now have our 7ine 0ensing 8odule all tuned upM

Specifications

)nput 3oltage: (3olts +ptimum detecting distance: 1'mm

IR Pro&imity Sensor Mod'le

he )1 pro4imity sensor module is based around the 0+# sensor, commonly used in 3 remote receivers. his module is able to detect ob*ects at a distance of (cm to 1(cm. he ma4imum etectable distance varies in accordance with the color and te4ture of the ob*ect.

For e4ample, a hite ob*ect can be easily detected from a distance of 1(cm while a blac" ob*ect would be etectable from a ma4imum distance of (cm. T'nin% t#e obstacle detection mod'le$ Jou need the power supply6battery, controller board, )1 pro4imity sensor module and a screw river. he sensors can be tuned so as to change the ma4imum detectable distance. his can be varied y changing the intensity of the )1 emitter. 0tep 1: Connect you module to one of the sensor port on the i!ot controller. 1efer the ad*oining figure for reference. 0tep 2: urn on the power supply of your i!ot controller. 0tep A: With the help of a screw driver, turn the potentiometer in such a way that the indicator 7$% *ust turns off. ;if its already turned off, s"ip this step< 0tep &: #lace an ob*ect ;non2blac"< in front of the module at a distance of about 1'cm and turn the potentiometer such that the indicator 7$% *ust lights up. his step ma"es sure that the same ob*ect would always be detected at a ma4imum distance of 1'cm. 0imilarly, you could move the ob*ect and turn your potentiometer to achieve an optimum distance Specifications$

+perating 3oltage: (3olts

%etectable distance: (cm to 1(cm !OTE$ )1 light is invisible to the human eye but digital cameras li"e webcams or cell2 phone cameras are capable of detecting it. #oint your camera towards the )1 emitter ;while turned on< and see for yourselfM his is a very handy debugging tool.

T#e DC Po-er S'pply and Battery


Po-er S'pply$ he %C #ower supply provides I3olts and a ma4 current of up to 1A. )t also has a provision to safely charge the I./3 Gi28h battery pac" at a constant preset current. ;#hoto of the power supply< Add schematic.

T#e Battery Pack$ he battery pac" consists of - AA Gi28h Cells of 1.23 each, rated at 1A''mAh. hus, the total voltage rating of the battery pac" is of I./3olts. )n order to charge the pac", simply connect its plug to the charger port and turn on the supply. A full charge would ta"e about 1' to 12hrs.

Pro%rammin% t#e "ine 0ollo-in% Robot


33 sensors are connected to P,A* and P,A, and motors are connected to port 5@ NincludeO1$C8+%(2.hP void main;< Q while;1< Q if;#1R'SS155#1R1SS1< Q #2S(> 66 running both motors in forward direction T if;#1R'SS'55#1R1SS1< Q #2S&> 66 stop the right motor and run the left motor T if;#1R'SS155#1R1SS'< Q #2S1> 66 stop the left motor and run the right motor T if;#1R'SS'55#1R1SS'< Q #2S'> 66 stop both motors T T T