// Conditions for 9600/4=2400 Baud SW UART, SMCLK = 1MHz #define Bitime_5 0x05*4 // ~ 0.5 bit length + small adjustment #define Bitime 13*4//0x0D

Similar documents
CPE 323: MSP430 Timers

Lab 4: Interrupt. CS4101 Introduction to Embedded Systems. Prof. Chung-Ta King. Department of Computer Science National Tsing Hua University, Taiwan

Fall. Accelerometer RGB LED control Vishal Shah Rebel Sequeira Pratiksha Patil Pranali Dhuru Chris Blackden. George Mason University

CPE 323 Introduction to Embedded Computer Systems: ADC12 and DAC12. Instructor: Dr Aleksandar Milenkovic Lecture Notes

ECE2049: Embedded Computing in Engineering Design A Term Fall 2017 Lecture #16: Interrupts and Event Driven Code

2.996/6.971 Biomedical Devices Design Laboratory Lecture 6: Microprocessors II

Timers and Clocks CS4101 嵌入式系統概論. Prof. Chung-Ta King. Department of Computer Science National Tsing Hua University, Taiwan

Lecture 5: MSP430 Interrupt

CPE 325: Embedded Systems Laboratory Laboratory #7 Tutorial MSP430 Timers, Watchdog Timer, Timers A and B

CPE 325: Embedded Systems Laboratory Laboratory #11 Tutorial Analog-to-Digital Converter and Digital-to-Analog Converter

Texas Instruments Mixed Signal Processor Tutorial Abstract

Interrupts, Low Power Modes

What is an Interrupt?

CPE/EE 323 Introduction to Embedded Computer Systems Homework V

Hacettepe University

ECE PRACTICE EXAM #2 Clocks, Timers, and Digital I/O

MSP430 Interrupts. Change value of internal variable (count) Read a data value (sensor, receive) Write a data value (actuator, send)

ECE2049: Embedded Computing in Engineering Design C Term Spring 2018 Lecture #15: More ADC Examples

ECE 492 WINTER 2015 GROUP 2. Texas Instruments MSP430-FR Bit ADC Setup Guide

University of Texas at El Paso Electrical and Computer Engineering Department. EE 3176 Laboratory for Microprocessors I.

Timer Module Timer A. ReadMeFirst

Hacettepe University

TAxCTL Register

CONTENTS: Program 1 in C:

University of Texas at El Paso Electrical and Computer Engineering Department. EE 3176 Laboratory for Microprocessors I.

Analog Peripherals. Introduction. Objectives

Lab 1: I/O, timers, interrupts on the ez430-rf2500

Interfacing CMA3000-D01 to an MSP430 ultra low-power microcontroller

Interrupts CS4101 嵌入式系統概論. Prof. Chung-Ta King. Department of Computer Science National Tsing Hua University, Taiwan

Lab 4 Interrupts ReadMeFirst

Supporting Information for. Simultaneous Atomic-Level Visualization and High Precision

Interfacing CMR3000-D01 to an MSP430 ultra low-power microcontroller

15.1 Timer_A Introduction

Using peripherals on the MSP430 (if time)

ECE2049: Embedded Computing in Engineering Design C Term Spring Lecture #11: More Clocks and Timers

ECE 492 WINTER 2015 GROUP 2. Texas Instruments MSP430-FR Bit ADC Setup Guide

Designing for Ultra-Low Power with MSP430

Copyright 2015 by Stephen A. Zajac & Gregory M. Wierzba. All rights reserved..spring 2015.

Physics 319 Spring 2015: Introduction to the Programming and Use of Microprocessors

IV B.Tech. I Sem (R13) ECE : Embedded Systems : UNIT -2 1 UNIT 2

CPE 323 Introduction to Embedded Computer Systems: MSP430 System Architecture An Overview

Block diagram of processor (Harvard)

EEL 4924 Electrical Engineering Design (Senior Design) Final Design Report 18 April 2011

Wireless Sensor Networks (WSN)

