TI中文支持网
TI专业的中文技术问题搜集分享网站

ADC10 channel 只想設置A4 and A5

ADC10MCTL0 = ADC10INCH_5; //A0~A5
請問若只想監聽A4/A5的話該如何設置?
Susan Yang:

可以尝试下面两者方法之一

1 您使用单通道转换,在每次转换时触发一个中断,并在ISR内部切换通道并重新开始转换。

2 继续使用ADC10MCTL0 = ADC10INCH_5; //A0~A5,要从序列中选择一个样本的话,您可以让ADC10在每次转换时触发一个中断,并且在中断处理程序中,选择仅存储ISR的第五次和第六次调用的结果。

Ken Chang1:

回复 Susan Yang:

感謝回復

那請問如果用MSP430F530x_adc10_10.c這隻範例來改該怎麼修改呢?

#include <msp430.h>

unsigned char ADC_Result[3];// 8-bit ADC conversion result array

int main(void)
{WDTCTL = WDTPW | WDTHOLD;// Stop WDT
// Configure ADC10ADC10CTL0 = ADC10SHT_2 | ADC10MSC | ADC10ON;// 16ADCclks, MSC, ADC ONADC10CTL1 = ADC10SHP | ADC10CONSEQ_1;// sampling timer, s/w trig.,single sequenceADC10CTL2 &= ~ADC10RES;// 8-bit resolutionADC10MCTL0 = ADC10INCH_2;// A0,A1,A2(EoS), AVCC reference// Configure DMA0 (ADC10IFG trigger)DMACTL0 = DMA0TSEL_24;// ADC10IFG trigger__data16_write_addr((unsigned short) &DMA0SA,(unsigned long) &ADC10MEM0);// Source single address__data16_write_addr((unsigned short) &DMA0DA,(unsigned long) &ADC_Result[0]);// Destination array addressDMA0SZ = 0x03;// 3 conversions DMA0CTL = DMADT_4 | DMADSTINCR_3 | DMASRCBYTE | DMADSTBYTE | DMAEN | DMAIE; // Rpt, inc dest, byte access, // enable int after seq of convswhile(1){while (ADC10CTL1 & ADC10BUSY);// Wait if ADC10 core is activeADC10CTL0 |= ADC10ENC | ADC10SC;// Sampling and conversion start__bis_SR_register(CPUOFF | GIE);// LPM0, ADC10_ISR will force exit__delay_cycles(5000);// Delay between sequence convs__no_operation();// BREAKPOINT; check ADC_Result}
}

#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=DMA_VECTOR
__interrupt void DMA0_ISR (void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(DMA_VECTOR))) DMA0_ISR (void)
#else
#error Compiler not supported!
#endif
{switch(__even_in_range(DMAIV,16)){case0: break;// No interruptcase2: // sequence of conversions complete__bic_SR_register_on_exit(CPUOFF);// exit LPMbreak;// DMA0IFGcase4: break;// DMA1IFGcase6: break;// DMA2IFGcase8: break;// Reservedcase 10: break;// Reservedcase 12: break;// Reservedcase 14: break;// Reservedcase 16: break;// Reserveddefault: break; }
}

Susan Yang:

回复 Ken Chang1:

这个例程的话是序列采样,采样A0-A2这3个通道的值,建议您使用第2种方法

可以让ADC10在每次转换时触发一个中断,并且在中断处理程序中,选择仅存储ISR的第五次和第六次调用的结果。

赞(0)
未经允许不得转载:TI中文支持网 » ADC10 channel 只想設置A4 and A5
分享到: 更多 (0)