Hello,
I am trying to configure the ADC on the MSP430 experimenters board (MSP430F5438) to continuously sample a signal that is in the 10 kHz range. After each sample, the data is pushed to a radio through UART. I'm testing by sampling a sine wave at various frequencies. The problem is that I cannot seem to sample sine waves above about 50 Hz. From my ADC configuration, I think the ADC should be sampling at about 153 kSps. 12 MHz clock, 12b resolution, 64 cycle SHP (12MHz/(13+65) = ~0.153 MHz).
My best guess is that the actual sampling rate is significantly lower because I call UART_send() in the ADC ISR but I am not sure of another way to do it.
Can anyone give me an idea of what's going on? My code is below, ADC conversions are started by a timer which is not shown in the code.
Thanks, Ben.
int ADC_result;
char str[10];
static unsigned char index = 0;
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
clock_init(); // ACLK = 32 kHz, SMCLK = 12 MHz, MCLK = 12 MHz
UART_init();
UART_send();
timer_init();
ADC_init();
__bis_SR_register(LPM0_bits + GIE); // Enter LPM0, interrupts enabled
}
void UART_init(void)
{
P3SEL = 0x30; // P3.4,5 = USCI_A0 TXD/RXD
UCA0CTL1 |= UCSWRST; // **Put state machine in reset**
UCA0CTL1 |= UCSSEL_2; // SMCLK
UCA0BR0 = 104; // 12MHz - 115200 (see User's Guide)
UCA0BR1 = 0; // 12MHz - 115200
UCA0MCTL |= UCBRS_1 + UCBRF_0; // Modulation UCBRSx=1, UCBRFx=0
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
UCA0IE |= UCRXIE + UCTXIE; // Enable USCI_A0 RX interrupt + TX interrupt
}
void UART_send(void)
{
int i;
sprintf(str,"%04d\r\n",ADC_result);
for(i=0;i<6;i++)
{
while (!(UCTXIFG)); // USCI_A0 TX buffer ready?
UCA0TXBUF = str[i]; // send char
__delay_cycles(1000);
}
}
void ADC_init(void)
{
// ADC init
ADC12CTL0 = ADC12SHT0_5 + ADC12MSC; // 64 cycles per sample Sampling time, multiple samples
ADC12CTL0 |= ADC12ON; // ADC12 on
ADC12CTL1 = ADC12SHP + ADC12CONSEQ_2; // Use sampling timer, repeat single channel, SMCLK - 12 MHz?
ADC12CTL1 |= 0x0018; // SMCLK - 12 MHz?
ADC12CTL2 = ADC12RES_2; // 12 bit res
ADC12IE = 0x0001; // Enable interrupt
ADC12MCTL0 = ADC12INCH_7; // map CH 7 to MEM0
ADC12CTL0 |= ADC12ENC; // enable conversion
P6SEL |= 0x80; // P6.7 ADC option select
// ADC start, now in TA CCR1
//ADC12CTL0 |= ADC12SC; // Start sampling/conversion
}
// ADC ISR
#pragma vector = ADC12_VECTOR
__interrupt void ADC12_ISR(void)
{
switch(__even_in_range(ADC12IV,34))
{
case 0: break; // Vector 0: No interrupt
case 2: break; // Vector 2: ADC overflow
case 4: break; // Vector 4: ADC timing overflow
case 6: // Vector 6: ADC12IFG0
ADC_result = ADC12MEM0;
index++;
UART_send();
break;
case 8: break; // Vector 8: ADC12IFG1
case 10: break; // Vector 10: ADC12IFG2
case 12: break; // Vector 12: ADC12IFG3
case 14: break; // Vector 14: ADC12IFG4
case 16: break; // Vector 16: ADC12IFG5
case 18: break; // Vector 18: ADC12IFG6
case 20: break; // Vector 20: ADC12IFG7
case 22: break; // Vector 22: ADC12IFG8
case 24: break; // Vector 24: ADC12IFG9
case 26: break; // Vector 26: ADC12IFG10
case 28: break; // Vector 28: ADC12IFG11
case 30: break; // Vector 30: ADC12IFG12
case 32: break; // Vector 32: ADC12IFG13
case 34: break; // Vector 34: ADC12IFG14
default: break;
}
}