Name: Clint Furrer Project Number: TI003 Project Description: Safety Walking Lights. Description:

MSP430. More on MSP430

5xx Active & Low Power Mode Operation

Monitoring System for a Laundry System with ez430-rf2500 Development Kit

6. General purpose Input/Output

Asservissement en température numérique d'une cavité ultra-stable au LPL pour le Strontium

UC Berkeley EE40/100 Lab Lab 6: Microcontroller Input/Output B. Boser, etc.

C Language Programming through the ADC and the MSP430 (ESCAPE)

The 16-bit timer/counter register, TAR, increments or decrements (depending on mode of operation) with each rising edge of the clock signal.

ECET 491Senior Design Project Title: Wind Speed Data Logger

The digital I/O is configured with user software. The setup and operation of the digital I/O is discussed in the following sections.

Getting Started with the MSP430 LaunchPad

Getting Started with the MSP430 LaunchPad

MSP430 Teaching Materials

CPE/EE 421 Microcomputers

volatile int results[5]; // variables para la interrupcion del acelerometro //Funciones del acelerometro para mandar y recibir información

WeatherSense. EEL4924 Final Design Report. Justin Mills. April 23 rd, 2013

File: /media/j/texas/my msp430/g3tr/g3tr.c Pagina 1 di 5

Towards Hard Real-time Performance in a Highly Asynchronous Multitasking MSP430 Application Andrew E. Kalman, Ph.D.


ECE2049: Embedded Computing in Engineering Design C Term Spring 2019 Lecture #22: MSP430F5529 Operating Mode & the WDT

CPE/EE 421 Microcomputers

EEL 4924 Electrical Engineering Design (Senior Design) Team Baudiophile. Wireless Headphones

ECE2049 Homework #4 Analog-to-Digital Conversion and the ADC12 (Due Thursday 2/15/2018 to box outside AK-011 by 9 am)

MSP430F149 P3.4/UTXD0 P3.5/URXD0 P1.5 P1.6 P1.7 MSP430F149 P1.0 P5.4 P5.3 P5.2 P5.1. Figure B-1. BSL Replicator Block Diagram

Embedded Systems. 3. Hardware Software Interface. Lothar Thiele. Computer Engineering and Networks Laboratory

Reading: Davies , 8.3-4, , MSP430x55xx User's Guide Ch. 5,17, MSP430F5529 Launchpad User's Guide

MSP430F20xx Device Erratasheet

Alex Milenkovich 1. CPE/EE 421 Microcomputers. Course Administration. Review: Outline. Getting Started with EasyWeb2. Review: MSP bit RISC

Network Embedded Systems Sensor Networks. Tips and Tricks. Marcus Chang,

Reading: Davies , 8.3-4, , MSP430x55xx User's Guide Ch. 5,17

Getting Started with the Texas Instruments ez430

Network Embedded Systems Sensor Networks Fall Hardware. Marcus Chang,

Lecture 2 MSP430 Architecture. Atul Lele Ramakrishna Reddy

Designing for Ultra-Low Power with MSP430

MSP430FG4618 Programming Reference Revision 3

Chapter 26 Topic Page 26.1 ADC12 Introduction

Lecture 2 ECEN 4517/5517

ECE2049: Embedded Computing in Engineering Design A Term Fall Lecture #8: Making it work: LEDs, Buttons & Keypad

Lecture 2 ECEN 4517/5517

2002 Mixed Signal Products SLAU056B

PRODUCT PREVIEW. MSP430x11x2, MSP430x12x2 MIXED SIGNAL MICROCONTROLLER. description

Design Implementation Of A Microcontroller Based External Facility Access Control System

Lecture test next week

University of Texas at El Paso Electrical and Computer Engineering Department. EE 3176 Laboratory for Microprocessors I.

The following article introduces and shows an example of how to set up and use the watchdog timer on the M16C/26 microcontroller (MCU).

ECGR 4101/5101, Fall 2016: Lab 1 First Embedded Systems Project Learning Objectives:

