openXvario+C Current Sensor Support

Development & General Chat for the superb openxvario project.

Moderator: rainer

Patrick74
Posts: 7
Joined: Fri Apr 25, 2014 5:59 am
Country: -

Re: openXvario+C Current Sensor Support

Post by Patrick74 »

Doesn't work :(

I tried with FRSKY_SPORT protocol on S.Port, with Hub protocol on "Data in"and different SENSOR_ID and with default value of the file. I tried with differents setup of #define SETUP_DATA_TO_SEND...

But doesn't work :evil:

However as stated above, the vario high precision can work as a bridge with FAS-40/100 on "Data in", but I haven't found the correct configuration. I wonder if there are not some conflicts with address fields sended in my config... But which one?
Trying to make an oXs current sensor work with Vario high Precision on RX port on a D4R-II and FBVS

User avatar
MikeB
9x Developer
Posts: 17993
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: openXvario+C Current Sensor Support

Post by MikeB »

The FrSky vario will convert 'hub' protocol to SPort protocol, but NOT SPort to 'hub'.

Mike.
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
User avatar
Kilrah
Posts: 11109
Joined: Sat Feb 18, 2012 6:56 pm
Country: Switzerland

Re: openXvario+C Current Sensor Support

Post by Kilrah »

mstrens wrote: If the vario is a bridge than can convert SPORT protocol to Hub protocol (I am not sure it is)
No, the vario only does hub->Sport, not the opposite.

I just tried the data in->data out method and it works fine for me (I've got no current sensor but I get a varying value from my floating wire, so it should be OK).

Config file attached and diff below.
There may be a bug in OXS though, as in hub mode sending current into DEFAULTFIELD the value will vary between 0 and 0.9 while sending it into FRSKY_USERDATA_CURRENT (which should be the same) results in values about 1000x bigger, with the same scaling settings. I presume FRSKY_USERDATA_CURRENT is the correct one.

EDIT: found it, seems to be normal:
CURRENTMA (in Hub protocol, with DEFAULTFIELD , Arduino takes the absolute value of current in milliAmp), divide it automatically by 100 (so no additional multiplier/divider is needed)
But still, with default mAmpPerStep I only get 0.9A with A2 tied to VCC, doesn't seem normal.

Code: Select all

-#define FRSKY_SPORT	   // put this line as comment if OXS is connected to a D serie receiver ( = Hub protocol); do not comment for X serie receiver.
+//#define FRSKY_SPORT	   // put this line as comment if OXS is connected to a D serie receiver ( = Hub protocol); do not comment for X serie receiver.
 
 #define SETUP_DATA_TO_SEND    \
-                        DEFAULTFIELD , ALTIMETER , 1 , 1 , 0 ,\
-                        DEFAULTFIELD , VERTICAL_SPEED , 1 , 1 ,0 , \
                         DEFAULTFIELD , CURRENTMA , 10 , 1 , 0, \
-                        FUEL_FIRST_ID , MILLIAH, -100 , 390 , 100, \
-                        CELLS_FIRST_ID , CELLS_1_2 , 1, 1 , 0
 
-#define VARIO // set as comment if there is no vario 
+//#define VARIO // set as comment if there is no vario 
Attachments
oxs_config.h
(43.28 KiB) Downloaded 320 times
DSC01038.jpg
Patrick74
Posts: 7
Joined: Fri Apr 25, 2014 5:59 am
Country: -

Re: openXvario+C Current Sensor Support

Post by Patrick74 »

It works !!!

I don't know why?! I just started again with a new clean file and it works now :?

I also put "#define VARIO" as comment and disable ALTIMETER and VERTICAL_SPEED... in SETUP_DATA_TO_SEND \

The multiplier factor for CURRENTMA seems not involve the result on the Taranis.
The "Cnsm" field on the Taranis seems also not correct. I tested 60 seconds at ~650mA result = 9-10mAh ! is it a right value?
I will test the offset factor tomorrow.
Trying to make an oXs current sensor work with Vario high Precision on RX port on a D4R-II and FBVS
mstrens
Posts: 1435
Joined: Fri Dec 27, 2013 7:49 pm
Country: -

Re: openXvario+C Current Sensor Support

Post by mstrens »

Patrick74 wrote:It works !!!

I don't know why?! I just started again with a new clean file and it works now :?

I also put "#define VARIO" as comment and disable ALTIMETER and VERTICAL_SPEED... in SETUP_DATA_TO_SEND \

The multiplier factor for CURRENTMA seems not involve the result on the Taranis.
The "Cnsm" field on the Taranis seems also not correct. I tested 60 seconds at ~650mA result = 9-10mAh ! is it a right value?
I will test the offset factor tomorrow.
To measure a current, OXS read in fact a voltage using an ADC (analog digital converter).
This ADC gives to XOS program a value between 0 and 1023; 0 when voltage is 0 volt, 1023 when voltage is equal to the maximum voltage. This maximum can be :
- or 1.1 volt - if internal ref is used
- or Vcc (normaly 5 volt)
Selecting 1.1 or Vcc is done by the line //#define USE_INTERNAL_REFERENCE (see section 5.1 in config.h)

The value (0...1023) that XOS program get from the ADC has then to be converted in milliamp.
This is done by XOS using 2 parameters in config.h file.
#define offsetCurrentSteps 0 // 66mv offset (set to zero for now)
#define mAmpPerStep 0.9775 // INA282 with 0.1 ohm shunt gives 5000mv/A
See section 5.2 in config.h file to have more explanation.

Please note that even if the current consumption can be calculated inside OXS, it does not make sense to send this value to TX because most Tx firmware (e.g. Taranis) calculates it anyway on Tx side.

So, please adjust first the 2 parameters to calibrate the current.

If this explanation is not clear enough, I can calculate the values to be used for XOS if you provide more details on the voltages provided by you current sensor for 2 current e.g.
- voltage for 0 milliamp = X
- voltage for Y milliamp = Z
Gives then X,Y and Z.

Patrick74
Posts: 7
Joined: Fri Apr 25, 2014 5:59 am
Country: -

Re: openXvario+C Current Sensor Support

Post by Patrick74 »

Thank you for your help :)

