我想用ADC10的重复多通道模式做一个多路数据采集,这样问题就来了:1.ADC10MEM是16位的寄存器,只能储存一次数据,但多路数据是怎么储存的。
2.如果采用ADC10DTC1寄存器和ADC10SA,那么得到的数据怎么不是对的?
3.以上两种,对于单通道单次采样有啥区别呢?代码如下:
#include "msp430g2553.h"
#include "normal.h"
#include "LCDdriver.h"
uchar flag;
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
uchar i;
ulong buffer1,buffer2;
float voltage1,voltage2;
lcdinit();
P1DIR &=~(BIT0+BIT1); // A0 A1
ADC10AE0 |=0x03;
ADC10CTL1 = INCH_1 + ADC10DIV_3 + CONSEQ_3; //A1 A0, repeat sequence
ADC10CTL0 = SREF_1 + ADC10SHT_3 + MSC + REFON +REF2_5V+ ADC10ON + ADC10IE;
delayms(100);
ADC10DTC1 = 0x10;
flag=1;
while(1)
{
if(flag)
{
flag=0;
ADC10CTL0 &= ~ENC;
ADC10DTC1 = 0x10; // 16 conversions
while (ADC10CTL1 & BUSY); // Wait if ADC10 core is active
ADC10SA = 0x200; // Data buffer start
buffer1=0;
buffer2=0;
for(i=0;i<32;i++)
{
if(i<16)
buffer1+=*(uint *)(0x200+2*i);
else
buffer2+=*(uint *)(0x200+2*i);
}
voltage1 = (float)(buffer1)*2.5/(8*1023);
voltage2= (float)(buffer2)*2.5/(8*1023);
display_hanz(1,1,"A1:");
LCD_DispDec(1,4,voltage1,1,3);
delayms(100);
display_hanz(2,1,"A0");
LCD_DispDec(2,4,voltage2,1,3);
delayms(200);
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
__bis_SR_register(CPUOFF+GIE);
}
}
}
// ADC10 interrupt service routine
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR(void)
{
flag=1;
__bic_SR_register_on_exit(CPUOFF);
} |