LAB MANUAL ON MICROPROCESSORS AND MICROCONTROLLERS (15A04607) III B.TECH – II SEMESTER EEE (JNTUA – R15) PREPARED BY Mrs.T.Vedavathi .,M.Tech ASSISTANT PROFESSOR DEPARTMENT OF ELECTRONICS AND ELECTRICAL ENGINEERING CHADALAWADA RAMANAMMA ENGINEERING COLLEGE CHADALAWADA NAGAR, RENIGUNTA ROAD, TIRUPATI (A.P) - 517506
86
Embed
LAB MANUAL ON · lab manual on microprocessors and microcontrollers (15a04607) iii b.tech – ii semester eee (jntua – r15) prepared by mrs.t.vedavathi .,m.tech assistant professor
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY ANANTAPUR
B. Tech III-II Sem. (EEE)
15A04607 MICROPROCESSORS AND MICROCONTROLLERS LABORATORY
Part A : 8086 Microprocessor Programs using NASM/8086 microprocessor kit.
1. Introduction to MASM Programming.
2. Programs using arithmetic and logical operations
3. Programs using string operations and Instruction prefix: Move Block, Reverse string,
Sorting, String comparison
4. Programs for code conversion
5. Multiplication and Division programs
6. Sorting and multi byte arithmetic
7. Programs using CALL and RET instructions
Part B Embedded C Experiments using MSP430 Microcontroller
1. Interfacing and programming GPIO ports in C using MSP430 (blinking LEDs , push
buttons)
2. Usage of Low Power Modes: ( Use MSPEXP430FR5969 as hardware platform and
demonstrate the low power modes and measure the active mode and standby mode current)
3. Interrupt programming examples through GPIOs
4. PWM generation using Timer on MSP430 GPIO
5. Interfacing potentiometer with MSP430
6. PWM based Speed Control of Motor controlled by potentiometer connected to MSP430
GPIO
7. Using ULP advisor in Code Composer Studio on MSP430
8. Low Power modes and Energy trace++:
a. Enable Energy Trace and Energy Trace ++ modes in CCS
b. Compute Total Energy, and Estimated lifetime of an AA battery.
Note : Any six experiment from Part A and Six experiments from Part B are to be
conducted
LIST OF EXPERIMENTS
Note: The students are required to perform any Six Experiments from each Part of the
following.
S.NO NAME OF THE EXPERIMENT
PART A: 8086 Microprocessor Program using MASM/8086 kit
1. Introduction to MASM Programming.
2. Programs using arithmetic and logical operations.
3. Programs using string operations and Instruction prefix: Move Block, Reverse string, Sorting,String comparison.
4. Programs for code conversion.
5. Multiplication and Division programs.
6. Sorting and multi byte arithmetic.
7. Programs using CALL and RET instructions.
PART B: Embedded C Experiments using MSP430 Microcontroller
1. Interfacing and programming GPIO ports in C using MSP430 (blinkingLEDs, push buttons).
2. Usage of Low Power Modes: (Use MSPEXP430FR5969 as hardwareplatform and demonstrate the low power modes and measure the activemode and standby mode current).
3. Interrupt programming examples through GPIOs.
4. PWM generation using Timer on MSP430 GPIO.
5. Interfacing potentiometer with MSP430.
6. PWM based Speed Control of Motor controlled by potentiometerconnected to MSP430 GPIO.
7. Using ULP advisor in Code Composer Studio on MSP430.
8. Low Power modes and Energy trace++: a. Enable Energy Trace and Energy Trace ++ modes in CCS b. Compute Total Energy, and Estimated lifetime of an AA battery.
PART A
INTRODUCTION TO 8086 MICROPROCESSORS
This chapter is intended serve as an introduction to the programming and
some features of 8086 Microprocessor. The users are requested to read 8086
Architecture and organization of 8086 for better understanding.
The 8086-programming model includes general purpose registers, segment
registers, flag registers, base and pointer register whose functions are briefly given
below.
SEGMENT REGISTERS:
Code segment register-CS-stores the base address of the code segment.
Stack segment register-SS-stores the base address of the Stack.
Data segment register-DS-stores the base address of the Data.
Extra segment register-ES-stores the base address of the Extra segment.
INDEX REGISTERS:
Source index Register-SI-Store the base address of the Source data.
Destination index Register-DI-Store the base address of the Destination data.
POINTER REGISTERS:
Instruction Pointer-IP-stores the address of next instruction.
Stack Pointer-SP-stores the address of Top of the stack.
Base Pointer-BP-stores the base address.
GENERAL PURPOSE REGISTERS:
Accumulator-AX-Used in all arithmetic Instructions.
Base Register-BX-used to store Base address while programming.
Counter Register-CX-Used as counter during programming.
Destination Register-DX-used to store base address while programming.
Extended Accumulator-DX; AX-used in some arithmetic Instructions.
All these 16 bit registers can also be used as a pair of 28-bit registers.
FLAG REGISTERS:
The flag register in 8086 is of 16 bit Wide in which only 9 bits are used as flags
and other bits are in don’t care condition. For complete flag format the users are
requested to refer to the books, here only the functions of each flags are briefly given
in order to be helpful while programming.
A flag is a flip flop, which is set or reset after an operation according to the
data conditions of the result in the accumulator and other registers.
1. Zero flag-Z: the flag is set to 1 when the result is Zero, otherwise it is
Reset.
2. Carry flag (barrow)-CY : If an arithmetic operation result in a carry, the
CY flag is set, otherwise it is Reset.
3. Sign flag-S: the sign flag is set if the MSB bit of the result is 1, otherwise
it is Reset.
4. Parity flag-P: If the Result has an even number of 1’s, the flag is set, For
odd number of 1’s the flag is Reset.
5. Direction flag-D: This flag selects increment or decrement mode for the
DI and /or SI registers during string instructions. If the D=1, the
registers are automatically decremented; if D=0 the registers are
automatically incremented.
6. Overflow flag-O: Overflow occurs when signed numbers are added or
subtracted. An overflow indicates that the result has exceeded the
capacity of machine.
7. Trap flag-T: The trap flag unable trapping through an on chip
debugging feature.
8. Interrupt flag-I: The Interrupt flag controls the operation of INTR input
Pin .if I=1 INTR is enabled otherwise it is disabled.
9. Auxiliary carry flag-AC: The Auxiliary carry holds the carry (half
carry) after addition or barrow after subtraction between bit positions 3
and 4 of the result. This bit is tested in special instructions like DAA
and DAS.
Instructions set of 8086:
An instruction is an command to the microprocessor to perform a given task
on specified data. Each instruction has two parts. One is task to be performed, called
the operation code (opcode) and the second is the data to be operated on, called the
operand. The entire group of instructions, called the instruction set, determines what
functions the microprocessor can perform.
The 8086 instructions can be classified into following categories depending on
their functions.
1. Data transfer instructions:
This group of instructions copies the data from a location called source
to another location called destination, without modifying the contents
of the source. The one more specialty of this group is they will not
affect any of the flags in the flag register. The data transfer may be
between registers, memory location and a register, immediate data and
memory or register and between I/O devices and the accumulator.
2. Arithmetic Instructions:
This Instruction performs arithmetic operations such as addition,
subtraction, increment and decrement. The flags are effected by this
group of instructions depending on the results they produce but some
special instructions will not effect flags.
3. Logical, shift or rotate Instructions:
These Instructions perform various logical operations such as AND,
OR, NOT, Compare etc.These instructions will also effect flags.
4. Branching Instructions:
This group of instructions alters the sequence of program execution
either conditionally or unconditionally. Flags are generally used to
generate conditions in case of first type of branch instructions.
5. Machine control Instructions:
These Instructions control machine functions such as HALT, Interrupt
and do nothing etc.
6. String Instructions:
These Instructions special set which are not present in 8085 and these
serve the purpose of operations on strings.
1. INTRODUCTION TO MASM/TASM
Aim: To perform 16-bit addition& subtraction operations using 8086 µp.
THEORY:
There are two ways to execute 8086 programs using a computer. One is using the
DOS tool called DEBUG and the second way is using the Assembler MASM. Hence both the
ways are to be learned.
DEBUG:
The DOS utility called DEBUG allows entering assembly language programs, to
execute these programs to view memory locations and also to trace the program execution.
Starting and Quitting DEBUG:
The simple way of starting the DEBUG is to type the command DEBUG at the DOS
prompt. After the DEBUG is loaded the DEBUG prompt ‘-‘is displayed. Then the DEBUG is
ready to accept any DEBUG commands.
To quit DEBUG the command is Q. This command takes control back to DOS.
DEBUG can be started along with a file also. To load DEBUG with a program say test 1.com
at the DOS prompt type DEBUG test 1.com
DEBUG Commands:
The commands which are required to run / enter the programs are the following.
A Assemble
D Display/Dump
E Enter data
F Fill memory
G Run the program
L Load
N Name a program
P Proceed
Q Quit
R register
T Trace
U Unassembled
W Write
The DEBUG does not detect errors until Enter Key is pressed. If there is any syntax
mistake then the command line is redisplayed with the word error added at the point at which
the error was detected. If a command line contains more than one error, only the first error
will be detected and indicated and execution will stop at that point.
Assemble (A) Command:
The Assemble command is used for entering assembly language mnemonics and
translating them directly to machine language instructions. The syntax for this command is A
address.
Display/Dump (D) Command:
This command displays the content of a block of memory locations. The syntax for
the command is D address 1 address 2
Address 1 is the starting address of the memory block and address 2 is the ending address.
When the ending address is not specified then from the starting address the contents of 128
locations will be displayed. The display consists of both HEX and ASCII formats. In each
line 16 HEX/ASCII numbers will be displayed.
Enter (E) Command:
This command can be used to change the contents of specific memory locations. The
Syntax of this command is E address changes
Address is the beginning address for entering the changes and changes is an optional
list of changes to be made. If the changes are not specified in the command line then DEBUG
enters a special entry mode in which the values of memory locations, beginning at address are
displayed. Then these values can be changed one byte at a time. After each entry press space
bar to display the contents of next location. To exit the entry
Mode and to go back to DEBUG prompt press Enter. If no changes are required for any byte
then simply press Space Bar to go for the next location without changing the values.
Go (G) Execute Command:
This command can be used to run the machine language programs. The syntax of this
command is G=start break1 break2.
=start is an optional starting address of the program and break1 and break2.. are the break
point addresses. If the start address is not specified then the execution starts form the current
value of the instruction pointer. First time DEBUG is loaded with a COM program IP is set to
100. So to execute the COM program simply type the command G.
Load (L) Command:
This command will load a COM file or EXE file in to memory. The syntax of the
command is simply L. The file should be given with another command N. The COM file will
loaded into the memory from CS: 0100 address. After a file have been loaded BX: CX
contains the number of bytes successfully read.
Name (N) Command:
The Name command can be used to specify the file name for Load and Write
commands. The syntax of the command is N file name
Eg: N Test1.com
Register (R) Command:
This command allows us to view the contents of a register and also to change the
values. The syntax for this command isR Register. This “Register” is the optional name of
the register to modify the any of the AX, BX, CX, DX, SP, BP, SI, DI, DS, ES, SS, CS, IP or
F. If the command is given without any parameter DEBUG displays the contents of all the
registers. If a particular register is specified then DEBUG displays the content of that register
and allows us to change the content.
Trace (T) Command:
Trace command is used for single step execution of the program. After the execution
of each instruction the contents of all the registers will be displayed. The Syntax of this
command isT=start count
Start is the beginning address and count is the number os instructions to trace, both
these parameters are optional. If the start is not specified then execution will begin with the
current address stored in IP. If the count is excluded then only one instruction will be
executed.
Unassembled (U) Command:
This command is used to list the program which is already loaded or assembled.
The syntax of this command is U range
Range is an optional when it is used start and end address should be given separated
by a space. If the range is not specified then DEBUG displays the instructions starting from
the current contents of the IP or with the byte following the last byte displayed by the most
recent U command. When range is not specified 16 bytes will decoded and displayed.
Write (W) command:
This command can be used to store the Assembled program on the Hard disk or
Floppy disk. The syntax is just W.
MASM/TASM is an assembler which converts the assembly program to machine
code. While writing the program labels can be used so that there is no need to calculate the
addresses as in case of DEBUG. The program can be just entered in the same way as we
write. The machine code generated by the assembler will not be in the format ready for
execution. The memory specifications will not be there. For this Linker software is required.
The linker software substitutes all the required memory values and makes the machine
program ready for execution.
The input file given to the assembler should be .ASM. It can be created by any text
editors. The assembler converts this .ASM file to .OBJ file when the given program is syntax
error free. This OBJ file is converted into .EXE by using the linker software. The machine
program thus generated can be executed by using DEBUG. If the results are stored in
memory then DEBUG is compulsory to execute the program. If the results are to be displayed
on CRT then the Program can be directly executed just by typing the name of the EXE
program at the DOS prompt.In addition to the mnemonics used in a program we can write
some instructions to the complier also. These instructions are called Assembler Directives.
Assembler directives are not converted into machine language.
PROCEDURE:
1. Writing an ALP
Assembly level programs generally abbreviated as ALP are written in text editor
EDIT.
Type EDIT in front of the command prompt to open an untitled text file.
EDIT<file name>
After typing the program save the file with appropriate file name with an extension
.ASM.
Ex: Add.ASM
2. Assembling an ALP
To assemble an ALP we needed executable file called MASM.EXE. Only if this file
is in current working directory we can assemble the program. The command is
MASM<filename.ASM>
If the program is free from all syntactical errors, this command will give the OBJECT
file. In case of errors it lists out the number of errors, warnings and kind of error.
Note: No object file is created until all errors are rectified.
3. Linking
After successful assembling of the program we have to link it to get Executable file.
The command is LINK<File name.OBJ>
This command results in <Filename.exe> which can be executed in front of the
command prompt.
4. Executing the Program
Open the program in debugger by the command(note only exe files can be open)by
the command. CV <Filename.exe>
This will open the program in debugger screen where in you can view the assemble
code with the CS and IP values at the left most side and the machine code. Register
content, memory content also be viewed using VIEW option of the debugger.
Execute option in the menu in the menu can be used to execute the program either in
single steps(F7) or burst execution(F5).
Result:
2. ARITHMETIC & LOGICAL OPERATIONS
(A) Arithmetic Operations
Aim: To perform 16-bit addition& subtraction operations using 8086 µp.
Apparatus Required:
1. TASM SOFTWARE
2. PERSONAL COMPUTER
Program for addition:
CODE SEGMENT
ASSUME CS: CODE, DS: CODE, ES: CODE, SS: CODE
START: ORG 1000H MOV AX, 0006H
MOV BX, 0004H ADD AX, BX
INT 03H
CODE ENDS
END START
Input:AX, 0006H
BX, 0004H
Output: AX= 000AH
Program for Subtraction:
CODE SEGMENT
ASSUME CS: CODE, DS: CODE, ES: CODE, SS: CODE
START: ORG 1000H
MOV AX, 0008H
MOV BX, 0005H
SUB AX, BX
INT 03H
CODE ENDS
END START
Input:AX = 0008H
BX = 0005H
Output:AX= 0003H
Result:
(B) Logical Operations
Aim: To perform Logical operations of a 16-bit Number using 8086 µp.
Apparatus Required:
1. TASM SOFTWARE
2.PERSONAL COMPUTER
Logical, shift and Rotate Operations:
1) Logical AND:
START: ORG 1000H
MOV AX, 000FH
MOV BX, 000BH
AND AX, BX
INT 03 H
CODE ENDS
END START
Input:AX= 000FH
BX= 000BH
Output:AX= 000BH
2) Logical OR:
START: ORG 1000H
MOV AX, 000CH
MOV BX, 000DH
OR AX, BX
INT 03H
CODE ENDS
END START
Input:AX = 000CH
BX = 000DH
Output:AX= 000DH
3) Logical NOT:
START: ORG 1000H
MOV AX, 000EH
NOT AX
CODE ENDS
END START
Input:AX= 0012H
Output:AX= FFECH
4) 1’s complement:
START: ORG 1000H
MOV AX, 0005H
NOT AX
CODE ENDS
END START
Input:AX= 0005H
Output:AX= FFFAH
5) 2’s complement:
SATRT: ORG 1000H
MOV AX, 0005H
NOT AX
ADD AX, 0001H
INT 03H
CODE ENDS
END START
Input:AX= 0005H
Output:AX= FFEBH
6) Logical EX-OR:
START: ORG 1000H
MOV AX, 000BH
MOV BX, 000CH-
XOR AX, BX
INT 03H
CODE ENDS
END START
Input:AX= 000BH
BX= 000CH
Output:AX= 0000H
7) Logical SHL:
START: ORG 1000H
MOV AX, 0012H
SHL AX, 01H
INT 03H
CODE ENDS
END START
Input:AX= 0012H
Output:AX= 0024H
8) Logical SHR:
START: ORG 1000H
MOV AX, 0012H
SHR AX, 01H
INT 03H
CODE ENDS
END START
Input:AX= 0012H
Output:AX= 0006H
9) Logical ROR:
START: ORG 1000H
MOV AX, 0012H
MOV CL ,01H
ROR AX, CL
INT 03H
CODE ENDS
END START
Input:AX= 0012H
Output:AX= 0006H
10) Logical ROL:
START: ORG 1000H
MOV AX, 0012H
MOV CL, 01H
ROL AX, CL
CODE ENDS
END START
Input:AX= 0012H
Output:AX= 0006H
Result:
3. STRING OPERATIONS AND INSTRUCTION PREFIX
3(A) String Operations
Aim:To perform string operations like Reverse of a string, String copy, String
AIM:The main objective of this experiment is to understand how to configure the PWM module
of the MSP-EXP430FR5969 Launchpad to control the brightness of LED using external input.
APPARATUS REQUIRED:
● Code composer studio software
● MSP430FR5969 target Launchpad
● USB cable
THEORY:
The MSP430FR5969 has two LED’s and two push BUTTONS connected to GREEN LED
(P1.0),S2(P1.1) and RED LED (P4.6),S1(P4.5) on the MSP430FR5969 LaunchPad for visual
feedback. In this experiment, the code programmed into the MSP430FR5969 processor increase
the brightness of LED when button is pressed gradually and decrease the brightness of LED
when another button is presses gradually.Actually here we are increasing and decreasing the
width of the pulse by varying the values in CCR1 of the Timer.
MSP430FR59xx
-----------------
/|\| XIN|-
| | | 32kHz
--|RST XOUT|-
| |
LED<--| P4.6 P1.0 |--> LED
S1←| P4.5 P1.1 |-->S2
-------------------
PROCEDURE:
1. Connect the MSP430FR5969 LaunchPad to the PC using the USB cable supplied.
2. Build, program and debug the code into the LaunchPad using CCS to view the status of the
LED.
3. In the CCS debug perspective, select View --> Registers
4. Observe the GREEN LED brightness increase whenever S1 is pressed and decreases when S2
is pressed.
PROGRAM:
#include<msp430.h> int j=0; intmain(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer PM5CTL0 &= ~LOCKLPM5; // Disable the GPIO power-on default high-impedance //mode to activate previously configured port settings P1DIR |= BIT0; // Set P1.0 to output direction P1OUT &= ~BIT0; // Switch LED off P1DIR &= ~BIT1; // Set P1.1 as input P1OUT |= BIT1; // Configure P1.1 for Pull-Up P1REN |= BIT1; // Enable Pull Up of P1.1 P4DIR &= ~BIT5; // Set P4.5 as input
#include<msp430.h> intmain(void) { WDTCTL = WDTPW | WDTHOLD; // Stop WDT // GPIO Setup P1OUT &= ~BIT2; // Clear MOTOR to start P1DIR |= BIT2; // Set P1.2/MOTOR to output P1SEL1 = BIT3; // Configure P1.3 for ADC P1SEL0 = BIT3 | BIT2; // PWM output to MOTOR P1.2 // Disable the GPIO power-on default high-impedance mode to activate // previously configured port settings PM5CTL0 &= ~LOCKLPM5; // Configure TimerA0 TA0CCTL1 = OUTMOD_7; // Reset/Set Mode TA0CTL = TASSEL_2 + MC_1 +TACLR ; // SMCLK / Upmode TA0CCR0 = 64-1; // PWM frequency // Configure ADC12 ADC12CTL0 = ADC12SHT0_2 | ADC12ON; // Sampling time, S&H=16, ADC12 on ADC12CTL1 = ADC12SHP; // Use sampling timer ADC12CTL2 |= ADC12RES_2; // 12-bit conversion results ADC12MCTL0 |= ADC12INCH_3; // A3 ADC input select; Vref=AVCC ADC12IER0 |= ADC12IE0; // Enable ADC conv complete interrupt while (1) { __delay_cycles(5000); ADC12CTL0 |= ADC12ENC | ADC12SC; // Start sampling/conversion __bis_SR_register(LPM0_bits | GIE); // LPM0, ADC12_ISR will force exit __no_operation(); // For debugger } } #pragma vector = ADC12_VECTOR __interrupt voidADC12_ISR(void) { switch(__even_in_range(ADC12IV, ADC12IV_ADC12RDYIFG)) { case ADC12IV_NONE: break; // Vector 0: No interrupt case ADC12IV_ADC12OVIFG: break; // Vector 2: ADC12MEMx Overflow case ADC12IV_ADC12TOVIFG: break; // Vector 4: Conversion time overflow case ADC12IV_ADC12HIIFG: break; // Vector 6: ADC12BHI case ADC12IV_ADC12LOIFG: break; // Vector 8: ADC12BLO case ADC12IV_ADC12INIFG: break; // Vector 10: ADC12BIN
case ADC12IV_ADC12IFG0: TA0CCR1 = ADC12MEM0/64; // Vector 12: ADC12MEM0 Interrupt __bic_SR_register_on_exit(LPM0_bits); // Exit active CPU break; // Clear CPUOFF bit from 0(SR) case ADC12IV_ADC12IFG1: break; // Vector 14: ADC12MEM1 case ADC12IV_ADC12IFG2: break; // Vector 16: ADC12MEM2 case ADC12IV_ADC12IFG3: break; // Vector 18: ADC12MEM3 case ADC12IV_ADC12IFG4: break; // Vector 20: ADC12MEM4 case ADC12IV_ADC12IFG5: break; // Vector 22: ADC12MEM5 case ADC12IV_ADC12IFG6: break; // Vector 24: ADC12MEM6 case ADC12IV_ADC12IFG7: break; // Vector 26: ADC12MEM7 case ADC12IV_ADC12IFG8: break; // Vector 28: ADC12MEM8 case ADC12IV_ADC12IFG9: break; // Vector 30: ADC12MEM9 case ADC12IV_ADC12IFG10: break; // Vector 32: ADC12MEM10 case ADC12IV_ADC12IFG11: break; // Vector 34: ADC12MEM11 case ADC12IV_ADC12IFG12: break; // Vector 36: ADC12MEM12 case ADC12IV_ADC12IFG13: break; // Vector 38: ADC12MEM13 case ADC12IV_ADC12IFG14: break; // Vector 40: ADC12MEM14 case ADC12IV_ADC12IFG15: break; // Vector 42: ADC12MEM15 case ADC12IV_ADC12IFG16: break; // Vector 44: ADC12MEM16 case ADC12IV_ADC12IFG17: break; // Vector 46: ADC12MEM17 case ADC12IV_ADC12IFG18: break; // Vector 48: ADC12MEM18 case ADC12IV_ADC12IFG19: break; // Vector 50: ADC12MEM19 case ADC12IV_ADC12IFG20: break; // Vector 52: ADC12MEM20 case ADC12IV_ADC12IFG21: break; // Vector 54: ADC12MEM21 case ADC12IV_ADC12IFG22: break; // Vector 56: ADC12MEM22 case ADC12IV_ADC12IFG23: break; // Vector 58: ADC12MEM23 case ADC12IV_ADC12IFG24: break; // Vector 60: ADC12MEM24 case ADC12IV_ADC12IFG25: break; // Vector 62: ADC12MEM25 case ADC12IV_ADC12IFG26: break; // Vector 64: ADC12MEM26 case ADC12IV_ADC12IFG27: break; // Vector 66: ADC12MEM27 case ADC12IV_ADC12IFG28: break; // Vector 68: ADC12MEM28 case ADC12IV_ADC12IFG29: break; // Vector 70: ADC12MEM29 case ADC12IV_ADC12IFG30: break; // Vector 72: ADC12MEM30 case ADC12IV_ADC12IFG31: break; // Vector 74: ADC12MEM31 case ADC12IV_ADC12RDYIFG: break; // Vector 76: ADC12RDY default: break; } }
RESULT:
7. ULTRA LOW POWER (ULP) ADVISOR
AIM:The main objective of this experiment is to optimize the power efficiency of an application
on MSP- EXP430FR Launchpad using ULP Advisor in CC Studio. This experiment will help to
learn and understand the ULP Advisor capabilities and usage of ULP Advisor to create
optimized, power-efficient applications on the MSP-EXP430FR Launchpad.
APPARATUS REQUIRED:
● Code composer studio software
● MSP430FR5969 target Launchpad
● USB cable
THEORY:
ULP (Ultra-Low Power) Advisor is a tool that provides advice on how to improve the
energy efficiency of an application based on comparing the code with a list of ULP rules at
compile time. The ULP Advisor helps the developer to fully utilize the ULP capabilities of
MSP430 microcontrollers, This tool works at build time to identify possible areas where
energy and power use is inefficient. A description of the ULP rule that is violated, a link to
the ULP Advisor wiki page, links to relevant documentation, code examples and forum posts
are all included for each rule violation in the application code. Once the feedback has been
presented, the developer can then learn more about the violation and go back to edit the code
for increased power efficiency or continue to run the code as-is. The ULP Advisor is built
into Code Composer StudioTM IDE version 5.2 and newer. After compiling the code, a list
of the ULP rule violations is provided in the Advice window. Unlike errors, these suggestions
will not prevent the code from successfully compiling and downloading onto the target.A list
of some unique rule violations are shown in Table 7-1.
This experiment explains in detail how to use ULP Advisor on MSP430FR5969.
Three code files are used in this experiment and one file is included in the build at a time.
Each file performs the same function: every second an Analog-to-Digital Converter (ADC)
temperature measurement is taken,the degrees Celsius and Fahrenheit are calculated, and the
results are sent through the back channel Universal Asynchronous Receiver/Transmitter
(UART) at 9600bps.
The first code file - Inefficient.c, begins with an inefficient implementation of this
application. The ULP Advisor is used to observe the extreme inefficiency of this version.
Based on the feedback from the ULP Advisor,improvements are made for the somewhat
efficient second version of the code - Efficient.c. The process is repeated, and ULP Advisor is
used to compare this improved version with the original. Finally, steps are taken to improve
the code even further in the very efficient third version of the code - MostEfficient.c. Table 7-
2 briefs the descriptions of the experiment code
Table 7-1 : ULP Rule Violations
Table 7-2 : Experiment Code Descriptions
PROCEDURE:
1. Connect the MSP-EXP430FR LaunchPad to the PC using the USB cable supplied.
2. Download the CCS example project ULP_Case_Study from http://www.ti.com/lit/zip/slaa603
and extract using 7zip.
3. Import the project into your CCS workspace as shown in Figure 7-1.
a. Click Project Import Existing CCS Eclipse Project.
b. Browse the directory for the downloaded file.
c. Check the box next to the ULP_Case_Study project in the Discovered projects window.
d. Uncheck the check box Copy projects into workspace.
e. Click Finish
Figure 7-1 : Importing Project
4. To set as active project, click on the project name. The active build configuration should be
Inefficient. If not, right click on the project name in the Project Explorer, then click Build
Configurations Set Active Inefficient as shown in Figure 7-2.
Figure 7-2: Selection of Build Configuration
5. Build the project
6. The Advice window shows suggestions from the ULP Advisor under the Power (ULP) Advice
heading. Click View Advice as shown in Figure 7-3.
Figure 7-3 Opening the Advice Window
The Advice window appears as shown in Figure 7-4.
Figure 7-4: Advice Window
7. Click the link #1532-D, which corresponds to the first ULP violation (for using sprintf()), to
open the ULP Advisor wiki page in a second Advice tab. All the information for this particular
rule violation is provided as shown in Figure 7-5.
8. Scroll down to the Remedy section. Here, the first suggestion is to avoid using sprintf()
altogether and work with the raw data.
Figure 7-5 ULP Advisor Wiki Page
Observation
In the ULP Advisor of Inefficient.c, the first suggestion given is to avoid using sprintf(). The
ULP Advisor implements the advice for the next version of code i,e., Efficient.c as shown in
Figure 7-6.
Figure 7-6 ULP Advice Window for Effiecient.c
There are no advices related to Power optimization in ULP Advisor of MostEfficient.c, as shown
inFigure 7-7 below
Figure 7-7 ULP Advice Window for MostEffiecient.c
RESULT:
8. ENERGY TRACE++ANDESTIMATION OF BATTERY LIFE
AIM:The main objective of this experiment is to compute the total energy of MSP-EXP430FR
Launchpad running an application and to estimate the lifetime of a battery.
APPARATUS REQUIRED:
● Code composer studio software
● MSP430FR5969 target Launchpad
● USB cable
THEORY:
To measure the total energy of the MSP-EXP430FR and estimated life time of a battery the
Energy Trace Technology is must and should. Energy Trace Technology is an energy-based code
analysis tool that measures and displays the application's energy profile and helps to optimize it
for ultra-low power consumption. MSP430 devices with built-in Energy Trace+ [CPU State]+
[Peripheral States] (or in short, Energy Trace++™) technology allow real-time monitoring of
many internal device states while user program code executes. Energy Trace++ technology is
supported on selected MSP430 devices and debuggers.
To achieve this, the on-board emulation of a Launchpad that contains the Energy Trace
technology circuitry is used to program and debug the intended target. In this experiment, to
program and debug we use the MSP-EXP430FR5969 Launchpad which contains the Energy
Trace Technology on-board circuitry. When the Energy Trace mode is enabled in the target
device, the profile window shows some statistical data about the application that has been
profiled. The following are the parameters shown in the profile window:
• Captured time
• Total energy consumed by the application (in mJ)
• Minimum, mean, and maximum power (in mW)
• Mean voltage (in V)
• Minimum, mean, and maximum current (in mA)
• Estimated life time of the selected battery (in days) for the captured energy profile
PROCEDURE:
1. Build the example code of Experiment 2: Low Power Modes and Current Measurement for
which you want to compute the total energy and estimate the life time of a battery using Energy
Trace technology.
2. Enable Energy Trace technology
• Click Window -->Preferences -->Code Composer Studio-->Advanced Tools→ Energy
Trace Technology
• Make sure that the box next to Enable is checked
• Select the Energy Trace++ mode
• Click Apply and OK.
3. Debug the example code, the Energy Trace window will open automatically. If the window
does not open automatically, click View-->Others -->MSP430 Energy Trace -->Energy
Trace Technology
4. Run the code. The Energy Trace Technology window will update the real time data.
Observation
Figure 8-1 Energy Trace Profile Window in Active Mode
The Energy trace profile for active and stand by code is analyzed using Energy Trace
technology. The Energy Trace profile window of the application in active mode provides us the
estimated lifetime of a battery of 35.9 days. If the same application run in standby mode, the
estimated lifetime of a battery exceeds to 94.3 days
The formula to calculate the battery lifetime assumes an ideal 3-V battery and does not
account for temperature, aging, peak current and other factors that could negatively affect battery
capacity. Figure 8-1 and Figure 8-2 show the Energy Trace Profile windows for the application in
active and standby modes respectively.
Figure 8-2 Energy Trace Profile Window in Standby Mode
RESULT:
ADDITIONAL EXPERIMENTS
1. TEMPERATURE SENSING
AIM:The main objective of this experiment is to interface Temperature sensor to
MSP430FR5969 Launchpad and give the signal whenever temperature reaches certain value.
APPARATUS REQUIRED:
● Energia IDE
● MSP430FR5969 target Launchpad
● USB cable
THEORY:
The MSP430FR5969 has two LED’s and two push BUTTONS connected to GREEN LED
(P1.0), S2(P1.1) and RED LED (P4.6),S1(P4.5) on the MSP430FR5969 LaunchPad for visual
feedback. In this experiment, the code programmed into the MSP430FR5969 processor to blink
RED LED whenever temperature exceeds 100 (Temperature sensor is connected to P4.2-in
Energia it will take as pin A10). In this experiment we are Energia IDE which is used to dump
the program.
MSP430FR59xx
-----------------
/|\| XIN|-
|| | 32kHz
--|RST XOUT|-
TEMPERATURE sensor |P4.2 | P1.3
LED<--| P4.6 P1.0 |--> LED
S1←| P4.5 P1.1|-->S2
-------------------
PROCEDURE:
1. Connect the MSP430FR5969 LaunchPad to the PC using the USB cable supplied.
2. Select the Microcontroller board and communication Port which you have connected to PC.
3. Save the program and compile it.
4. Once compiling is done successfully then Upload the program to board.
5. Observe the Temperature readings in ”Serial Monitor” window in Energia IDE also increase
the temperature to blink LED when value reaches 100.
PROGRAM:
#define LED RED_LED//choosing which LED we want to use intTempSensorValue=0;//initialize sensor value to zero voidsetup() { Serial.begin(9600);//begin the serial communication pinMode(A10,INPUT);//defining Temperature sensor is input pinMode(LED,OUTPUT);//defining led as output }
voidloop() { int value=analogRead(A10); //read value from sensor (here temperature sensor is analog) TempSensorValue = value/4;//divide by 4 to get the values in 0-255 range (default 0-1023) Serial.println(TempSensorValue); //print the sensor value in serial monitor if(TempSensorValue>100) { digitalWrite(LED,HIGH); //turn ON LED when temperature exceeds 100 Serial.println("Temperature="+TempSensorValue); //print sensor value in serial monitor } else { digitalWrite(LED,LOW);//turn OFF LED when temperature is less than 100 } }
OBSERVATION:
RESULT:
2. MOTION DETECTION
AIM:The main objective of this experiment is to interface Motion sensor to MSP430FR5969
Launchpad and give the signal whenever any Motion is detected.
APPARATUS REQUIRED:
● Energia IDE
● MSP430FR5969 target Launchpad
● USB cable
THEORY:
The MSP430FR5969 has two LED’s and two push BUTTONS connected to GREEN LED
(P1.0), S2(P1.1) and RED LED (P4.6),S1(P4.5) on the MSP430FR5969 LaunchPad for visual
feedback. In this experiment, the code programmed into the MSP430FR5969 processor to blink
GREEN LED whenever motion is detected (Motion sensor is connected to P1.3-in Energia it will
take as pin11). In this experiment we are Energia IDE which is used to dump the program.
MSP430FR59xx
-----------------
/|\| XIN|-
| | | 32kHz
--|RST XOUT|-
| P1.3|-Motion sensor
LED<--| P4.6 P1.0 |--> LED
S1←| P4.5 P1.1 |-->S2
-------------------
PROCEDURE:
1. Connect the MSP430FR5969 LaunchPad to the PC using the USB cable supplied.
2. Select the Microcontroller board and communication Port which you have connected to PC.
3. Save the program and compile it.
4. Once compiling is done successfully then Upload the program to board.
5. Observe the readings in ”Serial Monitor” window in Energia IDE also move around motion
sensor to blink LED.
PROGRAM:
#define LED GREEN_LED//choosing which LED we want to use voidsetup() { Serial.begin(9600);//begin the serial communication pinMode(11,INPUT);//defining motion sensor is input pinMode(LED,OUTPUT);//defining led as output } voidloop() { inti=digitalRead(11);//read the value from sensor(here motion sensor is digital) Serial.println(i);//print the sensor value in serial monitor if(i==1) {
digitalWrite(LED,HIGH);//turn ON LED when motion is detected Serial.println("Motion is Detected"); } else { digitalWrite(LED,LOW);//turn OFF LED when motion is not detected } }