Quantcast
Channel: MSP430 Technical Forums
Viewing all articles
Browse latest Browse all 2077

Multiple channels ADC

$
0
0

Hi, I'm working on the msp430f2274 and I need help regarding multiple analog channels. I'm using channels A0,A1,A2,A3,A4 and DTC to store the value in an array. But the values of each channel doesn't store in the array[#] correctly. For example in my code, value at A0 is suppose to be at samples[4], but it will appear on other samples[#] . There's a picture at the end to show what I meant.

#include  <msp430.h>
#define BIT0                (0x0001)
#define BIT1                (0x0002)
#define BIT2                (0x0004)
#define BIT3                (0x0008)
#define BIT4                (0x0010)
#define BIT5                (0x0020)
#define BIT6                (0x0040)
#define BIT7                (0x0080)
#define BIT8                (0x0100)
#define BIT9                (0x0200)
#define BITA                (0x0400)
#define BITB                (0x0800)
#define BITC                (0x1000)
#define BITD                (0x2000)
#define BITE                (0x4000)
#define BITF                (0x8000)

// Global variables
unsigned int samples[5];
// Function prototypes
void ConfigureAdc(void);

void main(void)
{
	{
		WDTCTL = WDTPW + WDTHOLD;		// Stop WDT
		BCSCTL1 = CALBC1_1MHZ;			// Set range   DCOCTL = CALDCO_1MHZ;
		BCSCTL2 &= ~(DIVS_3);			// SMCLK = DCO = 1MHz
		P2SEL |= BIT4 + BIT3 + BIT2 + BIT1 + BIT0;	// ADC input pin P2.4
		P1REN = 0;		// Pull-Up/Pull-down Resistors Disabled on P1 ports
		P1SEL = 0;		// Clear any previous settings
		P1DIR = 0;		// Clear any previous settings
		P1OUT = 0;		// Initialize port outputs to low state
		P3REN = 0;		// Pull-Up/Pull-down Resistors Disabled on P3 ports
		P3SEL = 0;		// Clear any previous settings
		P3DIR = 0;		// Clear any previous settings
		P3OUT = 0;		// Initialize port outputs to low state
		P4REN = 0;		// Pull-Up/Pull-down Resistors Disabled on P4 ports
		P4SEL = 0;		// Clear any previous settings
		P4DIR = 0;		// Clear any previous settings
		P4OUT = 0;		// Initialize port outputs to low state
		ConfigureAdc();		// ADC set-up function call
		__enable_interrupt();	// Enable interrupts.

		while(1)
		{
			__delay_cycles(1000);			// Wait for ADC Ref to settle
			ADC10SA = (unsigned int)samples;
			ADC10CTL0 |= ENC + ADC10SC;		// Sampling and conversion start
			__bis_SR_register(CPUOFF + GIE);// Low Power Mode 0 with interrupts enabled
	
		}

	}
}

// ADC10 interrupt service routine
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR (void)
{
	__bic_SR_register_on_exit(CPUOFF);        // Return to active mode }
}

// Function containing ADC set-up
void ConfigureAdc(void)
{

	ADC10CTL1 = INCH_4 + ADC10DIV_0 + CONSEQ_3 + SHS_0;         // Channel 4, ADC10CLK/3
	ADC10CTL0 &= ~(ENC);
	ADC10CTL0 = SREF_0 + ADC10SHT_3 + MSC + ADC10ON + ADC10IE;  // Vcc & Vss as reference, Sample and hold for 64 Clock cycles, ADC on, ADC interrupt enable
	ADC10AE0 |= BIT4 + BIT3 + BIT2 + BIT1 + BIT0;               // ADC input enable P2.4,P2.3,P2.2,P2.1,P2.0
	ADC10DTC1 = 5;
}

From the picture at the end. The top shows value(200+) of channel A0 on samples[4], then the next moment(bottom pic) shows value(200+) of channel A0 at samples[3].
 


Viewing all articles
Browse latest Browse all 2077

Trending Articles