mstrens / oXs_on_RP2040

version of openXsensor to be used on raspberry pi pico RP2040 (more protocols, more functionalities)
92 stars 23 forks source link

Strange issues encountered by JETI in testing current and temperature #91

Closed aepub closed 1 year ago

aepub commented 1 year ago
 During the use of OXS, there were problems with the constantly fluctuating values of the tested voltage, current, consumption capacity, temperature, etc. Initially, it was thought that the interference caused by the interaction between the RP2040 ZREO module and other peripheral accessories was the reason. Therefore, we attempted to design a PCB that integrated RP2040 chip, MP6050, MS5611, and current sensor chip ASP758-150B.

 After the production of PCBway was completed, testing was carried out, but unfortunately, the integrated PCB board also encountered the same problem. The measured values of voltage, current, temperature, etc. being tested could not display fixed data, and there was always a phenomenon of up and down deviation. The battery capacity consumed was also slowly increasing. A phenomenon similar to 'leakage' occurs.

I tested the main and test branches of OXS, as well as changing the JETI mode to exbus or UDI, and all encountered the same problem.

This is the video taken: https://www.youtube.com/shorts/pH-MBhFZkRk

Before using OXS, the current measurement module I used separately came from https://www.rc-thoughts.com/jeti-ampsensor/ It is very stable. Always displaying a fixed value,

This is a video from thoughts.com: https://www.youtube.com/watch?v=YeZIwd81hs

What is the reason for this?

mstrens commented 1 year ago

I see 2 explanations:

oXs uses the ADC (analog to digital) component from the RP2040. The values provided by the ADC depends directly on the RP2040 Vcc voltage. You can perhaps add capacitors to increase power supply voltage.

An alternative is to let oXs perform more conversions. Currently the values transmitted by oXs are an average of 10 ADC conservions. This is defined a line in voltage.h

define SUM_COUNT_MAX_VOLTAGE 10 // number of ADC conversions to calculate averages

You can try to increase the number of conversions for calculating an average changing the line e.g. to:

define SUM_COUNT_MAX_VOLTAGE 100.

aepub commented 1 year ago

Thank you, mstrens. You provided a great project

The reason for data drift may not be due to the power supply, as I used a linear regulator (LDO) with a very small ripple coefficient and a power supply ripple suppression ratio (PSRR) of 70db. The 5V and 3.3V dual power supply systems. The ACS758LCB uses a 5V power supply, and the VIOUT terminal uses a 1K+2K resistor for voltage division to prevent the sampling voltage from exceeding 3.3V. At the same time, ADC0 and ADC1 also use 100pf capacitors (attempting to increase to 4.7u).

I tried to modify the # define SUM for voltage. h COUNT MAX_ VOLTAGE 10, compile and test before providing feedback.

Thank you again! rp2040

aepub commented 1 year ago

After testing, # define SUM COUNT MAX_ VOLTAGE 10

Change to # define SUM COUNT MAX_ VOLTAGE 100. The voltage, current, and temperature values displayed on the remote control will still jump, with a jumping frequency of approximately 2 seconds. The frequency will be changed to 250, and the jumping frequency will be approximately 1 second. However, the consequence is that the response speed to current changes is much slower. When pushing the accelerator, the current value changes very slowly, and I feel that I cannot modify this value too much. In the end, I still changed it to 10.

RP2040 is powered by a lithium battery, and the interference from the power supply should not be the main cause, it seems to be unsolvable! 250

aepub commented 1 year ago

I have compiled the latest test version and connected the GPS module. I found that not only the voltage value is jumping, but the GPS value is also jumping. In a stationary state, the GPS will display speed. I'm going crazy![[ https://www.youtube.com/shorts/TBldUnbiqCo

aepub commented 1 year ago

https://www.youtube.com/shorts/TBldUnbiqCo

mstrens commented 1 year ago

Perhaps you can make some tests to check if the jumps occurs when the data are captured or when they are transmitted. I expect that the jumps occurs when the data are captured. To exclude an issue during the transmission, you can send a command FVP or FVN via USB. Then oXs will still collect the data from the sensors but the values transmitted will be fixed predefined values. Normally after such a command the Tx should display always the same values (no jump at all). Note: after such a command, oXs will send fix values for all possible sensors (even those that are not defined in the configuration)

You can also use use the command FV to see the collected data on the PC display. Entering several FV commands should give some jumps in the values on the PC if the issue is in the process of collecting the data from the sensors.

About GPS: please note that by default, I think that oXs configure the GPS in order to get data at a frequency of 10Hz. At such a high frequency, it is probably not abnormal that GPS data fluctuates specially when GPS does not have a clear view of the satellites (e.g. when GPS is indoor)

