kjordan2001
Posts: 5
Joined: Tue Jul 21, 2015 4:26 pm

[EMW3165] ADC Readings

Tue Jan 05, 2016 7:26 pm

I'm trying to read from an ADC input but it gives me a consistent reading of around 26-28, except when starting up it gives me around 309. When reading from an unconnected ADC input it gives me the same values. Here is the code which I copied from another WICED example:

Code: Select all

void application_start( )
{
    uint16_t value;

    /* Initialise the WICED device */
    wiced_init();

    WPRINT_APP_INFO( ( "Analog in measurement...\n" ) );

    wiced_adc_init( WICED_ADC_5, 1000 );

    while ( 1 )
    {
        wiced_adc_take_sample( WICED_ADC_5, &value );
        WPRINT_APP_INFO( ( "Analog in: %d\n", value ) );
        wiced_rtos_delay_milliseconds( 1000 );
    }
}


I'm connected to pin 34 which should be the correct one for ADC_5.

petesoper
Posts: 10
Joined: Mon Dec 07, 2015 2:02 am

Re: [EMW3165] ADC Readings

Fri Feb 12, 2016 6:50 pm

I've confirmed odd behavior from two EMW3165 modules on WiFiMCU boards purchased last October: one running the WiFIMCU bits rev "0.9.6" and the other running Loboris' January bits rev "0.9.13_LoBo".

I connected a LM35DZ temperature sensor to the first ADC line (pin "D1" on the WifiMCU) and measured the voltage seen by the EMW3165 with a Rigol DM3068 (6 1/2 digit DMM) .

With the WiFiMCU 0.9.6 bits I get readings like this with about five seconds between each function call:

Code: Select all

                              print(read.adc(1))       (reading/4096)*3.3         Rigol DMM
 after power up          2982                              2.402v                             0.198v (i.e. 19.8C/68F)
 2nd reading                 833                              0.671v                             0.198v
 3rd reading                 529                               0.129v                             0.198v                       
 4th reading                 779                               0.627v                             0.198v


With the LoBo 0.9.13 bits:

Code: Select all

                                   print(read.adc(1))       (reading/4096)*3.3         Rigol DMM
 after power up            309                              0.249v                             0.198v (i.e. 19.8C/68F)
 2nd reading                   11                              0.009v                             0.198v
 3rd reading                   12                               0.010v                             0.198v                       
 4th reading                   11                               0.009v                             0.198v


If I grab the sensor with my fingers the meter indicates the expected voltage and the ADC readings reported by the function calls go up from one unbelievable value to a higher unbelievable value.

petesoper
Posts: 10
Joined: Mon Dec 07, 2015 2:02 am

Re: [EMW3165] ADC Readings

Fri Feb 12, 2016 10:38 pm

Aha, too many different boards and pin mappings. I feel silly.
The arguments to adc.read() for WiFiMCU are of course the raw "Dn" pin numbers. So the five analog pins correspond to read() arguments of 1, 13, 15, 16, and 17.

I ran some quick tests on all these pins with the same input of about 200mv and got impossible values from adc.read, but very much larger than what pin one gave me earlier in the day.

The Adafruit ESP8266 Huzzah's single ADC pin (10 bits, referenced to one volt) gives reasonable numbers from my sensor. Off by a few percent from what the DMM reports, but close enough to be able to say the ADC works.

loboris
Posts: 40
Joined: Tue Sep 15, 2015 7:47 am
Location: Zagreb, Croatia

Re: [EMW3165] ADC Readings

Sat Feb 13, 2016 11:30 am

petesoper wrote:Aha, too many different boards and pin mappings...

There was a bug in ADC mapping for D1 on WiFiMCU board which was mapped to the same pin as D17.
It will be fixed in the next release. I will also add the averaging algorithm to improve the ADC accuracy
ADC on pins D13, D15 and D16 works as expected (I've just tested them).
Pin D17 on WiFiMCU board is connected to BLUE LED and is practicaly not usable for ADC measurements.

Image

When converting ADC value to voltage, always use the voltage measured on 3.3V pin (it is never exactly 3.3000 V).

petesoper
Posts: 10
Joined: Mon Dec 07, 2015 2:02 am

Re: [EMW3165] ADC Readings

Sat Feb 13, 2016 3:50 pm

I connected a Siglent SPD3303S (precision power supply) to pins 13, 15 and 16 in turn and used adc.read(). Just as you said, the ADC function works fine. So there's a mystery with yesterday's measurements with the temp sensor, but that's my problem.

But for me with your .13_LoBo bits I cannot make the blue LED light. I tried this:
gpio.mode(17,gpio.OUTPUT)
gpio.mode(17,gpio.LOW)

On a board running the WiFiMCU vendor 0.9.6 firmware the same function calls do supply a ground and light the blue LED.

I can't get back to this for a day or two, but look forward to figuring out what I did wrong yesterday and trying out your latest binaries.

petesoper
Posts: 10
Joined: Mon Dec 07, 2015 2:02 am

Re: [EMW3165] ADC Readings

Sat Feb 13, 2016 3:53 pm

I forgot to ask what kind of frequency of averaging of ADC values are you planning, and will this be a simple running average?

loboris
Posts: 40
Joined: Tue Sep 15, 2015 7:47 am
Location: Zagreb, Croatia

Re: [EMW3165] ADC Readings

Sat Feb 13, 2016 7:14 pm

petesoper wrote:.. gpio.mode(17,gpio.LOW) ...

gpio.write(17,gpio.LOW) / gpio.write(17,gpio.HIGH) turns LED ON/OFF without problem (just tested)

Updated adc module will be ready tomorrow, then you'll be able to test it. Apart from fixed D1 issue, automatic/manual calibration with internal STM32F411 Embedded reference voltage and internal MCU temperature measurement (not very usefull) are added.
For now simple average of up to 128 values is added.
As we don't have the possibility to use external voltage reference, I don't think any more complex averaging algorithm makes sense.
The results I've got are quite good.

kjordan2001
Posts: 5
Joined: Tue Jul 21, 2015 4:26 pm

Re: [EMW3165] ADC Readings

Mon Mar 21, 2016 6:57 pm

There's incorrect mappings for the ADC channels in the EMW3165 WICED patch. I filed a pull request for it a while back.


Return to “General Discussion”

Who is online

Users browsing this forum: BelalMed and 2 guests