cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L1 strange ADC reading

giuseppe
Associate II
Posted on February 21, 2014 at 10:14

Hi, please I need a little help.

I'm using a STM32L151RCT6A in a project. We need to distiguish the hardware version of boards, so to use a single pin, we read the voltage on a partitor made of two resistor.

It is connected to pin PC5, corresponding to analog input 15.

Actually, lower resistor is 1,3k? and upper is 10k?. On 12 bits, I expect to read 471.

Now, the strange behaviour: the value read is greater, approx. 1300 to 1500 instead.

I tried to add delays, or some tests to control if value decreased because any discharge, but not, it stays at those levels.

But if I set a breakpoint after conversion, and then I retry to convert, value is correct!

I tried also to read with same code another ADC channel (nr. 4) where battery is connected, and it reads correctly.

Someone has an idea?

#show-code
7 REPLIES 7
Posted on February 21, 2014 at 11:29

Someone has an idea?

What's the sample time?
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
frankmeyer9
Associate II
Posted on February 21, 2014 at 11:47

What happens if you discard the first result, and use the second (or third one) ?

BTW, unless you are tight on GPIOs, using digital inputs for HW revision detection is more common. Just pull 3 or 4 inputs up (down), and insert jumpers (0R resistors) in a binary coded manner. Beside of never giving fuzzy results (like ADC readings), this allows for an easy visual recognition of HW revision, even by laymen.

giuseppe
Associate II
Posted on February 21, 2014 at 12:12

I set ADC_SampleTime_384Cycles, it works on channel 4.

What I find incredible it's if I execute code in run mode, the result is incorrect, but if I do it in step or setting SWSTART manually, then value is ok.

Thanks

giuseppe
Associate II
Posted on February 21, 2014 at 12:18

Dear fm, I used this system on other boards already with success.

On this project I haven't any other pin free to put digital jumpers.

I made a loop to check if values were differents each other to avoid glitches.

They are all about three times bigger!

Thanks

chen
Associate II
Posted on February 21, 2014 at 12:27

Hi

''I expect to read 471.

Now, the strange behaviour: the value read is greater, approx. 1300 to 1500 instead.''

''But if I set a breakpoint after conversion, and then I retry to convert, value is correct!''

If the test is being done in the boot/startup - it may be done before the supply rail has settled. The STM32 can start on a supply voltage as low as 1.8V

I am not saying this is the problem - just a thought.

giuseppe
Associate II
Posted on February 21, 2014 at 12:31

No, supply is stabilized.

Then, I'm testing, it's switched on from many hours.

frankmeyer9
Associate II
Posted on February 21, 2014 at 12:36

On this project I haven't any other pin free to put digital jumpers.

 

It was a mere suggestion, under the assumption you have free pins.

I made a loop to check if values were differents each other to avoid glitches.

 

They are all about three times bigger!

 

What is the reading if you connect this ADC input to 0V and 3.3V ?

Could you try to connect another ADC input to the same network, and compare both ?

Besides of possible ADC configuration problems, you do any scaling ?