ADC 14. Last updated 9/1/18

Texas Instruments Microcontroller HOW-TO GUIDE Interfacing Keypad with MSP430F5529

@databasescaling Wednesday, 18 th April 2013

Microcontrollers. vs Microprocessors

LECTURE - 4 Programming MSP430 using Code Composer Studio(CCS)

Embedded Technosolutions

TPL5000EVM User's Guide

Application Note One Wire Digital Output. 1 Introduction. 2 Electrical Parameters for One Wire Interface. 3 Start and Data Transmission

MSP430 Design in an hour

Transcription:

/****************************************************************************** * * * 1. Device starts up in LPM3 + blinking LED to indicate device is alive * + Upon first button press, device transitions to application mode * 2. Application Mode * + Continuously sample ADC Temp Sensor channel, compare result against * initial value * + Set PWM based on measured ADC offset: Red LED for positive offset, Green * LED for negative offset * + Transmit temperature value via TimerA to PC * + Button Press --> Calibrate using current temperature * Send character ' ' via UART, notifying PC ******************************************************************************/ #include <msp430g2231.h> #define green_led BIT0 #define red_led BIT6 #define BUTTON BIT3 #define TXD BIT1 // TXD on P1.1 #define RXD BIT2 // RXD on P1.2 #define APP_STANDBY_MODE 0 #define APP_APPLICATION_MODE 1 #define TIMER_PWM_MODE 0 #define TIMER_UART_MODE 1 #define TIMER_PWM_PERIOD 2000 #define TIMER_PWM_OFFSET 20 #define TEMP_SAME 0 #define TEMP_HOT 1 #define TEMP_COLD 2 #define TEMP_THRESHOLD 5 // Conditions for 9600/4=2400 Baud SW UART, SMCLK = 1MHz #define Bitime_5 0x05*4 // ~ 0.5 bit length + small adjustment #define Bitime 13*4//0x0D #define UART_UPDATE_INTERVAL 1000 // Loops until byte is sent unsigned char BitCnt; // Bit count, used when transmitting byte unsigned char applicationmode = APP_STANDBY_MODE; unsigned char timermode = TIMER_PWM_MODE; unsigned char tempmode; unsigned char calibrateupdate = 0; unsigned char temppolarity = TEMP_SAME; unsigned int TXByte; // Value sent over UART when Transmit() is called /* Using an 8-value moving average filter on sampled ADC values */ long tempmeasured[8]; unsigned char tempmeasuredposition=0; -1-

long tempaverage; long tempcalibrated, tempdifference; void InitializeLeds(void); void InitializeButton(void); void PreApplicationMode(void); void ConfigureAdcTempSensor(void); void ConfigureTimerPwm(void); void ConfigureTimerUart(void); void Transmit(void); void InitializeClocks(void); // Blinks LED, waits for button press void main(void) unsigned int uartupdatetimer = UART_UPDATE_INTERVAL; unsigned char i; // Transmit value counter WDTCTL = WDTPW + WDTHOLD; // Stop WDT InitializeClocks(); InitializeButton(); InitializeLeds(); PreApplicationMode(); /* Application Mode begins */ applicationmode = APP_APPLICATION_MODE; ConfigureAdcTempSensor(); ConfigureTimerPwm(); enable_interrupt(); /* Main Application Loop */ while(1) ADC10CTL0 = ENC + ADC10SC; bis_sr_register(cpuoff + GIE); // Blinks LEDs, waits for button press // applicationmode = '1' // Enable interrupts. // Sampling and conversion start // LPM0 with interrupts enabled /* Moving average filter out of 8 values to somewhat stabilize sampled ADC */ tempmeasured[tempmeasuredposition++] = ADC10MEM; if (tempmeasuredposition == 8) tempmeasuredposition = 0; tempaverage = 0; for (i = 0; i < 8; i++) tempaverage += tempmeasured[i]; tempaverage >>= 3; // Divide by 8 to get average if ((--uartupdatetimer == 0) calibrateupdate ) ConfigureTimerUart(); if (calibrateupdate) TXByte = 248; // A character with high value, outside of temp range Transmit(); calibrateupdate = 0; TXByte = (unsigned char)( (tempaverage * 423) / 1024-281 ); -2-

