This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430FR2433: ADC Interrupt

Part Number: MSP430FR2433


Hi,
the below is my ADC code, and we have integrated a uart to print the ADC value on console. the ADC configured for A single channel is converted repeatedly. and i am able to get the print continuously in ISR  if it's in debug mode,
if i flashed the code then i unable to get the print continuously. can you please say what may be the issue.


unsigned int ADC_Result;

int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop WDT

initClockTo16MHz();
// Configure GPIO
P1DIR |= BIT0; // Set P1.0/LED to output direction
P1OUT &= ~BIT0; // P1.0 LED off

#ifdef UART_PRINT_ENABLE
UART_config(); // Configures UART
#endif
// Configure ADC A1 pin
SYSCFG2 |= ADCPCTL1;

// Disable the GPIO power-on default high-impedance mode to activate
// previously configured port settings
PM5CTL0 &= ~LOCKLPM5;

// Configure ADC10
ADCCTL0 |= ADCSHT_2 | ADCON; // ADCON, S&H=16 ADC clks
ADCCTL1 |= ADCSHP; // ADCCLK = MODOSC; sampling timer
ADCCTL2 |= ADCRES; // 10-bit conversion results
ADCMCTL0 |= ADCINCH_3; // A1 ADC input select; Vref=AVCC
ADCIE |= ADCIE0; // Enable ADC conv complete interrupt

msp_uart_log_info ("MSP: ADC Configured......\n\r");
while(1)
{
ADCCTL0 |= ADCENC | ADCSC; // Sampling and conversion start
__bis_SR_register(LPM0_bits | GIE); // LPM0, ADC_ISR will force exit
__no_operation(); // For debug only
if (ADC_Result < 0x1FF)
P1OUT &= ~BIT0; // Clear P1.0 LED off
else
P1OUT |= BIT0; // Set P1.0 LED on
__delay_cycles(5000);
}
}

// ADC interrupt service routine
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=ADC_VECTOR
__interrupt void ADC_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(ADC_VECTOR))) ADC_ISR (void)
#else
#error Compiler not supported!
#endif
{
switch(__even_in_range(ADCIV,ADCIV_ADCIFG))
{
case ADCIV_NONE:
break;
case ADCIV_ADCOVIFG:
break;
case ADCIV_ADCTOVIFG:
break;
case ADCIV_ADCHIIFG:
break;
case ADCIV_ADCLOIFG:
break;
case ADCIV_ADCINIFG:
break;
case ADCIV_ADCIFG:
ADC_Result = ADCMEM0;
msp_uart_log_info ("MSP: ADC intrr %d\n\r",ADC_Result);

__bic_SR_register_on_exit(LPM0_bits); // Clear CPUOFF bit from LPM0
break;
default:
break;
}
}

  • Now i am getting the print continuously , i made only the change  

    ADC_Result = ADCMEM0;

     to 

    ADC_Result = (ADCMEM0 & 0x3FF); //iam trucating to 10bit adc

    due to this, how it's working i don't know

    and also i getting like values with out giving any input to P1.1

    MSP: ADC intrr 1023
    MSP: ADC intrr 1023
    MSP: ADC intrr 1020
    MSP: ADC intrr 1023
    MSP: ADC intrr 1023
    MSP: ADC intrr 1023
    MSP: ADC intrr 1023
    MSP: ADC intrr 1023
    MSP: ADC intrr 1021
    MSP: ADC intrr 1023
    MSP: ADC intrr 1022
    MSP: ADC intrr 1023

    with ADCMCTL0 |= ADCINCH_3; //mode//

    even iam giving a ldr to P1.1 the same result iam getting.

  • Can you pease explan how the value of ADCMEM0 is depends on ADCMCTL0 |= ADCINCH_*

  • 1.Do you also make the code free run in debug mode?

    2.Can you try to directly put the ADC result into UART TX register? I would assume it may have some problem with the prinf function.

  • I have run the code in debug mode also
    i think there is no wrong with uart log

  • ADCMCTL0 |= ADCINCH_3; // A1 ADC input select; Vref=AVCC
    This converts from channel A3 (P1.3). If you want to convert from channel A1 (P1.1), this should be

    ADCMCTL0 |= ADCINCH_1; // A1 ADC input select; Vref=AVCC

    If you're using the Launchpad, don't forget to remove the jumper from J11, so LED2 doesn't get in the way.

  • thank you bruce,

    and can you see the 1st reply and tell me how the ISR triggering happen continuously after this change in ISR --->ADC_Result = (ADCMEM0 & 0x3FF);

    and if iam thinking wrong please let me know, where we were configure(specify register) for continuous isr triggering and for A single channel is converted repeatedly mode

  • When the output isn't continuous, what does it look like? (a) nothing (b) a few messages then nothing (c) bursty

    The debugger can cause the (backchannel) UART to appear bursty (c). For (a)-(b) I'd pause the debugger to see where it's executing after it hangs.

**Attention** This is a public forum