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

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

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

Using peripherals on the MSP430 (if time)

Interrupt Driven Programming in MSP430 Assembly (ESCAPE) *

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

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

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

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

CPE/EE 323 Introduction to Embedded Computer Systems Homework V

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

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

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

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

// 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

Why embedded systems?

ECE2049 Homework #2 The MSP430 Architecture & Basic Digital IO (DUE Friday 9/8/17 at 4 pm in class)

1.2 - Introduction to the IAR Workbench IDE *

Lecture test next week

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

CONTENTS: Program 1 in C:

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

Real Time Embedded Systems. Lecture 1 January 17, 2012

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

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

Analog Peripherals. Introduction. Objectives

Texas Instruments Microcontroller HOW-TO GUIDE Interfacing Keypad with MSP430F5529

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

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

Introduction to Microcontroller Apps for Amateur Radio Projects Using the HamStack Platform.

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

Section 10. Watchdog Timer and Power Saving Modes

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

Interrupts, Low Power Modes

Design Document. May Logging DC Wattmeter. Team Member: Advisor : Ailing Mei. Collin Christy. Andrew Kom. Client: Chongli Cai

Microcontroller basics

INTERRUPTS in microprocessor systems

Review Activity 1 CALL and RET commands in assembler

Texas Instruments Mixed Signal Processor Tutorial Abstract

Lab 5: LCD and A/D: Digital Voltmeter

Overview of the ARM Embedded Processors from Texas Instruments *

Lab 5: LCD and A/D: Digital Voltmeter

Z8 Encore! XP F1680 Series 8-Bit Flash Solution with Extended Peripherals

Using Code Composer Studio IDE with MSP432

The Freescale MC908JL16 Microcontroller

For reference only Refer to the latest documents for details

Let s first take a look at power consumption and its relationship to voltage and frequency. The equation for power consumption of the MCU as it

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

By the end of Class. Outline. Homework 5. C8051F020 Block Diagram (pg 18) Pseudo-code for Lab 1-2 due as part of prelab

AVR XMEGA Product Line Introduction AVR XMEGA TM. Product Introduction.

EECS 373 Midterm 2 Fall 2018

Software Setup and Introductory Assembly programs for the MSP430 *

Exercise 4-1. DSP Peripherals EXERCISE OBJECTIVES

ECE2049 E17 Lecture 4 MSP430 Architecture & Intro to Digital I/O

Lecture 5: MSP430 Interrupt

EEE394 Microprocessor and Microcontroller Laboratory Lab #6

This Part-B course discusses design techniques that are used to reduce noise problems in large-scale integration (LSI) devices.

CSE 466 Exam 1 Winter, 2010

DSP Development Environment: Introductory Exercise for TI TMS320C55x

Objective: Additional project details: Code: PSEMBP 100 Category:STEM Level: High School/Community C.

Lab 4: Interrupts and Realtime

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

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

Introduction to ARM LPC2148 Microcontroller

Ultra Low Power Microcontroller - Design Criteria - June 2017

ECE2049: Embedded Computing in Engineering Design C Term Spring Lecture #7: More Digital IO

Ali Karimpour Associate Professor Ferdowsi University of Mashhad

The Atmel ATmega328P Microcontroller

TAxCTL Register

Overview of the ARM Embedded Processors from Texas Instruments

Introduction to the Texas Instruments ez430. By: Naren Anand

How to make a "hello world" program in Java with Eclipse *

Design and development of embedded systems for the Internet of Things (IoT) Fabio Angeletti Fabrizio Gattuso

Processor and compiler dependent

Wireless Sensor Networks (WSN)

Hello, and welcome to this presentation of the STM32L4 power controller. The STM32L4 s power management functions and all power modes will also be

ECE 511 Project Group 11: MP3 Boombox 12/03/2013. Carlos R Araujo Divya Chinthalapuri Leegia S Jacob Brian D Jarvis Shawn Wilkinson

Lab 5: EBI and ADC: Digital Voltmeter

LC-E201A. Application note. 1. Mechanical Specification: LC-E021A-application note page 1 of 16 Revision:

CN310 Microprocessor Systems Design

Moses Jones Application Note ECE 480 Design Team 7 Programming Altimeters. Using MSP 430 Launch Pad 11/8/2013

UNIVERSITY OF BOLTON SCHOOL OF ENGINEERING MSC SYSTEMS ENGINEERING AND ENGINEERING MANAGEMENT SEMESTER 2 EXAMINATION 2016/2017

Hello, and welcome to this presentation of the STM32 Touch Sensing Controller (TSC) which enables the designer to simply add touch sensing

Embedded Systems. Software Development & Education Center. (Design & Development with Various µc)

EL6483: Basic Concepts of Embedded System ModelingSpring and Hardware-In-The-Loo

ADC 14. Last updated 9/1/18

Bachelor of Engineering in Computer and Electronic Engineering

Network Embedded Systems Sensor Networks Fall Hardware. Marcus Chang,

PIC Microcontroller Introduction

Microcontroller Introduction

88 Dugald Campbell. Making Industrial Systems Safer Meeting the IEC standards

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

