The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
starter111
Posts: 40
Joined: Wed Mar 08, 2017 7:24 am

Hi, I'm trying to use pyboard measure negative voltage. Is it a way to do so? I can add circuit if needed it.

starter111
Posts: 40
Joined: Wed Mar 08, 2017 7:24 am

never mind, looks like just need add two resistors for voltage divider.

jimmo
Posts: 1769
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

A voltage divider can only be used to scale a voltage down. i.e. you cannot change its polarity.

Negative voltages (i.e. below your microcontroller's ground) could damage the microcontroller.

Can you describe what you're doing in more detail and we can give you some hints.

Roberthh
Posts: 2067
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Depending on the range of the negative voltage and it's impedance, a voltage divider may work, just between Vdd-ADC_Input-Sensing_Input instead of GND-ADC_Input-Sensing_Input. Don't forget to add a protective Diode to the input, so it cuts off negative voltages.

chrismas9
Posts: 148
Joined: Wed Jun 25, 2014 10:07 am

I have used the method suggested by @roberthh. Here's how it works. Say you want to measure down to -12V.

Make a 5:1 voltage divider, eg 10k and 40k. Connect 10k between Aref (3V3) and ADC input. Connect 40k from ADC input to negative voltage.

When Vin = 0V ADCin = 3.3 - (3.3 + 0)/5 = 2.44V.

When Vin = -12V ADCin = 3.3 - (3.3 + 12)/5 = 0.24V.

starter111
Posts: 40
Joined: Wed Mar 08, 2017 7:24 am

I have two 100k resistors.
r1.pin1 connect to 6v.
r2.pin2 connect to somewhere close to -3v(voltage going to measure).

so negative voltage = r1.pin2 v - (6v - r1.pin2 v)

jimmo
Posts: 1769
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

starter111 wrote:
Tue Jun 25, 2019 8:36 pm
so negative voltage = r1.pin2 v - (6v - r1.pin2 v)
Intuitively, with two 100k resistors, your ADC pin will be at the midpoint (i.e. the mean) between 6V and the voltage you're measuring.

So when the voltage is -3V, then you have 9V across the divider and so 4.5V across each resistor. So now your ADC is at 4.5V below 6V.

But yeah, don't forget the clamping diodes if you think that the input can go below -6V (or above 4V).

This is all assuming your negative voltage is referenced to the same ground etc.

chrismas9
Posts: 148
Joined: Wed Jun 25, 2014 10:07 am

I think there is a typo in your formula. With 100k resistors you will need a small cap on the ADC input as switched cap ADCs will draw transient current spikes from the inputs.

You don't say what MCU you are using but some STM32 ADC pins are completely intolerant of voltages outside supply and GND so use a Schottky diode pair like BAT54S to clamp to Vss and CDs.

starter111
Posts: 40
Joined: Wed Mar 08, 2017 7:24 am