MSP430F149的ADC12应用
MSP430F149的ADC12应用
1 概述
MSP430F149的ADC12为SAR型12位AD,共有16路输入通道,其中8路独立的外部输入通道,2路接外部Vref+,Vref-,3路内部通道可分别测内部温度传感器、AVCC、和外部参考源。
P6口第二功能为AD输入端。MSP430F149的10、11分别接外部电压参考源正负极,7脚可将内部电压参考源输出。
ADC12共有18个中断源,公用一个中断向量ADC12_VECTOR。
AD的参考源可选择内部电压参考源或外部电压参考源。内部电压参考源有1.5V,2.5V可选,使用时向ADC12CTL0写入REFON+ REF2_5V就打开了2.5V。外部电压参考源由REF+接入。上电时若不设置参考源,则参考源为系统供电电压3.3V。
参考框图:
2 使用方法概述
2.1程序架构
中断方式
- 1、设置 ADC12工作模式,启动转换,开全局中断,等待中断
- 2、写中断处理函数
查询方式
- 设置ADC12工作模式,启动转换,查询中断标志ADC12IFG
while (!(0x01 & ADC12IFG));
- 转换完毕读取采样值,系统自动清除中断标志
- 设置ADC12工作模式,启动转换,查询中断标志ADC12IFG
2.2 使用概述
主要参数进行配置
- 设置工作方式:四种方式选一: sing;sequence;re-sing;re-sequence;
- 设置转换时间:SHTx
- 设置触发源:ADC12SC;MSC;TimerA;TimerB
- 设置通道:外部通道;内部Temperature sensor
- 设置参考电压:系统电压;内部参考源;外部参考源
- 其他细节配置
一般要配置采样转换模式为脉冲(SHP),打开ADC12(ADC12ON),使能ADC12转换(ENC),使能中断(如果采取中断模式),触发转换(若采用ADC12SC触发)。
ADC12模数转换是在SHI的上升沿初始化的。
SHI信号有四个来源–参考ADC12CTL1寄存器说明:
- The ADC12SC bit;
- The Timer_A Output Unit 1;
- The Timer_B Output Unit 0;
The Timer_B Output Unit 1。
故单次采样时只需要每次设置ADC12CTL0 |= ADC12SC就采样一次;重复采样时,如Rep-sing,设置ADC12CTL1 = SHS_1 +CONSEQ_2就选择了Rep-sing模式,每次采样通过定时器A触发。
3 相关寄存器
1、ADC12CTL0
SHT1x Bits:15-12; Sample-and-hold time.
These bits define the number of ADC12CLK cycles in the sampling period for registers ADC12MEM8 to ADC12MEM15.
SHT0x Bits: 8-11; Sample-and-hold time.
These bits define the number of ADC12CLK cycles in the sampling period for registers ADC12MEM0 to ADC12MEM7.
MSC: Bit 7; Multiple sample and conversion.
Valid only for sequence or repeated modes.
0 : The sampling timer requires a rising edge of the SHI signal to trigger each sample-and-conversion.
1 : The first rising edge of the SHI signal triggers the sampling timer, but further sample-and-conversions are performed automatically as soon as the prior conversion is completed.
- ADC12ON : Bit 4; ADC12 on
- 0 : ADC12 off
- 1 : ADC12 on
- ENC: ENC Bit 1; Enable conversion
- 0 : ADC12 disabled
- 1 : ADC12 enabled
- ADC12SC: Bit 0; Start conversion.
Software-controlled sample-and-conversion start. ADC12SC and ENC may be set together with one instruction. ADC12SC is reset automatically.- 0 : No sample-and-conversion-start
- 1 : Start sample-and-conversion
2、ADC12CTL1
CSTARTADDx: Bit 15-12;
Conversion start address. These bits select which ADC12 conversion-memory register is used for a single conversion or for the first conversion in a sequence. The value of CSTARTADDx is 0 to 0Fh, corresponding to ADC12MEM0 to ADC12MEM15.
SHSx: Bits 11-10; Sample-and-hold source select
- 00 : ADC12SC bit
- 01 : Timer_A.OUT1
- 10 : Timer_B.OUT0
- 11 : Timer_B.OUT1
SHP:Bit 9; Sample-and-hold pulse-mode select.
This bit selects the source of the sampling signal (SAMPCON) to be either the output of the sampling timer or the sample-input signal directly.
- 0 SAMPCON signal is sourced from the sample-input signal.
- 1 SAMPCON signal is sourced from the sampling timer.
- ISSH: Bit 8; Invert signal sample-and-hold
- 0 The sample-input signal is not inverted.
- 1 The sample-input signal is inverted.
ADC12DIVx: Bits 7-5; ADC12 clock divider
- 000 /1
- 001 /2
- 010 /3
- 011 /4
- 100 /5
- 101 /6
- 110 /7
- 111 /8
ADC12 SSELx: Bits 4-3; ADC12 clock source select.
- 00 ADC12OSC
- 01 ACLK
- 10 MCLK
- 11 SMCLK
CONSEQx: Bits 2-1; Conversion sequence mode select
- 00 : Single-channel, single-conversion
- 01 : Sequence-of-channels
- 10 : Repeat-single-channel
- 11 : Repeat-sequence-of-channels
ADC12 BUSY: Bit 0; ADC12 busy. This bit indicates an active sample or conversion operation.
- 0 No operation is active.
- 1 A sequence, sample, or conversion is active.
3、ADC12IE
ADC12 Interrupt Enable Register
- ADC12IEx: Bits 15-0
Interrupt enable. These bits enable or disable the interrupt request for the ADC12IFGx bits.
– 0 : Interrupt disabled
– 1 : Interrupt enabled
4、ADC12IFG
ADC12 Interrupt Flag Register
- ADC12IFGx Bits 15-0
ADC12MEMx Interrupt flag. These bits are set when corresponding
ADC12MEMx is loaded with a conversion result. The ADC12IFGx bits are
reset if the corresponding ADC12MEMx is accessed, or may be reset with software.
- 0 : No interrupt pending
- 1 : Interrupt pending
5、ADC12MCTLX
ADC12 Conversion Memory Control Registers
- EOS: Bit 7; End of sequence.
Indicates the last conversion in a sequence.
- 0 Not end of sequence
- 1 End of sequence
SREFx: Bits 6-4; Select reference
- 000 VR+ = AVCC and VR− = AVSS
- 001 VR+ = VREF+ and VR− = AVSS
- 010 VR+ = VeREF+ and VR− = AVSS
- 011 VR+ = VeREF+ and 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
6、ADC12MEMx
ADC12 Conversion Memory Registers
Conversion Results: Bit 15-0;
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 ADC12ADC12CTL1 = SHP; // Use sampling timerADC12IE = 0x01; // Enable interruptADC12CTL0 |= ENC; // Conversion enabledP6SEL |= 0x01; // P6.0 ADC option selectP2DIR |= 0x01;ADC12CTL0 |= ADC12SC;#pragma vector=ADC12_VECTOR
__interrupt void ADC12_ISR (void)
{if (ADC12MEM0 < 0x7FF)P2OUT = 0; // Clear P1.0 LED offelseP2OUT = 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 ADC12ADC12CTL1 = SHP; // Use sampling timerADC12MCTL0 = SREF_1; // Vr+=Vref+for ( i=0; i<0x3600; i++); // Delay for reference start-upADC12CTL0 |= ENC; while (1){ADC12CTL0 |= ADC12SC; // Start conversionwhile ((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 sensorADC12MCTL0 = SREF_1 + INCH_10; // Channel A10, Vref+ADC12IE = 0x01; // Enable ADC12IFG.0ADC12CTL0 = SHT0_8 + REF2_5V + REFON + ADC12ON + ENC; // Config ADC12TACCTL1 = OUTMOD_4; // Toggle on EQU1 (TAR = 0)TACTL = TASSEL_2 + MC_2; // SMCLK, cont-modewhile (!(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 offelse 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/4096IntDegF = (temp - 2519) * 761;IntDegF = IntDegF / 4096;
// oC = ((x/4096)*1500mV)-986mV)*1/3.55mV = x*423/4096 - 278
// IntDegC = (ADC12MEM0 - 2692)* 423/4096IntDegC = (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 resultsADC12CTL1 = SHP+CONSEQ_3; // Use sampling timer, repeated sequenceADC12MCTL0 = INCH_0; // ref+=AVcc, channel = A0ADC12MCTL1 = INCH_1; // ref+=AVcc, channel = A1ADC12MCTL2 = INCH_2; // ref+=AVcc, channel = A2ADC12MCTL3 = INCH_3+EOS; // ref+=AVcc, channel = A3, end seq.ADC12IE = 0x08; // Enable ADC12IFG.3ADC12CTL0 |= ENC; // Enable conversionsADC12CTL0 |= ADC12SC; // Start conversion_BIS_SR(LPM0_bits + GIE); // Enter LPM0, Enable interrupts
#pragma vector=ADC12_VECTOR
__interrupt void ADC12ISR (void)
{static unsigned int index = 0;A0results[index] = ADC12MEM0; // Move A0 results, IFG is clearedA1results[index] = ADC12MEM1; // Move A1 results, IFG is clearedA2results[index] = ADC12MEM2; // Move A2 results, IFG is clearedA3results[index] = ADC12MEM3; // Move A3 results, IFG is cleared// Increment results index, modulo; Set Breakpoint hereindex = (index+1)%Num_of_Results;
}
MSP430F149的ADC12应用相关推荐
- MSP430F5XXX中的ADC12使用
MSP430F5XXX中的ADC12使用 MSP430F5xxx ADC12 框图 使用流程 AD部分主要配置ADC12模块的时钟.参考源.采样通道.采样模式.存储和采样保持. 下面一个部分一个部分来 ...
- MSP430F5529 DriverLib 库函数学习笔记(八)模数转换模块(ADC12)
目录 硬知识 模数转换概述 MSP430单片机ADC12模块介绍 MSP430单片机ADC12模块操作 ADC12的转换模式 采样和转换 转换存储器 使用片内集成温度传感器 ADC12模块寄存器 AD ...
- MSP430X1XX系列ADC12和DMA详解(附带程序)(上)--ADC12详解与源码
目录 一,ADC12基本原理 1.1,参考电压发生器 1.2,时钟发生器 1.3,转换结果存储 1.4,具有采样保持功能的 12 位模数转换内核 1.5,采样转换时续控制电路 二,寄存器设置 2.1, ...
- Msp430学习笔记—ADC12(一)
编自CSX_锅! ADC12: 采样→保持→量化→编码 12 bits:200ksps(kilo samples per second) 逐次逼近法实现 analog to digital: ADC1 ...
- 体重计c语言程序,利用MSP430F149和HX711模块制作体重秤?
已结贴√ 问题点数:20 回复次数:1 利用MSP430F149和HX711模块制作体重秤? 以下代码是我从另一个论坛大拿那里看来的,如何改动才能只保留数码管显示体重呢?不需要蓝牙模块等等.救救毕设做 ...
- 基于MSP430F149操作数字电位器ISL23425WFVZ
本文主要讲述基于MSP430F149操作数字电位器ISL23425WFVZ,包含引脚功能.数据结构分析.编写代码.测试验证结果. 一.硬件连接 1.数字电位器ISL23425WFVZ的引脚功能如表1所 ...
- MSP430F5529库函数——模数转换模块(ADC12)软件触发
需提前观看:MSP430F5529库函数学习--串口 目录 代码 ADC初始化部分 引脚复位 ADC12_A_init() 函数声明 baseAddress sampleHoldSignalSourc ...
- 基于MSP430f149单片机的简单秒表
单片机:MSP430f149 实现功能:按下一个按键,计时开始,再次按下该按键计时暂停,即由一个按键实现暂停看开始功能,设置另一个按键,按下该按键三秒以上,秒表清零.要求计时精度,10毫秒. 该实验用 ...
- MSP430F149程序移植——0.96OLED(ssd1306驱动)
链接:https://pan.baidu.com/s/1ov-lE3sD2nMpV33Q9E7omw 提取码:2333 一.引脚说明 1.1 接口定义 引脚 功能说明 GND 电源地 VCC 电源正 ...
最新文章
- 量子力学 一 基础8 经典概率与量子概率
- mysql 之后,装完MySQL之后的一些操作
- css——模态框【遮罩层的制作;信息层;往白色的块里添加表单】
- thinkphp路由的作用
- vim编辑器---批量注释与反注释
- 如何求解两个数的最大公约数
- 限制按钮点击_Android | 使用 AspectJ 限制按钮快速点击
- python实现使用最近最久未使用算法的请求分页存储管理_答疑(存储管理)之一...
- java war目录_java war包 路径--解决war包中文件路径问题
- 【转】在Ubuntu 12.04 上为Virtualbox 启用USB 设备支持--不错
- python入门视频教程-Python入门视频全套教程
- 心得:调整边缘、叠加模式的妙用
- Python实现简易的图书借阅管理系统
- 寻找被黑金毁掉的黑客精神
- CentOS故障排除详解(2): 进程相关
- django注册登录
- PowerDesigner安装教程
- (转)一位资深程序员大牛给予Java初学者的学习路线建议
- pwm频率输出不对解决思路
- 互联网跟移动互联网_互联网如何说话
热门文章
- 如何设置取消小票的二维码
- 完全优化MySQL数据库性能的八大巧方法
- 本机Ajax异步通信
- python源码笔记_python源码学习笔记(一)
- jBPM4.4 window下启动tomcat
- 怎样用Jquery实现拖拽层,并实现网站自定义化模块功能?
- Java熔断框架有哪些_降级熔断框架 Hystrix 源码解析:滑动窗口统计
- oracle配置的监听文件,配置oracle监听文件
- vba传值调用_Access VBA如何使用Shell命令以及如何传递参数
- python如何使用字典_python字典怎么使用zip