Prof. Chung-Ta King Department of Computer Science

Slides:



Advertisements
Similar presentations
Interrupts, Low Power Modes and Timer A (Chapters 6 & 8)
Advertisements

Chung-Ta King National Tsing Hua University
Chung-Ta King National Tsing Hua University
Chung-Ta King National Tsing Hua University
ECE 447 Fall 2009 Lecture 9: TI MSP430 Interrupts & Low Power Modes.
2008EECS Dealing with Analog Signals A Microcontroller View Jonathan Hui University of California, Berkeley.
Introduction of Holtek HT-46 series MCU
LAB 6: Serial Communication
Notes on the ez430-RF2500. Sources
Timers and Interrupts Shivendu Bhushan Summer Camp ‘13.
CS4101 嵌入式系統概論 Timers and Clocks 金仲達教授 國立清華大學資訊工程學系 Materials from MSP430 Microcontroller Basics, John H. Davies, Newnes, 2008.
CS4101 嵌入式系統概論 Software UART Revisited Prof. Chung-Ta King Department of Computer Science National Tsing Hua University, Taiwan ( Materials from MSP430.
Chung-Ta King National Tsing Hua University
LAB 7: WDT+ and Low-Power Optimization
T IMERS - 2. O UTPUT U NIT Each capture/compare block contains an output unit. The output unit is used to generate output signals such as PWM signals.
Lecture 18: ADC Implementation Lecturers: Professor John Devlin.
EE 1106: Introduction to EE Freshman Practicum
7/23 Timers in Coldfire Processor Computer Science & Engineering Department Arizona State University Tempe, AZ Dr. Yann-Hang Lee (480)
MSP430 Mixed Signal Microcontroller – Parte 2 Afonso Ferreira Miguel Source: slau056d – Texas instruments.
CPE 323 Introduction to Embedded Computer Systems: Watchdog Timer, Timer A Instructor: Dr Aleksandar Milenkovic Lecture Notes.
Lab 5 System Design Thomas Watteyne EE290Q – Spring 2010
MCU: Interrupts and Timers Ganesh Pitchiah. What’s an MCU ?
CS4101 嵌入式系統概論 Analog-to-Digital Converter 金仲達教授 國立清華大學資訊工程學系 ( Materials from MSP430 Microcontroller Basics, John H. Davies, Newnes, 2008 )
CPE 323 Introduction to Embedded Computer Systems: ADC12 and DAC12 Instructor: Dr Aleksandar Milenkovic Lecture Notes.
Lecture 11: TI MSP430 Timers Compare Modes
LAB 8: Program Design Pattern and Software Architecture
Ultra-low Power Motion Detection using the MSP430F2013.
UBI >> Contents Lecture 8 SAR ADC MSP430 Teaching Materials Texas Instruments Incorporated University of Beira Interior (PT) Pedro Dinis Gaspar, António.
Network and Systems Laboratory nslab.ee.ntu.edu.tw.
Lab 3: ADC.
UNIT 2. CPUXV2 20-bit addressing User-definable Boot Strap Loader RAM starts at 0x1C00 Beginning of MAIN flash moves according to RAM Vector table starts.
Chapter 7 ADC, DAC, and Sensor Interfacing 1. Microcontroller Connection to Sensor via ADC 2.
ECE 382 Lesson 32 Lesson Outline Lab 6 Introduction Pulse Width Modulation Capture / Compare Example Lab 6 Tips Admin Lab#6 “prelab” due BOC lesson 33.
Application Case Study Christmas Lights Controller
Recall the Container Thermometer
Recall the Container Thermometer
Chapter 10 Digital-to-Analogue Conversion
Introduction to MSP430G2553 and MPU6050
Introduction Why low power?
Introduction Why low power?
CS4101 嵌入式系統概論 General Purpose IO
Outline Analog to digital conversion (ADC) of NuMaker TRIO
ECE 3430 – Intro to Microcomputer Systems
Lecture 8: TI MSP430 Interrupts, ISRs
CS4101 嵌入式系統概論 Interrupts Prof. Chung-Ta King
Lesson Outline Interrupts Admin Assignment #9 due next lesson
PWM and DC Motor Control
CS4101 Introduction to Embedded Systems Lab 6: Low-Power Optimization
EMBEDDED SYSTEMS Unit 3.
CS4101 嵌入式系統概論 Interrupts Prof. Chung-Ta King
CS4101 Introduction to Embedded Systems Lab 1: General Purpose IO
Prof. Chung-Ta King Department of Computer Science
ECE 3430 – Intro to Microcomputer Systems
CS4101 嵌入式系統概論 General Purpose IO
Instructor: Dr Aleksandar Milenkovic Lecture Notes
MSP432 ARM Timer Programming
National Tsing Hua University CS4101 Introduction to Embedded Systems Lab 2: Timer and Clock Prof. Chung-Ta King Department of Computer Science National.
National Tsing Hua University CS4101 Introduction to Embedded Systems Lab 3: Interrupt Prof. Chung-Ta King Department of Computer Science National Tsing.
National Tsing Hua University CS4101 Introduction to Embedded Systems Lab 6: Serial Communication Prof. Chung-Ta King Department of Computer Science National.
ECE 3430 – Intro to Microcomputer Systems
CS4101 Introduction to Embedded Systems Lab 7: Serial Communication
CS4101 Introduction to Embedded Systems Lab 4: Interrupt
MSP430 Teaching Materials
CS4101 Introduction to Embedded Systems Lab 7: Serial Communication
Lecture 9: TI MSP430 Interrupts & Low Power Modes
CS4101 Introduction to Embedded Systems Lab 2: Basic IO and Timer
MSP430 Clock System and Timer
ECE 3567 Microcontroller Lab
ECE 3567 Microcontrollers Lab
A modular robot for use in the RoboSumo lab
Presentation transcript:

CS4101 Introduction to Embedded Systems Lab 5: Analog-to-Digital Converter Prof. Chung-Ta King Department of Computer Science National Tsing Hua University, Taiwan

Introduction In this lab, we will learn ADC of MSP430 Configuration of ADC10 Use of ADC10 to measure the temperature of LauchPad

Simplified Block Diagram of ADC10 Voltage reference Clock sources Conversion trigger

ADC10 Registers Where the data is saved Register Short Form Register Type Addr. Initial State ADC10 input enable register 0 ADC10AE0 Read/write 04Ah Reset with POR ADC10 input enable register 1 ADC10AE1 04Bh ADC10 control register 0 ADC10CTL0 01B0h ADC10 control register 1 ADC10CTL1 01B2h ADC10 memory ADC10MEM Read 01B4h Unchanged ADC10 data transfer control register 0 ADC10DTC0 048h ADC10 data transfer control register 1 ADC10DTC1 049h ADC10 data transfer start address ADC10SA 01BCh 0200h with POR power-on reset (PoR) Where the data is saved 3

Enabling Sampling and Conversion

Steps for Single Conversion (1) Configure ADC10, including the ADC10ON bit to enable the module. The ENC bit must be clear so that most bits in ADC10CTL0 and ADC10CTL1 can be changed. (2) Set the ENC bit to enable a conversion. This cannot be done if the module is being configured in (1). (3) Trigger the conversion. This is done either by setting the ADC10SC bit or by an edge from Timer_A. ADC10ON, ENC, ADC10SC are all in control register ADC10CTL0

ADC10CTL0 ideal for the temperature sensor 6

ADC10CTL0 cont’d The settling time for the internal reference is < 30µs. A value of 5 cycles would be 40µs. We should allow thirteen ADC10CLK cycles before we read the conversion result. Thirteen cycles of the 5MHz ADC10CLK is 2.6µs. Even a single cycle of the DCO/8 would be longer than that. When the conversion is complete, the encoder and reference need to be turned off. ADC10CTL0 = SREF_2 + ADC10SHT_1; // Reference range & SH time 7

ADC10CTL1 8

ADC10CTL1 cont’d ADC10CTL1 = INCH_10 + ADC10DIV_0; // Temp Sensor ADC10CLK 9

Sample Code 1 for ADC10 Repetitive single conversion: A single sample is made on A1 (pin P1.1) with reference to Vcc If A1 > 0.5*Vcc, P1.0 set, else reset. Software sets ADC10SC to start sample and conversion. ADC10SC automatically cleared at end of conversion. Use ADC10 internal oscillator to time the sample and conversion.

Sample Code 1 for ADC10 #include "msp430.h" void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT // H&S time 16x, interrupt enabled ADC10CTL0 = ADC10SHT_2 + ADC10ON + ADC10IE; ADC10CTL1 = INCH_1; // Input from A1 ADC10AE0 |= 0x02; // Enable pin A1 for analog in P1DIR |= 0x01; // Set P1.0 to output ADC10CTL0 |= ENC + ADC10SC; // Start sampling for (;;) { } } #pragma vector=ADC10_VECTOR __interrupt void ADC10_ISR(void) { if (ADC10MEM < 0x1FF) P1OUT &= ~0x01; else P1OUT |= 0x01; ADC10CTL0 |= ENC + ADC10SC; // enable sampling Pulse-width modulation (PWM): The load is switched on and off periodically so that the average voltage has the desired value. The fraction of the time while the load is active is called the duty cycle D. 11 11

Sample Code 2 for ADC10 Continuous sampling driven by Timer0_A A1 is sampled 16/second (ACLK/2048) with reference to 1.5V, where ACLK runs at 32 KHz driven by an external crystal. If A1 > 0.5Vcc, P1.0 is set, else reset. Timer0_A is run in up mode and its CCR1 is used to automatically trigger ADC10 conversion, while CCR0 defines the sampling period Use internal oscillator times sample (16x) and conversion (13x).

Sample Code 2 for ADC10 #include "msp430.h“ int i=1; void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT // TA1 trigger sample start ADC10CTL1 = SHS_1 + CONSEQ_2 + INCH_1; ADC10CTL0 = SREF_1 + ADC10SHT_2 + REFON + ADC10ON + ADC10IE; __enable_interrupt(); // Enable interrupts TA0CCR0 = 30; // Delay for Volt Ref to settle TA0CCTL0 |= CCIE; // Compare-mode interrupt TA0CTL = TASSEL_2 + MC_1; // SMCLK, Up mode while(i); // Wait for settle TA0CCTL0 &= ~CCIE; // Disable timer Interrupt __disable_interrupt(); SHS_1: S&H triggering source  OUT1 CONSEQ_2: Conversion sequence mode select (Repeat-single-channel) SREF_1: Select reference (VR+ = VREF+ and VR- = VSS) ADC10SHT_2: Sample-and-hold time (6 × ADC10CLKs) REFON: reference generator on 13 13

Sample Code 2 for ADC10 ADC10CTL0 |= ENC; // ADC10 Enable ADC10AE0 |= 0x02; // P1.1 ADC10 option select P1DIR |= 0x01; // Set P1.0 output TA0CCR0 = 2048-1; // Sampling period TA0CCTL1 = OUTMOD_3; // TACCR1 set/reset TA0CCR1 = 2046; // TACCR1 OUT1 on time TA0CTL = TASSEL_1 + MC_1; // ACLK, up mode while(1); } Timer0_A CCR1 out mode 3: The output (OUT1) is set when the timer counts to the TA0CCR1 value. It is reset when the timer counts to the TA0CCR0 value. 14 14

Sample Code 2 for ADC10 // ADC10 interrupt service routine #pragma vector=ADC10_VECTOR __interrupt void ADC10_ISR(void){ if (ADC10MEM < 0x155) // ADC10MEM = A1 > 0.5V? P1OUT &= ~0x01; // Clear P1.0 LED off else P1OUT |= 0x01; // Set P1.0 LED on } #pragma vector=TIMERA0_VECTOR __interrupt void ta0_isr(void){ TA0CTL = 0; i = 0 15 15

Lab 5 Basic 1: Flash red and green LED at 1 Hz based on the interrupt from TA1R of Timer1_A driven by ACLK sourced by VLO. The red LED should be on for 0.4 sec and off for 0.6 sec based on the interrupt from TA1CCR0. The green LED should be on for 0.2 sec and off for 0.8 sec, based on the interrupt from TA1CCR1. Enable button interrupt. Every time the button is pushed, measure the temperature, convert it to Celsius scale, and assign it into a variable. Show the value of the variable in the debug mode of CCS. Lab 4 Basic 1

Lab 5 Basic 1: (cont’d) Use 1.5V voltage reference. Choose single-channel-single- conversion as the conversion sequence mode and ADC10SC as the triggering source. Hint: V = 0.00355 * C + 0.986, where V is Voltage and C is Celsius

Lab 5 Basic 2: Measure the temperature of MSP430 every 0.5 second. Flash both LEDs at 1 Hz if the average temperature of the last 2 seconds remains unchanged between two consecutive measurements. Flash the red LED at 2 Hz if the average temperature rises and the green LED at 1 Hz if it drops. Choose repeat-single-conversion as the conversion sequence mode The sampling of ADC10 must be triggered continuously by Timer0_A.

Lab 5 Bonus: Repeat Basic 2 but handle all the events (timer up, DAC done, …) with interrupts.