90 likes | 102 Views
第九章 MSP430 的 ACD 模組. ADC 簡介. 取樣 (sampling). 類比 Analog continuous. 數位 Digital discrete (discontinuous). ADC 簡介. ADC 簡介. 12-Bit ADC Core. Ex. 當 V R- = 0V, V R+ = 2.5V, 若 Vin= 1V 時, N ADC = ? . ADC_01.C. 以電源供應器供給固定電壓,並觀察 ADC12MEM0 暫存器內容. ADC_01.C. ADC_01.C. V REF =3.3V. ADC_02.C.
E N D
ADC簡介 • 取樣(sampling) • 類比Analog continuous • 數位Digitaldiscrete (discontinuous)
12-Bit ADC Core • Ex. 當VR-=0V, VR+=2.5V, 若Vin=1V時,NADC= ?
ADC_01.C • 以電源供應器供給固定電壓,並觀察ADC12MEM0暫存器內容
ADC_01.C • VREF=3.3V
ADC_02.C void main(void) { WDTCTL = WDTPW+WDTHOLD; // Stop watchdog timer P6SEL |= 0x01; // Enable A/D channel A0 ADC12CTL0 = ADC12ON+SHT0_2; // Turn on ADC12, set sampling time ADC12CTL1 = SHP; // Use sampling timer ADC12CTL0 |= ENC; // Enable conversions P1DIR |= 0x0f; while (1) { ADC12CTL0 |= ADC12SC; // Start conversion while ((ADC12IFG & BIT0)==0); // Check ADC interrupt flag if(ADC12MEM0>620) if(ADC12MEM0>1241) if(ADC12MEM0>1861) if(ADC12MEM0>2482) P1OUT = 0x00; // Vin > 2.0Volt 4 LED else P1OUT = 0x08; // 2.0Volt > Vin > 1.5Volt 3 LED else P1OUT = 0x0C; // 1.5Volt > Vin > 1.0Volt 2 LED else P1OUT = 0x0E; // 1.0Volt > Vin > 0.5Volt 1 LED else P1OUT = 0x0F; // 0.5Volt > Vin 0 LED } } • VREF=3.3V利用ADC的功能,偵測由電源供應器輸入電壓大小,並反映至LED燈的點亮數目。