Wednesday, January 28, 2009

Weeling Project (Cont...)

Recently I update the software adding the feature to store the odometer distance into the internal Flash.
This are the added static variables:

unsigned int uiDistanceTrip; // ODO meter distance (reset at SW start)
unsigned int uiDistanceOdo; // Total Distance meter (stored in Flash memory)

During the drive also the estimated distance is calculated multiplying the RPM by the weel circonference lenght

// Disntance Calculation
uiDistanceTrip += ( (float) (uiRPM_REAR) * CFR ); // to get Km, divide by 1000

Now, once the bike is stop for at least 3 min, the total distance will be written to the internal Flash:

case STATE_IDLE:
// Initialize the Derivative calculation
uiOldRPM_FRONT = uiRPM_FRONT;
uiOldRPM_REAR = uiRPM_REAR;

// If Bike Speed is greater then 5.0 Km/h then change state to DRIVE
if ( uiSpeed > 50 )
uiWeelingStatus = STATE_DRIVE;

// Reset the Gear shift counter
iGearShift = 0;

// Check since how long the Bike is in IDE state: if more then 300 sec then store ODO into Flash
if ( iGPT_Counter == 300 )
{
uiWeelingStatus = STATE_OFF;
// Update the Total Distance Km
uiDistanceOdo += uiDistanceTrip;
// Reset the Trip meter
uiDistanceTrip = 0;
// Flash the Total Distance Km
EEPROMWrite ( uiDistanceOdo );

}

break;

Afterward the internal status will be set to STATE_OFF. STATE_OFF? Yes, I had to add a new status to be safe and do not continuosly program the flash when the bike is in the pit-lane.
This is the new STate Machine description:

No comments: