Hi,
I am using the MSP430G2553 and would like to sample values using the ADC10 at 80 Hz. Currently, I am converting the samples in my main loop (it runs at approximately 12.9 kHz) and wait until the conversion is done before moving on to execute the rest of the main loop. Vss and 2.5Vref are used as references. Using an interrupt, I save the converted values at 80 Hz. The relevant ADC code is attached.
To see if the ADC is working I input a constant signal and store 200 int values of the digital signal after sampling and view them in the CCS debugger. I am seeing some slight noise in my signal, up to 8 quantization levels (or up to 19.5 mV). Attached is a plot of the 200 values stored after ADC. When looking at the input signal using a Labview DAQ, there is baseline noise of only 6 mV as opposed to 19.5 mV seen in the digital signal.
I am wondering if the noise present in my digital signal is likely caused by the conversion and saving of ADC values. If yes, am I using ADC10 correctly to save my samples? Or is there a better method to sample at a specified frequency?
Thanks!
Tyler
#include "msp430g2553.h" #include <in430.h> #include "main.h" static const int timer_A = 1600; int testdata[200]; volatile unsigned int update = 0; //incremented with adc volatile unsigned int updatetd = 0; int main( void ) { WDTCTL = WDTPW + WDTHOLD; setupGPIO(); //setup the pins setupTimer_A(); //setup timer A setupADC(); //setup the ADC TA0CTL |= MC_1; __enable_interrupt(); //enable interrupts while(1) { ADC10CTL0 |= ENC + ADC10SC; //enable and start conversion of ADC samples while((ADC10CTL1 & ADC10BUSY)); //wait until conversion is done if(update > 0) { //////Toggle pin to determine ADC rate P2OUT ^= BIT0; update = 0; //turn off update } } } //----------------------INTERRUPTS---------------------- //Timer A interrupt for saving adc values(80 Hz) #pragma vector=TIMER0_A0_VECTOR __interrupt void Timer_A( void ) { update= 1;//turn on update testdata[updatetd]=ADC10MEM; updatetd++; } //----------------------FUNCTIONS---------------------- void setupGPIO( void ) { //Pins for checking rates //P2.0 for length of main loop P2SEL &= ~BIT0; P2DIR |= BIT0; P2OUT &= ~BIT0; //turn off } //Timer A is for saving adc values at 80 Hz void setupTimer_A( void ) { TA0CTL = TASSEL_2 + ID_3 + MC_0 + TACLR; //source from SMCLK, divide by 8, keep the timer off initially, clear the timer TA0CCTL0 = CCIE; //capture/compare interrupt enabled TA0CCR0 = timer_A; //Timer A to trigger at 80 Hz } //ADC is for sampling P1.1 void setupADC( void ) { ADC10CTL0 = ADC10SHT_3 + SREF_1 + REF2_5V + REFON + ADC10ON; ADC10CTL1 = INCH_1; ADC10AE0 |= BIT1; P1SEL |= BIT1; }