weird response when using arm_math library

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

weird response when using arm_math library

596 Views
hunglam
Contributor II

hi,

I have encountered a very weird response of of the internal adc when including the arm_math library. I use kinetis design studio and ksdk 1.3. in my application I use adc0 in the 16bit differential mode. my board is custom made and is based on the k64f mcu. My aim to use the arm_math library to process the digitized data. however, when I include the arm_math library by (#include arm_math.h ), the digitized data show just half the value of the previous measurement without the arm_math library. I have made sure that the measurement conditions have been kept all the same for both measurement.

does anyone have any explanation for that or have encountered this problem?

thanks

0 Kudos
3 Replies

418 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Friend,

Regarding your question, if you use the api function defined in arm_math.h, you have to know the data type in the api function. When you use 16 bits mode and differential mode of ADC to sample external analog signal, the sample can be positive or negative,we say that the sample is in q16 mode, this is the q16 mode representation. In differential mode, the maximum positive is 0x7FFF(32767 in decimal) , which represent 3.3V, the minimum negative value is 0x8000, which represents -3.3V. In differential, the ADC range is enlarged twice, in other words, the adc range is from -3.3V to +3.3V, the total range is 6.6V. In differential mode, the ADC resolution is 6.6V/65535. In the case, you can call the function with q16 data type.

If you use 16 bits mode and single-ended mode of ADC, because the ADC can not sample/represent negative, you will get the value from 0 to 65535, the 65535(0xFFFF) represent 3.3V. In other words, the ADC range is 3.3V instead of 6.6V as that of differential mode. in single-ended mode, the ADC resolution is 3.3V/65535.

I think it can explain why you get half in differential mode than than in single-ended mode.

Hope it can help you.

BR

Xiangjun Rong

pastedImage_0.png

0 Kudos

418 Views
hunglam
Contributor II

hi xiangjun,

thanks for your reply. I need to describe the situation better. I haven't used any of the api functions of arm_math at all. I have just included the arm_math library in my code. the second thing is that I also haven't changed the adc mode. before having included the library and afterwards the adc mode has always been differential, not single ended. the only change in my code is just the addition of this line (#include arm_math.h). just because of this line, the value of the result of the ad conversion has reduced by ABOUT half, and not exactly half. what is also very strange is that the change seems to be irreversible. when i restore my code to its original by removing  the  #include arm_math.h line the value of the ad conversions remains just half...  I just wonder whether that has to do with processor expert that i have used for coding?

0 Kudos

418 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Iam,

I suggest you use a multimeter to test the differential voltage and the ADC sample, then have a list, for example:

times           voltage            sample(reading from ADC_R reg)

1                  1V                      xxx

2                  1.5V                    yyy

3                 2V                       zzz

then you can compute if the sample is correct or not. Note before you reading the ADC_R register, you have to check if the conversion is over by checking the COCO bit in ADCx_SC1n register.

BR

Xiangjun Rong

0 Kudos