I tried adc using the ADC12 in msp430fg4618 experimenter's board. I saw the datasheet and it says the frequency of ADC12OSC oscillator is 5Mhz. I used that clock. According to the user guide about 15 cycles of ADC12OSC is spent for sampling and analog to digital conversion. After this the data will be stored in ADC12MEM register and I call the interrupt. There I tried to send the data in that register outside bit by bit. I also toggled one led (LED4) to see when the interrupt is called ( i.e. entire sampling time). I encounters this problem-
*Initially I just tried to toggle without sending any data outside. At that time the frequency of the LED4 that I got in the oscilloscope is 32 Khz.
*The next time I sent 2 bits of the ADC12MEM register to the i/o pins. Then I saw the frequency of LED4 and it had changed to 1khz!
*The next time I included the entire code where I sent the 12 bits of ADC12MEM register to the i/o pins and the frequency of LED4 was 263 Hz!!!
I need a sampling rate of 22Khz and not 263 hz.
Here's the code
#include "msp430xG46x.h"
long int data[12];
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
ADC12CTL0 = SHT0_0 + ADC12ON; // Sampling time, ADC12 on
ADC12CTL1 = SHP; // Use sampling timer
ADC12IE = 0x01; // Enable interrupt
ADC12CTL0 |= ENC;
P6SEL |= 0x01; // P6.0 ADC option select
P5DIR |= 0x02; // P5.1 output
P4DIR=0xFF;
P3DIR=0xF0;
while (1)
{
ADC12CTL0 |= ADC12SC; // Start sampling/conversion
__bis_SR_register(LPM0_bits + GIE); // LPM0, ADC12_ISR will force exit
}
}
#pragma vector = ADC12_VECTOR
__interrupt void ADC12_ISR(void)
{
int a[4];
// Toggled this to check the sampling rate
P5OUT^=0x02;
//This is the part where I send the converted data to the pins.
//I extracted each bit here-
data[0]=( ADC12MEM0 & 0x0001);
data[1]=( ADC12MEM0 & 0x0002);
data[2]=( ADC12MEM0 & 0x0004);
data[3]=( ADC12MEM0 & 0x0008);
data[4]=( ADC12MEM0 & 0x0010);
data[5]=( ADC12MEM0 & 0x0020);
data[6]=( ADC12MEM0 & 0x0040);
data[7]=( ADC12MEM0 & 0x0080);
data[8]=( ADC12MEM0 & 0x0100);
data[9]=( ADC12MEM0 & 0x0200);
data[10]=( ADC12MEM0 & 0x0400);
data[11]=( ADC12MEM0 & 0x0800);
// This is done so that it goes to the pins 7,6,5,4 of the port3.
a[0]=data[8]/0x0010;
a[1]=data[9]/0x0010;
a[2]=data[10]/0x0010;
a[3]=data[11]/0x0010;
//This is the place where I have sent the data to the i/o pins.
P4OUT=data[7]|data[6]|data[5]|data[4]|data[3]|data[2]|data[1]|data[0];
P3OUT=a[3]|a[2]|a[1]|a[0];
__bic_SR_register_on_exit(LPM0_bits); // Exit LPM0
}