ADC is very noisy

I connect PA3 to GND and try measure on my FEZ Portal rev B

var analog = AdcController.FromName(SC20260.Adc.Controller3.Id).OpenChannel(SC20260.Adc.Controller3.PF9);
var m = 3300.0 / Math.Pow(2, analog.Controller.ResolutionInBits); // 3300.0/65536
while (true)
  var val = analog.ReadValue();
  double d = val * m;
  Debug.WriteLine("An-> val=" + val.ToString() + " d=" + d.ToString());

An-> val=0 d=0
An-> val=35 d=1.76239013671875
An-> val=5 d=0.25177001953125
An-> val=15 d=0.75531005859375
An-> val=0 d=0
An-> val=21 d=1.05743408203125
An-> val=135 d=6.79779052734375
An-> val=0 d=0
An-> val=0 d=0
An-> val=0 d=0
An-> val=0 d=0
An-> val=0 d=0
An-> val=66 d=3.3233642578125
An-> val=9 d=0.45318603515625
An-> val=1 d=0.05035400390625
An-> val=10 d=0.5035400390625
An-> val=0 d=0
An-> val=11 d=0.55389404296875
An-> val=0 d=0
An-> val=7 d=0.35247802734375
An-> val=0 d=0
An-> val=0 d=0
An-> val=22 d=1.1077880859375

Why is the ADC making so much noise?

The ADC’s reference is the same 3.3V used to power the module. Not the best solution when you want a more stable ADC. It was the same on the old G120 and I ended up with a digital filter applied to the sensor reading (thermocouple)

There is a ferrite bead between the ADC REF and 3.3V but that alone is not enough for a stable reference.

The only time this really works is when you use the same ref to power your external sensor and works great with resistance bridges such as mV output pressure transducers.

If you need a more stable reading, your only real option is an external ADC with a stable REF. I think there are some Click options for this. The MCP3428 that I use for 4-20mA sensing duties gives a ver nice stable reading but is only good to 2.048V without external scaling.

What are you planning to connect to the ADC?

Would grounding the unused pins on the ADC multiplexor help?

The FEZ boards are designed for simplicity but the modules have analog grounds if you need to design something with better analog signals

You still need a stable REF to get a stable reading and it also depends on the input loading too but connecting unused inputs to the ground via a pulldown is still a good idea.

I tried

var AdcPin = GpioController.GetDefault().OpenPin(SC20260.Adc.Controller3.PF6);

for unused inputs. It does not help

What resolution in bits does it respond with?

[EDIT] Saw the 65536 in your source so 16 bits.

analog.Controller.ResolutionInBits = 16

Looking at the math’s you are using, what does d represent? I assume that is mV?

If I use 3.3 / 65536 and use your val of 135 I get a reading d of 0.006797V which is 6.797mV as per your d value.

6.67mV is not that bad considering the ADC ref is not a stable input. :wink:

Yes, mV
I was expecting instability at most 4 LSBs

what filter are you using? Can you share? :slight_smile:

With a stable REF, possibly.

See the modified one here from Ian Lee. Original was Mr_John_Smith.

1 Like

Can I used ADC in differential mode?

Why I get exception?

  AdcController.FromName(SC20260.Adc.Controller3.Id).ChannelMode = AdcChannelMode.Differential;
catch (Exception ex)
#### Exception System.NotSupportedException - CLR_E_NOT_SUPPORTED (1) ####
#### Message: 
#### GHIElectronics.TinyCLR.Devices.Adc.Provider.AdcControllerApiWrapper::SetChannelMode [IP: 0000] ####
#### GHIElectronics.TinyCLR.Devices.Adc.AdcController::set_ChannelMode [IP: 0008] ####
#### TinyCLRApplication1.Program::Main [IP: 0024] ####

Exception: “System.NotSupportedException” in GHIElectronics.TinyCLR.Devices.Adc.dll

I do not think we support differential. We probably should remove from libs. @Dat_Tran what do you think?