aepub commented 1 year ago

Thanks! As you mentioned, I used the command FV to view the collected data on the PC monitor. The GPS jump was just discovered and not tested, but the voltage and temperature values will appear as random values on the PC monitor, around 50-200, rather than a fixed value.

mstrens commented 1 year ago

ADC has a resolution of 12 bits = 4096 steps. So if you use a voltage divider that allows to measure max 20 volt (as example), it means that ideally the ADC can provide a value with an error of 20000mv/4096 = 5mv. In the RP2040, it is said that the error can sometime be 8 X bigger => 40mv. 200mv seems quite big.

The error is perhaps because there is only one ADC shared by 4 analog inputs. Perhaps that when I switch from one input to another one I have to wait some time before asking for the conversion (to let the voltage stabilize on the internal capacitor). There is an easy way to test if this could be the reason of the issue. If you measure only one voltage (or current), there will be no need for the ADC to switch from one input to another. Could you make a test where you change the configuration in order to ask only e.g. for VOLT1 (so disabling VOLT2, VOLT3, VOLT4 pins). If this is a solution, I could change the code in order to have more time between selecting the analog pin and performing the conversion.

aepub commented 1 year ago

Thank you. I compiled using the code from the main branch I made the following modifications to the code, and now the voltage value stabilizes at a fixed value, and the screen data flashes approximately once per second!

https://www.youtube.com/shorts/SBOvbc_-Bzk

VOLTAGE::VOLTAGE() {}

void VOLTAGE::begin(void ) { if ( config.pinVolt[0] == 255 and config.pinVolt[1] == 255 and config.pinVolt[2] == 255 and config.pinVolt[3] == 255 ) return ; adc_init(); // prepare ADC for (int cntInit = 0 ; cntInit < 1 ; cntInit++) { if ( config.pinVolt[cntInit] != 255) { adc_gpio_init(config.pinVolt[cntInit]); // prepare the pin for ADC mVolt[cntInit].value = 0; mVolt[cntInit].available = false ; }
} // end for // 330 because the max volt is 3.3V and we expect 3 decimals to get it in mvolt mVoltPerStep[0] = 0; // 0 means that the value must not be transmitted (set scale = 0 to avoid sending the data) //mVoltPerStep[1] = 0; // mVoltPerStep[2] = 0; //mVoltPerStep[3] = 0; if ( config.scaleVolt1 != 0) mVoltPerStep[0] = 3300 / 4095.0 config.scaleVolt1; //if ( config.scaleVolt2 != 0) mVoltPerStep[1] = 3300 / 4095.0 config.scaleVolt2; //if ( config.scaleVolt3 != 0) mVoltPerStep[2] = 3300 / 4095.0 config.scaleVolt3; // if ( config.scaleVolt4 != 0) mVoltPerStep[3] = 3300 / 4095.0 config.scaleVolt4;
offset[0] = config.offset1; //offset[1] = config.offset2; //offset[2] = config.offset3; //offset[3] = config.offset4; } // end begin

void VOLTAGE::getVoltages(void){ static uint8_t sumCount = 0; static uint32_t lastVoltagemillis = 0 ; static uint32_t enlapsedMillis =0; static uint32_t lastConsumedMillis = millisRp(); float value; if ( config.pinVolt[0] == 255 and config.pinVolt[1] == 255 and config.pinVolt[2] == 255 and config.pinVolt[3] == 255 ) return ; enlapsedMillis = millisRp() - lastVoltagemillis; if ( enlapsedMillis > VOLTAGEINTERVAL ) { // every 2 msec performs 1...4 conversions lastVoltagemillis = millisRp() ; for (int cntInit = 0 ; cntInit < 1 ; cntInit++) { if ( config.pinVolt[cntInit] != 255) { adc_select_input(cntInit); // select the pin sumVoltage[cntInit] += adc_read(); // convert and sum }
} sumCount++; if ( sumCount == SUM_COUNT_MAX_VOLTAGE ) { // after XX conversions, calculates averages sumCount = 0; for (int cntInit = 0 ; cntInit < 1 ; cntInit++) { if ( config.pinVolt[cntInit] != 255) { // calculate average only if pin is defined
//fields[cntInit + MVOLT].value = ( ((float) sumVoltage[cntInit]) / (( float) SUM_COUNT_MAX_VOLTAGE) mVoltPerStep[cntInit]) - offset[cntInit]; if (mVoltPerStep[cntInit] !=0) { value = ( ((float) sumVoltage[cntInit]) / (( float) SUM_COUNT_MAX_VOLTAGE) mVoltPerStep[cntInit]) - offset[cntInit]; // Volt3 and Volt 4 can be used as temperature or voltage depending on value of config.temperature // volt 2 is used for current and consumed capacity is then calculated too if (cntInit == 1) { if (value < 0) value = 0; } //only display >1 val // if ( (cntInit == 2) && (config.temperature == 1 || config.temperature == 2) ) { // sent2Core0( TEMP1 , (int32_t) value ); // } else if ( (cntInit == 3) && (config.temperature == 2) ) { // sent2Core0( TEMP2 , (int32_t) value ); // } else { // sent2Core0( cntInit + MVOLT, (int32_t) value ); // save as MVOLT, CURRENT, RESERVE1 or RESERVE2 // } // if (cntInit == 1) { // when we are calculating a current we calculate also the consumption

            //            consumedMah += (value * (millisRp() - lastConsumedMillis)) / 3600000.0 ;  // in mah.
            //            lastConsumedMillis =  millisRp(); 
             //           sent2Core0( CAPACITY, (int32_t) consumedMah );
             //       }
                    //fields[cntInit + MVOLT].available = true ;
                }
                sumVoltage[cntInit] = 0 ;
                //printf("voltage has been measured: %d value= %d \n", cntInit , (int) mVolt[cntInit].value);

            }    
        }    
    }
}        

}

