current sensor

Development & General Chat for the superb openxvario project.

Moderator: rainer

Post Reply
ronron84
Posts: 48
Joined: Sat Apr 18, 2020 7:13 pm
Country: -

current sensor

Post by ronron84 »

Hi,

I've read a lot of thread, but i didn't understand the way to find the value for those line in case i use bridge divider. :(

RESISTOR_TO_GROUND_FOR_CURRENT
RESTSTOR_TO_CURRENT_SENSOR

Thanks for your answers

GRacing
Posts: 25
Joined: Mon Dec 23, 2019 5:53 pm
Country: Portugal

Re: current sensor

Post by GRacing »

Hello ronron84,

The voltage levels accepted by the atmega328 from the arduino depends on is operating voltage, 3,3V or 5V.
So the ADC can´t get higher voltage then the supply voltage.
If you are powering the current sensor from the 3,3 or 5,0 volt you won´t get problems.
In that case you put :

#define RESISTOR_TO_GROUND_FOR_CURRENT 0 // put as comment or set to 0 if no divider is used
#define RESISTOR_TO_CURRENT_SENSOR 0 // put as comment or set to 0 if no divider is used

What current sensor are you using?
mstrens
Posts: 1435
Joined: Fri Dec 27, 2013 7:49 pm
Country: -

Re: current sensor

Post by mstrens »

I presume you have read this (extract of oXs_config_description.h)

* 6.5 - Current sensor parameters **************************************************************************************
* It is possible to measure a current (and current consumption) if a current sensor is connected.
* Connecting a current sensor is an optional feature.
* It requires some additional hardware. It can be an IC like ACS712 (for 5, 20, 30 amp) or ACS758 (for 50, 100, 150, 200 amp).
* Most sensors can read bidirectional currents but ACS758 has "U" types that read only unidirectional current (providing then an higher sensitivity).
* Those current sensors are quite cheap (see e.g. ebay) and return a voltage that depends on the current. This voltage is measured by OXS via an analog pin.
* The Pin value to enter in the oXs_config.h is a number from 0 up to 7 (0 means A0, 1 means A1, ...7 means A7).
* If a current sensor is used, do not to use a pin that is already used by a voltage.
* !! Take care that the voltage applied to Arduino pin may not exceed Vcc (normally 5 volt) or 1.1 volt (if internal reference voltage is used).
* It can be that you have to use a voltage divider in order to reduce the voltage applied on Arduino pin.
* See explanation above (6.2) about voltage divider.
* Take care : do NOT use pins A4 and A5 if you use a vario or an airspeed (those pins are reserved for the barometric and pressure sensors).
* Note: The current sensor is normally powered by the 5 volt VCC from OXS (same as the vario sensor).
* There are bidirectional sensor and unidirectional sensor.
* For bidirectional, output is normally equal to VCC/2 when current = 0 Amp and, for unidirectional, output is normally 0,6 volt at 0 Amp.
* If OXS is connected to a battery giving less than 5.2 volt, the supply voltage for the current sensor will vary with the OXS supply voltage.
* Therefore VCC/2 ( = O amp) will varies with VCC.
* This is an issue if the Arduino ADC is configured to use the 1.1 volt internal reference.
* So, in this case it is better to configure the ADC in order to use VCC as reference for conversion.
*
* In order to use a current sensor, you must say YES in line ARDUINO_MEASURES_A_CURRENT and you have in PIN_CURRENTSENSOR the Arduino pin connected to the current sensor.
* You must also define 2 parameters depending of the type of sensor being use; those parameters are given in the datasheet of the sensor).
* - MVOLT_AT_ZERO_AMP = milliVolt generated by the sensor when current is 0 Amp: normal value is :
* - for a bidirectional sensor : Vcc from current sensor / 2 (so = 2500 if sensor is connected to Arduino Vcc and Arduino Vcc is 5 Volt).
* - 600 for unidirectional sensor
* - MVOLT_PER_AMP = milliVolt per Amp. The value depend on the sensitivity of the sensor (e.g. an ACS712ELCTR-30A-T has a sensitivity of 66 mvolt/A, a ACS758LCB-050U has a sensitivity of 60 mv/Amp)
*
* If you use the 1.1 internal reference to measure voltagse and current, you must also use a voltage divider in order to scale down the voltage produced by the current sensor.
* See the section 6.2 above about voltage divider. The principle are just the same but the names of the 2 paraameters are:
* - RESISTOR_TO_GROUND_FOR_CURRENT
* - RESISTOR_TO_CURRENT_SENSOR
* Note: those parameters are automatically discarded when ARDUINO_MEASURES_A_CURRENT is NO.
* Note: When current sensor is used, oXs can also calculate and transmit current consumption (milliAh) and Fuel (in % going down from 100% to 0%).
* If you want the last one, then use a setup like "Fuel , MILLIAH , -100 , 4000 ,0" in "data to transmit section" (and replace 4000 by the capacity - in milliAmph - of your battery) (see below).
* Still, with Tx using openTx or Ersky9x software, it is better to let the Tx calculates those values by it self based on the current.
* This ensure that values are consistent; it allows to reset the values on Tx side; it allows to change the value of the battery capacity on Tx side (so without having to reload another set up in Arduino oXs).
* E.g on Ersky9x, in Telemetry menu set up "current source" set "FAS"; in "mAh Alarm", set the mah you want for alarm to sound and select warning sound/voice,
* ie 70% of 2200 mAh lipo, use 1540. then the FUEL percentage will start from 100% count down to 0% when 1540 is consumed.



