Hi, I have not been successful with making a differential measurement on ADC0_DP0 and ACD0_DM0.
I was taking the approach similar to 'Multiple Channel' measurements. My thought was DP0 would have a value and DM0 would also have a value. As a result, I anticipated DP0 - DM0 would give my final "Differential" result. This didn't work.
I then proceeded to take the single-end channel approach, even though I set 'Mode Select' to 'Differential'.
I was thinking the 'Differential' result would be one value that I can read. I still think this was wrong. I'm also not clear on my resolution actually is.
Below is a screen capture of ADC1 Component settings, Methods, and finally my code.
Can someone help me get this started?
Also note, I used the Debuger to step through my code and highlighted the &value variable at various voltages from 0Vdc to 3.3Vdc and received the following:
0Vdc = 0x8000
.5Vdc = 0x92f0
1.0Vdc = 0xa690
1.5Vdc = 0xb9e0
2Vdc = 0xce10
2.5Vdc = 0xe0d0
3.2Vdc = 0xfff8
The ADC has a single-ended or differential mode select. When in single-ended mode you know how it works.
If differential mode is selected (DIFF is set in ADC1_SC1A) it configures the ADC input to not be take from a single pin but to be taken from the difference between two specific pins (or an internal differential connection to the temperature sensor, band-gap or VREFSH). External pins are limited to channels 0..3 (if available).
Apart from the configuration and connection there is no difference in reading. The same single value can be read from the ADC's RA register.
Here's what I found.
In my code above I declared the global variable 'value' as "static unit16_t ..."
However, in Component Inspector I set 'A/D resolution' to 12bits.
Equally important, in 'Methods' I chose "GetValue16". I assume this was a problem as well.
My corrections were:
1. In Main.c I changed global variable 'value', "static unit16_t ..." to "static int value;"
2. Also in Main.c in conjunction with "Components" I changed "GetValue16" to "GetValue".
Now when use debuger and watch the variable 'value', I get the correct answer.
Below I have included my code with the above changes for all to see if anyone has the same issue.
I'm certain there are other ways to do it as well. If anyone would like to share another way please be my guest.