View Single Post
Old 09-06-2008, 05:49 PM   #6 (permalink)
ac7ss
EcoModding Lurker
 
Join Date: Aug 2008
Location: Olympia, wa
Posts: 96

Red Beast - '82 Honda V45 Sabre Vetter Fairing
90 day: 39.38 mpg (US)

The Wife's bike - '82 Honda CM450E Red
90 day: 57.22 mpg (US)

Yellow Submarine - '04 Dodge Neon SXT
90 day: 28.71 mpg (US)
Thanks: 6
Thanked 1 Time in 1 Post
Quote:
Originally Posted by forgottenmindset View Post
Here's my attempt at smoothing out the vss output

(idea courtesy ac7ss)

Takes 3 values (say 50, 51, 70)

Finds out if the current reading is way off (70) by comparing it to the other two values (50, 51).

If it is a strange number, it just takes the other two values and averages them:

return (50 + 51) / 2


I think it helps some but it still will show an absurd value time to time like when accelerating or putting the clutch in, mabey my threshold needs to be adjusted...

This code could be added to your mpguino for better accuracy if you have funny readings

dcb, I'm sure you could write a better version, but I think it needs to be added for us guys with worn out speed sensors, it won't hurt the guys with good ones
Code:
// CUSTOM BY FORGOTTENMINDSET
// FOR ERROR PROOFING
// Mod By AC7SS

unsigned long g_vssReading[3];
//AC7SS Remove unneccesary global variables

//AC7SS I assume this is to return valid VSS time value correct?
unsigned long instantmph(){      
  cli();
//AC7SS remove  unsigned long vssPulseTimeuS = (lastVSS1 + lastVSS2) / 2;
  sei();
  init64(tmp1,0,1000000000ul);
  init64(tmp2,0,parms[vssPulsesPerMileIdx]);
  div64(tmp1,tmp2);
  init64(tmp2,0,3600);
  mul64(tmp1,tmp2);
  init64(tmp2,0,vssPulseTimeuS);
  div64(tmp1,tmp2);
//AC7SS: Added internal values:
  unsigned long minVssPulseTime;
  unsigned long maxVssPulseTime;
  unsigned long avgVssPulseTime;

   
  //////////////////////////////////////////////////////////////////////////
  // VALIDATE
  // WEED OUT ANY ODD READINGS FROM VSS Sensor
  //////////////////////////////////////////////////////////////////////////
  
  // Counter Mechanism
// AC7SS replace with shift of registers.  
//  if( g_vssReadingCount < 3 )  
//    g_vssReadingCount++;
//  else
//    g_vssReadingCount = 0;
   g_vssReading[0] = g_vssReading[1];
   g_vssReading[1] = g_vssReading[2];
   // Update vss reading chain
   g_vssReading[2] = tmp1[1];
   
   
//AC7SS: simpler algorithm:
  //Three cases:
    //find minimum/max/average of all three values:
    minVssPulseTime = g_vssReading[0];
    maxVssPulseTime = g_vssReading[0];
    if(g_vssReading[1]<minVssPulseTime) minVssPulseTime = g_vssReading[1];
    if(g_vssReading[2]<minVssPulseTime) minVssPulseTime = g_vssReading[2];
    if(g_vssReading[1]>maxVssPulseTime) maxVssPulseTime = g_vssReading[1];
    if(g_vssReading[2]>maxVssPulseTime) maxVssPulseTime = g_vssReading[2];
    avgVssPulseTime = (g_vssReading[0] + g_vssReading[1] + g_vssReading[2])/3;

  //case 1: all are within tolerances (say 3%), return last reading.
    if((minVssPulseTime/maxVssPulseTime)>0.97) return g_vssReading[2];

  //case 2: last reading is anomalous: return previous reading. (Please re-write to get the correct method, I am away from my reference material)
    if(1.03>(g_vssReading[2]/avgVssPulseTime)>0.97) return g_vssReading[1];
  //case 3: either of the other readings is the anomalous one:
    return g_vssReading[2];

}
Run this through the compiler and check the byte counts. (I know I made errors, deal with them.)

The meat of the program is the last 3 lines of code. no conversion to mph is necessary, all you want to do is set a threshold for rejection (3% in this code example). You never change the actual values of the readings, so if they are real readings that are outside of the range, it will still return the real value. I figure you will not be able to make a 3% change in speed between pulses. at 5 mph, you would have to speed up to 6 mph in 7 pulses. At 50 mph, you would have to speed up to 53 mph in 2 pulses. at 4000 pulses per mile, NOT BLOODY LIKELY.
__________________
  Reply With Quote