I've made what I think are suitable changes. Untested (I don't have a baro sensor), but it does compile and I think everything is covered.
Here's a patch to apply to the ms2extra-release-2.4.2 code:
Code: Select all
diff -Naur orig/ms2_extra_misc.c new/ms2_extra_misc.c
--- orig/ms2_extra_misc.c 2016-09-24 07:43:49.000000000 +1000
+++ new/ms2_extra_misc.c 2016-09-24 09:15:29.000000000 +1000
@@ -609,49 +609,40 @@
tmpadc = 0;
}
- // adcval = (long)flash4.baro0 +
- // ((long)(flash4.baromax - flash4.baro0) * tmpadc) / 1023; // kPa x 10
- __asm__ __volatile__ (
+ if(first_adc) { // start with 64xfirst sample
+ adc_count = 63;
+ outpc.baro = tmpadc << 6;
+ } else {
+ accum_baro += tmpadc;
+ }
+ if (++adc_count == 64)
+ {
+ adc_count = 0;
+ // convert accumulated value to mean kPa x 10.
+ // outpc.baro = flash4.baro0 + (long)
+ // ((flash4.baromax - flash4.baro0)*accum_baro / 65536)
+ __asm__ __volatile__ (
"ldd %1\n"
"subd %2\n"
"ldy %3\n"
"emul\n"
- "ldx #1023\n"
- "ediv\n"
"tfr y,d\n"
"addd %2\n"
- : "=d"(tmp1)
+ : "=d"(outpc.baro)
: "m"(flash4.baromax),
"m"(flash4.baro0),
- "m"(tmpadc)
+ "m"(accum_baro)
: "y", "x");
-
- if(first_adc)
- outpc.baro = tmp1;
- else {
- // outpc.baro += (short)((flash4.adcLF * (adcval - outpc.baro)) / 100);
- __asm__ __volatile__ (
- "ldd %1\n"
- "subd %3\n"
- "tfr d,y\n"
- "clra\n"
- "ldab %2\n" // it is a uchar
- "emuls\n"
- "ldx #100\n"
- "edivs\n"
- "tfr y,d\n"
- "addd %3\n"
- : "=d"(outpc.baro)
- : "m"(tmp1),
- "m"(flash4.adcLF),
- "m"(outpc.baro)
- : "x", "y" );
- }
- if (outpc.baro < flash4.baro_lower) {
- outpc.baro = flash4.baro_lower;
- } else if (outpc.baro > flash4.baro_upper) {
- outpc.baro = flash4.baro_upper;
+ if (outpc.baro < flash4.baro_lower) {
+ outpc.baro = flash4.baro_lower;
+ } else if (outpc.baro > flash4.baro_upper) {
+ outpc.baro = flash4.baro_upper;
+ }
}
+
+ // Convert ADC units to kPa x 10
+ // adcval = (long)flash4.baro0 +
+ // ((long)(flash4.baromax - flash4.baro0) * tmpadc) / 1023; // kPa x 10
}
if (((flash4.EgoOption & 0x07) == 2) || ((flash4.EgoOption & 0x07) == 4)) {
diff -Naur orig/ms2_extra_vars.h new/ms2_extra_vars.h
--- orig/ms2_extra_vars.h 2016-09-24 07:43:49.000000000 +1000
+++ new/ms2_extra_vars.h 2016-09-24 09:08:44.000000000 +1000
@@ -211,12 +211,12 @@
extern unsigned int TC_ovflow;
extern unsigned long lmms,t_enable_IC,t_enable_IC2,Rpm_Coeff,ltch_lmms,ltch_lmms2,rcv_timeout;
extern unsigned int asecount, adc_lmms;
-extern unsigned char flocker,tpsaclk,egocount,igncount,altcount,next_adc,first_adc,
- txmode, burn_idx, crc_idx, synch,
+extern unsigned char flocker,tpsaclk,egocount,igncount,altcount,next_adc,first_adc,
+ txmode, burn_idx, crc_idx, synch, adc_count,
egopstat[2], FSensStat,knk_clk,knk_clk_test,knk_stat,knk_count,mms,millisec;
extern unsigned char rxmode, srl_err_cnt;
extern unsigned int burnstat;
-extern unsigned int boost_ctl_timer;
+extern unsigned int boost_ctl_timer, accum_baro;
#define SYNC_SYNCED 0x1
#define SYNC_FIRST 0x2
#define SYNC_RPMCALC 0x4
Apply the patch by:
- save patch file to my.patch
- cd ms2extra
patch -p1 < my.patch
Removed more lines than were added, but the image ended up 29 bytes larger. Could have reused first_adc to keep count, but decided to keep it simple. 3 extra bytes of RAM used.
Fingers crossed, this will make your baro correction a bit steadier. I'm sure you'll let us know.
Have fun,
Rob.