mstrens commented 1 year ago

I put on github (in test branch) a version 2.6.9 where:

aepub commented 1 year ago

Mstrens I tested version 2.6.9 and it seems to be better, but the voltage still jumps. https://youtube.com/shorts/NXvZgVaA5Qo fv

mstrens commented 1 year ago

In the video, Volt1 is quite stable. It is strange that Temp changes. I put on github a new version where

aepub commented 1 year ago

I tested 2.6.10 and the data is much larger! Video address:https://www.youtube.com/shorts/XphEmHMoiYo

mstrens commented 1 year ago

Indeed, I multiplied by 2 instead of dividing by 4. I fix it in new version on github Otherwise, it seems better.

aepub commented 1 year ago

It's much better now, but the data won't remain absolutely zero

  1. The voltage and current values are approximately offset by 0.01V;
  2. The battery consumption capacity will slowly increase from 0 to 20mha after about 20 minutes;
  3. I may have chosen the wrong model for the temperature sensor, which does not have reference value,I purchased the DS18B20 digital temperature sensor and it cannot be used. I have found the DL-LM35DZ. Anyway, it's much better than before, it's amazing! Thank you! https://www.youtube.com/watch?v=O_i3Ta-GsiI
aepub commented 1 year ago

Today, I conducted a current and voltage test on oXs using an electronic load, and the results showed a significant error. The power supply is a 4S lithium battery, about 15.0V. The voltage and current displayed on the electronic load are different from the data read on the remote control, especially the current, which is very different! This is a test video! https://www.youtube.com/shorts/kc31wqAXhTg This is a 1-5A photo taken, and the 10A current of the electronic load is approximately 7A on the remote control 4A ACS758LCB-100B 100B

mstrens commented 1 year ago

I suggest that you plot the real values and the oXs values in a chart (for the current). You will see that there is a linear relation between the 2 set of datas. I did it in XLS. So, if you change the offset and the scale oXs parameters (for current), you will get realistic values on the Tx display.

aepub commented 1 year ago

I used an electronic load to measure the current from 0A to 10A and tested the relationship between the electronic load and the OXS display current, as well as the changes in the sampling voltage of ACS758LCB-100B. I don't understand how to adjust the scale and offsets values. OXS-test OXS-test.xlsx

mstrens commented 1 year ago

I will try to explain it but first, could you

aepub commented 1 year ago

I w scale111111 ill record the test data to execl with offset=0 and scale=1. The current value displayed in this situation is very stable, without any jumping!

OXS-test.xlsx https://www.youtube.com/watch?v=EjtYL2DWYy8

aepub commented 1 year ago

Today, I tested 100B and 150B, with operating voltages of 5V and 3.3V, respectively. The 5V used a divider resistor and calculated the scale and offset values. In practical use, only when the current value is 0, the current value displayed on the remote control and the electronic load is basically the same. When the current value of the electronic load is increased, there is a significant difference between the data displayed on the remote control and the current value displayed on the electronic load. Is there an error in my settings? How should I set it up? Thank you!

oxs-scle-offset OXS-test (100-150).xlsx

mstrens commented 1 year ago

I used you xls to calculate scale and offset to apply. See the second tab. I put the values (for 150 sensor) in mVolt and mA (because those are the internal units used by oxs) I used them to plot a chart. I selected the chart and selected an icon disposition (it is in French - not sure about the name in English) and add a trend (select linear trend) + select other options (in the drop list about trends). In other options, I activated the box about "display equation on the chart" (again this is perhaps not the right name in english) OXS-test.100-150.xlsx