Page 2 of 2

Re: OpenXSensor @8MHz

Posted: Mon Jul 14, 2014 8:21 am
by mstrens
davx wrote:Hi,

I've made some tests with the original OXS code and cells function doesn't work either...
- In HUB mode, I can see the 3 cells display in the default telemetry screen but the values are wrong.
- In S.Port mode, no cells display on the default screen.
Davx,
could it be that you where using Analog pin 7 to read one of your voltage?
I found a bug in oxs_arduino.cpp
There is a line
if ( arduinoData.mVoltPin[cntVolt] < 7) {
It must be
if ( arduinoData.mVoltPin[cntVolt] < 8) {

I am still not sure that this is on the only one bug.
Your feedback is welcome.


Edit:
I had a look at your config file.
It seems that you where using pin 0, 1, 2; so the bug about pin 7 does not explain your issue.

But I found perhaps a mistake in your config file.
You have
#define offset_1 0
#define mVoltPerStep_1 ( ARDUINOVCC * 1000.0 / 1023.0 * 1.0 ) // => 1 is the divider factor
#define offset_2 0
#define mVoltPerStep_2 ( ARDUINOVCC * 1000.0 / 1023.0 * 1.0 )
#define offset_3 0
#define mVoltPerStep_3 ( ARDUINOVCC * 1000.0 / 1023.0 * 1.0 )

When you want to measure a 3s lipo you for sure have to use at least 2 dividers (if using Vcc as reference - and 3 if using internal 1.1 Vref). So you had to adapt the divider factors. It can't be 1 for the 3 cases.
Still not sure this is the solution because your said that Voltages where OK.
Did you try to get all 3 voltages individually?
Which values did you got (e.g. 4000, 8000, 12000 mv)

Let me know if this solves the issue.

Re: OpenXSensor @8MHz

Posted: Mon Jul 14, 2014 12:10 pm
by mstrens
I found another bug in oxs_out_frsky.cpp in the section used for Hub protocol
Here the code that you could try (it should replace the current code for the function SendCellVoltage )
There were mistakes in the reformatting.
Let me know if it is OK for Hub protocol.
For SPORT I still have to look for.

/**********************************************************/
/* SendCellVoltage => send a cell voltage */
/**********************************************************/
void OXS_OUT_FRSKY::SendCellVoltage( uint32_t voltage) {
static byte cellID ;
static uint16_t cellVolt;
// voltage is formatted as (kex) 12 34 56 78 where 123 = volt of cell n+1 (divided by 2), 456 idem for cell n, 7 = max number of cell and 8 = n (number of cell)
// target format for Hub (hex) : 84 56 and (8+1)1 23
cellID = (voltage & 0x0000000f);
cellVolt = ((voltage >> 8) & 0x0fff) ;
uint8_t v1 = (cellID<<4 & 0xf0) | ((cellVolt & 0x0f00)>>8) ;
uint8_t v2 = (cellVolt & 0x00ff);
uint16_t Value = (v2<<8) | (v1 & 0x00ff) ;
SendValue(FRSKY_USERDATA_CELL_VOLT, Value);
cellID++;
if (cellID < NUMBEROFCELLS) {
cellVolt = (voltage & 0xfff00000) >> 20 ;
uint8_t v1 = (cellID<<4 & 0xf0) | ((cellVolt & 0x0f00)>>8) ;
uint8_t v2 = (cellVolt & 0x00ff);
uint16_t Value = (v2<<8) | (v1 & 0x00ff) ;
SendValue(FRSKY_USERDATA_CELL_VOLT, Value);
}
}

Re: OpenXSensor @8MHz

Posted: Mon Jul 14, 2014 4:24 pm
by davx
Hi,
mstrens wrote: There is a line
if ( arduinoData.mVoltPin[cntVolt] < 7) {
It must be
if ( arduinoData.mVoltPin[cntVolt] < 8) {
I've corrected that but
It seems that you where using pin 0, 1, 2; so the bug about pin 7 does not explain your issue.
indeed ;)
But I found perhaps a mistake in your config file.
...
When you want to measure a 3s lipo you for sure have to use at least 2 dividers (if using Vcc as reference - and 3 if using internal 1.1 Vref). So you had to adapt the divider factors. It can't be 1 for the 3 cases.
Still not sure this is the solution because your said that Voltages where OK.
Did you try to get all 3 voltages individually?
Which values did you got (e.g. 4000, 8000, 12000 mv)
I'm testing directly with the arduino vcc voltage source so I can apply manually to every Ax input or all at the same time.

Here are the values sent:

Code: Select all

#define SETUP_DATA_TO_SEND    \
                        DEFAULTFIELD , ALTIMETER , 1 , 1 , 0 , \
                        DEFAULTFIELD , VERTICAL_SPEED , 1 , 1 , 0 , \
                        FRSKY_USERDATA_VFAS_NEW , VOLT1 , 1 , 10000 , 0 , \
                        FRSKY_USERDATA_TEMP1 , VOLT2 , 1 , 100 , 0 , \
                        FRSKY_USERDATA_TEMP2 , VOLT3 , 1 , 1 , 0 , \
                        DEFAULTFIELD , CELLS_1_2 , 1 , 1 , 0 , \
                        DEFAULTFIELD , CELLS_3_4 , 1 , 1 , 0
I'm sure the different voltages are correctly measured because I can see them in Vfas, T1 and T2 but the divider factors are not taken into account so I get millivolts...
mstrens wrote:I found another bug in oxs_out_frsky.cpp in the section used for Hub protocol
Here the code that you could try (it should replace the current code for the function SendCellVoltage )
There were mistakes in the reformatting.
Let me know if it is OK for Hub protocol.
I just tried your correction and it's better but still not quite good ;)
When I put Vcc on the Ax pins one at a time, I get the corresponding cell display correctly in the default telemetry screen.
But with the 3 pins at Vcc at the same time, the screen shows wrong unstable values...

Re: OpenXSensor @8MHz

Posted: Mon Jul 14, 2014 7:26 pm
by davx
davx wrote: I'm testing directly with the arduino vcc voltage source so I can apply manually to every Ax input or all at the same time.
I just realized that the cell function is only valid for a serial battery pack...

I will test properly later.

Re: OpenXSensor @8MHz

Posted: Mon Jul 14, 2014 7:55 pm
by mstrens
davx wrote:
davx wrote: I'm testing directly with the arduino vcc voltage source so I can apply manually to every Ax input or all at the same time.
I just realized that the cell function is only valid for a serial battery pack...

I will test properly later.
Indeed.
Cell function calculates the difference between adjacent voltages.
There are some checks on the values too (e.g. a voltage must be > 500 mv otherwise it is considered as 0.
This allow e.g. to configure OXS to measure a 3S lipo but to connect only a 2s (some noise on voltage 3 will have no effect).

I looked at the issue about not applying the divider.
I found a bug for VOLT1, VOLT2, ... in Hub mode.
I hope I fix it with a new version of oxs_out_frsky.cpp and .h
I put them on google.
Can you test using them.
Please note that when you use VFAS_NEW, TX make some formating too. So you probably have to play with multiplier and/or divider to get the correct value.
This issue should not exist for Temp1 or Temp2 I think.

Re: OpenXSensor @8MHz

Posted: Tue Jul 15, 2014 4:54 pm
by davx
mstrens wrote: Indeed.
Cell function calculates the difference between adjacent voltages.
For the moment, I can't try with a real serial mount battery but I will do it soon.
I looked at the issue about not applying the divider.
I found a bug for VOLT1, VOLT2, ... in Hub mode.
I hope I fix it with a new version of oxs_out_frsky.cpp and .h
Yes, it works now !

Good job !!

Re: OpenXSensor @8MHz

Posted: Wed Jul 16, 2014 4:23 pm
by davx
mstrens wrote:I found another bug in oxs_out_frsky.cpp in the section used for Hub protocol
Here the code that you could try (it should replace the current code for the function SendCellVoltage )
There were mistakes in the reformatting.
Let me know if it is OK for Hub protocol.
For SPORT I still have to look for.

/**********************************************************/
/* SendCellVoltage => send a cell voltage */
/**********************************************************/
void OXS_OUT_FRSKY::SendCellVoltage( uint32_t voltage) {
static byte cellID ;
static uint16_t cellVolt;
// voltage is formatted as (kex) 12 34 56 78 where 123 = volt of cell n+1 (divided by 2), 456 idem for cell n, 7 = max number of cell and 8 = n (number of cell)
// target format for Hub (hex) : 84 56 and (8+1)1 23
cellID = (voltage & 0x0000000f);
cellVolt = ((voltage >> 8) & 0x0fff) ;
uint8_t v1 = (cellID<<4 & 0xf0) | ((cellVolt & 0x0f00)>>8) ;
uint8_t v2 = (cellVolt & 0x00ff);
uint16_t Value = (v2<<8) | (v1 & 0x00ff) ;
SendValue(FRSKY_USERDATA_CELL_VOLT, Value);
cellID++;
if (cellID < NUMBEROFCELLS) {
cellVolt = (voltage & 0xfff00000) >> 20 ;
uint8_t v1 = (cellID<<4 & 0xf0) | ((cellVolt & 0x0f00)>>8) ;
uint8_t v2 = (cellVolt & 0x00ff);
uint16_t Value = (v2<<8) | (v1 & 0x00ff) ;
SendValue(FRSKY_USERDATA_CELL_VOLT, Value);
}
}
This code seems to work very well !! You can put it in the repository.


I saw you removed the function "SendAltGPS" from oxs_out_frsky.cpp, can you keep it ?
I don't think it's a problem, even if not used, and I've a GPS which I'd like to use with OXS as we have a serial connexion available ;)

Re: OpenXSensor @8MHz

Posted: Wed Jul 16, 2014 6:55 pm
by mstrens
davx wrote:
mstrens wrote:I found another bug in oxs_out_frsky.cpp in the section used for Hub protocol
Here the code that you could try (it should replace the current code for the function SendCellVoltage )
There were mistakes in the reformatting.
Let me know if it is OK for Hub protocol.
For SPORT I still have to look for.

/**********************************************************/
/* SendCellVoltage => send a cell voltage */
/**********************************************************/
void OXS_OUT_FRSKY::SendCellVoltage( uint32_t voltage) {
static byte cellID ;
static uint16_t cellVolt;
// voltage is formatted as (kex) 12 34 56 78 where 123 = volt of cell n+1 (divided by 2), 456 idem for cell n, 7 = max number of cell and 8 = n (number of cell)
// target format for Hub (hex) : 84 56 and (8+1)1 23
cellID = (voltage & 0x0000000f);
cellVolt = ((voltage >> 8) & 0x0fff) ;
uint8_t v1 = (cellID<<4 & 0xf0) | ((cellVolt & 0x0f00)>>8) ;
uint8_t v2 = (cellVolt & 0x00ff);
uint16_t Value = (v2<<8) | (v1 & 0x00ff) ;
SendValue(FRSKY_USERDATA_CELL_VOLT, Value);
cellID++;
if (cellID < NUMBEROFCELLS) {
cellVolt = (voltage & 0xfff00000) >> 20 ;
uint8_t v1 = (cellID<<4 & 0xf0) | ((cellVolt & 0x0f00)>>8) ;
uint8_t v2 = (cellVolt & 0x00ff);
uint16_t Value = (v2<<8) | (v1 & 0x00ff) ;
SendValue(FRSKY_USERDATA_CELL_VOLT, Value);
}
}
This code seems to work very well !! You can put it in the repository.


I saw you removed the function "SendAltGPS" from oxs_out_frsky.cpp, can you keep it ?
I don't think it's a problem, even if not used, and I've a GPS which I'd like to use with OXS as we have a serial connexion available ;)
davx,
did you test it with a lipo cell and checking on the Taranis display?
I had a look at the Frsky spec and they say that the cell Id must start from 1 and not from 0

Here the extract from there spec.
0001(1) means the first cell of pack, the last 12bit 0x834 (2100) means the value is 4.2V

Re: OpenXSensor @8MHz

Posted: Wed Jul 16, 2014 7:06 pm
by davx
I've made a 3 cells NiMh pack cause I don't have voltage divider and every test I made were in real situation.

I've seen the protocol doc and I wonder if OpenTX is adapting itself whether there is a first cell number 0 or 1...
However, I think you should stick to the FrSky doc, less questions that way ;)

Re: OpenXSensor @8MHz

Posted: Wed Jul 16, 2014 7:12 pm
by mstrens
davx wrote:I've made a 3 cells NiMh pack cause I don't have voltage divider and every test I made were in real situation.

I've seen the protocol doc and I wonder if OpenTX is adapting itself whether there is a first cell number 0 or 1...
However, I think you should stick to the FrSky doc, less questions that way ;)
Ok nowI understand why you had the same value in the parameters for voltage divider.

The next version I will put on google will have 1 for the first cell id, 2, ...
It should be good if you recheck that it works then.

Re: OpenXSensor @8MHz

Posted: Thu Jul 17, 2014 11:21 am
by davx
@mstrens,
davx wrote: I saw you removed the function "SendAltGPS" from oxs_out_frsky.cpp, can you keep it ?
I don't think it's a problem, even if not used, and I've a GPS which I'd like to use with OXS as we have a serial connexion available ;)
What do you think ?

Re: OpenXSensor @8MHz

Posted: Thu Jul 17, 2014 11:32 am
by mstrens
I can put it again as comment but even if it not in the latest version,you always can find it back in google (because you can find the all history and see chenges between 2 versions). I think that the original functions to format measurements in hub protocol are in version r199

Re: OpenXSensor @8MHz

Posted: Thu Jul 17, 2014 11:49 am
by davx
Ok.