Hello everyone,
I seem to have some kind of problem trying to use ADCs in my code. I need to measure voltage on the row of 8 potentiometers, and additionaly i measure 2 other voltages. My device is MSP430F2232 which according to the datasheet has 12 ADC inputs. Out of these 12 i need 10. So i figured, the easiest way to read them is to use sequence of channels mode. The channels i use are A0-7, and A12-13, which are enabled by the following code
ADC10AE0 |= BIT0 + BIT1 + BIT2 + BIT3 + BIT4 + BIT5 + BIT6 + BIT7; // A0-7 enable
ADC10AE1 |= BIT4 + BIT5; //A12-13 enable
Besides i choose Channel 13 as a highest channel in my sequence of conversions in ADC10CTL1 register.
The results are supposed to be stored in the array. Here's my whole program
#include "msp430x22x2.h"
unsigned int ADC[10];
int c;
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
BCSCTL1 = CALBC1_16MHZ; // Kalibrierdaten des Herstellers
DCOCTL = CALDCO_16MHZ; // Kalibrierdaten des Herstellers
ADC10CTL1 = INCH_13 + CONSEQ_1; // Channel 13 single sequence
ADC10CTL0 = ADC10SHT_2 + MSC + ADC10ON + ADC10IE;
ADC10DTC1 = 10; // 10
ADC10AE0 |= BIT0 + BIT1 + BIT2 + BIT3 + BIT4 + BIT5 + BIT6 + BIT7; // A0-7 enable
ADC10AE1 |= BIT4 + BIT5; //A12-13 enable
//PWM
P1DIR |= BIT2;
TACCTL0 = CCIE; // Enable Periodic interrupt
TACCR0 = 1024; // Periode
TACTL = TASSEL_2 + MC_1; // Quelle SMCLK, aufwärts zählen
CCTL1 = OUTMOD_7; //PWM Reset/Set
P1SEL |= BIT2; //Pin als TA1
for (;;)
{
ADC10CTL0 &= ~ENC;
while (ADC10CTL1 & BUSY); // Wait if ADC10 core is active
ADC10SA = (short)&ADC[0]; // Data buffer start
CCR1 = ADC[0];
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
__bis_SR_register(CPUOFF + GIE); // LPM0, ADC10_ISR will force exit
}
}
// ADC10 interrupt service routine
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR(void)
{
c++;
__bic_SR_register_on_exit(CPUOFF); // Clear CPUOFF bit from 0(SR)
}
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A (void)
{
ADC10CTL0 |= ENC + ADC10SC; // Enable Sampling and start conversion.
}
(The PWM part is only to test which channel corresponds to which part of the data stored in array.)
So the problem is, the data in the array is located in very strange fashion. Data from some ADC is not written at all!
From what i know it's supposed to go like that: first number stored in the array is the result of the first conversion i.e. the voltage from the highest channel i chose. In my case channel 13. The second would be 12 and so on.
In my case this rule only seem to apply to the first 2 conversions. The whole list goes like that
[0] A13
[1] A12
[2] meaningless number about 500
[3] meaningless number about 500*
[4] A3
[5] A4
[6] A7
[7] A6
[8] A5
[9] A4 (for the second time!)
*The [2] and [3] show some numbers which i can not influence by rotating my potentiometers.
Data from A0, A1 and A2 is not there at all.
When using the same principle i tried to read data from channels A0-7, it worked perfectly! And even numbers of array variables made sense. So i think there is a problem with how i configure those 2 channels A12 and A13. Could it be those 2 strange numbers are in fact data from 2 unused ADCs which aren't even connected on my PCB?
Would appreciate any help or suggestions!