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.

MSP430F5529 USB interfere with timer A0

Other Parts Discussed in Thread: MSP430F5529

Hello,

I am using USB HID communication on  MSP430f5529 to stream ADC data to PC. I want to trigger ADC conversion every 100us (10kHz) put conversion results in buffer and send data through via USB HID protocol. Whole thing is working except that every 4ms or so timer A0 (that I use to trigger ADC conversion) is skipping (or delaying) one capture/compare interrupt. After skipping one interrupt timer continues normally for 4ms and than does it again.

When I comment out my USB code timer is working perfectly. In the interrupt priority table in documentation it looks like TA0 has greater priority than USB or DMA interrupts.

For USB transfer I am using hidSendDataInBackground function that i found in TI example. That function is implemented using USBHID_sendData function that uses only usbDisableInEndpointInterrupt that should not disable all interrupts (just USB ones):

uint16_t usbDisableInEndpointInterrupt(uint8_t edbIndex)
{
uint16_t state;
state = USBIEPIE & (1 << (edbIndex + 1));
USBIEPIE &= ~(1 << (edbIndex + 1));
return (state);
}

This is relevant part of my code:

Initialization of timer and ISR for timer:

void setupPeriodicTimer()
{
       TA0CCR0 = 1250;
       TA0CTL = TASSEL_2+MC_1+TACLR; // ACLK, count to CCR0 then roll, clear TAR
       TA0CCTL0 = CCIE;
}


#if defined(__TI_COMPILER_VERSION__) || (__IAR_SYSTEMS_ICC__)
#pragma vector=TIMER0_A0_VECTOR
__interrupt void TIMER0_A0_ISR (void)
#elif defined(__GNUC__) && (__MSP430__)
void __attribute__ ((interrupt(TIMER0_A0_VECTOR))) TIMER0_A0_ISR (void)
#else
#error Compiler not found!
#endif
{
         P4OUT ^= BIT1; //toggle the pin just for debug
        ADC12CTL0 |= ADC12ENC + ADC12SC;
}

USB communication call:

if (hidSendDataInBackground((uint8_t*)bufferY,MEGA_DATA_LENGTH,
HID0_INTFNUM,0))
{
          // Operation probably still open; cancel it
         USBHID_abortSend(&w,HID0_INTFNUM);
         break;
}

Can anyone help me finding why USB is interfering with timer TA0? Is it possible that USB interrupt routine is so long that it blocks all things for 100us (My clock is at 25Mhz)?

Thank you all in advance.

  • And why not use CDC without USB and DMA interrupts? In this case for sure timer interrupt will not be disturbed.

    If USB / DMA Interrupt is executing, then higher priority of timer will not help, because it must wait running ISR to finish.

  • Thank you Zrno Soli for your response.

    Thank you for your advice for CDC but my client wants HID.
    I guess if ISR for USB takes that long to finish than I can't do much about it.
    Thank you anyway.
  • My advice would be to eliminate the Timer interrupt code that is used to start the ADC conversion altogether.

    Take a look at the MSP430F5529 datasheet, specifically Table 14 on Page 31. Timer output TA0.1 can be used as a trigger to start an ADC conversion.

    Configure the ADC to sample when the TA0.1 trigger fires. Configure TA0 so that output TA0.1 (CCR0) is at the desired rate.

    In the ADC completion interrupt, queue up the data into the USB HID send buffer as needed.
  • Thank you Brian for your response.

    I will try with that approach and check if I will get more stable sampling intevals.

**Attention** This is a public forum