University of Florida EEL 4744 Spring 2014 Dr. Eric M. Schwartz Department of Electrical & Computer Engineering 1 April Apr-14 9:03 AM

ICN12. I2C to UART Bridge, ADC,DAC and I/O

OpenStax-CNX module: m Java3002r Review * R.G. (Dick) Baldwin

USB Debug Adapter. Power USB DEBUG ADAPTER. Silicon Laboratories. Stop. Run. Figure 1. Hardware Setup using a USB Debug Adapter

ECE2049-E18 Lecture 6 Notes 1. ECE2049: Embedded Computing in Engineering Design E Term Lecture #6: Exam Review

Explanation of PIC 16F84A processor data sheet Part 1: overview of the basics

Ali Karimpour Associate Professor Ferdowsi University of Mashhad

Physics 364, Fall 2012, Lab #9 (Introduction to microprocessor programming with the Arduino) Lab for Monday, November 5

Transcription:

OpenStax-CNX module: m46087 1 C Language Programming through the ADC and the MSP430 (ESCAPE) Matthew Johnson Based on C Language Programming through the ADC and the MSP430 by Matthew Johnson This work is produced by OpenStax-CNX and licensed under the Creative Commons Attribution License 3.0 Abstract Updated references to work with the ADC12 and the ESCAPE platform 1 The C Language and Analog Interfacing: Your Task This lab covers the basic principals behind Analog to Digital Conversion, as well as the basics of programming in C. You are expected to have some background in C from class, but if you are confused, see this basic reference 1. 1. Using Code Composer Studio 5, write a C language program turning your ESCAPE Platform into a simple 10 level light meter. Your program should divide the 0-3.3V input range of the ADC into 10 zones, and then output from a 0 to a 9 on the LED display depending on the input voltage. IN GENERAL, DO NOT EXCEED AN INPUT VOLTAGE OF 3.3V (You don't have to worry about this during this light sensor lab). You will damage your circuits and destroy your MSP430 if you measure a raw voltage greater than 3.3V though. Assignment Details (Section 3: Assignment Details) 2 The ADC and "C" Through a Practical Example 2.1 Interfacing with the Analog World: The ADC ADC's play an incredibly important role in digital electronics and DSP. ADC stands for Analog to Digital Converter, and it does exactly what you would expect it to. It samples an external voltage, and then converts that voltage to a binary number compared to the reference voltage range from Vdd to Vss. (In plain English terms, the ADC samples what fraction the input is of some maximum allowed reference voltage.) The ADC's Version 1.1: Apr 2, 2013 3:56 pm -0500 http://cnx.org/content/m37386/1.3/ http://creativecommons.org/licenses/by/3.0/ 1 PROGRAMMING FUNDAMENTALS IN C++ <http://cnx.org/content/col10788/latest/>

OpenStax-CNX module: m46087 2 result gets written to a memory mapped register, where the programmer can access it and use it in his or her code. An ADC has a nite voltage range it can safely convert (usually related to its power supply range, but not always). The precision of the converted sample is related to the number of bits used by the ADC. More bits means more precision (more nite "slots" into which the innitely variable analog single can be quantized) and a lower "quantization error." To learn more about error and ADC, see this except from the Introduction to Electrical Engineering course notes 2. ADC's also have a maximum sampling rate specication (how frequently the ADC can make a conversion), but in this course we will be sampling very low frequency signals, so we won't need to worry about it. 2.2 The MSP430 ADC The MSP430 F5637 has one 16 channel 12 bit 200Khz ADC. ADC channels allow the single ADC to select between several dierent signals (such as two dierent analog inputs on dierent GPIO pins) like an analog multiplexer. In the F5637, channels 1-8 are connected to the 8 P6 GPIO pins, and channel 10 is connected to the chip's internal temperature sensor. For this lab, we will congure the ADC to use the internal 3.3 Vdd as the reference voltage. A voltage of 3.3V would result in the ADC register holding 1111 1111 1111 (0x0FFF) A voltage of 0.0V would result in the ADC register reading 00 0000 0000 (0x0000) A voltage of 1.65V would result in the ADC register reading 0111 1111 1111 (0x07FF) The ADC will have a sample resolution of 3.3V/4096 [Voltage Range/2 #Bits ], or.00081 Volts. The ADC is a peripheral device, so it operates independently from the CPU. It has several operation modes (congured by writing to its control registers). Denition 1: Peripheral A device that can operate independently from direct CPU support and control. Peripherals often rely on interrupts to notify the CPU when they have completed some given task or need attention, and use independent control registers for conguration. The ADC 12 is a peripheral, as well as the MSP430's UART (serial controller) and timers. ADC12 Operation Modes Single Sample and Hold the ADC12 will start a conversion when triggered by the CPU. After that conversion, it will hold the converted value in the ADC12MEMx registers and automatically go into sleep mode until signaled to begin another conversion. We will mostly use this mode. Sequence of Channels Sample and Hold the ADC12 will convert a series of dierent channels once, and store the result to ADC12MEM. Repeat Single Channel Mode it will continuously sample on channel, continuously updating the ADC12MEM register. Repeat Sequence of Channels Mode the ADC will continuously sample through a series of channels. The MSP430's ADC 12 also has a built in memory controller. We won't be using it, but it becomes important when using the repeat modes. The memory controller can automatically write the ADC data into main memory as conversions nish, bypassing the CPU. The F5637's ADC can run o of one of several available clock signals of varying speeds. Once a sample has been captured, it is held ready in the ADC10MEMx registers for a dened number of clock cycles. Since we are concerned with a low frequency signal, we will want to slow down the ADC12 as much as possible. (Students who have had Elec241 will notice some fundamental aws in the assumptions made regarding high-frequency noise, but in practice this has very little eect on the nal results). Even in its slowest mode, the ADC12 will still sample too quickly, so the use of some kind of moving average will help stabilize its DC readings. 2 "Amplitude Quantization" <http://cnx.org/content/m0051/latest/>

OpenStax-CNX module: m46087 3 2.3 Controlling the ADC12 in C 2.3.1 C Basics Your C program will be structured similarly to its assembly language counterparts, but with a much dierent syntax. Like before, the register names are all pre-dened in the "msp430.h" header le. To set a register, now just use an equals sign and set it like any other variable. For example, you will want to disable the watchdog timer in the rst line of your program. WDTCTL=WDTPW+WDTHOLD; The compiler will execute the void main(void) function rst. From that function, you can call any other functions or run any loops that you would like. C Skeleton Program #include <msp430.h> //Global Variable Declarations //Global Function Declarations int main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT //Other Setup } //Your Program Here //Can call other helper functions, loops, etc. return 0; 2.3.2 Conguring the ADC12 The ADC12 has two main control registers ADC12CTL0 and ADC12CTL1, and 16 memory control registers ADC10MCTLx (12bit ADCMemory CoNtroL0/1/2... channel 0-15). These registers control all the timing and conversion aspects of the ADC.

OpenStax-CNX module: m46087 4 ADC12CTL0 Figure 1 In the rst control register (ADC12CTL0), we only need to change two parameters, ADC12SHT0_x12bit ADCSample Hold Time a higher value means each sample will be held for a longer period of time. We want to set this at the max value of ADC12SHT0_8. ADC12ON12bit ADCON/OFFsetting this bit to "1" (denoted by the label ADC12ON) turns on the ADC, a vital step to performing any conversion! To actually do this in C, just use addition and an equals sign: ADC12CTL0 = ADC12SHT0_8 + ADC12ON ; ADC12CTL1 Figure 2 In the second control register (ADC12CTL1), we want to set two parameters. aside: Since some of the bit labeling is inconsistent (especially between dierent versions of a microcontroller), it is always good to examine the header le for a controller to see how its aliases are dened before using them in your code.

OpenStax-CNX module: m46087 5 ADC12CTL1 = ADC12SHP + ADC12CONSEQ_0; Figure 3 We also need to set the appropriate input channel to our output memory address in the ADC12MCTL0 register ADC12INCH_x12 bit ADCInput Channel # this 4 bit section determines which of the possible input channels the ADC will actually convert and store into the ADC12MEM0 register. ADC12MCTL = ADC12INCH_0; Lastly, analog conversion must be enabled on the input ports themselves. These act as gates to prevent leakage current from owing from a pin set as an output through the ADC to ground a substantial waste of power. To enable the ADC for your desired GPIO pin, just set the corresponding bit in P6SEL (Port 6 Special Function SELect) to "1". P6SEL = BIT#; For more info about the ADC12's conguration options, see the MSP430 manual starting on page 742. 2.3.3 Using the ADC To read a sample from the ADC, just read from the ADC12MEM register after the sample has completed. while (ADC12CTL1&ADC12BUSY); // Wait in naive loop for conversion to complete my_var= ADC12MEM0; Remember that we have setup the ADC for single conversion and hold, so if you want another value, you will have to tell it to sample and convert again. You do so by modifying two values in ADC12CTL0: ADC12ENC 12bit ADCEnable Conversion locks in the ADC settings and stabilizes it for conversion. ADC12SC12bit ADCStart Conversion setting this bit to one actually triggers the ADC's conversion cycle. ADC12CTL0 = ADC12ENC + ADC12SC; note: Be sure to use OR equal ( =) so that the conguration bits you set before don't get overridden. note: Also, don't forget to congure P3 as usual. You will need to set the pins you wish to use as outputs in the P3DIR register to display a value on the LEDs. You can congure the P3 registers using aliases and variable assignments just like with the ADC registers.

OpenStax-CNX module: m46087 6 3 Assignment Details Using Code Composer Studio 5, write a C language program turning your MSP430 ESCAPE Platform into a simple 10 level voltmeter. Your program should divide the 0-3.3V input range of the ADC into 10 zones, and then output from a 0 to a 9 on the LED display depending on the input voltage from the light sensor. Don't worry about a value landing on the boundary between two zones, just deal with it consistently. Test your volt meter by sampling pin P6.0 and exposing it to dierent light intensities. Your Program should consist of: A "void main(void)" function that drives your program A successful setup routine that properly congures the ADC12 An output routine that loop innitely and successfully re-scales the 4096 ADC possibilities to 10 zones