P6SEL = 0x7F //管脚功能选择成ADC
ADC12CTL0=ADC12ON+MSC+SHT0_2+REFON+REF2_5V//打开ADC内核/连续采样/采样率设置/打开内部参考电压源/选择2.5V参考电压
ADC12CTL1 = SHP+CONSEQ_1 //采样信号来自采样定时器/序列通道单次转换模式
ADC12MCTL0 = INCH_0+SREF_1 //通道0/参考电压源选择内部参考电压
ADC12MCTL1 = INCH_1+SREF_1
ADC12MCTL2 = INCH_2+SREF_1
ADC12MCTL3 = INCH_3+SREF_1
ADC12MCTL4 = INCH_4+SREF_1
ADC12MCTL5 = INCH_5+SREF_1
ADC12MCTL6 = INCH_6+SREF_1+EOS//EOS序列转换结束
ADC12IE = 0x40 //使能ADC中断
ADC12CTL0 |= ENC//允许转换
ADC12CTL0 |= ADC12SC//开始转换
_EINT() //全局中断使能 }
interrupt[ADC_VECTOR] void ADC12ISR (void)
{
results[0] = ADC12MEM0 //将通道0采样结果读出,赋给RESULTS数组
results[1] = ADC12MEM1
results[2] = ADC12MEM2
results[3] = ADC12MEM3
results[4] = ADC12MEM4
results[5] = ADC12MEM5
results[6] = ADC12MEM6
#include <msp430x44x.h>void main(void)
{
WDTCTL = WDTPW + WDTHOLD// Stop WDT
//串口初始化
FLL_CTL0 |= XCAP18PF// Configure load caps
P2SEL |= 0x30 // P2.4,5 = USART0 TXD/RXD
ME1 |= UTXE0 + URXE0// Enable USART0 TXD/RXD
UCTL0 |= CHAR // 8-bit character
UTCTL0 |= SSEL1 // UCLK = SMCLK
UBR00 = 0x36// 1MHz 19200
UBR10 = 0x00// 1MHz 19200
UMCTL0 = 0x6B // Modulation
UCTL0 &= ~SWRST // Initialize USART state machine
unsigned int adtable[256]
unsigned int i
unsigned int AD_Times
AD12Init()
ADC12CTL0 |= ENC //enable conversion
ADC12CTL0 |= ADC12SC // Sampling open
while(1)
{
If (AD_Times==256)
{
for(i=0i<256i++)
{
TXBUF0 = adtable[i] //Send by 2 Bytes
adtable[i]>>8
TXBUF0 = adtable[i]
}
}
}
void AD12Init(void)
{
P6SEL |= 0x01 // P6.0 ADC option select
ADC12CTL0 &= ~ENC
ADC12CTL0 = SHT0_6 + ADC12ON+MSC+REFON+REF2_5V// set the register
ADC12CTL1 = SHP+CONSEQ_2 // Use sampling timer
ADC12MCTL0 = SREF_1+INCH_0
ADC12CTL0 |= ENC// Conversion enabled
ADC12IE = 0x01 //interrupt
}
#pragma vector=ADC_VECTOR
__interrupt void ADC12_ISR (void)
{
vu32 temp
temp = ADC12MEM0
adtable[AD_Times] = temp *2500/4095 // change to mv Value
AD_Times++
if(AD_Times == 256)
{
ADC12CTL0 &= ~ENC
ADC12CTL0 &= ~ADC12SC
}
应该是这个样子的,没调试过,有错误自己搞定吧
100HZ,直接用MSP430的内部ADC模块就可以采集了,可以每个周期采64个点,也就是大概1.5625ms进行一次采样,这个采样率MCU完全可以承受得了。MSP430的内部ADC的使用例程,你可以到TI官网去下载,然后开一个定时器,每隔1.5625ms进行一次ADC采样,每采一次,保存到数组中(真浪费RAM资源)。采够200就停止就可以了
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)