how about this for calculating fuel flow, rpm isn't needed for something like this. I haven't had time to mess with the ide everyone is using but it is still C so it should be similar to the codevision stuff I know.
unsigned long int timecount = 0; //global time counter, or at least the left 8 bits of one
unsigned long int period; // total amount if time the injector is open
unsigned long int time;
unsigned long int openstartcount;
Set a timer to count at whatever clock speed you are needing 10khz or whatever. Usually they are only 8 bit or whatever so you have to manipulate the bits to get a larger number.
set an interrupt for the timer overflow.
if (timecount == 16777215) timecount = 0; else timecount += 1;
what this does is make 2 numbers the timecount variable is the left 8 bits and the timer itself is the right set of bits. It is checking to make sure timecount doesn't overflow with the if statement. And when it does it starts it back at 0.
now set a pin to interrupt on going high and a pin to interrupt on going low. It is ok to connect the two pins together on the circuit. Or one interrupt could be used and when it goes high it changes the interrupt to low and when it interrupts low it sets the interrupt to high.
interrupt [EXT_INT0] void ext_int0_isr(void) //this would be when the injector fires (pins go low)
{
time = timecount<<8;
time = time + TCNT0; // shift the timecount left 8 bits and add the timer to the right half so you have a 16 bit timer
openstartcount = time; // this sets the start time that the injectors are open. I know this could be simplified but it is easier to follow hopefully.
}
interrupt [EXT_INT1] void ext_int1_isr(void) //this would be when the injector closes (pins go high)
{
time = timecount<<8;
time = time + TCNT0; // shift the timecount left 8 bits and add the timer to the right half so you have a 16 bit timer
if (time > openstartcount) period = period + (time - openstartcount);
else period = 4294967295 - time + openstartcount;
// this if statement is making sure that the time hasn't overflowed and started at 0 again. If it hasn't then it adds the current injector open time to the total open time. If it has overflowed and started back at 0 it knows that the largest number is 42... and time was something before that so it needs that amount of time plus however much has passed since starting back at 0 to get the correct number for period.
With that it gives you total injector open time. So the easiest thing would be to set a timer that is about 3/4 to 1 second interrupt. In this one it knows the vss signal that would be just a simple counter and it knows the total amount of time the injectors are open so it would be a simple matter of saying for miles per gallon, miles = # of vss pulses * some factor / injector open time * some factor. and for L/Km or whatever units you want just do the same thing basically. It would need a way to check to make sure the injector isn't currently open and then zero out the period variable. If it was open a small routine could be added to the injector close time to calc the mileage on injector closing for that time.
I didn't check all that code for overflowed variables or anything so I don't guarantee it will work more than just a way to show how to do this without needing rpm. It should basically work and could be tested with a function generator putting out a square wave if anyone has one handy.