Prof. Chung-Ta King Department of Computer Science

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
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.
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.
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.
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.
Introduction In this lab , we will learn
Recall the Container Thermometer
Recall the Container Thermometer
Lab 7 Basic 1: Game of Memory
Introduction In this lab , we will learn
Outline Introduction to digital-to-analog converter (DAC)
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 Introduction to Embedded Systems Lab 10: Tasks and Scheduling
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
CS4101 Introduction to Embedded Systems Lab 1: MSP430 LaunchPad IDE
CS4101 嵌入式系統概論 Interrupts Prof. Chung-Ta King
Chapter 6 General Purpose Input/Output
CS4101 Introduction to Embedded Systems Lab 1: General Purpose IO
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.
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
Prof. Chung-Ta King Department of Computer Science
MSP430 Clock System and Timer
ECE 3567 Microcontroller Lab
ECE 3567 Microcontrollers Lab
ECE 3567 Microcontroller Lab
A modular robot for use in the RoboSumo lab
Presentation transcript:

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

Sample Code 1 for ADC10 Repetitive single conversion: Repetitively perform single samples on A1 (pin P1.1) with reference to Vcc If A1 > 0.5*Vcc, P1.0 set, else reset. Set ADC10SC to start sample and conversion But ADC10SC automatically cleared at end of conversion. Enable the next conversion in ISR of ADC10 and iterate Use ADC10 internal oscillator to time the sample and conversion

Sample Code 1 for ADC10 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 Why not read ADC10MEM right after setting ADC10CTL0? While wait for interrupt? What is the time to go through one iteration? Any one of the pins of Port 1 can be set to be an analog input. Thus up to 8 channels are available for separate ADC inputs. Analog Enable control register ADC10AE0 will be use for enabling the corresponding input channels. 2 2

Sample Code 2 for ADC10 Continuous sampling driven by Timer0_A3 A1 is sampled 16/second with reference to 1.5V, where ACLK runs at 32 KHz driven by an external crystal (2048 ACLK cycles give 1/16 second (ACLK/2048)) If A1 > 0.5V, P1.0 is set, else reset. Timer0_A3 is run in up mode with CCR0 defining the sampling period (2048 cycles) Use CCR1 to automatically trigger ADC10 conversion

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: internal reference generator on The settling time for the internal reference is < 30µs. If DCOCLK is 1 MHz, then 1 cycle takes 6µs and 30 cycles gives long enough delay for the internal reference voltage to settle down. How to break? 4 4

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 and is reset when the timer counts to the TA0CCR0 value. 5 5

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; Where do these two ISRs return to? Break the while loop in main() that waits for the internal voltage reference to settle 6 6

Lab 4 Basic 1: Flash the red and green LED alternatively on interrupts from button releases. The LEDs flash at 1 Hz (0.3 sec on and 0.7 sec off) by interrupts (ACLK sourced from VLO). Every time the button is pushed, measure the temperature once, convert it to Celsius and store in a variable. Show the value of the variable in the debug mode of CCS. Use 1.5V voltage reference, the single-channel-single- conversion mode, and the triggering source of ADC10SC. Hint: V = 0.00355 * C + 0.986, where V is Voltage and C is Celsius If voltage >= 1.125V, change LED flash frequency to 2 Hz (0.3 sec on and 0.2 sec off); otherwise, back to 1 Hz.

Lab 4 Basic 2: When the button is up, neither of the LEDs is on. When the button is down, only flash the green LED at 1 Hz (0.3 sec on and 0.7 sec off) with ACLK sourced from VLO. While the button is pressed, measure the temperature every 0.5 sec, using repeat-single-conversion mode triggered continuously by Timer0_A3. If the average temperature of the last second rises, then flash the red LED instead (on for 0.2 sec and off for 0.8 sec), which is controlled by Timer1_A3 driven by SMCLK sourced by DCO. Otherwise, flash the green LED as specified above. All events must be detected and handled by interrupts.