Chung-Ta King National Tsing Hua University

Slides:



Advertisements
Similar presentations
Why Keliang’s code maybe did (or maybe didn’t) work … or High (impedance) Anxiety.
Advertisements

Lab 1 I/O, timers, interrupts on the eZ430-RF2500 Thomas Watteyne EE290Q – Spring 2010
UBI >> Contents Chapter 7 Timers Laboratories MSP430 Teaching Materials Texas Instruments Incorporated University of Beira Interior (PT) Pedro Dinis Gaspar,
Interrupts, Low Power Modes and Timer A (Chapters 6 & 8)
Chung-Ta King National Tsing Hua University
Chung-Ta King National Tsing Hua University
Chapter 9 Data Acquisition SAR ADC
ECE 447 Fall 2009 Lecture 9: TI MSP430 Interrupts & Low Power Modes.
Instructor: Dr Aleksandar Milenkovic Lecture Notes
Introduction of Holtek HT-46 series MCU
LAB 6: Serial Communication
Notes on the ez430-RF2500. Sources
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
Timers. Range of timers Watchdog timer: Included in all devices (watchdog timer+). Its main function is to protect the system against malfunctions but.
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.
ARM Timers.
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.
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.
SIGMA-DELTA ADC SD16_A Sigma-Delta ADC Shruthi Sujendra.
Lecture 11: TI MSP430 Timers Compare Modes
LAB 8: Program Design Pattern and Software Architecture
Ultra-low Power Motion Detection using the MSP430F2013.
WISP.
TI MSP430 MICROCONTROLLERS BY ADITYA PATHAK. THE MSP FAMILY Ultra-low power; mixed signal processors Widely used in battery operated applications Uses.
ECE 447 Fall 2009 Lecture 7: MSP430 Polling and Interrupts.
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.
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.
Recall the Container Thermometer
Recall the Container Thermometer
Introduction to MSP430G2553 and MPU6050
Introduction Why low power?
Introduction Why low power?
CS4101 嵌入式系統概論 General Purpose IO
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
CS4101 Introduction to Embedded Systems Lab 6: Low-Power Optimization
68HC11 Interrupts & Resets.
CS4101 嵌入式系統概論 Interrupts Prof. Chung-Ta King
Refer to Chapter 5 in the reference book
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
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.
Subject Name: Microcontroller Subject Code: 10ES42
CS4101 Introduction to Embedded Systems Lab 4: Interrupt
I/O PORTS : MSP430x5xx devices have up to 12 digital I/O ports :
ECE 3430 – Intro to Microcomputer Systems
MSP430 Teaching Materials
CPE 323 Introduction to Embedded Computer Systems: DMA Controller
Lecture 9: TI MSP430 Interrupts & Low Power Modes
MSP432™ MCUs Training Part 6: Analog Peripherals
CS4101 Introduction to Embedded Systems Lab 2: Basic IO and Timer
Prof. Chung-Ta King Department of Computer Science
MSP430 Clock System and Timer
ECE 3567 Microcontroller Lab
ECE 3567 Microcontrollers Lab
Presentation transcript:

Chung-Ta King National Tsing Hua University CS 4101 Introduction to Embedded Systems LAB 5: ADC Chung-Ta King National Tsing Hua University

Introduction In this lab, we will learn The configuration of ADC10 The use of ADC10 to detect the internal temperature of LauchPad

ADC of MSP430 Provide continuous sampling of multiple analog inputs and store sampled data

ADC of MSP430 Provide continuous sampling of multiple analog inputs and store sampled data Interrupt CPU on every word sampled from ADC Use software (ISR run by the CPU) to move data from ADC to memory

ADC of MSP430 Provide continuous sampling of multiple analog inputs and store sampled data Use hardware (Data Transfer Controller, DTC) to move data from ADC to memory Interrupt CPU when block transfer is completed

Simplified Block Diagram of ADC10 Voltage reference Clock sources Conversion trigger

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 while the module is being configured in the previous step. (3) Trigger the conversion, either by setting the ADC10SC bit or by an edge from Timer_A. ADC10ON, ENC, ADC10SC are all in control register ADC10CTL0

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 9