Firstly, I'm not sure if I have to set internal 1.1 volt or VCC. My VCC is from the ESC which varies according to the load (receiver, servos,...) ~4.86v (seen by the Taranis).

The current ~650mA I told above is the value read on the Taranis (0.6 to 0.7A) and it's an approximate value (it's 0.57 with multimeter). But it is the result mAh calculated by the Taranis is not right! 60sec. at ~650mA is not 9~10mAh but something like 39mAh. Right?

Otherwise I set the value 512 for #define offsetCurrentSteps. This is a +/-5A sensor.
and for #define mAmpPerStep I simply measured several step. But this is not accurate. I have 2.48v for 0mA, and 2.62v for 0.72A. So it's 194mV/A
If I use that value for #define mAmpPerStep = 194*1024/5000=39.73 But I have to put 28 to read the correct value on the Taranis. ?????

So what is wrong?
Trying to make an oXs current sensor work with Vario high Precision on RX port on a D4R-II and FBVS
mstrens
Posts: 1435
Joined: Fri Dec 27, 2013 7:49 pm
Country: -

Re: openXvario+C Current Sensor Support

Post by mstrens »

Patrick74 wrote:Thank you for your help :)

Firstly, I'm not sure if I have to set internal 1.1 volt or VCC. My VCC is from the ESC which varies according to the load (receiver, servos,...) ~4.86v (seen by the Taranis).

The current ~650mA I told above is the value read on the Taranis (0.6 to 0.7A) and it's an approximate value (it's 0.57 with multimeter). But it is the result mAh calculated by the Taranis is not right! 60sec. at ~650mA is not 9~10mAh but something like 39mAh. Right?

Otherwise I set the value 512 for #define offsetCurrentSteps. This is a +/-5A sensor.
and for #define mAmpPerStep I simply measured several step. But this is not accurate. I have 2.48v for 0mA, and 2.62v for 0.72A. So it's 194mV/A
If I use that value for #define mAmpPerStep = 194*1024/5000=39.73 But I have to put 28 to read the correct value on the Taranis. ?????

So what is wrong?
Your current sensor needs a VCC.
I do not know how does it get this VCC.
It could be:
- the (about) 5 volt provided by the ESC
- VCC from Arduino.

