LowPowerLab Forum

Hardware support => Moteino => Topic started by: G550_Pilot on March 30, 2018, 01:09:06 PM

Title: Moteino USB ADC Resolution - PSI Readings on Analog Pin (Sanity Check)
Post by: G550_Pilot on March 30, 2018, 01:09:06 PM
Hey Everyone -

I am trying to fine tune my programming work on my pool control system and I am finally getting around to fine-tuning my pressure readings and I think I may have screwed up on my math to convert my reading from my analog input to PSI.

When I started digging back into it, the first question is what is the ADC resolution on the Moteinos? An I correct that it is a 12-bit ADC and hence 0-1023 values for 0v to 5v readings?

Here is my code:


// Get our Filter Pressure
void get_filter_pressure()
{
  sensorVoltage = analogRead(PSI_SENSOR_PIN);   // Let's read our pressure sensor
  PSI = ((sensorVoltage-146)/204)*25;  // Some calibration to convert the output to voltage and then to PSI
  pool_sensors.PSI = PSI;
}


The 146 value is what I am reading when there is ambient (or 0) pressure.

I am just looking for a sanity check on the math.

Thanks
Title: Re: Moteino USB ADC Resolution - PSI Readings on Analog Pin (Sanity Check)
Post by: perky on March 30, 2018, 01:18:21 PM
Careful with integer maths truncation. I assume sensorVoltage is a float? If not you might need to cast it to a float. I assume PSI is also a float?

Mark.
Title: Re: Moteino USB ADC Resolution - PSI Readings on Analog Pin (Sanity Check)
Post by: G550_Pilot on March 30, 2018, 02:10:31 PM
Yes sensor is a float but PSI in an int.


// Pool Filter Pressure Sensor Setup
#define PSI_SENSOR_PIN  0    // Sensor on A0 on MotenioUSB R5
float sensorVoltage = 0;
int PSI = 0;
Title: Re: Moteino USB ADC Resolution - PSI Readings on Analog Pin (Sanity Check)
Post by: TomWS on March 30, 2018, 04:08:42 PM
Quote from: G550_Pilot on March 30, 2018, 01:09:06 PM
When I started digging back into it, the first question is what is the ADC resolution on the Moteinos? An I correct that it is a 12-bit ADC and hence 0-1023 values
As a clarification, it is a 10bit ADC with 0-1023 values.
Quote
for 0v to 5v readings?
Better not put anything higher than 3.3V (Moteino VDD) on the Analog input pin...

Tom
Title: Re: Moteino USB ADC Resolution - PSI Readings on Analog Pin (Sanity Check)
Post by: G550_Pilot on March 30, 2018, 04:32:29 PM
Thanks Tom -

While there is the capability of going above 3.3V, if that were to happen that means my filter pressure is almost 75psi and I would have a lot more problems to worry about than the mote.

As a side note, why can the Mote not take above 3.3v on the analog pins? What would you have to do if you wanted to measure say, 200Psi?
Title: Re: Moteino USB ADC Resolution - PSI Readings on Analog Pin (Sanity Check)
Post by: TomWS on March 30, 2018, 05:15:11 PM
Quote from: G550_Pilot on March 30, 2018, 04:32:29 PM
Thanks Tom -

While there is the capability of going above 3.3V, if that were to happen that means my filter pressure is almost 75psi and I would have a lot more problems to worry about than the mote.

As a side note, why can the Mote not take above 3.3v on the analog pins? What would you have to do if you wanted to measure say, 200Psi?
A voltage greater than VDD will forward bias the substrate diode at the input pin, creating a low impedance path into VDD - not good.

Any voltage you measure needs to be no more than VDD AT THE PIN (you can't convert anything higher than 1023@VDD anyway).  However, if your sensor can put out 5.00V at 200PSI, then a resistor divider of 170K:330K or some such combination will produce a full scale reading at the ADC for the 5V output from the sensor.

Tom

Title: Re: Moteino USB ADC Resolution - PSI Readings on Analog Pin (Sanity Check)
Post by: Uncle Buzz on March 30, 2018, 06:21:05 PM
Quote from: G550_Pilot on March 30, 2018, 04:32:29 PM
What would you have to do if you wanted to measure say, 200Psi?

Psi is not something than the microcontroller can read, it reads only electrical values, so you use something which convert PSI (or whatever else like higher electrical values the microcontroller can't read directly) to electrical value in the range of the microcontrolleur.
If you need precision, you can't use the same conversion to read some PSI or some hundred PSI.

For PSI (or any other unit of pressure) you can find some pressure sensor with I2C (from 10 bits (cheaper) to 24 bits (~100$))
Title: Re: Moteino USB ADC Resolution - PSI Readings on Analog Pin (Sanity Check)
Post by: G550_Pilot on April 08, 2018, 08:21:59 PM
Ah...I see what I was doing, I was assuming 5.0v on A0 in my calculations instead of 3.3v!!
Title: Re: Moteino USB ADC Resolution - PSI Readings on Analog Pin (Sanity Check)
Post by: TomWS on April 08, 2018, 10:00:52 PM
Quote from: G550_Pilot on April 08, 2018, 08:21:59 PM
Ah...I see what I was doing, I was assuming 5.0v on A0 in my calculations instead of 3.3v!!
What I find is useful is to always take a 'readVCC' measurement on every sample time (useful for monitoring battery level) and then using the result to scale any other analogRead value using VDD as the reference against this reading.  This typically provides very accurate 'other' readings rather than assuming the VDD is 3.300Volts.

Tom