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.

msp430 f5529 adc12 with timerb trigger

hi,

I am a newcomer to msp430 platform.I am trying to implement  a project in which timerb0 controls sampling sequence of adc12.

Timerb0 works in upmode and in the first half of the period a pulse is generated and when CCR1 hits the half period pulse is stopped.

What I want to do is start sampling after  certain clock cycles when the pulse is stopped.Following is my code.My problem is adc12 isr is never triggered .

void main(void){
WDT_A_hold(WDT_A_BASE);
isPulseHigh=false;
initPorts();
initAdc12();
initPwm();
while(1)
{
// Enable GIE
__bis_SR_register(LPM0_bits+GIE);
__no_operation();
}
}
void initPorts(){
PULSE_PORT_DIR = BIT0+BIT2;                       
PULSE_PORT_OUT=BIT0+BIT2;
}
void initPwm(){
//Set up Timer B in continuous mode for multiple time base PWMs
 TBCCTL0 =OUTMOD_4+CCIE;               
 TBCCTL1 =OUTMOD_4 + CCIE;              
 TBCCTL2 =OUTMOD_4 + CCIE;               
 TBCCTL3 = OUTMOD_4 + CCIE;               
 
 TBCCR0=200;   /
 TBCCR1=100;
 TBCCR2=110;
 TBCCR3=120;
 TBCTL = TBSSEL_2 + MC_1 + TBIE;
__bis_SR_register(LPM0_bits + GIE);     
__no_operation();                        
}
void initAdc12(){
P6SEL |= 0x01;                            // Enable A/D channel A0
ADC12CTL0 = ADC12ON+ADC12SHT0_8+ADC12MSC; // Turn on ADC12, set sampling time
// set multiple sample conversion
ADC12CTL1 = ADC12SHP+ADC12CONSEQ_2;       // Use sampling timer, set mode
ADC12IE = 0x01;                           // Enable ADC12IFG.0
//ADC12CTL0 |= ADC12ENC;                    // Enable conversions
//ADC12CTL0 |= ADC12SC;                     // Start conversion
__bis_SR_register(LPM0_bits + GIE);       // Enter LPM4, Enable interrupts
   __no_operation();
}
void startConversion(){
ADC12CTL0 &= ~ADC12ENC;
ADC12IE = 0x01;                           // Enable ADC12IFG.0
ADC12CTL0 |= ADC12ENC;                    // Enable conversions
ADC12CTL0 |= ADC12SC;                     // Start conversion
}
void stopConversion(){
ADC12CTL1&= ~ADC12CONSEQ_2;
ADC12CTL0 &= ~ADC12ENC;
ADC12CTL0 |= ADC12ENC;
}
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=ADC12_VECTOR
__interrupt void ADC12ISR (void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(ADC12_VECTOR))) ADC12ISR (void)
#else
#error Compiler not supported!
#endif
{
  static unsigned char index = 0;
  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;
    }
    __bic_SR_register_on_exit(LPM0_bits+GIE);
    break;
  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;
  }
}
// Timer B0 interrupt service routine
#pragma vector=TIMERB0_VECTOR
__interrupt void TIMERB0_ISR (void)
{
PULSE_PORT_OUT=BIT0+BIT2;
__bic_SR_register_on_exit(LPM0_bits+GIE);
}
// Timer_B1 Interrupt Vector (TBIV) handler
#pragma vector=TIMERB1_VECTOR
__interrupt void TIMERB1_ISR(void)
{
switch(__even_in_range(TBIV,14))
{
case 0: break;
case 2:
PULSE_PORT_OUT ^=BIT0;     //Pulse is stopped
__bic_SR_register_on_exit(LPM0_bits+GIE);
break;
case 4:                                            //Here conversion should  start
PULSE_PORT_OUT ^=BIT2;
startConversion();
__bic_SR_register_on_exit(LPM0_bits+GIE);
break;
case 6:
stopConversion();         //Here conversion should  stop
__bic_SR_register_on_exit(LPM0_bits+GIE);
break;
case 14:
break;
default: break;
}
}

  • Hi Tufan!

    Did you check if the startConversion()-function is called inside the timer ISR?

    Dennis
  • Thank you for your kind reply Dennis.

    As per my problem, yes start and stop conversion functions are called and executed but adc12 never hits the isr.I think my problem is that I have to hard wire timerb output to adc wtih this adc configuration.I tried a double channel repeated conversion.channel 0 for start and stop conversion and channel 1 for actual readings.I hardwired P7.4 (signal generated by timerb) to 6.0 for starting and stopping the conversions.It seems to work but there must be a way to manipulate the sequence with software only.

    Thanks,

    Tufan

  • and I figured out that I have one more problem.I think the timerb isr is not hit in correct sequence.what I want to do is first catch case2, then case4 and case6 and finally timerb0 isr.

    when I run the program it hits timerb0 isr before but not after case6.

    Any help will be highly appreciated.
    Thanks in advance,

    Tufan
  • Hi Tufan,
    You can start a ADC conversion with the ADC12SC bit manually by setting this bit in an ISR for example or with another source which can be your timer for example. This source you have to configure with the ADC12SHS bits. In your code I cannot find the ADC12SC bit or the trigger source configuration. In our users guide is a good overview about this settings, please have a look at the ADC12 block diagram. For triggering the ADC12 with Timer, you don’t need to hardware any pins.

    Tobias
  • Tobias Oschmann said:
    In your code I cannot find the ADC12SC bit

    tufan takak said:
    void startConversion(){
    ADC12CTL0 &= ~ADC12ENC;
    ADC12IE = 0x01;                           // Enable ADC12IFG.0
    ADC12CTL0 |= ADC12ENC;                    // Enable conversions
    ADC12CTL0 |= ADC12SC;                     // Start conversion
    }

**Attention** This is a public forum