ADC Conversion

Questions and discussion about The WiPy 1.0 board and CC3200 boards.
Target audience: Users with a WiPy 1.0 or CC3200 board.
Oli_
Posts: 15
Joined: Sun Nov 15, 2015 1:36 am

ADC Conversion

Post by Oli_ » Sun Nov 15, 2015 2:04 am

Hi,

While playing with ADC to read the Lipo voltage from my expansion board, I experience strange behavior with the modulus operator on ADC readout.

Try the following :
>>> from machine import ADC
>>> adc = ADC()
>>> lipo = adc.channel(pin='GP3')
>>> lipo()
3594
>>> lipo()
3603
>>> lipo()
3601
>>> lipo(),lipo()%4095
(3600, 3603)
>>> lipo(),lipo()%4095
(3601, 3603) <----
>>> lipo(),lipo()%4095
(3601, 3607) <----
>>> lipo(),lipo()%4095
(3602, 3602)
>>> lipo(),lipo()%4095
(3601, 3601) <----
>>> lipo(),lipo()%4095
(3602, 3602)
>>> lipo(),lipo()%4095
(3601, 3602) <----
>>> lipo(),lipo()%4095
(3602, 3600)
>>>
If in the REPL I type 3601%4095 several times, no surprise I always get 3601.
If I readout ADC value, the modulus to 4095 of same readout does not return the same value. See example here above.

Any thought ?

Olivier

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: ADC Conversion

Post by dhylands » Sun Nov 15, 2015 4:26 pm

The ADC line will have fluctuations as the MCU consumes varying amounts of current as it runs. This is normal.

scudderfish
Posts: 24
Joined: Sun Oct 04, 2015 9:06 am

Re: ADC Conversion

Post by scudderfish » Sun Nov 15, 2015 5:19 pm

As Dave said (but in other words) uour two calls to lipo() will be returning different values. Call it once and assign it to a variable.
a=lipo()
a,a%4095

Regards,
David

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: ADC Conversion

Post by dhylands » Sun Nov 15, 2015 7:05 pm

And also, Not quite sure why you're using modulo 4095, which will give values between 0 and 4094. I would have expected you to use modulo 4096 which will give values between 0 and 4095 (unrelated to the issue you posted about, just an observation).

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: ADC Conversion

Post by pythoncoder » Mon Nov 16, 2015 10:46 am

Well, indeed. But given the essentially similar results without the modulo operator I can't see it serves any purpose here.
Peter Hinch
Index to my micropython libraries.

Oli_
Posts: 15
Joined: Sun Nov 15, 2015 1:36 am

Re: ADC Conversion

Post by Oli_ » Tue Nov 17, 2015 12:14 am

scudderfish wrote:As Dave said (but in other words) uour two calls to lipo() will be returning different values. Call it once and assign it to a variable.
a=lipo()
a,a%4095

Regards,
David
Yes ! Of course ... this was a dumb question ... I forgot that I made two calls ...

Thanks David and Dave

Oli_
Posts: 15
Joined: Sun Nov 15, 2015 1:36 am

Re: ADC Conversion

Post by Oli_ » Tue Nov 17, 2015 12:17 am

dhylands wrote:And also, Not quite sure why you're using modulo 4095, which will give values between 0 and 4094. I would have expected you to use modulo 4096 which will give values between 0 and 4095 (unrelated to the issue you posted about, just an observation).
Yes, its a typo ;)

Oli_
Posts: 15
Joined: Sun Nov 15, 2015 1:36 am

Re: ADC Conversion

Post by Oli_ » Tue Nov 17, 2015 12:26 am

pythoncoder wrote:Well, indeed. But given the essentially similar results without the modulo operator I can't see it serves any purpose here.
Indeed, but I was just trying to understand why I got different values.
Before doing this test I was writing a method to convert the ADC to a decimal formated value and used modulus to compute it.

Oli_
Posts: 15
Joined: Sun Nov 15, 2015 1:36 am

Re: ADC Conversion

Post by Oli_ » Fri Nov 20, 2015 6:16 am

I continue on the same topic for an other issue.
It's written in the documentation of the Wipy that the maximum voltage at the input of the ADC is 1.4V.
This mean that I should have an ADC reading of 4095 for 1.4V, right ?
Practically, if I do a rules of 3 with my actual readings, the full scale voltage is 1.53V.
Do you experience the same thing ?

Olivier

Oli_
Posts: 15
Joined: Sun Nov 15, 2015 1:36 am

Re: ADC Conversion

Post by Oli_ » Fri Nov 27, 2015 6:17 pm

Hi All,

Nobody did the test ?

Post Reply