ADC and Safe Mode

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
mschulz
Posts: 35
Joined: Fri Apr 17, 2015 11:26 am
Location: Germany

ADC and Safe Mode

Post by mschulz » Wed Jun 24, 2015 12:48 pm

Hello
I have a problem with the ADC (PinX19-X21, X3-X7 and X11 and X12) and the USB.

At the start I read the "zero" values to calc the difference. When the difference is psoitiv the red led get on and when negatie a green led.

When I use putty to schow the prints it runs very vell, but when I start it with the rest button without USB-Cable ist don't work.
The values of the ADC are greater.

To use Putty I start the pyboart in the Safe mode. http://docs.micropython.org/en/latest/t ... reset.html
Do you have any Idea?

Thank you
Last edited by mschulz on Thu Jun 25, 2015 2:30 pm, edited 1 time in total.

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

Re: ADC and USB

Post by dhylands » Wed Jun 24, 2015 4:43 pm

Do you have a schematic which shows how things are connected?

How are you powering the board when not plugged into USB?

Have you measured the voltage being fed to the adc to verify that its the same?

Is A3V3 the same voltage in both cases?

mschulz
Posts: 35
Joined: Fri Apr 17, 2015 11:26 am
Location: Germany

Re: ADC and USB

Post by mschulz » Wed Jun 24, 2015 6:24 pm

Hallo
The following picture schows the Pins I used.
used Pins:
https://www.dropbox.com/s/g476ysd5z0cdh ... e.png?dl=0
Platine Top
https://www.dropbox.com/s/rruqd1zyfdz0q ... p.png?dl=0
Platine Bottom
https://www.dropbox.com/s/8wcuf3uqia047 ... t.png?dl=0

Over the Timer 1 and 8 I controll an RGB LED.

Power:
The board is powered by 24V and a voltage regulator (on the right side). I think there is enough power.
The Sensors I use have an Output between 2,5-5V and get the power from the same source.
To avoid voltage drop the servos have there own voltage regulator (on the left side).

Voltage fed on the ADC: I am so shocked, that I dosn't do something, but I don't know why it should change...
Tomorrow I will check the A3V3 voltage and the ADC input in both cases.

Will make sense to pull up the A3V3 to the same value with I supply the sensors? (of course over the same voltage divider)

Thank you for your helpful questions. So I know what I can check tomorrow .

Edit: Change the URL to the pictures, but there is an error too.
Last edited by mschulz on Thu Jun 25, 2015 5:15 pm, edited 3 times in total.

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

Re: ADC and USB

Post by dhylands » Wed Jun 24, 2015 8:17 pm

You mentioned that the sensors output up to 5V. I just wanted to make sure that you're aware of the fact that the ADC inputs need to be limited to 3.3v.

The digital inputs are 5v tolerant. The analog inputs are not.

mschulz
Posts: 35
Joined: Fri Apr 17, 2015 11:26 am
Location: Germany

Re: ADC and USB

Post by mschulz » Thu Jun 25, 2015 7:27 am

I know. therefore I use a valtage divider.

Today I do not change anything on the hardware or Software. I only start the board on diffferend ways.
First case safe: mode (start with putty [Str. + D)
second case: reset, start with the RST button


The ADC input Voltage is in both cases the same (about 1,7V )
A3V3 voltage is in both cases 3,28 V

The start is in both cases equal. But than in the safe mode it does what it is supposed to, (green LED on) but in the RST modus the red LED is on.

mschulz
Posts: 35
Joined: Fri Apr 17, 2015 11:26 am
Location: Germany

Re: ADC and Safe Mode

Post by mschulz » Fri Jun 26, 2015 9:07 am

My experiments show, that I have an offset between the adc in safe mode and normal boot modus.

Have anybody an Idea why? Or where could be my mistake?


Edit:
I do not find the cause, but I think It was an error with the doftware in my adc class.

mdblabs
Posts: 2
Joined: Mon Jun 29, 2015 10:58 pm

Re: ADC and Safe Mode

Post by mdblabs » Mon Jun 29, 2015 11:01 pm

Almost same problem as you.
I'm trying to read analog sensor in pins from X5 to X8, with values from 0 to 3.3V.
In other analog port I can read it without any problem (example: in X1 to X4).
My really simple code, from an example:

Code: Select all

from pyb import USB_VCP
from pyb import Pin, ADC

u = USB_VCP()
adc = ADC(Pin('X8'))

while True:
    lectura = adc.read()
    print(lectura)

Any idea? Thank you very much.

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

Re: ADC and Safe Mode

Post by dhylands » Tue Jun 30, 2015 6:00 am

Your example works fine for me.

I connected a 10K pot between 3.3v and 0v with the center tap going to X8, and I get values between 0 and 4095 as I adjust the pot from one extreme to the other.

I tried booting up normally and booting up in safe mode and got about the same vaues from the pot in both cases. Both times I was powered from USB.

mschulz
Posts: 35
Joined: Fri Apr 17, 2015 11:26 am
Location: Germany

Re: ADC and Safe Mode

Post by mschulz » Tue Jun 30, 2015 1:35 pm

for me this is a very strange problem,

I have the problem not with determined pins, but with some parts of the software.
I solved it, by comment some parts of my code and decommant it. So I do not found the reason, but for the moment it works.

If sombody whant to look in my code I can send both versions. ( one is ok abnd one has the error)


@mdblabs:
Do you define the Pins with the problems in other part of the code for an other function?
I makte this mistake at the first, because I include an old part of software that I do not use anymore.

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

Re: ADC and Safe Mode

Post by dhylands » Tue Jun 30, 2015 2:26 pm

Sure - I can take a look. You can email the good and bad files to dhylands at gmail dot com.

Post Reply