#include "msp430g2553.h" #include #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; }