SparkFun Forums 

Where electronics enthusiasts find answers.

Discussions on how to get your MSP JTAG programmer up and running.
By EugenBesel
#6608
Hello,
I have a problem, if I try to use ADC12MEM1 then I get no data.
I want to use channel P6.0 and P6.1 as AD-channel
here is my quelltext.

#include <msp430x14x.h>
#include <stdio.h>
unsigned char rf_buf[8],
unsigned int adc1,adc2;

void main(void) {
P6SEL |= 0x03; // Channel 1 + 2
ADC12CTL0 = REF2_5V + REFON + SHT0_2 + ADC12ON + MSC ;
ADC12CTL1 = SHP +CONSEQ_1; //if I use CONSEQ_1 then I have no interrupts

ADC12MCTL0 = SREF_1 + INCH_0; // Chanel 1
ADC12MCTL1 = SREF_1 + INCH_1; // Chanel 2
ADC12IE = 0x01; // ???
ADC12CTL0 |= ENC;
WDTCTL = WDT_ADLY_250;
IE1 |= WDTIE;
_EINT();
for (;;) {
_BIS_SR(LPM0_bits);
_NOP();
sprintf(rf_buf,"%d\r",adc2); //
rf_poi = rf_buf;
}
}

interrupt [WDT_VECTOR] void wdt_isr(void) {
ADC12CTL0 |= ADC12SC;
}

interrupt[ADC_VECTOR] void ADC12ISR (void) {
adc1 = ADC12MEM0; // Memory 0 in the temp
adc2 = ADC12MEM1; // Memory 1 in the temp, but here I get no value
_BIC_SR_IRQ(LPM0_bits);
}

int __low_level_init(void) {
WDTCTL = WDTPW + WDTHOLD;
return 1;
}

I thank you fo the answer.

with best regards.
By m
#6610
EugenBesel wrote:[...]
ADC12MCTL0 = SREF_1 + INCH_0; // Chanel 1
ADC12MCTL1 = SREF_1 + INCH_1; // Chanel 2
ADC12IE = 0x01; // ???
ADC12CTL0 |= ENC;
[...]
with best regards.
The
Code: Select all
ADC12IE=0x1
says to interrupt as soon as the first channel finishes. You want ADC12IE= 2; You also have CONSEQ_1 which will only run it once and then stop. You may want CONSEQ_3 to repeatedly run the interrupt?

You also need to add an EOS on MCTL1. A working example for 3 channels (just cut and pasted from a program I have lying around).

Code: Select all
  ADC12CTL0 =   SHT0_5 |        // 96 clock cycles sampling time. (ADC12CLK) = ~ 20uS
                ADC12ON ;       // turn on ADC.

  ADC12CTL1 =   CSTARTADD_0 |   // Start at MCTL0
                SHS_1 |         // Use sampling timer Timer_A.OUT1
                SHP |           // Sample-and-Hold Pulse select.
                0 |             // ISSH_0. Do no invert signal.
                ADC12DIV_0 |    // divide clock by 1.
                ADC12SSEL_0 |   // Use internal 5Mhz clock (ADC12OSC).
                CONSEQ_3        // Repeat sequence-of-channels.
                ;

  ADC12MCTL0 = INCH_3;          // Input channel 3 using Vcc and Vss as voltage reference.
  ADC12MCTL1 = INCH_4;          // channel 4.
  ADC12MCTL2 = INCH_5 | EOS;    // channel 5 and End of sequence.

  ADC12IE = 1 << 2;               // Enable interrupt when MCTL2 completes.

  ADC12CTL0 |= ENC;
This actually used timerA to trigger the sampling. The timerA setup for completeness is
Code: Select all
  TACCR1 = 64;                  // raise interupt at 64 counts.
  TACCTL1 = OUTMOD_2;           // Toggle OUT_1 at CR1 and reset at at CR0
  TACCR0 = 128;                 // Set period to 128 counts == 128/32Khz == ~ 4000 uS
  TACTL =       TASSEL_1 |      // Use ACLK as clock. (32Khz)
                MC_1;           // Start timer and count up to TACCR0.