ES Lab Manual
ES Lab Manual
IV B. Tech. I Sem.
LAB MANUAL
PREPARED BY
Dept. of ECE
TABLE OF CONTENTS
EXP.N
O NAME OF THE EXPERIMENT PAGE.NO.
1. Introduction to MSP430 Launch Pad and Programming Environment:
a) Investigation of MSP430G2553 & MSP430F5529 Launch pad details
b) Familiarization with MSP430 based Integrated Development 3-13
Environment: CCS V6.1& Energia
c) Flash on-board LED/s
2. Read input from switch and automatic control/flash LED (Software delay): 14-18
Read Status of on-board Push button switch and operate LED using Polling
3. Interrupts Programming using GPIO: 19-22
Activate and configure Interrupts associated with GPIO pin associated with on-
board push button and define ISR to operated on-board LED/s
4. Configure Watchdog timer in watchdog and Interval Modes: 23-26
Using WDT in interval mode to operate on-board LED/s at different frequencies
5. Configure Timer for signal generation (with given frequency): 27-32
a) Using TimerA in up-mode – generate 1Hz symmetric square wave of
1Hz frequency (Sourcing TimerA from ACLK and polling TAIF)
b) Configuring TimerA interrupt to generate – generate 1Hz symmetric
square wave of 1Hz frequency
6. PWM Generator: Generate PWM using Timer A in compare mode to change 33-38
the light Intensity of on-board LED
7. Configuring MSP430 on-board ADC :
a) Configure ADC10 to read temperature of launch pad using on-chip 39-42
temperature sensor
b) Configure ADC12 to use potentiometer as Sensor 43-47
8. Speed Control of Motor:
a) Configure ADC to interface potentiometer to control the speed of DC 48-51
Motor using CCS
b) Configure ADC to interface potentiometer to control Servo Motor using 52-53
Energia
9. Use Comparator to compare the signal threshold level:
Configure Comparator_A to detect a voltage threshold-Using an external
potentiometer, an unknown voltage is applied to P1.1. and compared with 54-55
internal reference
10. Test Various Power down modes in MSP430: Analyze current drawn /Power
Consumed by the MSP430G2553 launch pad in different modes of operation 56-61
(AM, LPM0, LPM1, LPM2, LPM3 & LPM4)
11. Serial Peripheral Interface: Establish communication between Master & 62-69
Slave launch pads using SPI
12. Networking MSP using WiFi Module ( CC3100 Booster Pack): Scan 70-73
available networks for enabling MSP as IOT to print the Wifi MAC address,
and scans for available Wifi networks. Every ten seconds, it scans again.
Experiment No.:1
AIM
a) To Investigation Features of MSP430G2553 & MSP430F5529 Launch pads
b) To Familiarize with MSP430 based Integrated Development Environment: CCS V6.1& Energia
c) To Develop High level code and use IDE to Flash on-board LED/s
APPARATUS
PC Installed with CCSV6 & Energia
Launch pads: MSP-EXP430G2553 & MSP-EXP430F5529LP
USB Cable to interconnect Launch pad to windows enabled PC
Theory
a) Comparison of two launch pads
Feature MSP430G2553 MSP430F5529
Pinout 20 pin DIP 80 Pin QFP
Supply Voltage range 3.6 down to 1.8V
Low power modes 1 Active and 5 Low power modes 1 active and 6 software
(LPM0 to LPM4) selectable low power modes
4. In CCS project
Select Target as MSP430G2553.
Select Connection as TIMSP430 USB1 (default).
Give project name as per requirement. (Ex. LED_BLINK).
Select Compiler version as TIv4.4.5.
Select empty project (with main .c).
Click Finish.
5. Now connect the MSP-EXP430G2 Launch pad to the system by using USB cable.
Digital I/O
MSP430G2553 devices have up to eight digital I/O ports (P1 to P8). Each port has up to eight
I/O pins that are configured with user software. Every I/O pin is individually configurable as
input or output, and can be individually read or written to.
The MSP430G2553 has two general-purpose digital I/O pins connected to green LED (P1.6) and
red LED (P1.0) on the MSP-EXP430G2 Launch Pad for visual feedback. In this experiment, the
code programmed into the MSP430G2553 processor toggles the output on Port P1.0 at fixed
time
intervals computed within the code. A HIGH on P1.0 turns the LED ON, while a LOW on P1.0
turns the LED OFF. Thus, the toggling output blinks the red LED connected to it. The functional
block diagram shown in Figure 1-1 illustrates the working principle of the experiment.
#include <msp430g2553.h>
P1DIR |= BIT0;
for (;;)
{
P1OUT |= BIT0;
__delay_cycles(1000000);
P1OUT &= ~BIT0;
__delay_cycles(1000000);
}
}
8. Now compile the program by clicking on compiler icon as shown below .By this the program
building (compiling) will be finished and hence we can check for errors if any.
9. Now debug the program by clicking on the debug icon as shown below.
12. Now we can watch the output on the launch pad as per the program.
This ends the process of using the MSP430G2553 Launch pad for performing various
operations in Embedded Systems.
3.Go to Tools and select the required serial port(decide it based on the serial port in “device
manager—port—MSP application UART1 “).
void setup ( )
void loop ( )
pinMode ( )
pinOut ( )
void setup() {
pinMode(LED, OUTPUT);
void loop() {
digitalWrite(LED, LOW); // turn the LED off by making the voltage LOW
Experiment No.:2
AIM
To Read input from on-board push button switch and by polling its status in P1IN SFR control/
flash on-board LED by using the CCS and Energia
APPARATUS
PC Installed with CCSV6 & Energia
Launch pads: MSP-EXP430G2553 & MSP-EXP430F5529LP
USB Cable to interconnect Launch pad to windows enabled PC
THEORY
Digital I/O
MSP430 devices have up to eight digital I/O ports (P1 to P8). Each port has up to eight I/O pins
that are configured with user software. Every I/O pin is individually configurable as input or
output, and can be individually read or written to.
The MSP-EXP430G2 LaunchPad has two general-purpose digital I/O pins connected to green
and red LEDs for visual feedback. It also has two push buttons for user feedback and device
reset. In this experiment, the input from the left push button switch (S2) connected to Port P1.3 is
read by the processor for LED control. If the switch is pressed, the green LED is turned OFF by
output at port P1.6 reset to ’0’. Else, the output at port P1.6 is set HIGH and the green LED is
turned ON. The LED is therefore controlled by the switch S2.
The functional block diagram shown in Figure 2-1 illustrates the working principle of the
experiment.
Figure 2-2 shows the Launchpad schematics for the connection of Digital I/O pins to the on-
board LEDs in the LaunchPad.
The input pins for the MSP430G2553 need to be either pulled-up or pulled-down with a resistor
to avoid floating inputs. The selection of a pull-up or pull down resistor for the inputs is
performed in software. A pull-up resistor enables a default hardware connection for the pin to
VCC as shown in Figure 2-3. Hence, when the switch is open, the VCC (logic HIGH) is
available on the input pin of the MCU
PROGRAM
a) CCS
//The below code turns on green LED until switch is in on state else turns red LED
//on.
#include <msp430g2553.h>
volatile unsigned int i;
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P1DIR = BIT0+BIT6;
P1REN = BIT3;
P1OUT = BIT3;//pull up
while(1)
{
if ( !(P1IN & BIT3))
{
for (i=0; i<=255;i++)
P1OUT | =BIT6;
P1OUT & = ~BIT0;
}
else
{
for (i=0; i<=255;i++)
P1OUT | =BIT0;
P1OUT & = ~BIT6;
}
}
}
b) Energia
void setup( )
{
void loop( ){
buttonState = digitalRead(buttonPin); // read the state of the pushbutton value
if (buttonState == HIGH)
{
}
}
Experiment No.:3 :
APPARATUS
PC Installed with CCSV6 & Energia
Launch pads: MSP-EXP430G2553 & MSP-EXP430F5529LP
USB Cable to interconnect Launch pad to windows enabled PC
THEORY:
Interrupts
When an interrupt is requested from a peripheral and the peripheral interrupt enable bit and GIE
bit are set, the interrupt service routine is requested. The interrupt service routine involves the
following execution steps:
1. The SR with all previous settings pops from the stack. All previous settings of GIE, CPUOFF,
etc., are now in effect, regardless of the settings used during the interrupt service routine.
2. The PC pops from the stack and begins execution at the point where it was interrupted.
The current experiment makes complete use of the GPIO interrupts. In this experiment P1.3 is
configured as an input pin with a falling edge interrupt. The general interrupts are enabled so
that the pin will make the CPU to call the Interrupt Service routine. This routine sets a flag
that causes toggling of the green LED which is connected to P1.6 of the MSP_EXP430G2XL
Launchpad.The functional block diagram shown in Figure 4-1 illustrates the working
principle of the experiment.
Program
a) CCS
#include <msp430G2553.h>
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P1DIR |= BIT6; // Set P1.6 to output direction
P1REN |= BIT3; // Enable P1.3 internal resistance
P1OUT |= BIT3; // Set P1.3 as pull up resistance
P1IES |= BIT3; // P1.3 High/Low Edge
P1IFG &= ~BIT3; // P1.3 IFG Cleared
P1IE |= BIT3; // P1.3 Interrupt Enabled
_bis_SR_register(LPM4_bits + GIE); // Enter LPM4 w/ interrupt
_no_operation(); // For debugger
#pragma vector=PORT1_VECTOR
__interrupt void Port_1 (void)
{
P1OUT ^= BIT6; // Toggle P1.6
P1IFG &= ~BIT3; // P1.3 IFG Cleared
}
b) Energia
pinMode(RED_LED, OUTPUT);
pinMode(PUSH2, INPUT_PULLUP);
attachInterrupt(PUSH2,blink,FALLING);
}
void loop()
{
noInterrupts();
/* critical, time-sensitive code here */
digitalWrite(RED_LED, Led_state)
interrupts();
/* other code here */
}
/* ISR */
void blink() {
led_state = !led_state; /* Toggle state value of LED */
}
Experiment No.:4
APPARATUS
PC Installed with CCSV6 & Energia
Launch pads: MSP-EXP430G2553 & MSP-EXP430F5529LP
USB Cable to interconnect Launch pad to windows enabled PC
THEORY:
Watchdog Timer+ (WDT+) Introduction:
The primary function of the WDT+ module is to perform a controlled system restart after
a software problem occurs. If the selected time interval expires, a system reset is generated. If the
watchdog function is not needed in an application, the module can be configured as an interval
timer and can generate interrupts at selected time intervals.
Assuming the MSP430 system clock has a frequency of 1Mhz and the watchdog timer is clocked
by the sub-master clock (SMCLK), the following intervals are available:
PROGRAM
#include "MSP430G2553.h"
#include "intrinsics.h"
void main(void)
{
WDTCTL = WDT_MDLY_0_5; // WDT as interval timer (period 0,5 ms)
IE1 |= WDTIE; // Enable WDT interrupt
P1DIR |= BIT0+BIT6; // Set P1.0 & P1.6 as output
P1OUT |= BIT0+BIT6; // P1.0 & P1.6 are ON at start
delay1 = 5000; // LED1 toggle period = 509 ms
delay2 = 10000; // LED1 toggle period = 1717 ms
__low_power_mode_1(); // Enable interrupt and enter LPM1 mode
}
{ // Countdown of intervals
P1OUT ^= BIT0; // Toggle LED1 (P1.0) state
delay1 = 5000; // Reload delay counter 1.
}
if(--delay2==0)
{
P1OUT ^= BIT6; // Toggle LED2 (P1.6) state
delay2 = 10000; // reload delay counter 2.
}
}
Experiment No.:5
.
AIM
a) Using TimerA in up-mode – generate 1Hz symmetric square wave of 1Hz frequency
(Sourcing TimerA from ACLK and polling TAIF)
b) Configuring TimerA interrupt to generate – generate 1Hz symmetric square wave of 1Hz
frequency
APPARATUS
PC Installed with CCSV6 & Energia
Launch pads: MSP-EXP430G2553 & MSP-EXP430F5529LP
USB Cable to interconnect Launch pad to windows enabled PC
THEORY:
Inside Timer_A
Timer Mode
• MCx=01: Up mode
UP MODE:
The up mode is used if the timer period must be different from 0FFFFh counts.
CONTINUOUS MODE:
• In the continuous mode, the timer repeatedly counts up to 0FFFFh and restarts from zero
• The TAIFG interrupt flag is set when the timer resets from 0FFFFh to zero
UP/DOWN MODE:
The up/down mode is used if the timer period must be different from 0FFFFh counts, and if a
symmetrical pulse generation is needed.
• MSP430 addresses the conflicting demands for high performance, low power, precise
frequency by using 3 internal clocks, which can be derived from up to 4 sources
– Master clock (MCLK): for CPU & some peripherals, normally driven by digitally
controlled oscillator (DCO) in megahertz range
– External; used with a low- or high frequency crystal; an external clock signal can
also be used; connected to MSP430 through XIN and XOUT pins
CALCULATIONS
Consider f=1 HZ i.e. T = Ton +Toff = 1 Sec.
So, driving an on-board LED with such a square wave is equivalent to toggle state of LED once
for every 0.5 sec.
If Timer is sourced from ACLK ~=32KHz i.e. Taclk * (2^16) gives max delay = 2 Sec. If Timer
is operated in up-mode with can stop timer by ¼ th of 2 Sec. delay i.e. 0.5 sec by loading CCR0
with corresponding count.
PROGRAM
a) By Polling TAIFG toggle on-board LED once for every 0.5 Sec.
Dept. of ECE Page 30
ES Lab (16BT70432) Manual
#include <msp430g2553.h>
#define LED1 BIT0
void main (void)
{
WDTCTL = WDTPW|WDTHOLD; // Stop watchdog timer
P1OUT = ~LED1;
P1DIR = LED1;
TACCR0 = ¼ * 65536;
TACTL = MC_1|ID_0|TASSEL_1|TACLR; //Setup Timer_A
//up mode, divide clk by 1, use ACLK, clr timer
for (;;) { // Loop forever
;---------------------------------------------------------------
.cdecls C,LIST, "msp430.h"
;---------------------------------------------------------------------
----------
.def RESET ; Export program entry-
point to
; make it known to linker.
;---------------------------------------------------------------------
---------
.text ; Progam Start
;---------------------------------------------------------------------
---------
RESET mov.w #0280h,SP ; Initialize stackpointer
StopWDT mov.w #WDTPW+WDTHOLD,&WDTCTL ; Stop WDT
SetupP1 bis.b #001h,&P1DIR ; P1.0 output
SetupC0 mov.w #CCIE,&CCTL0 ; CCR0 interrupt enabled
mov.w #1000-1,&CCR0 ; CCR0 counts to 1000
SetupTA mov.w #TASSEL_1+MC_1,&TACTL ; ACLK, upmode
;
;
;---------------------------------------------------------------------
----------
TA0_ISR; Toggle P1.0
;---------------------------------------------------------------------
----------
xor.b #001h,&P1OUT ; Toggle P1.0
reti ;
;
;---------------------------------------------------------------------
---------
; Interrupt Vectors
;---------------------------------------------------------------------
---------
.sect ".reset" ; MSP430 RESET Vector
.short RESET ;
.sect ".int09" ; Timer_A0 Vector
.short TA0_ISR ;
.end
Experiment No.:6
AIM
Generate PWM using Timer A in compare mode to change the light Intensity of on-board LED
using CCS and Energia.
APPARATUS
PC Installed with CCSV6 & Energia
Launch pads: MSP-EXP430G2553
USB Cable to interconnect Launch pad to windows enabled PC
THEORY:
PWM
Pulse Width Modulation (PWM) is a method of digitally encoding analog signal levels. High-
resolution digital counters are used to generate a square wave of a given frequency, and the duty
cycle of the square wave is modulated to encode the analog signal. The duty cycle determines the
time during which the signal pulse is HIGH. For example, Figure 5-1 shows the different
waveforms for varying duty cycles of a signal.
In PWM, a large analog voltage results in increased pulse width and vice versa. Hence, the duty
cycle of the wave changes with the analog voltage that is encoded as shown in Figure 5-2.
Timer A and Timer B of the MSP430G2553 are capable of PWM outputs in compare mode.
In this experiment, the brightness of the on-board, green LED is altered by varying the voltage
on pin P1.6 which is connected to the green LED. The MSP430G2553 does not have a digital-to-
analog (DAC) module; therefore, Pulse Width Modulation is used to achieve this.The device is
kept in low power mode zero till it is woken up by the Timer interrupt. In the Timer ISR, the
brightness of the LED is varied by varying the duty cycle of the signal supplied to the output
from the predefined array. The brightness of the LED will be gradually increased as per the
array declared. The functional block diagram shown in Figure 5-3 illustrates the working
principle of the experiment.
• Compare mode:
– Compare the value of TAR with the value stored in TACCRn and update an
output when they match
– Records the “time” (value in TAR) at which the input changes in TACCRx
– The input, usually CCIxA and CCIxB, can be either external or internal from
another peripheral or software, depending on board connections
PROGRAM
a) CCS
#include <msp430g2553.h>
unsigned int i=0;
int a[5]= {0,32,64,128,255,320,450,512};
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
P1DIR |= BIT6;
P1SEL |= BIT6;
TA0CCR0 =512-1 ; //Period
TA0CCR1 = a[0]; // Ton = 0 initially
TA0CCTL1 = OUTMOD_7; // PWM Set-Reset Mode
TA0CTL = TASSEL_2 + MC_1 + TAIE + ID_3;
_bis_SR_register (LPM0_bits + GIE);
while(1); }
#pragma vector=TIMER0_A1_VECTOR
__interrupt void Timer (void)
{
TA0CTL &=~TAIFG;
while(1)
{
for( i=0;i<7;i++)
{
TA0CCR1 = a[i];
__delay_cycles(1000000);
}
for(i=7;i>1;i--)
{
TA0CCR1 = a[i];
__delay_cycles(1000000);
}
}
}
b) Energia
APPARATUS
PC Installed with CCSV6
Launch pads: MSP-EXP430G2553 & MSP-EXP430F5529LP
USB Cable to interconnect Launch pad to windows enabled PC
THEORY
ADC10 Introduction
The MSP430G2553 has ADC10 - a 10-bit analog-to-digital converter which converts the analog
input into a maximum of 1024 discrete levels. The ADC10 module is capable of 8 external
inputs and 4 internal analog sources. The ADC10 can be configured to convert a single channel
or a block of contiguous channels and can optionally repeat its conversions automatically. Each
conversion takes multiple cycles. The timing is controlled by an ADC clock. While a conversion
is in progress, the busy flag is set. After conversion, the result is stored in the ADC10MEM
register. There is a possible interrupt signaled when a conversion is complete. There is also a
'data transfer controller' that can steal cycles from the CPU and store a block of conversion
results directly in memory.
There is an on-chip Temperature Sensor connected to A10 input of ADC10. This Sensor can
track the launch pad temperature and we can display the value of ADC10MEM using Watch
window.
The SFRs available to program ADC10 are
ADC10CTL0 & ADC10CTL1 can be programmed for converting Temperature to display in the
watch window.
PROGRAM
#include <msp430.h>
long temp;
long IntDegC;
int main(void)
{
while(1)
{
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
__bis_SR_register(CPUOFF + GIE); // LPM0 with interrupts enabled
// oC = ((A10/1024)*1500mV)-986mV)*1/3.55mV = A10*423/1024 - 278
temp = ADC10MEM;
IntDegC = ((temp - 673) * 423) / 1024;
__no_operation(); // SET BREAKPOINT HERE
}
}
// ADC10 interrupt service routine
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR (void)
{
__bic_SR_register_on_exit(CPUOFF); // Clear CPUOFF bit from 0(SR)
}
#pragma vector=TIMER0_A0_VECTOR
__interrupt void ta0_isr(void)
{
TACTL = 0;
LPM0_EXIT; // Exit LPM0 on return
}
Experiment No.:7(b)
APPARATUS
PC Installed with CCSV6 & Energia
Launch pad : MSP-EXP430F5529LP
USB Cable to interconnect Launch pad to windows enabled PC
THEORY
The ADC12_A module supports fast 12-bit analog-to-digital conversions (SAR type).
CONNECTIONS
1.Connect Launchpad to the PC using the USB cable supplied.
2. Connect the positive lead of the potentiometer to the 3.3V pin on the Launchpad and the
negative lead of the potentiometer to the GND pin.
3. Connect the output lead of the potentiometer to pin P6.0 or Analog Channel A0.
PROGRAM
a) CCS
#include <msp430f5529.h>
unsigned int ADC_result =0;
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
ADC12CTL0 = ADC12SHT02 + ADC12ON; // Sampling time, ADC12 on
ADC12CTL1 = ADC12SHP; // Use sampling timer
ADC12IE = 0x01; // Enable interrupt
ADC12CTL0 |= ADC12ENC;
P6SEL |= 0x01; // P6.0 ADC option select
int sensorPin = A0; // select the input pin for the potentiometer
int ledPin = 13; // select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the sensor
void setup() {
// declare the ledPin as an OUTPUT:
pinMode(ledPin, OUTPUT);
}
void loop() {
APPARATUS
PC Installed with CCSV6 & Energia
Launch pad : MSP-EXP430F5529LP
USB Cable to interconnect Launch pad to windows enabled PC
THEORY:
PWM
Pulse Width Modulation (PWM) is a method of digitally encoding analog signal levels. High-
resolution digital counters are used to generate a square wave of a given frequency, and the duty
cycle of the square wave is modulated to encode the analog signal. The duty cycle determines the
time during which the signal pulse is HIGH. For example, Figure 5-1 shows the different
waveforms for varying duty cycles of a signal.
In PWM, a large analog voltage results in increased pulse width and vice versa. Hence, the duty
cycle of the wave changes with the analog voltage that is encoded as shown in Figure 5-2.
The Timer A and Timer B of the MSP430G2553 are capable of PWM outputs in compare mode.
Analog-Digital Converter
The MSP430G2553 has ADC10, a 10-bit analog-to-digital converter which converts the analog
input into a maximum of 1024 discrete levels. The ADC10 module is capable of 8 external
inputs and 4 internal analog sources. The ADC10 can be configured to convert a single channel
or a block of contiguous channels and can optionally repeat its conversions automatically. Each
conversion takes multiple cycles. The timing is controlled by an ADC clock. While a conversion
is in progress, the busy flag is set. After conversion, the result is stored in the ADC10MEM
register. There is a possible interrupt signaled when a conversion is complete. There is also a
'data transfer controller' that can steal cycles from the CPU and store a block of conversion
results directly in memory.
Low-power mode 0 (LPM0)
• CPU is disabled
• ACLK and SMCLK remain active, MCLK is disabled
The block diagram for this experiment is shown in Figure 7-3. In this experiment, the analog
signal from potentiometer connected to P1.3 is read by the ADC10, and the converted digital
value is used to vary the duty cycle of the PWM output. The PWM output in turn controls the
speed of the DC motor which is connected to PWM pin P1.6. The PWM period is set to 1024 in
the Timer A capture/ compare register 0 (TA0CCR0). The digital value after conversion is stored
in ADC10MEM which is passed to the TA0CCR1 register to set the PWM duty cycle. This value
can vary from 0 to 1024 based on the position of the potentiometer. The timer interrupt is set to
sample and convert the analog input to digital output. The device is kept in low power mode,
until it is woken up by the interrupt.
PROGRAM:
#include<msp430g2553.h>
void main()
{
WDTCTL=WDTPW + WDTHOLD;
ADC10CTL0|= ADC10ON + SREF_0 + ADC10SHT_2; //Enable ADC //module,reference
//voltage, sample & //hold time
ADC10CTL1|= INCH_3; //Select input channel 3
ADC10AE0|= 0x08; //Analog Enable channel 3
P1DIR|=BIT6; //Make Port1-->Pin6 as output
P1SEL|=BIT6; //Select PWM Function
TA0CTL|=TASSEL_2+ID_3+MC_1+TAIE; //Configure Timer0,//SMCLK,UP mode,
//Clock Source divide by
8,//InterruptEnable
TA0CCTL1|=OUTMOD_7 ; //Select OUTPUT MODE 7; RESET/SET
TA0CCR0=1024; //Configure PWM time period
TA0CCR1=1; //Configure PWM ON_TIME(Duty Cycle)
__bis_SR_register(GIE); //General Interrupt Enable
while(1);
}
#pragma vector=TIMER0_A1_VECTOR
__interrupt void timer(void)
{
ADC10CTL0|=ENC+ADC10SC;//ADC enable conversion & start conversion
TA0CCR1= ADC10MEM; //Copy ADC buffer value into CCR1 to vary duty cycle
}
APPARATUS
Dept. of ECE Page 51
ES Lab (16BT70432) Manual
THEORY:
Connection details:
1. Connect Brown wire to gnd on launchpad
2. Connect Red wire to +5V on launch pad
3. Connect Orange wire to output PWM – P2.5 – pin no. 40
4. use 10K pot middle pin at A0=Pin6.0 = A0 to control Servo angle ( for program ii)
PROGRAM:
i) Sweep: to sweep servo continuously
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position
void setup()
{
ii) using Knob: Controlling a servo position using a potentiometer (variable resistor)
#include <Servo.h>
Servo myservo; // create servo object to control a servo
int potpin = 0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
void setup()
{
myservo.attach(40); // attaches the servo on pin 9 to the servo object
}
void loop()
{
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 4095, 0, 179); // scale it to use it with the servo (value between 0 and 180)
myservo.write(val); // sets the servo position according to the scaled value
delay(15); // waits for the servo to get there
}
Experiment No.:9
PROGRAMMING COMPARATOR A+
APPARATUS:
PC Installed with CCSV6
Launch pad : MSP-EXP430G2553
USB Cable to interconnect Launch pad to windows enabled PC
10K Potentiometer
THEORY:
Configure Comparator_A to detect a voltage threshold-Using an external potentiometer, an unknown
voltage is applied to P1.1. and compared with an internal reference
Internal Circuitry
The experiment is to Compare External Analog input at P1.1 (CA1) with 0.25 VCC and glow
LED at P1.0 to indicate that it is above 0.25 VCC.
PROGRAM:
#include <msp430.h>
int main (void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P1DIR |= 0x01; // P1.0 output
Experiment No.:10
LOW POWER MODES
AIM : To Test Various Power down modes in MSP430 - Analyze current drawn /Power
Consumed by the MSP430G2553 launch pad in different modes of operation (AM, LPM0,
LPM1, LPM2, LPM3 & LPM4) using code composer studio.
APPARATUS:
THEORY:
The MSP430 family is designed for ultra low-power applications. The MSP430G2553 supports
one active mode and five software selectable low-power modes of operation. The operating
modes take into account three different needs:
• Ultra low-power
• Speed and data throughput
• Minimization of individual peripheral current consumption
The low power modes for the MSP430G2553 are configured in the status register. An interrupt
event can wake up the device from any of the low-power modes. It services the request and
restores back to the same low-power mode if the status register is not altered within the interrupt
service routine. Power consumption of target device is directly related to the clock speed. Hence,
the power consumption is reduced by disabling the clock for a particular peripheral as per the
application requirement.
The state of the CPU and clocks for the different low power modes of the MSP430G2553 is
given below
The power consumption of MSP430G2553 is the maximum in active mode, where CPU clock
and related peripheral clocks are enabled. Stand by current consumption of the MSP430G2553
device depends upon the particular low power mode as shown below.
In the current experiment, we are measuring the active current and standby current of the
MSP430G2553 for a given application.The majority of the power used by the application is
spent in the while (1) loop, waiting for an interrupt.We can place the device in a low-power
mode during that time and save a considerable amount of power.
In this experiment, we will turn on interrupts and put the device in LPM3 mode. It is to be noted
that this mode will place restrictions on the resources available during the low-power mode. The
CPU,MCLK, SMCLK and DCO are off in LPM3 mode. Only the ACLK (sourced by the VLO in
our code) is still running. In MSP430G2553, all device pins must be configured to draw the
lowest current to demonstrate low power modes. MSP430G2553 port 1 defaults to GPIO, among
them only P1.3 is configured as an input to support push button switch SW2, and the rest are
configured as outputs. P2.6 and P2.7 default to crystal inputs, so in the current example program,
they are configured as GPIO.
PROGRAM:
Active Mode:
#include <msp430g2553.h>
#ifndef TIMER0_A1_VECTOR
#define TIMER0_A1_VECTOR TIMERA1_VECTOR
#define TIMER0_A0_VECTOR TIMERA0_VECTOR
#endif
volatile long tempRaw;
volatile unsigned int i;
void FaultRoutine(void);
void ConfigWDT(void);
void ConfigClocks(void);
void ConfigPins(void);
void ConfigADC10(void);
void ConfigTimerA2(void);
void main(void)
{
ConfigWDT();
ConfigClocks();
ConfigPins();
ConfigADC10();
ConfigTimerA2();
_BIS_SR(GIE);
while(1)
{
for (i = 100; i > 0; i--);
for (i = 5000; i > 0; i--); }
}
void ConfigWDT(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
}
void ConfigClocks(void)
{
if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF)
FaultRoutine(); // If calibration data is erased
// run FaultRoutine()
BCSCTL1 = CALBC1_1MHZ; // Set range
DCOCTL = CALDCO_1MHZ; // Set DCO step + modulation
Standby Mode:
#include <msp430g2553.h>
#ifndef TIMER0_A1_VECTOR
#define TIMER0_A1_VECTOR TIMERA1_VECTOR
#define TIMER0_A0_VECTOR TIMERA0_VECTOR
#endif
volatile long tempRaw;
//volatile unsigned int i;
void FaultRoutine(void);
void ConfigWDT(void);
void ConfigClocks(void);
void ConfigPins(void);
void ConfigADC10(void);
void ConfigTimerA2(void);
void main(void)
{
ConfigWDT();
ConfigClocks();
ConfigPins();
ConfigADC10();
ConfigTimerA2(); // _BIS_SR(GIE);
while(1)
{
_bis_SR_register(LPM3_bits + GIE); // Enter LPM3 with interrupts
}
}
void ConfigWDT(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
}
void ConfigClocks(void)
{
if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF)
FaultRoutine(); // If calibration data is erased
// run FaultRoutine()
BCSCTL1 = CALBC1_1MHZ; // Set range
DCOCTL = CALDCO_1MHZ; // Set DCO step + modulation
BCSCTL3 |= LFXT1S_2; // LFXT1 = VLO
IFG1 &= ~OFIFG; // Clear OSCFault flag
BCSCTL2 |= SELM_0 + DIVM_3 + DIVS_3; // MCLK = DCO/8, SMCLK = DCO/8
}
void FaultRoutine(void)
{
P1OUT = BIT0; // P1.0 on (red LED)
while(1); // TRAP
}
void ConfigPins(void)
{
P1DIR = ~BIT3; // P1.6 and P1.0 outputs
P1OUT = 0;
P2SEL = ~(BIT6 + BIT7);
P2DIR |= BIT6 + BIT7;
P2OUT = 0; // LEDs off
}
void ConfigADC10(void)
{
ADC10CTL1 = INCH_10 + ADC10DIV_0; // Temp Sensor ADC10CLK
}
void ConfigTimerA2(void)
{
CCTL0 = CCIE;
CCR0 = 36000;
TACTL = TASSEL_1 + MC_2;
}
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A (void)
{
ADC10CTL0 = SREF_1 + ADC10SHT_3 + REFON + ADC10ON;
_delay_cycles(4); // Wait for ADC Ref to settle
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
PROCEDURE:
Demonstration Involves two steps: Measurement of current in Active Mode & Measurement of
current in Standby (LPM3) Mode.
Initially, connect the MSP-EXP430G2 LaunchPad to the PC using the USB cable supplied.
The current consumption in both the active and standby modes operating MSP in various low
power modes is measured while running the application code with a digital multimeter. The
Typical current consumption curve looks like.
Experiment No.:11
AIM : To establish network and handle communication between master and slave launch pads
using code composer studio.
APPARATUS:
PC Installed with CCSV6
Launch pads : MSP-EXP430F5529 – 2 Nos.
USB Cables to interconnect Launch pad to windows enabled PC
Connecting probes to interconnect master to slave
THEORY:
Universal Serial Communication Interface (USCI):
The MSP430F5529 consists of two Universal Serial Communication Interfaces (USCI) which
support multiple serial communication modes as shown below.
• UART mode
• Pulse shaping for IrDA communications
• Automatic baud rate detection for LIN communications
• Synchronous SPI mode
• I2C mode
• Synchronous SPI (Serial Peripheral Interface) mode
In synchronous SPI mode, the USCI connects the MSP430F5529 to an external system via three
or four pins as shown in Figure.
SPI mode is selected when the UCSYNC bit is set and SPI mode (3-pin or 4-pin) is selected with
the UCMODEx bits.
The block diagram for the experiment is as shown in below figure . In this experiment the SPI
master talks to SPI slave using 3-wire mode. The USCI_A0 module is configured as a SPI
interface. Master sends the data starting at 0x01 to the slave mode. The slave will receive the
data which is expected to be same as the previous data transmission.In the master, USCI_RX
ISR is used to handle communication with the CPU, normally in LPM0. In the slave, USCI_ RX
ISR is used to handle communication with the CPU, normally in LPM4.
MASTER:
SLAVE:
PROGRAM:
MASTER:
#include<msp430f5529.h>
WDTCTL = WDTPW+WDTHOLD;
P1OUT |= 0x02;
// P1DIR |= 0x03;
P4DIR |=BIT7;
P3SEL |= BIT3+BIT4;
P2SEL |= BIT7;
UCA0CTL1 |= UCSWRST;
UCA0CTL0 |= UCMST+UCSYNC+UCCKPL+UCMSB;
UCA0CTL1 |= UCSSEL_2;
// SMCLK
UCA0BR0 = 0x02;
UCA0BR1 = 0;
UCA0MCTL = 0;
// No modulation
//UCA0IE |= UCRXIE;
P1OUT |= 0x02;
// SLV_Data = 0x00;
//UCA0TXBUF = MST_Data;
__bis_SR_register(LPM0_bits + GIE);
P4OUT^=BIT7;
MST_Data = 0x01;
UCA0IE |= UCTXIE;
#pragma vector=USCI_A0_VECTOR
P1OUT|=BIT0;
SLAVE :
#include <msp430.h>
int main(void)
// Echo character
#pragma vector=USCI_A0_VECTOR
#elif defined(__GNUC__)
#else
#endif
switch(__even_in_range(UCA0IV,4))
UCA0TXBUF = UCA0RXBUF;
break;
default: break;
}}
Experiment No.:12
AIM : To Scan available networks for enabling MSP as IOT to print the Wifi MAC address, and scans
for available Wi-fi networks once for every 10 seconds.
APPARATUS:
PC Installed with Energia
Launch pads : MSP-EXP430F5529
CC3100 WiFi booster pack
USB Cables to interconnect Launch pad to windows enabled PC
THEORY:
To interconnect MSP launchpad with internet it can be done by stacking CC3100 WIFI launch
pad over it. This code in Energia checks for near by active WIFI networks for accessing MSP
using internet using SPI.
PROGRAM:
#include <SPI.h>
#endif
#include <WiFi.h>
void setup() {
Serial.begin(115200);
WiFi.init();
Serial.println(WiFi.firmwareVersion());
printMacAddress();
listNetworks();
void loop() {
delay(10000);
listNetworks();
void printMacAddress() {
byte mac[6];
WiFi.macAddress(mac);
Serial.print("MAC: ");
Serial.print(mac[5], HEX);
Serial.print(":");
Serial.print(mac[4], HEX);
Serial.print(":");
Serial.print(mac[3], HEX);
Serial.print(":");
Serial.print(mac[2], HEX);
Serial.print(":");
Serial.print(mac[1], HEX);
Serial.print(":");
Serial.println(mac[0], HEX);
void listNetworks() {
if (numSsid == -1)
while (true);
Serial.println(numSsid);
// print the network number and name for each network found:
Serial.print(thisNet);
Serial.print(") ");
Serial.print(WiFi.SSID(thisNet));
Serial.print("\tSignal: ");
Serial.print(WiFi.RSSI(thisNet));
Serial.print(" dBm");
Serial.print("\tEncryption: ");
printEncryptionType(WiFi.encryptionType(thisNet));
switch (thisType) {
case ENC_TYPE_WEP:
Serial.println("WEP");
break;
case ENC_TYPE_TKIP:
Serial.println("WPA");
break;
case ENC_TYPE_CCMP:
Serial.println("WPA2");
break;
case ENC_TYPE_NONE:
Serial.println("None");
break;
case ENC_TYPE_AUTO:
Serial.println("Auto");
break;