I've been trying to operate the SD16 in continuous sampling mode while sequentially scanning through 3 channels.
The idea is to cycle through channels A0 -> A3 -> A6 -> A0 -> etc. In order to evaluate operation, a simple setup as
shown in the attached image was used.
The readings are however not as expected. The readings on A0 and A3 are almost the same value. The readings
from A6 (internal temperature sensor) are way too low. I suspect that either I'm doing something wrong, or that the
SD16 cannot be operated this way.
The code I'm using is attached to this posting.
Key points:
- The channel is changed after reading the converted value.
- An interrupt delay of 4 samples is enabled
- The values are read into dummy variables and their value is read using a debug watch.
My question is whether such an arrangement can work, or if I have a mistake in my code.
Regards
Edwin
/* --- hardware_init_adc --- */ // -- ADC pin enable SD16AE = SD16AE7 | SD16AE6 | SD16AE1 | SD16AE0; SD16CTL = SD16REFON + SD16VMIDON + SD16SSEL_0 + SD16DIV_3; // enable VREF output, MCLK/8 SD16INCTL0 = SD16INCH0; // Select channel A0+/- SD16CCTL0 |= SD16IE + SD16SC + SD16DF; // enable interrupt, start conversion, 2's complement SD16INCTL0 |= SD16INTDLY_0; // Interrupt on 4th sample #pragma vector = SD16_VECTOR __interrupt void SD16_ISR(void) { long tmp; switch (SD16IV) { case 2: // SD16MEM Overflow break; case 4: // SD16MEM0 IFG tmp = SD16MEM0; switch(ch_counter) { case 0: // 200mV SD16INCTL0 = SD16INCH_3; v1 += tmp; ch_counter = 1; break; case 1: // 400mV SD16INCTL0 = SD16INCH_6; v2 += tmp; ch_counter = 2; break; case 2: // temperature SD16INCTL0 = SD16INCH_0; ch_counter = 0; Temperature += tmp; smp_counter++; break; } // process readings after 256 sampling runs if (smp_counter == 256) { v1/=256; v2/=256; Temperature/= 256; smp_counter = 0; // <-breakpoint here Temperature = 0; v1 = 0; v2 = 0; } } _BIC_SR_IRQ(LPM0_bits); // Exit LPM0 }