PIT LDVAL issue using TimerUnit_LDD on Kinetis

Discussion created by ScottW on Feb 9, 2012
Latest reply on Aug 23, 2012 by emilien

I'm using a PIT timer on a Kinetis K10 to drive ADC sampling, using the TimerUnit_LDD PE component.  My sampling rate is slightly off, I think because the LDVAL value is being calculated incorrectly by PE.

The datasheet (K10P81M100SF2RM Rev. 5, 8 May 2011) says on p. 985 the LDVAL register should be calculated this way:
LDVAL trigger = (period / clock period) - 1

Which in my case:
Period: 5ms (I want a 200Hz sampling rate)
Clock Period: .5us (bus running at 2MHz)

LDVAL = (5000 / .5) - 1 = 9999

If I enter 5ms into the Counter Restart / Period field, the generated code for the component has this:
  /* PIT_LDVAL0: TSV=0x2710 */
  PIT_LDVAL0 = (uint32_t)0x2710UL;     /* Set up load register */

The hex 0x2710 is decimal 10000, (off by one from what I was expecting), and this value gives me a slight error in my sampling rate.  My workaround for now is to enter a period of 4999.5us.

I'm using CW 10.1 with what should be the latest PE 10.1 patches; I also tried with CW 10.2 and I see the same behavior.  

The bottom of my generated files has this for versioning:
**     This file was created by Processor Expert 5.2 [04.49]
**     for the Freescale Kinetis series of microcontrollers.

The top of the generated component file has this for versioning:
Project   : ProcessorExpert
Processor : MK10DN512ZVLK10
Component : TimerUnit_LDD
Version   : Component 01.122, Driver 01.05, CPU db: 3.00.001
Compiler  : CodeWarrior ARM C Compiler

Let me know if this is a bug, or working as intended... then I'll know if I need to keep an eye on undoing this workaround if it gets modified.