Transmit(); uartupdatetimer = UART_UPDATE_INTERVAL; ConfigureTimerPwm(); tempdifference = tempaverage - tempcalibrated; if (tempdifference < -TEMP_THRESHOLD) tempdifference = -tempdifference; temppolarity = TEMP_COLD; P1OUT &= ~ red_led; if (tempdifference > TEMP_THRESHOLD) temppolarity = TEMP_HOT; P1OUT &= ~ green_led; temppolarity = TEMP_SAME; TACCTL0 &= ~CCIE; TACCTL1 &= ~CCIE; P1OUT &= ~(green_led + red_led); if (temppolarity!= TEMP_SAME) tempdifference <<= 3; tempdifference += TIMER_PWM_OFFSET; TACCR1 = ( (tempdifference) < (TIMER_PWM_PERIOD-1)? (tempdifference) : ( TIMER_PWM_PERIOD-1) ); TACCTL0 = CCIE; TACCTL1 = CCIE; void PreApplicationMode(void) P1OUT = green_led; P1OUT &= ~red_led; // To enable the LED toggling effect BCSCTL1 = DIVA_1; // ACLK = VLO/2 = 6 KHz BCSCTL3 = LFXT1S_2; // VLO = 12kHz => ACLK TACCR0 = 1200; // capture compare reg value 0.2s TACTL = TASSEL_1 MC_1; // Timer_A: ACLK selected as clock source, // Up mode: the timer counts up to TACCR0. TACCTL1 = CCIE + OUTMOD_3; // Capture/compare interrupt enabled, // set/reset out mode: (figure 12-12) // The output is set when the timer counts to the TACCRx value. // It is reset when the timer counts to the TACCR0 value. TACCR1 = 600; // capture compare reg value 0.1s bis_sr_register(lpm3_bits + GIE); // LPM0 with interrupts enabled -3-

void ConfigureAdcTempSensor(void) unsigned char i; /* Configure ADC Temp Sensor Channel */ ADC10CTL1 = INCH_10 + ADC10DIV_3; // Temp Sensor, ADC10OSC/4 (ADC10SSEL = '00') // VR+ = VREF+ and VR- = VSS, ADC10 sample-and-hold time = 64 ADC10CLKs, // Reference generator on, ADC10 on, ADC10 interrupt enable = ADC10IFG // is set when conversion results are loaded into ADC10MEM ADC10CTL0 = SREF_1 + ADC10SHT_3 + REFON + ADC10ON + ADC10IE; delay_cycles(1000); // Wait for ADC Ref to settle ADC10CTL0 = ENC + ADC10SC; // Enable conversion, Start conversion. bis_sr_register(cpuoff + GIE); // LPM0 with interrupts enabled tempcalibrated = ADC10MEM; for (i=0; i < 8; i++) tempmeasured[i] = tempcalibrated; tempaverage = tempcalibrated; void ConfigureTimerPwm(void) timermode = TIMER_PWM_MODE; TACCR0 = TIMER_PWM_PERIOD; // TACTL = TASSEL_2 MC_1; // TACLK = SMCLK, Up mode. TACCTL0 = CCIE; TACCTL1 = CCIE + OUTMOD_3; // TACCTL1 Capture Compare TACCR1 = 1; void ConfigureTimerUart(void) timermode = TIMER_UART_MODE; // Configure TimerA0 UART TX CCTL0 = OUT; TACTL = TASSEL_2 + MC_2 + ID_3; P1SEL = TXD + RXD; P1DIR = TXD; // TXD Idle as Mark // SMCLK/8, continuous mode // P1.1 & 2 TA0, rest GPIO // P1.1 output, other inputs // Function Transmits Character from TXByte void Transmit() BitCnt = 0xA; // Load Bit counter, 8data + ST/SP while (CCR0!= TAR) // Prevent async capture CCR0 = TAR; // Current state of TA counter CCR0 += Bitime; // Set time till first bit TXByte = 0x100; // Add mark stop bit to TXByte TXByte = TXByte << 1; // Add start bit (which is logical 0) CCTL0 = CCIS0 + OUTMOD0 + CCIE; // TXD = mark = idle, Set signal, intial value, enable interrupt while ( CCTL0 & CCIE ); // Wait for TX completion // Timer A0 interrupt service routine #pragma vector=timera0_vector interrupt void Timer_A (void) -4-

