# ADC

**URL:** <https://community.sparkfun.com/t/adc/7087>\
**Category:** MicroMod\
**Tags:** msp\
**Created:** [April 19, 2008, 9:58pm UTC](https://community.sparkfun.com/t/adc/7087 "2008-04-19T21:58:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![colsandurz](https://avatars.discourse-cdn.com/v4/letter/c/c5a1d2/32.png) [@colsandurz](https://community.sparkfun.com/u/colsandurz)\
**Post date:** [April 19, 2008, 9:58pm UTC](https://community.sparkfun.com/t/adc/7087/1 "2008-04-19T21:58:01Z")

</div>

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

```auto
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.

---

<div class="post-metadata">

**Author:** ![leon\_heller](https://yyz1.discourse-cdn.com/sparkfun/user_avatar/community.sparkfun.com/leon_heller/32/7602_2.png) [@leon\_heller](https://community.sparkfun.com/u/leon_heller)\
**Post date:** [April 19, 2008, 10:30pm UTC](https://community.sparkfun.com/t/adc/7087/2 "2008-04-19T22:30:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![colsandurz](https://avatars.discourse-cdn.com/v4/letter/c/c5a1d2/32.png) [@colsandurz](https://community.sparkfun.com/u/colsandurz)\
**Post date:** [April 21, 2008, 2:29am UTC](https://community.sparkfun.com/t/adc/7087/3 "2008-04-21T02:29:10Z")

</div>

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

```auto
#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)
    }
  } 
}

```

---

<div class="post-metadata">

**Author:** ![gm](https://avatars.discourse-cdn.com/v4/letter/g/e95f7d/32.png) [@gm](https://community.sparkfun.com/u/gm)\
**Post date:** [April 23, 2008, 2:02am UTC](https://community.sparkfun.com/t/adc/7087/4 "2008-04-23T02:02:47Z")

</div>

Take a look at the fet440\_adc12\_08.c file in [http://www.ti.com/lit/zip/slac019](http://www.ti.com/lit/zip/slac019). It is almost identical to what you are attempting to do.

Hope this helps,

Greg