ADC10CTL0 ideal for the temperature sensor

ADC10CTL0 cont’d ADC10CTL0 = SREF_1 + ADC10SHT_2 + REFON + ADC10ON + ADC10IE; // Reference range & SH time 11

ADC10CTL1 12

ADC10CTL1 cont’d ADC10CTL1 = INCH_10 + ADC10DIV_0; // Temp, ADC10CLK 13

Sample Code 1 for ADC10 Repetitive single conversion: A single sample is made on A1 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 "msp430g2231.h" void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT // H&S time 16x, interrupt enabled ADC10CTL0 = ADC10SHT_2 + ADC10ON + ADC10IE; ADC10CTL1 = INCH_1; // Input A1 ADC10AE0 |= 0x02; // Enable pin A1 for analog in P1DIR |= 0x01; // Set P1.0 to output for (;;) { ADC10CTL0 |= ENC + ADC10SC; // Start sampling __bis_SR_register(CPUOFF + GIE); // Sleep if (ADC10MEM < 0x1FF) // 0x1FF = 511 P1OUT &= ~0x01; // Clear P1.0 LED off else P1OUT |= 0x01; // Set P1.0 LED on } } 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. 15 15 15

Sample Code 1 for ADC10 // 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) } 16 16 16

Sample Code 2 for ADC10 Continuous sampling driven by Timer_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. Timer_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 "msp430g2231.h" 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. TACCR0 = 30; // Delay for Volt Ref to settle TACCTL0 |= CCIE; // Compare-mode interrupt. TACTL = TASSEL_2 + MC_1; // SMCLK, Up mode. LPM0; // Wait for settle. TACCTL0 &= ~CCIE; // Disable timer Interrupt __disable_interrupt(); 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. 18 18 18

Sample Code 2 for ADC10 ADC10CTL0 |= ENC; // ADC10 Enable ADC10AE0 |= 0x02; // P1.1 ADC10 option select P1DIR |= 0x01; // Set P1.0 output TACCR0 = 2048; // Sampling period TACCTL1 = OUTMOD_3; // TACCR1 set/reset TACCR1 = 2047; // TACCR1 OUT1 on time TACTL = TASSEL_1 + MC_1; // ACLK, up mode // Enter LPM3 w/ interrupts __bis_SR_register(LPM3_bits + GIE); } Timer_A CCR1 out mode 3: The output (OUT1) is set when the timer counts to the TACCR1 value. It is reset when the timer counts to the TACCR0 value. 19 19 19

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){ TACTL = 0; LPM0_EXIT; // Exit LPM0 on return 20 20 20

Basic Lab Measure the temperature of MSP430 every second using the temperature sensor inside ADC10. Flash the red LED if the temperature rises and the green LED if it drops. Flash both LEDs if the temperature remains unchanged between two consecutive measurements. The sampling of ADC10 must be triggered continuously by Timer_A. You can use an infinite loop to flash the LEDs. Clocking: MCLK and SMCLK = 1.1MHz // ACLK = 12kHz VLO

Set DCO as src of MCLK, 1 MHz, and VLO as ACLK Close watchdog timer Set DCO as src of MCLK, 1 MHz, and VLO as ACLK Setup both LED lights and set it initially off You can modify the sample code 2 to finish the basic, you can first set timer_A source from MCLK(DCO) to settle 30 micro second delay, and then set timer_A source from ACLK(VLO). Set ADC configuration into: Sample-and-hold source from timer_A Temperature sensor channel Use ideal reference Conversion sequence mode : Repeat-single-channel Enable ADC10 interrupt Every second ADC10IFG is set when conversion results(temperature) are loaded into ADC10MEM and invoke ADC ISR.

Bonus Enable button interrupt. Every time the button is pushed, measure the temperature of MSP430. If the temperature is higher than 737, turn on the red light for a second. Otherwise, turn on the green light for a second.