Then in section 6.2 of the same doc you have:
* !! Take care that the voltage applied to Arduino pin may not exceed Vcc (normally 5 volt) or 1.1 volt (if internal reference voltage is used).
* It can be that you have to use voltage divider in order to reduce the voltage applied on Arduino pin compared to the voltage you want to measure.
* For each voltage to scale down, proceed as follow:
* - make a divider with 2 resistors
*
* ------> End point = connect to the device to measure (battery, Current sensor, ...)
* |
* __|__
* | |
* | | R2 (Resistor_To_Voltage)
* | |
* |_____|
* |
* |------> mid point = connect to Arduino pin A0,A1,A2,A3, A6 or A7
* __|__
* | |
* | | R1 (Resistor_To_Ground)
* | |
* |_____|
* |
* ------> connect to Ground
* Note: a capacitor (e.g. 100nf) could be added too between ground and Arduino Analog pin in order to get more stable values.
*
* - R1 and R2 are chosen to make sure that voltage apply to Arduino is quiet close to ( but never exceed) VCC or 1.1 volt depending on your choice regarding the current & voltage measurement (see here above)
* - Volt on Arduino pin = VCC (or 1.1 volt) = "max voltage to measure from this sensor" * R1 / (R1 + R2)
* - R1 could be 10 kOhm; so R2 = R1 * ( ( "max voltage to measure from this sensor" / VCC [or 1.1 depending on the reference] ) - 1 )
* e.g. using 1.1 internal voltage reference and in order to measure max 6 volt with R1 = 10000, then R2 = 10000 * (( 6 / 1.1 ) - 1) = 45545 Ohm; best rounded up to high available value e.g 47000 ohm
*
* The resistors used in voltage dividers have to be specified in lines #define RESISTOR_TO_GROUND and #define RESISTOR_TO_VOLTAGE.
* Eeach line, must contains 6 values (one for each voltage); each value represent the resistance in Ohm or kOhm but use the same unit for both lines.
* If no divider is used for some voltage, set both resistors to 0 (zero)
* If no divider at all is used, lines can be commented (adding "//" in front)