if (timermode == TIMER_UART_MODE) CCR0 += Bitime; // Add Offset to CCR0 if (CCTL0 & CCIS0) // TX on CCI0B? if ( BitCnt == 0) CCTL0 &= ~ CCIE; // If all bits TXed, disable interrupt CCTL0 = OUTMOD2; // TX Space if (TXByte & 0x01) CCTL0 &= ~ OUTMOD2; // TX Mark TXByte = TXByte >> 1; BitCnt --; if (temppolarity == TEMP_HOT) P1OUT = red_led; if (temppolarity == TEMP_COLD) P1OUT = green_led; TACCTL0 &= ~CCIFG; #pragma vector=timera1_vector interrupt void ta1_isr(void) TACCTL1 &= ~CCIFG; if (applicationmode == APP_APPLICATION_MODE) P1OUT &= ~(green_led + red_led); P1OUT ^= (green_led + red_led); void InitializeClocks(void) BCSCTL1 = CALBC1_1MHZ; DCOCTL = CALDCO_1MHZ; void InitializeButton(void) P1DIR &= ~BUTTON; P1OUT = BUTTON; P1REN = BUTTON; P1IES = BUTTON; P1IFG &= ~BUTTON; P1IE = BUTTON; void InitializeLeds(void) P1DIR = green_led + red_led; // Set range // Configure Push Button // The pin is an input // pulled up // pullup/pulldown resistor enabled // Flag triggered by the pin going from '1' to '0' // Clearing flag // Interrupt enabled // P1.0 and P1.6 are -5-

output P1OUT &= ~(green_led + red_led); // P1.0 and P1.6 set to '0', leds off /* ************************************************************* * Port Interrupt for Button Press * 1. During standby mode: to exit and enter application mode * 2. During application mode: to recalibrate temp sensor * *********************************************************** */ #pragma vector=port1_vector interrupt void PORT1_ISR(void) P1IFG = 0; P1IE &= ~BUTTON; /* Debounce */ WDTCTL = WDT_ADLY_250; // WDTCTL = WDT_ADLY_250 // WDT_ADLY_250 sets the following bits // (WDTPW+WDTTMSEL+WDTCNTCL+WDTSSEL+WDTIS0) 250ms interval: // WDTPW: WDT password // WDTTMSEL: Selects interval timer mode // WDTCNTCL: Clears count value // WDTSSEL: WDT clock source select IFG1 &= ~WDTIFG; /* clear interrupt flag */ IE1 = WDTIE; // Enable WDT interrupt if (applicationmode == APP_APPLICATION_MODE) tempcalibrated = tempaverage; calibrateupdate = 1; applicationmode = APP_APPLICATION_MODE; // Switch from STANDBY to APPLICATION MODE bic_sr_register_on_exit(lpm3_bits); #pragma vector=wdt_vector interrupt void WDT_ISR(void) IE1 &= ~WDTIE; /* disable interrupt */ IFG1 &= ~WDTIFG; /* clear interrupt flag */ WDTCTL = WDTPW + WDTHOLD; /* put WDT back in hold state */ P1IE = BUTTON; /* Debouncing complete */ // ADC10 interrupt service routine #pragma vector=adc10_vector interrupt void ADC10_ISR (void) bic_sr_register_on_exit(cpuoff); // Return to active mode -6-