Hi All,
I am looking for some assistance with using the eCAP modules on a TMS320F28335 using Spectrum Digital's eZdsp board. We were having problems with our initial use (detection of transitions of optical encoders for speed estimation), so I wrote a simpler test case to help isolate the problem. The test program continuously buffers data in the 4 registers of one eCAP module. After each capture, an ISR is called to process the data in the current register. Processing consists of accumulating 1000 values and printing the average of the 1000 values on call 1000. Essentially the program is a frequency counter(measuring period) for the input signal. The printing is done directly in the ISR, which is not the best architecture because of the printing time, but it is simple and not responsible for the problems since they occur with or without the printing. No input signal prescaling was used (ECCTL1 bits 13:9 are cleared). I have tried the program with captures of both rising edges and falling edges, and with delta times and absolute times (4 tests). I have also tried all of the possible input qualifications possible. The input for the testing was square waves from 0 to 3 V at a low frequencies around 100 Hz.
There are two problems. First there are sequencing errors. The ISR uses a static variable to keep track of the next register to read: reg 1, reg2, reg3, reg4, reg1, and so on. Sometimes, the sequencing is wrong. That is, the flags provided by the eCAP module to the ISR indicate a different register from next one in the sequence. The second problem is the accuracy of the captures. The frequency of the signal was quite stable based on other measurements, but the period values that were printed varied a lot.
Below is a small excerpt of the output from one of the test cases with delta times.
period = 137853
***ERROR #call 7180, index 3; flags 3; capture: 7528 ALL: 25719 7528 7528 7528
***ERROR #call 7185, index 0; flags 17; capture: 69858 ALL: 69858 69858 74649 354634
***ERROR #call 7190, index 1; flags 17; capture: 53332 ALL: 53332 53332 53332 3459108
***ERROR #call 7195, index 2; flags 3; capture: 70226 ALL: 1303483 70226 70226 70227
***ERROR #call 7200, index 3; flags 9; capture: 42205 ALL: 42205 42205 5499543 42205
period = 129146
period = 123080
***ERROR #call 9205, index 0; flags 17; capture: 7531 ALL: 7531 7531 7531 7144894
period = 127723
***ERROR #call 10210, index 1; flags 9; capture: 7518 ALL: 7518 7518 10243 7518
***ERROR #call 10215, index 2; flags 17; capture: 63551 ALL: 58760 58760 63551 1065067
period = 127000
***ERROR #call 11220, index 3; flags 9; capture: 7525 ALL: 7526 7526 242237 7525
***ERROR #call 11225, index 0; flags 5; capture: 58020 ALL: 58020 569745 58020 58020
***ERROR #call 11230, index 1; flags 9; capture: 59061 ALL: 59061 59061 2574790 59061
period = 137974
***ERROR #call 12235, index 2; flags 3; capture: 7523 ALL: 23934 7523 7523 7523
***ERROR #call 12240, index 3; flags 3; capture: 25338 ALL: 727068 7958 25338 25338
period = 125263
***ERROR #call 13245, index 0; flags 9; capture: 7530 ALL: 7530 7530 19414 7530
***ERROR #call 13250, index 1; flags 3; capture: 58598 ALL: 827327 58598 58598 74707
***ERROR #call 13255, index 2; flags 3; capture: 29337 ALL: 3183281 29337 29337 29337
***ERROR #call 13260, index 3; flags 5; capture: 77109 ALL: 77109 2273121 77109 77109
***ERROR #call 13265, index 0; flags 9; capture: 35364 ALL: 35364 35364 2756127 35364
***ERROR #call 13270, index 1; flags 9; capture: 70414 ALL: 70414 70414 2963684 70414
***ERROR #call 13275, index 2; flags 3; capture: 342 ALL: 2772579 342 342 342
***ERROR #call 13280, index 3; flags 9; capture: 69955 ALL: 69955 69956 1132026 69955
***ERROR #call 13285, index 0; flags 9; capture: 59330 ALL: 59330 59330 4985942 59330
period = 128417
***ERROR #call 14290, index 1; flags 17; capture: 7516 ALL: 7516 7516 7516 9193590
period = 127076
***ERROR #call 15295, index 2; flags 3; capture: 7520 ALL: 8435661 7520 7520 7520
***ERROR #call 15300, index 3; flags 9; capture: 1359 ALL: 12445 12445 2212674 1359
***ERROR #call 15305, index 0; flags 5; capture: 52523 ALL: 52523 2687709 52523 52523
***ERROR #call 15310, index 1; flags 3; capture: 76938 ALL: 1898510 76938 76938 76938
***ERROR #call 15315, index 2; flags 17; capture: 64903 ALL: 64903 64903 64903 5801824
***ERROR #call 15320, index 3; flags 7; capture: 76586 ALL: 1203874 5 76586 76586
***ERROR #call 15325, index 0; flags 17; capture: 63936 ALL: 63936 63936 63936 5571434
As mentioned earlier, the period is an average of 1000 values of a stable signal, so there should be very little variation.
Each time the ISR is called, the eCAP data is validated to ensure that the flags match the expected values. The LSB of the ECFLG register, bit 0, indicates that an interrupt is present, and should always be set when the ISR is called. Bits 1-4 indicate capture events 1-4, respectively have occurred; bit 5 indicates an overflow, and the remainder of the bits are either reserved or used for the PWM functions. A valid flag value should have the INT bit set, the overflow not set, and at least the bit corresponding to the next capture event set. Others may be set if the ISR is not processed quickly enough.
The content of the error message is as follows. After the “***ERROR” prefix, total number of calls to the ISR since the program was started is printed followed by the index of the register that should have data, the flags returned by the eCAP module, the capture data for the register that should have data based on the sequencing of registers so that they would form a circular buffer, and lastly the capture data of all register as they existed at the time. For example, the very last message shows that the error occurred on call number 15325 to the ISR. The data should be in eCAP register 0+1 (capture event 1). Flags show that capture event 4 has occurred. The capture data for the expected event 1 is 63936, and the values in capture register values at that time was 63936, 63936, 63936, and 5571434.
Here are some things I have observed about the errors.
- The calls are always multiples of 5. If the program is run long enough, there is some offset, but they still occur within a small time interval in multiples of 5.
- The errors are tightly grouped in time.
- The flag capture register with the largest value matches the one indicated by the ECFLG register as being the event that occurred.
I would like to know how to get an accurate period measurement and why the errors are occurring and how to handle that issue. There was some variation in the period depending on whether rising edges or falling edges were being detected. Since the controller is socketed on the eZdsp board, I tried a different 28335, and interestingly, the period again changed somewhat. As mentioned before, I tried qualification, and also adding a low-pass filter. Qualification does help to reduce the number of errors with the most giving the best results, although the filter made the problem worse for some reason. The delta measurements had better accuracy than the absolute measurements.
Thanks for any assistance!
Jim Monte
