AnsweredAssumed Answered

KL24 Input Capture for Duty Cycle

Question asked by Luciano Moretti on Mar 30, 2016
Latest reply on Mar 31, 2016 by EARL GOODRICH

Having issues setting up Input Capture to measure a Duty cycle. The pulse I'm trying to capture is ~2uS in length, approximately 28uS between pulses.  I've got the TimeUnit_LDD set to a 48mhz counter frequency, Channel 0 capture on both edges with Interrupts enabled with a high priority.


My OnChannel0 ISR routine stores 10 samples and then would calculate  the duty cycle from those numbers.


void TU2_OnChannel0(LDD_TUserData *UserDataPtr)


  static uint32_t captureValues[10] = {0};

  static int captureIndex = 0;


  TU2_GetCaptureValue(TU2_DeviceData, 0, &captureValues[captureIndex]);


  if(captureIndex == 10){

    // TODO: Calculate duty cycle here

    Duty_Cycle = 0;   

    // Reset the index to start a new measure.

    captureIndex = 0;





If I breakpoint in the if(captureIndex ==10) what I end up seeing is my captureValues array being populated with pairs of values like the following:


[991, 991, 2358, 2358, 3725, 3725, 5092, 5092, 6460, 6460]


The time between the even slotted numbers seems to be equivalent to the 28uS period between rising edges I expect. The odd slots are supposed to correspond to the falling edge 2uS later, but I end up with the same counter value as the preceding even slot.  The interrupt appears to be happening twice, as my indexes increment.