Hello,
in the last days I've been trying to configure the ADC-Component of the processor expert to do an average over 32 samples.
When setting number of conversions to 1 everything works fin. But as soon as I set the number of conversions to another value the conversion routines calculate false values.
As far as i can tell there is a bug in the generated code (or in my configuration for Processor Expert):
The OnMeasurementComplete-method of the ADC-LDD component uses a DWORD to save the result of the conversation:
dword ResultData; | /* Temporary result data */ |
ResultData is passed on as a pointer to the GetMeasuredValues-method.
the GetMeasuredValues converts this pointer to a pointer to AdcLdd1_TResultData (which is a typedefed as a uint16_t).
This causes the processor to write a u16-value into the dereferenced dword-variable, which wreaks havoc in the OnMeasurementComplete-method.
My opinion is that the variable ResultData should be of Type AdcLdd1_TResultData in order to work properly.
When I change the cody by hand everything works fine, but Processor Expert will overwrite my changes when I generate the code again, so that's not an option.
I am using the newest KDS IDE 2.0 release, but the error already existed in KDS IDE 1.0.1.
The Processor I am using is Kinetis MK22FN1M0VLQ12.
Is this a bug in Processor Experts generated code or am In configuring PE wrong?
best regards,
JustAnotherUser
Solved! Go to Solution.
Hi just,
Yes , you are right , and i have also said that "If use pBuffer ++ save the data of ADC result , there will be error ."
So , the best way is change ResultData to type AdcLdd_TResultData as you said .
Wish it helps you!
If you still have question, please contact me!
Best Regards,
Alice
Hello ,
After you change the code by hand ,you can prevent the Processor Expert change your code by " right on the ADC ->Code Generation ->Don't Write Generated Component Modules".
Thus when you click the generation code , the ADC code not change .
About your said situation , I will check as soon as possible .
Hope it helps
ALice
Thank you Alice, preventing the Processor Expert from regenerating the ADC-Code will help me until the issue is resolved.
Hello Justan,
I have checked the code about you said. (I use the latest vision KDS 2.0)
Yes ,the AD2_OutV is defined to "word", while in this function :
"LDD_TError AdcLdd1_GetMeasuredValues()"
the code "AdcLdd1_TResultData *pBuffer = (AdcLdd1_TResultData *)BufferPtr;" it forced BufferPtr point to 16 bit space , so there is no error .
If use pBuffer ++ save the data of ADC result , there will be error .
Best Regards
ALice
Please find attached a demo project for the FRDM-K20D50M:
The code generation for the ADC is disabled in this demo project because I left a comment and a breakpoint in the ADC-Routines.
As soon as I set the number of conversions to a value other than 1 the temporary variable "dword ResultData;" is introduced to the AdcLdd1_OnMeasurementComplete()-function.
This variable is neither initialized to zero, nor completely overwritten in the getMeasuredValues-Function.
As far as I can see this causes wrong output values.
Since it depends on the initialization-value of ResultData (which depends on the current stack content) I couldn't reproduce the error I am seeing in my project, but if I
or
the wrong measurements will disappear immediately.
Hi just,
Yes , you are right , and i have also said that "If use pBuffer ++ save the data of ADC result , there will be error ."
So , the best way is change ResultData to type AdcLdd_TResultData as you said .
Wish it helps you!
If you still have question, please contact me!
Best Regards,
Alice
Thank you,
Everything works as expected now.
But I think this Bug in Processor Expert should be taken care of. It's a nasty kind of bug that'll work most of the time, but depending on the stack will ruin the whole application because of some misleading A/D-values.