cancel
Showing results for 
Search instead for 
Did you mean: 

Strange first ADC values when sampling using AnalogIn on MbedOS.

MKren.1
Associate

Hello,

I’m using the B-L475E-IOT01A with MbedOS and have the following code:

hall_a3 = new AnalogIn(A3);

hall_a4 = new AnalogIn(A4);

hall_a5 = new AnalogIn(A5);

while(true) {

printf("Hall A3: %f\n", hall_a3->read());

printf("Hall A4: %f\n", hall_a4->read());

printf("Hall A5: %f\n", hall_a5->read());

wait_ms(3000);

}

I’ve attached all of the analog pins to ground, so I should get all 0.000000 values. Unfortunately I get the following output:

Hall A3: 0.294261

Hall A4: 0.000000

Hall A5: 0.000000

I assumed there would be an issue with the ADC. To test this, I added the A2 channel into the while loop, so that now 4 analog channels would be sampled in a row. I got the following result:

Hall A2: 0.301581

Hall A3: 0.000000

Hall A4: 0.000000

Hall A5: 0.000000

There is no issue when pulling the AnalogIn pins high. When I connect them all to AVcc, I get the following, as expected:

Hall A2: 1.000000

Hall A3: 1.000000

Hall A4: 1.000000

Hall A5: 1.000000

So now I have no idea what the issue might be. Any ideas on how I can solve this? I’ve confirmed that when I actually plug in my sensor that the first channel in the sequence does see expected changes. For example, when I plug in a Hall-Effect sensor, I see the values go up and down for all of the channels in the presence of a magnetic field. However, the first channel never goes below a certain value.

1 REPLY 1

Isn't mbed open source? I believe that it is, so you can debug it as normally, i.e. go through the code and check if it follows the direction in the RM; instrument the code to output intermediate values where appropriate; single-step in debugger, observing the registers content and checking against the expected, etc.

Is the observed behaviour related to powerup, or does it appear also after warm reset? Does it change if you introduce a delay comparable to conversion duration after startup? Can't it be some startup time (ADC analog powerup, VREF powerup) violated?

JW