I am running the ADC calibration routine on a K20 and a K10 MCU. When developing the code for the calibration I originally used the COCO bit, as documented in both MCU's reference manuals and in AN3939 and AN4168 for similar ADCs, to determine when the calibration has ended before adding up the registers and putting the results in the offset and gain registers; the COCO bit never became set. I waited over an hour on two occasions.I then found that the CAL bit is cleared when the calibration is complete, in the reference manual's description of the registers, so I wrote my code to look for that condition instead of COCO becoming set and this worked on both a K20 and a K10.
Well a couple months later I learned that on my production units I have an inaccuracy in my ADC results and I tracked it down to be that the ADC calibration is failing. Further investigation showed that the CAL bit was being cleared before calibration had resolved and when setting the gain register the CALF would be set failing the calibration, due to an ADC register being written too. I then re-implemented the COCO bit as the determining factor of when the ADC calibration finished an now that is currently working in my production software (which is very similar to the code where only the CAL bit worked). I am sure that all code that matters is the same between testing code and production code, and I have tried both versions on several MCUs and they behave inconsistently. So my question becomes which method is correct? I need this to work across all units and I have conflicting results.