Tool/software:
Hi everyone,
I am currently working for a project in which I have three analog inputs on PIN1.1, PIN2.2 & PIN2.4. I want to read all of these PINs with my ADC.
Currently I am doing this with the ADC10 and I am reading the three inputs in sequence. But I don't know how to specifically use the PIN1 and afterwards the PIN2 for the ADC.
Thank you very much for your help.
Yours sincerely,
Timo
#include <msp430.h> #include <stdint.h> #define CURRENT BIT1 // Pin 1.1 #define VOLTAGE BIT4 // Pin 2.4 #define TEMPERATURE BIT2 // Pin 2.2 volatile uint16_t current = 0; // Variable to store ADC result volatile uint16_t voltage = 0; // Variable to store ADC result volatile uint16_t temperature = 0; // Variable to store ADC result void start_ADC_conversion(); void main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer ADC10CTL1 = INCH_4 + ADC10SSEL_1; // Channel select A4 + Conversion sequence mode select == Sequence-of-channels + ACLK - clock (no input div) ADC10CTL0 = SREF_0 + ADC10SHT_2 + ADC10ON + ADC10IE; // REF = VCC & VSS + ADC SampleAndHoldTime 16 x ADC10CLKs + + // ADC10AE0 |= CURRENT; // These bits enable the PIN 1.1 for analog input ADC10AE0 |= (VOLTAGE | TEMPERATURE); // These bits enable the PIN 2.2 & 2.4 for analog input P1SEL |= CURRENT; // ADC input select mode P1.1 P2SEL |= (VOLTAGE | TEMPERATURE); // ADC input select mode P2.2 & 2.4 __bis_SR_register(GIE); // Enable global interrupts while (1) { start_ADC_conversion(); // Start an ADC conversion __delay_cycles(500000); // Delay for a while (for demonstration purposes) } } void start_ADC_conversion() { ADC10CTL1 = INCH_1; // select channel A1 for ADC ADC10CTL0 |= ADC10SC + ENC; // ADC10SC == 0 >> no sample start conversation + ENC == EnableConversation current = ADC10MEM; // saves the ADC measure while (ADC10CTL1 & ADC10BUSY); ADC10CTL0 &= ~ENC; // disable conversation ADC10CTL0 &= ~ADC10IFG; // deletes the ADC-InterruptFlag for the next conversation ADC10CTL1 = INCH_4; // select channel A4 as input ADC10CTL0 |= ADC10SC + ENC; voltage = ADC10MEM; // save ADC measure while (ADC10CTL1 & ADC10BUSY); ADC10CTL0 &= ~ENC; ADC10CTL0 &= ~ADC10IFG; // deletes the ADC-InterruptFlag for the next conversation ADC10CTL1 = INCH_2; // select channel A2 as input ADC10CTL0 |= ADC10SC + ENC; temperature = ADC10MEM; // save ADC measure while (ADC10CTL1 & ADC10BUSY); ADC10CTL0 &= ~ENC; } #pragma vector=ADC10_VECTOR __interrupt void ADC10_ISR(void) { ADC10CTL0 &= ~ADC10IFG; // Clear interrupt flag __bic_SR_register_on_exit(CPUOFF); // Clear CPUOFF bit to exit LPM0 }