Fluctuation in ADC reading in Particle P1

I am using PA0 (A7) ADC on particle P1. I am reading at every 25ms and printing it on Serial at 1 sec. but i get reading like this. 248 247 148 246 246 246 0 246 245 245 246 0 0 245 244 245 0 245 148 244 245 146 from these all values correct value seems 146 around. why i am getting this wrong value. anyone knows about this?

A few of questions:

  1. what is the signal amplitude on A7 - it should be 0-3.3V maximum. If not you may have damaged the analog input.
  2. Is your signal source sharing a ground with the P1? If not then you could just be seeing ground drift.
  3. Are you just using analogRead() to get the values shown - you haven’t set pinMode()?

Also, what is the source of the signal. The impedance of that source is important as the ADC has quite a low input impedance and usually, a 0.1uF capacitor is recommended at the input to improve things.

For analogRead() pinMode() is not requierd, as the function itself does that already, if the pin is only used for analogRead() you even shouldnot set pin mode to avoid switching overhead.

Exactly - that’s why I asked :wink:

@peekay123 - this is a new one on me, how exactly should the 100nF capacitor be connected - I assume pin to ground on device?

@armor, what’s the impedance of your source signal?

Off hand I don’t know - I will ask the electronics engineer.

1 Like

@armor @peekay123 @ScruffR,

  1. yes amplitude will be only between 0-3.3V on adc pin.
  2. yes signal source is sharing ground with P1.
    i want to measure voltage at ADC and want to convert it to current. for current circuit i should have adc value arround 250 but what i get is arround 340. in addition if i place digital multimeter to measure voltage at adc pin it gives me correct voltage in dmm. but that measured value in dmm not matching with read by adc. and above setup is working fine with arduino. i also tried with 0.1uf ceramic capacitor at adc pin. not all readings are wrong like if i take 10 samles it have 1 or 2 reading 340 arround or 0 but that will change my average and it lead to error in reading.

Are you running 1,6A through these resistors?

144V / 90.5Ω = 1.59A that’s not 5W what your R1 & R2 are rated for but 229W and I’d not get anywhere near the device with 144V like that!


144 volt is just one case i used battery which have voltage range till 350. i used same setup for arduino that is working.

@tejasvini, that makes no sense. Are the resistors heating elements or just plain resistors? You are essentially shorting a 144v source a 90.5 ohms wire. Do the calculations!

Also, can you post your code for reading the ADC and converting the value to voltage and current? Assuming ohms law and power calculations don’t apply, with 144v, the voltage at the ADC input will be 0.8v. That translates to 0.8 * (4095/3.3) = 993. I suspect you were calculating with a max ADC count of 1023 based on the Arduino 10-bit ADC and a 5v range. Photon uses a 12-bit ADC and a voltage range of 3.3v or, to be more exact, the voltage on the 3V3 pin.


My electronics guy suggested a unity gain or buffer amplifier can be used where the input impedance can be tuned to the level required. He didn’t specify that for the signal from a current sensor and it works very well. Sorry if this is motherhood and apple strudel.

For @tejasvini I would suggest that you use a current sensor (ACS712 or similar) suitable for your voltage and current. The sensor will produce a voltage in linear proportion to the current and isolates the input to the ADC pin from the current and voltage you are trying to measure.

1 Like

@peekay123, 90 Ohm resistor looks similar to this and 1Ohms resistor like this image are just for reference.

#define ADC_MAX_VALUE      1023
#define CURRENT_MAX        6.6		//  I = V/R , 6.6 A= 3.3 V /0.5

#define BAT_CURRENT_ADC               A7

int AdcRes[10];

void IsrTimer()
   AdcRes[j] = ADCRead(CURRENT_ADC); 
   ActualCurrent = ( AdcRes[j] * MUL_TO_GET_TEST_CURRENT);
int ADCRead(int ADCPin)
 return(analogRead(ADCPin) >> 2);

as per current setup, voltage i receive correct but adc count is arround 504 (10-bit value). i know particle have 12 bit adc but i m using only 10 bit. this 504 value is in AdcRes[j] variable i m printing that on debug.
@armor, for now i can not change hardware more as i said it was working well with arduino.

@tejasvini Where are you setting the ADC resolution to 10 bits with the shift right by 2 bits? Also, I thought it was not recommended to be reading the ADC from within an ISR handler like IsrTimer().

I think you need to check out the Device OS reference.

analogRead() takes one argument pin: the number of the analog input pin to read from (A0 - A5)analogRead() returns an integer value ranging from 0 to 4095.

I appreciate that you have seen this setup work with an Arduino. Have you got a multi-meter and can you check the voltage (with reference to ground). Your circuit, I am guessing, is meant to be like a shunt resistor (very small) where you measure the voltage drop across the resistor and the direct current is then Vdrop/Resistance.