MSP430F149的ADC12模块
nd VR− = AVSS
100 VR+ = AVCC and VR− = VREF−/ VeREF−
101 VR+ = VREF+ and VR− = VREF−/ VeREF−
110 VR+ = VeREF+ and VR− = VREF−/ VeREF−
111 VR+ = VeREF+ and VR− = VREF−/ VeREF−
INCHx Bits
3-0
Input channel select
0000 A0
0001 A1
0010 A2
0011 A3
0100 A4
0101 A5
0110 A6
0111 A7
1000 VeREF+
1001 VREF−/VeREF−
1010 Temperature sensor
1011 (AVCC – AVSS) / 2
1100 (AVCC – AVSS) / 2
1101 (AVCC – AVSS) / 2
1110 (AVCC – AVSS) / 2
1111 (AVCC – AVSS) / 2
EOS Bit 7 End of sequence. Indicates the last conversion in a sequence.
0 Not end of sequence
1 End of sequence
4实例
4.1 single采样,参考电源为系统电源
1.设置ADC12CTL0,使ADC12通道0采样保持时间为16 ADC12CLK(SHT0_2),开启ADC12模块(ADC12ON);
2.设置ADC12CTL1,选择采样保持脉冲模式即SAMPCON为采样定时器(SHP)
3.设置ADC12IE,是通道0中断使能(0x01);
4.设置ADC12CTL0,使能AD转换(ENC)
5.设置模拟信号输入IO口P60
7.设置ADC12CTL0,开启AD转换(ADC12SC),等待中断
8.中断中读取通道0转换值ADC12MEM0
ADC12CTL0 = SHT0_2 + ADC12ON; // Set sampling time, turn on ADC12
ADC12CTL1 = SHP; // Use sampling timer
ADC12IE = 0x01; // Enable interrupt
ADC12CTL0 |= ENC; // Conversion enabled
P6SEL |= 0x01; // P6.0 ADC option select
P2DIR |= 0x01;
ADC12CTL0 |= ADC12SC;
#pragma vector=ADC12_VECTOR
__interrupt void ADC12_ISR (void)
{
if (ADC12MEM0 < 0x7FF)
P2OUT = 0; // Clear P1.0 LED off
else
P2OUT = 0XFF; // Set P1.0 LED on
__low_power_mode_off_on_exit();
// 与上面等价_BIC_SR_IRQ(CPUOFF); // Clear CPUOFF bit from 0(SR)
}
4.2 single采样参考源为2.5V
在ADC12CTL0中设置参考源
在ADC12MCTL0中为通道0选择参考源
ADC12CTL0 = ADC12ON+SHT0_2+REFON+REF2_5V; // Turn on and set up ADC12
ADC12CTL1 = SHP; // Use sampling timer
ADC12MCTL0 = SREF_1; // Vr+=Vref+
for ( i=0; i<0x3600; i++); // Delay for reference start-up
ADC12CTL0 |= ENC;
while (1)
{
ADC12CTL0 |= ADC12SC; // Start conversion
while ((ADC12IFG & BIT0)==0);
_NOP(); // SET BREAKPOINT HERE
}
4.3 Repeat-single采样,模拟输入为内部Temperature sensor
设置ADC12CTL1,采样保持源为定时器A,脉冲保持模式,Repeat-single模式
ADC12CTL1 = SHS_1 + SHP + CONSEQ_2; // TA trig., rpt conv.
设置ADC12MCTL0,通道0参考源为内部REF,模拟输入通道0选择为Temperature sensor
ADC12MCTL0 = SREF_1 + INCH_10; // Channel A10, Vref+
ADC12IE = 0x01; // Enable ADC12IFG.0
ADC12CTL0 = SHT0_8 + REF2_5V + REFON + ADC12ON + ENC; // Config ADC12
TACCTL1 = OUTMOD_4; // Toggle on EQU1 (TAR = 0)
TACTL = TASSEL_2 + MC_2; // SMCLK, cont-mode
while (!(0x01 & ADC12IFG)); // First conversion?
FirstADCVal = ADC12MEM0; // Read out 1st ADC value
_BIS_SR(LPM0_bits + GIE); // Enter LPM0 w/ interrupt
#pragma vector=ADC12_VECTOR
__interrupt void ADC12ISR (void)
{
if (ADC12MEM0 <= FirstADCVal + ADCDeltaOn)
P1OUT &= ~0x01; // LED off
else P1OUT |= 0x01; // LED on
}
摄氏温度和温度传感器电压转换关系:0摄氏度对应986mv,1摄氏度温差对应1.97mv温差
// oF = ((x/4096)*1500mV)-923mV)*1/1.97mV = x*761/4096 - 468
// IntDegF = (ADC12MEM0 - 2519)* 761/4096
IntDegF = (temp - 2519) * 761;
IntDegF = IntDegF / 4096;
// oC = ((x/4096)*1500mV)-986mV)*1/3.55mV = x*423/4096 - 278
// IntDegC = (ADC12MEM0 - 2692)* 423/4096
IntDegC = (temp - 2692) * 423;
IntDegC = IntDegC / 4096;
4.4 Repeat-sequence mode
Sequence模式时可以设置多个采样通道。在最后一个通道加上EOS就表明的采样通道结束位置。中断允许只需要设置最后一个通道。
为了采样速率尽可能快,可设置MSC,此时当SHI上升沿触发第一次采样后,后面的采样在上一次采样结束后自动进行。
ADC12CTL0 = ADC12ON+MSC+SHT0_8; // Turn on ADC12, extend sampling time
// to avoid overflow of results
ADC12CTL1 = SHP+CONSEQ_3; // Use sampling timer, repeated sequence
ADC12MCTL0 = INCH_0; // ref+=AVcc, channel = A0
ADC12MCTL1 = INCH_1; // ref+=AVcc, channel = A1
A
MSP430F149ADC12模 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)