No actually, it is this interrupt and its floating point math that I jumped to conclusions about...thoug I may simply have more dumb programming mistakes to fix instead.
void Repeats(){ //interrupt timer1 repeats every second-changed to 5 seconds...
//here is the math...we sample every 5 seconds. 9200 counts per gallon. FIXED-use float cast to convert integers to float before calculating
Calc = ((float)Count* ((float)720 / (float)k_factor)); //(Counts in 5 seconds/ number counts per gallon, converted from seconds to hours
//using a large value we can select any k-factor - use counts per gallon - perfect
// Calc is the gallons per hour.
if (!flag){ //reset flag so running total flag is run only once
flag=true;
} //this is used for averaging routine for average flow rate
if (Count>0){
stopped_flag++; //add 5 seconds to running time length
}
if (stopped_flag>5){ //this is to delay the time till we stop and wait....
//30 seconds or so...it decrements with no flow
stopped_flag=5; //add 5 seconds to length of time running, up to 30 seconds
//-each unit of increase = 5 seconds of stoppage
}
if (Count==0){ //decrement once per 5 second with zero flow...
stopped_flag--;
}
if (stopped_flag<=0){
stopped_flag=0; // no longer running
}
else {
running=true; //added this to ensure it stays running with flow
}
Count=0; //reset for next interrupt
//For some reason, when we start back up from stop, we re-enter the save routine.
if ((stopped_flag<=0) && (running) ){ //we were running, then stopped
state=10; //keeps returning to state 10, stop and save, and looping again
return;
}