ADC

I am trying to get my ADC to sample 4 channels either all at once or one every quarter second. So, each channel would be sampled about once every second. So far I think I have the ISR and the ADC all setup right, I just can’t seem to start the sampling process, here is my code

int main(void) {
 
  
  WDTCTL = WDTPW + WDTHOLD; //turn off watchdog timer
  
  P6SEL = 0x0F;

 int A0results = 0;
 int A1results = 0;
 int A2results = 0;
 int A3results = 0;
  
  /***** ADC ISR *****/ 

#pragma vector=ADC_VECTOR
__interrupt void ADC12ISR (void);
  {
    A0results = ADC12MEM0; // 5 volt rail voltage
    A1results = ADC12MEM1; // 5 volt rail current
    A2results = ADC12MEM2; // 12 volt rail voltage
    A3results = ADC12MEM3; // 12 volt rail current
  }
  
  /***** Setup ADC *****/ 
 
  ADC12CTL0 |= SHT0_6; //sample and hold time -- 128 cycles
  ADC12CTL0 |= REF2_5V; //2.5V Ref
  ADC12CTL0 |= REFON; //Ref On
  ADC12CTL0 |= ADC12ON; //Turn on ADC12
  ADC12CTL0 |= ENC; //ADC12 Enabled
  ADC12CTL0 |= ADC12SC; //Start Conversion
   
  ADC12CTL1 |= SHP;//selects ADC source to output of sampling timer
  ADC12CTL1 |= ADC12SSEL_1; 
  ADC12CTL1 |=  CONSEQ1;       				             // Use sampling timer signal sourced from sampling timer, use ACLK
  
  ADC12IE = 0x01;  //Enable Interrupts                                                           
  
  ADC12MCTL0 = INCH_0; // ref+=AVcc, channel = A0
  ADC12MCTL1 = INCH_1; // ref+=AVcc, channel = A1
  ADC12MCTL2 = INCH_2; // ref+=AVcc, channel = A2
  ADC12MCTL3 = INCH_3+EOS; // ref+=AVcc, channel = A3, end seq.
  
}

I would really appreciate any help, thanks.

It’s a good idea to start off with everything as simple as possible - polling the ADC with a single channel. Get that working first.

Leon

So I worked on my code (note: I am using IAR kickstart) a little more when I run this code in simulator it works pretty well, except ADC12BUSY always equals 1 indicating the ADC is always busy. However, when I actually use the chip all the registers change their values as I step though the code…

  1. the values are all random(there is no obvious patter and they seem to recur a lot, like 3 is frequent)

  2. the ADC12CTL0 and ADC12CTL1 registers are the same value

  3. Also the values change for almost every time I step over a line

I don’t really have any physical connections except for the JTAG connector and P6.0 to P6.3 connected to the voltages I want to convert. (do I need a reference for my ADC… which pin do I connect to ground??)

this is my code

#include <stdio.h>
#include "msp430x44x.h"  //msp430x41x.h?  
#include "demo.h"


int main(void) {

  WDTCTL = WDTPW + WDTHOLD;   //turn off watchdog timer

 int A0results = 0;
 int A1results = 0;
 int A2results = 0;
 int A3results = 0;
 
  ADC12CTL0 = ADC12ON; //Turn on ADC12 
  ADC12CTL0 |= SHT0_2;  //sample and hold time
  ADC12CTL0 |= REF2_5V; //2.5V Ref
  ADC12CTL0 |= REFON;   //Ref On
  
  ADC12CTL1 = SHS_0;      //Sets ADC12SC bit as source
  ADC12CTL1 |= CONSEQ_1;   //Sequence of Channels
  
  ADC12MCTL0 = INCH_0 + SREF_1; // ref+=AVcc, channel = A0
  ADC12MCTL1 = INCH_1 + SREF_1; // ref+=AVcc, channel = A1
  ADC12MCTL2 = INCH_2 + SREF_1; // ref+=AVcc, channel = A2
  ADC12MCTL3 = INCH_3 + SREF_1; // ref+=AVcc, channel = A3, end seq.
  
  while(1)
  {
  
    ADC12CTL0 |= ADC12SC + ENC; // Enable and start conversion
    P6SEL = 0x0F;
    
    while(ADC12BUSY != 1)
    {                         
      A0results = ADC12MEM0;
      A1results = ADC12MEM1;
      A2results = ADC12MEM2;
      A3results = ADC12MEM3;
      swDelay(1);  //Delays for about a second with an empty loop (in demo.h)
    }
  } 
}

Take a look at the fet440_adc12_08.c file in http://www.ti.com/lit/zip/slac019. It is almost identical to what you are attempting to do.

Hope this helps,

Greg