We are confused when comparing ADC timings from datasheet versus real measurements on the MCU. In real life the measuring takes longer than expected / calculated. This is not a problem as long as we know where the additional cycles come from.
It's important because we want to place the end of a particular SH phase to a well defined time (as usual in motor control applications).
System configuration is as following:
- SYSclock is 80MHz
- ADCclock is 20MHz
- NONOVERLAP mode is enabled
- Simultaneous sampling is activated for SOC0 to SOC9
- All channels use the same trigger which is ePWM2B
- All channels have the same SH windows size of 6
- The configurations of ADC channel, trigger selection and S-H window are written to the corresponding even SOCx numbers
- All corresponding odd SOCx numbers are initialized with 0
- All other unused SOCs are set to 0.
- ADC interrupt 5 is enabled and configured to trigger CLA task 5 after EOC07
- ADC interrupt 6 is enabled and configured to trigger CLA task 6 after EOC09
- Action qualifier registers are used inside CLA to toggle debug pins which are used to show occurrence of a task
Now what we wanna do is to place the end of the S+H window of EOC8 / EOC9 to a defined time. To calculate the corresponding ePWM2B trigger value we use the following formula:
PWMcounts = (SH_01 + C0 + C1 + SH_23 + C2 + C3 + SH_45 + C4 + C5 + SH_67 + C6 + C7 + SH_89) * SYSclock / ADCclock - or simplified to -
PWMcounts = (4 * (SH+ 2*C) + SH) * SYSclock / ADCclock - now with numbers -
PWMcounts = (4 * ((6+1)+ 2*13) + (6+1)) * 80M / 20M = 556
When we measure the rising edges of the debug pins and compare them to a PWM reference signal, both CLA taks 5 and 6 are too late by approximately 300ns. Delays for setting the pins are considered. Further the delay between task 6 and task 5 is closely to 1700ns which is equal to 34 ADC clocks. Subtracting the conversion time for both channels of 2 x 13 clocks a rest of 8 for SH remains.
According to the configured values for ACQPS = 6 and the technical reference we would expect here a value of 7 instead 8. Where does this offset come from?
Thank you in advance
Matt