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.

CC430 5137RF900 - Help with ADC12 triggered from Timer A1

Having trouble getting ADC12 to trigger sampling from Timer A1.  I am getting TImer A1 interrupts ok.  I had the ADC interrupt working until I treid to set the sampling source to Timer A1.  Banging my head against wall.  Could use some help please.

//main loop

BSP_Init();

 WDTCTL = WDTPW+WDTHOLD;                   // Stop watchdog timer
   
/* Initialize ADC12_A */ 
ADC12CTL0 = ADC12ON;               // Turn on ADC12
ADC12CTL0 |= ADC12SHT0_4;     // Sampling time 64 Clk Cycles
  
ADC12CTL1 = ADC12SHP + ADC12SHS_2 + ADC12CONSEQ_2;      // SAMPCON from Sampling Timer
                                                                                                                             // TA1 Trigger
                                                                                                                             // Single Channel Single Conversion
  
ADC12MCTL0 = ADC12INCH0 + ADC12SREF2; // Input A0, Vr+ = VeREF+ (ext) and Vr-=AVss

ADC12IE = 0x01;           // Enable ADC12IFG.0
ADC12CTL0 |= ADC12ENC;    // Enable conversions
ADC12CTL0 |= ADC12SC;     // Start conversion
  
//Init Timer A1 for 512Hz
TA1CCTL0 = CCIE;       // CCR0 interrupt enabled
TA1CCTL1 = OUTMOD_2;   //send trigger to ADC12
TA1CCR0 = 63;          // Set for 512Hz Sampling 32Khz -> 0.03ms/count
TA1CTL = TASSEL_1 + MC_1 + TACLR;   // ACLK, upmode, clear TAR
 __bis_SR_register(GIE); //enable interrupts
    
 while(1);


// Timer A0 interrupt service routine
#pragma vector=TIMER1_A0_VECTOR
__interrupt void TIMER1_A0_ISR(void)
{
 P2OUT ^= 0x02; //toggle P2.1
  __no_operation();
}

#pragma vector=ADC12_VECTOR
__interrupt void ADC12ISR (void)
{
  static unsigned char index = 0;

  P2OUT &= ~0x02; // Goop timing test
  switch(__even_in_range(ADC12IV,34))
  {
  case  0: break;                           // Vector  0:  No interrupt
  case  2: break;                           // Vector  2:  ADC overflow
  case  4: break;                           // Vector  4:  ADC timing overflow
  case  6:                                  // Vector  6:  ADC12IFG0
    results[index] = ADC12MEM0;             // Move results
    index++;                                // Increment results index, modulo; Set Breakpoint1 here
  
    if (index == 8)
      index = 0;                            // Reset the index; Set Breakpoint here
     
  case  8: break;                           // Vector  8:  ADC12IFG1
  case 10: break;                           // Vector 10:  ADC12IFG2
  case 12: break;                           // Vector 12:  ADC12IFG3
  case 14: break;                           // Vector 14:  ADC12IFG4
  case 16: break;                           // Vector 16:  ADC12IFG5
  case 18: break;                           // Vector 18:  ADC12IFG6
  case 20: break;                           // Vector 20:  ADC12IFG7
  case 22: break;                           // Vector 22:  ADC12IFG8
  case 24: break;                           // Vector 24:  ADC12IFG9
  case 26: break;                           // Vector 26:  ADC12IFG10
  case 28: break;                           // Vector 28:  ADC12IFG11
  case 30: break;                           // Vector 30:  ADC12IFG12
  case 32: break;                           // Vector 32:  ADC12IFG13
  case 34: break;                           // Vector 34:  ADC12IFG14
  default: break;
  }
  P2OUT |= 0x02; // timing test
}

  •  5137 datasheet does not list TA1 as a source for the ADC12SHS signal. The only trigger is TA0CCR1.
    I believe this somewhat misleading naming is because originally there wa sjsut a Tiemr A (TA) with its output signals TA0 to TAx. Now there are two TimerA (0 and 1) and still each has its own TA0..x output signal, which is routed to the global signal PM_TAnCCRxA.

    In other datasheets this has been clarified by using the notation TAn.x for the signals and output pins (some have up to 3 TimerA and another TimerB)

    Check teh device datasheet, the tables in the TAx sections. There the signal connections are listed.

  • Thanks so much for your quick reply Jens-Michael, it is much appreciated.  I took a closer look to the areas you mentioned but still have not had success getting Timer A1 to trigger ADC12.  It appeared from the CC430_5137 data sheet that only Timerr A0 would trigger ADC12 via CCR1 but I tried using Timer A0 and had no luck as well.

    In my code I tried experimenting with changing ADC12SHS_x from 0-3 with only SHS_0 generating ADC interrupts but not at the corrrect timing since it does not use the Timer source.  I placed a value in CCR1 as well to see if that would work.

        /* Initialize ADC12_A */
       ADC12CTL0 = ADC12ON + ADC12SHT0_4;  // Turn on ADC12, Sampling time 64 Clk Cycles
     
       ADC12CTL1 = ADC12SHP + ADC12SHS_1 + ADC12CONSEQ_2; // SAMPCON from Sampling Timer
                    // TA1 Trigger
                    // Single Channel Single Conversion
       ADC12MCTL0 = ADC12INCH0 + ADC12SREF2; // Input A0, Vr+ = VeREF+ (ext) and Vr-=AVss
       ADC12IE = 0x01;           // Enable ADC12IFG.0
       ADC12CTL0 |= ADC12ENC;    // Enable conversions
     
        //Init Timer A1 for 512Hz
     TA1CCTL0 = OUTMOD_2 + CCIE;    //send trigger to ADC12
       TA1CCR0 = 63;             // Set for 512Hz Sampling 32Khz -> 0.03ms/count
       TA1CCR1 = 15;
       TA1CTL = TASSEL_1 + MC_1 + TACLR;   // ACLK, upmode, clear TAR
       
       __bis_SR_register(GIE);    //enable interrupts

  • James Gravelin said:
    but still have not had success getting Timer A1 to trigger ADC12

    That is because TimerA1 cannot trigger the ADC12. only the TA1 signal from TimerA0 can. TA1 does not refer to TimerA1, but to the TA1 signal that is output by any timer module. And only the TA1 signal from Timer0.CCR1 is routed to the ADC triggers. (that is why I was talking about better calling it TA0.1 in opposition to TA1.1 from Timer1 which cannot trigger the ADC).

    In order to get a trigger, you'll need to configure TA0CCR1 properly. It won't just fire on TAR==CCR1. You need to set the outmode to something useful (set/reset, for example), so it will set on CCR1 and reset on TAR->0. This is why you can use the trigger signal as sampling timer too -  during 'set' phase of the trigger, the signal is sampled, and on the 'reset' phase the conversion starts. If you want to use the SHT_x smaple timing, you'll need to set ADC12SHP too, else the trigger signal level determines start and end of the sampling phase (and start of the conversion) 

    Just setting TA0CCR1 to something will eventually set the CCR1IFG bit, but nothing else. The OUT bit is low per default and since the default OUTMOD is OUT bit value, it (and therefore the TA0.1 signal) will stay low and never trigger anything.

    The 5137 has no other ADC12 trigger than TA0.1 routed to ADC12SHS_1. So TimerA0 CCR1 in an outmode that toggles its output signal is the only external trigger source to the ADC12.

  • Hi Jens-Michael, sorry for the delay in thanking you for a really great explanation and clarification on ADC and Timers.  I ended up getting pulled off to work on somethig else and now I am back and going to dust this off and see what I can do.

    Regards,

     

    Jamie

**Attention** This is a public forum