I also do not know how does your Arduino get is VCC
It could be that
- you can connect the RAW pin from Arduino directly to the battery if your lipo has not to many cells. It would be necessary to check the data sheet for Arduino pro mini to check the max voltage that the onboard 5 volt regulator accept. If max voltage of your lipo is yo high you can also add a voltage regulator in between. The main advantage of this solution his that Arduino board get a statble voltage (not impacted by servo/motor loads)
- you can connect the arduino VCC pin to the ESC. In this case Arduino VCC will vary a little more.
Note : Connecting arduino RAW pin to ESC is not so good because the voltage provided by ESC is less than 5.3 volt and so the arduino voltage regulator can't regulate.

Anyway, if you measure only a current and that your sensor measures positive and negative current (providing VCC/2 for 0 amp), the best result with be achieve if your current sensor get his power from Arduino VCC because VCC variation will neutralise them self.

Because your XOS measures only current it is better to use VCC instead of internal 1.1 reference. This allows that variations are neutralised and it avoids adding resistors to bring the curent sensor voltage back to 1.1 volt maxi.

650 milliAmp during 1 hour sould provide a current consumption of 650 milliAmph.
So, 60sec should provide a current consumption of 650/3600*60 so about 10.8 milliAmph.
If Taranis gives another value, then there should be an issue in the Taranis.

measuring 2.48 volt for 0 amp is normal for a sensor that measure positive and negative current
2.48 is your VCC/2.
If VCC would be measured by Arduino, ADC would return a value of 1203.
So, it is correct setting the offset to 1023/2 = 512.

If you have 2.48v for 0mA, and 2.62v for 0.72A, it's effectively 194mV/A
The XOS parameter is in milliAmp per (ADC) step.
Using VCC as reference we have:
- 1023 steps -> VCC = 4.86 volt
- 1 step -> 4.86 V / 1023 = 4,75073 mV
- 1000milliAmp -> 194 mv <-> 1023 / 4.86 * 0.194 = 40.84 steps
>> 1 step = 1000 / 40.84 = 24.49 milliAmp
So the parameter milliamp per step should be 24.49 I expect.
To calculate the Amp, XOS applies this formule :
( Steps returned by ADC - Offset parameter) * milliAmp/step parameter.

I hope I am right.
Patrick74
Posts: 7
Joined: Fri Apr 25, 2014 5:59 am
Country: -

Re: openXvario+C Current Sensor Support

Post by Patrick74 »

OK let me check all these informations :?
Trying to make an oXs current sensor work with Vario high Precision on RX port on a D4R-II and FBVS
Patrick74
Posts: 7
Joined: Fri Apr 25, 2014 5:59 am
Country: -

Re: openXvario+C Current Sensor Support

Post by Patrick74 »

The VCC is from an ESC by the Arduino but not from the same source of the current sensor. I have the Batt#1 with ESC to Arduino to the current sensor by raw pin (I could chge it by another, but this is the same way), and batt#2 measured with current sensor.

mstrens wrote: 650 milliAmp during 1 hour sould provide a current consumption of 650 milliAmph.
So, 60sec should provide a current consumption of 650/3600*60 so about 10.8 milliAmph.
ok so 9~10mAh is acceptable as the real current measured is 0.57~0.60A!
Thank you for this ;)

mstrens wrote: If you have 2.48v for 0mA, and 2.62v for 0.72A, it's effectively 194mV/A
The XOS parameter is in milliAmp per (ADC) step.
Using VCC as reference we have:
- 1023 steps -> VCC = 4.86 volt
- 1 step -> 4.86 V / 1023 = 4,75073 mV
- 1000milliAmp -> 194 mv <-> 1023 / 4.86 * 0.194 = 40.84 steps
>> 1 step = 1000 / 40.84 = 24.49 milliAmp
So the parameter milliamp per step should be 24.49 I expect.
To calculate the Amp, XOS applies this formule :
( Steps returned by ADC - Offset parameter) * milliAmp/step parameter.
I hope I am right.
I begin to understand, but your formula is different than the file. But much more closer than my value.

PS. I will add a 47nF capacitor on current sensor as Rainer told in the wiki
Trying to make an oXs current sensor work with Vario high Precision on RX port on a D4R-II and FBVS

Post Reply

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