由于项目中需要使用到ADC模块,那么就有必要对ADC模块进行研究了。
这是msp430F5428A datasheet首页上面对于ADC的描述:
12-Bit Analog-to-Digital Converter (ADC)
– Internal Reference
– Sample-and-Hold
– Autoscan Feature
– 14 External Channels, 2 Internal Channels
ADC12_A (Link to User's Guide)
The ADC12_A module supports fast 12-bit analog-to-digital conversions. The module implements a 12-bit SAR
core, sample select control, reference generator, and a 16-word conversion-and-control buffer. The conversionand-
control buffer allows up to 16 independent ADC samples to be converted and stored without any CPU
intervention.
也就是说ADC12_A可以同时转换16路的模拟信号。(没有cpu的介入)
把Msp430f5438A的ADC12_A的重要特点总结如下:
(1) 转换速率可以为200K/s
(2)12bit转换 无错码
(3) 由软件或计数器控制着的采样时间和保持时间
(4)内部有参考电压1.5V,2.0V及2.5V
(5)可以使用外接参考源,是否选择外部参考源由寄存器决定。
(6)有单沟道采样,重复单沟道采样,序列采样,重复序列采样4种模式可选(Single-channel, repeat-single-channel, sequence (autoscan), and repeat-sequence (repeated autoscan) conversion modes)
(7)16位转换结果存储寄存器ADC12MEMx,和ADC12转换结果存储寄存器ADC12MCTLx。
写下列程序:
void main(void)
{
WDTCTL = WDTPW+WDTHOLD; // Stop watchdog timer
ADC12CTL0 = ADC12ON+ADC12MSC+ADC12SHT0_15;// Turn on ADC12, set sampling time
ADC12CTL1 = ADC12SHP+ADC12CONSEQ_0; // Use sampling timer, single
ADC12MCTL0 =ADC12SREF_2 + ADC12INCH_3; // ref+=Veref=2.5V, channel = A3
// ADC12MCTL1 = ADC12INCH_2+ADC12EOS; // ref+=AVcc, channel = A9, end seq.
ADC12IE = 0x02; // Enable ADC12IFG.1, end channel
ADC12CTL0 |= ADC12ENC; // Enable conversions
ADC12CTL0 |= ADC12SC; // Start convn - software trigger
}
当在A3脚上加电压为1.404 V, 在debug界面观测到的为:
也就是说转换结果为08B3,对应电压为
[(8*256+11*16+3)/4096]*2.5V=1.359V
所以ADC成功将A3口上的信号转换为数字量并存储在ADC12MEM0中。
|