270 likes | 607 Views
The Analog-to-Digital Converter. Presented by IEEE of Texas A&M. About This Workshop. Based on the MSP430G2553 microcontroller by Texas Instruments Powerpoint and code available at ieeetamu.org/mcc/ theadc Workshop Reference available at ieeetamu.org/mcc/ wsref
E N D
The Analog-to-Digital Converter Presented by IEEE of Texas A&M
About This Workshop • Based on the MSP430G2553 microcontroller by Texas Instruments • Powerpoint and code available at ieeetamu.org/mcc/theadc • Workshop Reference available at ieeetamu.org/mcc/wsref • Footnotes refer to User Guide (UG), Datasheet, or Workshop Reference (WSRef) Example: UG §1.2.3, DS §4.5.6, WSRef §7.8.9
Import code projects into Code Composer • Follow instructions in the Workshop Reference or at ieeetamu.org/mcc/importing • Code: ieeetamu.org/mcc/theadc • Projects to import: • Photoresistor • Temperature WSRef § 1.2
Extremely Useful Documents • User's Guide – MSP430x2xx Family • ieeetamu.org/msp430ug • All general MSP430 information • Ex: MSP430 Architecture, Instruction Set, Registers, clocks, timers, module types and functionality • MSP430G2x53 Datasheet • ieeetamu.org/msp430ds • Information specific to individual set of chips • Ex: List of included modules, pin-outs, memory size
Analog-to-Digital Converter (ADC) Definition of ADC: “A device that converts a continuous physical quantity to a digital number that represents the quantity’s amplitude” - wikipedia
How ADC Works Analog-to-Digital Converter Analog Signal Digital Signal “Simplified” Flowchart
Applications of ADC Examples of analog signals that can be converted to digital signals: - Sound - Pressure - Temperature* - Light* - And more…
ADC on the MSP430 • One 10 Bit ADC module • 8 channels • 50-200 kilo-samples per second
ADC Temperature Example MSP430 Temperature LED Analog-to-Digital Converter Analog Signal Digital Signal
ADC Temperature Example • Open/Run temperature.cpp • Placing your finger on the M430g2553 chip to increase the temperature • The red LED should begin to blink faster
ADC Temperature Example #include"msp430g2553.h" staticsignedintadcStart = 0; staticsignedintcurrentDelay = 0; void main(void) { WDTCTL = WDTPW + WDTHOLD; P1DIR = BIT0; P1OUT = 0; ADC10CTL0 = SREF_1 + ADC10SHT_3 + REF2_5V + ADC10IE + REFON + ADC10ON; ADC10CTL1 = ADC10DIV_3 + INCH_10 + SHS_0 + CONSEQ_2 + ADC10SSEL_2;
ADC Temperature Example • ADC10CTL0 |= ENC + ADC10SC; • while(!(ADC10IFG & ADC10CTL0)) {} • adcStart = ADC10MEM;
ADC Temperature Example while(1) { ADC10CTL0 &= ~(ADC10SC); ADC10CTL0 |= ENC + ADC10SC; while(!(ADC10IFG & ADC10CTL0)) { } currentDelay= ((6 - (ADC10MEM - adcStart))); currentDelay*= currentDelay; P1OUT ^= BIT0; for(inti = 0; i < currentDelay; i++) { __delay_cycles(5000); } }
Photoresistor Definition: A resistor whose resistance decreases with increasing incident light intensity Small resistance lots of light Large resistance Little light
ADC Photoresistor Example #include"msp430g2553.h" intview_input = 0; voidmain(void) { WDTCTL = WDTPW + WDTHOLD; ADC10CTL0 = SREF_1 + REF2_5V + REFON + ADC10SHT_2 + ADC10ON + ADC10IE; ADC10CTL1 = INCH_1 ADC10AE0 |= BIT1; P1DIR |= BIT0; intADC_count = 0;
ADC Photoresistor Example while(1) { P1OUT ^= BIT0; while(ADC_count< 1000) { ADC10CTL0 |= ENC + ADC10SC; while(!(ADC10IFG & ADC10CTL0)) { } ADC_count+= ADC10MEM; __delay_cycles(100000); } ADC_count= 0; }
Changing the Reference Voltage Reference-generator voltage. (REFON must also be set.) • REF2_5V Bit 6 • 0 1.5 V • 1 2.5 V Reference generator on • REFON Bit 5 • 0 Reference off • 1 Reference on ADC10 on • ADC10ON Bit 4 • 0 ADC10 off • 1 ADC10 on
Changing the Reference Voltage Using SREF_1, and REF2_5V, try setting the reference voltage to 1.5V, 2.5V, and Vcc.
Changing the Reference Voltage • Using SREF_1, and REF2_5V, try setting the reference voltage to 1.5V, 2.5V, and Vcc. ADC10CTL0 = SREF_1 + REFON + ADC10SHT_2 + ADC10ON + ADC10IE; // 1.5V ADC10CTL0 = SREF_1 + REF2_5V + REFON + ADC10SHT_2 + ADC10ON + ADC10IE;// 2.5V ADC10CTL0 = REFON + ADC10SHT_2 + ADC10ON + ADC10IE; // Vcc
The Reference Voltage All ADCs need a reference voltage which an input voltage may be compared to Available for ADC10: • VCC (upper) • VSS (lower) • VEREF- (lower) (external references) • VEREF+ (upper) • VREF- (lower) (internal references) • VREF+ (upper) See 22.2.3, page 537, of user guide for details