The only think that change for Current is that there are no 6 values in the line but only one value.
If you use Vcc as reference, you do not have to use a divider and you can just put the 2 linea as comment (adding //) ot remove the 2 lines.
If you use 1.1 internal as reference than you have e.g. R1 = 10kOhm and R2 = 10000* ((5/1.1)-1)
GRacing
Posts: 25
Joined: Mon Dec 23, 2019 5:53 pm
Country: Portugal

Re: current sensor

Post by GRacing »

OK, from what i understand you are using the internal voltage reference.

I never did that in any of mine projects, because the IC is powered always above the internal voltage reference, in the case of the atmega 328.

You don´t need 6 values..the 6 values are for voltage reading,not current reading!

Tell me what current sensor are you using?
Are you using the Internal ref 1,1v?

You have the 3,3V arduino or the 5V one?

If you tell me that, i can easily help you.

Best Regards
ronron84
Posts: 48
Joined: Sat Apr 18, 2020 7:13 pm
Country: -

Re: current sensor

Post by ronron84 »

It is to use it with a ACS712 5A in a 5v arduino whith 1.1v selected. with a 10kohm and a 47kohm. I will get
#define RESISTOR_TO_GROUND_FOR_CURRENT 47000 // put as comment or set to 0 if no divider is used
#define RESISTOR_TO_CURRENT_SENSOR 10000 // put as comment or set to 0 if no divider is used

or
#define RESISTOR_TO_GROUND_FOR_CURRENT 47 // put as comment or set to 0 if no divider is used
#define RESISTOR_TO_CURRENT_SENSOR 10 // put as comment or set to 0 if no divider is used

in fact the exemple was not take from the explaination, it make me confused. (i know i'm not a light ! :shock: )

#define RESISTOR_TO_GROUND_FOR_CURRENT 0 // put as comment or set to 0 if no divider is used (e.g. 19.8 for 1.1 internal ref)
#define RESISTOR_TO_CURRENT_SENSOR 0 // put as comment or set to 0 if no divider is used (e.g 39 for 1.1 internal ref)

GRacing
Posts: 25
Joined: Mon Dec 23, 2019 5:53 pm
Country: Portugal

Re: current sensor

Post by GRacing »

i will give you mine humble opinion,

In the future use the VCC, 5V , or 3.3V for Vref instead of Internal ref.
You will gain resolution in the measured value, and don´t need voltage dividers.

The ACS712 only accept 5v of supply, not even 3.3v.
Assuming you are using the bidirectional version at 0 amp , according to the datasheet you will have vcc x 0.5 wich means 2.5V, wich is already more the twice the voltage of the internal ref (1.1V)

The ACS712 5A version gives an output of 185mV / A, wich means that at 5A you will have 2.5V + (0.185 V/A x 5A ) = 3.425V

You put 2 resistors in series in the output of the current sensor:

The first one 20K Ohm resistor and the second one 8K Ohm.
The end of the 8K Ohm resistor connect to ground, and in the connection between the end of the 20K and the start of the the 8K you connect to the analog Pin of the arduino.
With this, at 5A you will get a voltage output of 1V, wich is below the voltage ref (1.1V).

If you use a 47K and a 10K you will loose even more resolution.

But if you want to use it you need to switch the order (BUT PLEASE DON`T FORGET TO DO THE SAME IN REALITY ), but you can use 2 ways:

#define RESISTOR_TO_GROUND_FOR_CURRENT 10000 // put as comment or set to 0 if no divider is used
#define RESISTOR_TO_CURRENT_SENSOR 47000 // put as comment or set to 0 if no divider is used


47000/10000 = 4.7

or
#define RESISTOR_TO_GROUND_FOR_CURRENT 10 // put as comment or set to 0 if no divider is used
#define RESISTOR_TO_CURRENT_SENSOR 47 // put as comment or set to 0 if no divider is used

47/10 = 4.7


The divided value is what matters for the software...In a voltage divider the Highest resistor value is 98% of times for the output, and the smaller one to the ground...and the middle point of connection to the input of the MCU

https://www.allaboutcircuits.com/tools/ ... alculator/

If you didn´t understood , please say.

Regards
ronron84
Posts: 48
Joined: Sat Apr 18, 2020 7:13 pm
Country: -

Re: current sensor

Post by ronron84 »

thanks for your help now it is really clear for me i will use vcc 5v and no divider to get a better resolution with lipo. if i use nimh i can use a divider to compensate the discharge curve. Now i understand why the value are in homs or khoms. When i use your program I've got 1.43v with20k and 8k it's over the 1.1v?
thanks again
GRacing
Posts: 25
Joined: Mon Dec 23, 2019 5:53 pm
Country: Portugal

Re: current sensor

Post by GRacing »

Hello,

You don´t know me, and someone reading this might get it wrong...Every time i post something to help someone, like i was helped in this area from 20 years ago, i try to be precise in order to not induce someone in mistake..."Been there..Done That.." ;)
I only know , something now( a little bit), because a lot of people have helped me since those 20 years.
Attachments
voltage divider.jpg
ronron84
Posts: 48
Joined: Sat Apr 18, 2020 7:13 pm
Country: -

Re: current sensor

Post by ronron84 »

sorry, i put 5v instead of 3.425

Post Reply

Return to “OpenXVario - an open source vario supported by the open source firmwares!!”