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.

CCS/MSP430F133: Clocks and ADC understanding help

Part Number: MSP430F133

Tool/software: Code Composer Studio

Hello,

I've been working on an application that uses TimerA to generate various square waves using the GPIO.  I have that working.  I also need to periodically read the ADC.  When I add the ADC code, the square wave code stops running.  I've been pouring over the user guide to determine what I'm doing wrong but the user guide is somewhat obtuse and I've not found my problem yet...  The timer is setup as follows:

void Init_Clock()
{
// Stop Watchdog timer
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
CCTL1 = CCIE; // CCR1 interrupt enabled
CCR1 = TICS_FOR_50ms;
CCTL2 = CCIE; // CCR2 interrupt enabled
CCR2 = TICS_FOR_20ms;
TACTL = TASSEL_2 + MC_2 + TAIE; // SMCLK, Contmode,
}

The ADC is setup as follows.

void Init_ADC()

{

ADC12CTL0 = SHT0_10 + ADC12ON; // Set sampling time, turn on ADC12
ADC12CTL1 = SHP; // Use sampling timer, SMCLK
ADC12IE = 0x01; // Enable interrupt
ADC12CTL0 |= ENC; // Conversion enabled
P6SEL |= 0x01; // P6.0 ADC option select
}

I start the ADC acquisition periodically from the timerA  CCR2  countdown interrupt by calling

ADC12CTL0 |= ADC12SC;  // Start Conversion

The timerA code runs fine until I make the above start conversion call.  When I make that call, the repetitive TimerA interrupts (in which we create the square waves) stop being generated.

I'm sure I've not configured the clock for the ADC correctly but that secret sauce seems to elude me.  Obviously I need a better clock subsystem understanding.  

Suggestions appreciated.

- Dave

  • ADC cannot "steal"  clock from timer :) You enable ADC interrupt, but do not mention ISR (interrupt service routine), nor show it. If there's no proper ADC ISR - then this is your problem.

  • That's a good thought but I do have the ISRs defined (below).  The ADC ISR comes directly from one of the ADC sample programs.   In the timer ISR fires fine for approximately 15 seconds until I tell the ADC to sample.  After the ADC starts the timer ISRs stop.  The ADC ISR never fires since P3.2 never goes high...


    // ADC12 interrupt service routine
    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector=ADC12_VECTOR
    __interrupt void ADC12_ISR (void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(ADC12_VECTOR))) ADC12_ISR (void)
    #else
    #error Compiler not supported!
    #endif
    {
    P3OUT |= 0x04; // raise P3.2
    ADC12CTL0 &= ~ENC; // Conversion enabled


    // if (ADC12MEM0 < 0x7FF)
    // P3OUT &= ~0x02; // Clear P3.1 LED off
    // else
    // P3OUT |= 0x02; // Set P3.1 LED on

    __bic_SR_register_on_exit(LPM0_bits | GIE); // Clear CPUOFF bit from 0(SR)
    }

    // Timer_A3 Interrupt Vector (TAIV) handler
    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector=TIMERA1_VECTOR
    __interrupt void Timer_A(void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(TIMERA1_VECTOR))) Timer_A (void)
    #else
    #error Compiler not supported!
    #endif
    {
    switch( TAIV )
    {
    case 2: // CCR1
    {
    P3OUT ^= 0x01; // DEBUG Toggle P3.0
    CCR1 += TICS_FOR_50ms; // Add Offset to CCR1
    }
    break;
    case 4:
    {
    P3OUT ^= 0x02; // DEBUG Toggle P3.2
    P1OUT ^= 0x02; // Toggle P1.1
    CCR2 += TICS_FOR_20ms; // Add Offset to CCR1
    if (secondCountDown <= 0)
    {
    secondCountDown = TICS_PER_SECOND;
    secondCount++;

    // debug - start ADC
    if (secondCount == 15)
    StartADCFlag = 1;
    }
    else
    {
    secondCountDown--;
    // P3OUT &= ~0x04; // LOWER P3.2
    }
    }
    break; 
    case 10:
    {
    // P3OUT ^= 0x04; // Toggle P3.2
    }
    break; // overflow not used
    }
    __bic_SR_register_on_exit(LPM0_bits | GIE); // clear LPM0

    }

  • Lot of stuff is going on in your code, yet still it is not clear where problem resides. At least I can't see it. Maybe code where you start ADC conversions is not good. Make project copy, clean your code down to essential part of just timer, adc and their interaction, test it to see that problem is still there - then show us whole stuff. Note that showing commented-out trash code is not a good idea because we are getting impression that you don't care, so you cannot expect much care in return.

**Attention** This is a public forum