I am writing a program in Dynamic C for a rabbit BL2600
board.
The program is controlling a pressure chamber a top chamber and a bottom chamber with metal in between checking for perforation. I have a sensor on my pressure regulator and a sensor reading the opposite chamber.
I have a fail function that sees if the chambers are leaking from one side to the other. when I pressurize the chamber I am using a waitfor
to wait until the pressure in the chamber gets within 10% of what I am setting the pressure to. I want it to wait until that happens, but I also want to make sure that it does not wait forever and that it will detect a leak to outside the chamber. Basically I want it to waitfor
the pressure to build or xx amount of time and if xx amount of time passes return basically a failure.
I am a beginner at programming and this may be a simple solution, but I am having issues thinking of a resolution. I've pasted my cofunction below and as of now it only waits for the pressure to be within 10% so if it doesn't it is stuck there. P.S. sorry if the code is sloppy I am a beginner and it is a work in progress.
cofunc run()
{
if (status == 1 && fail() != 1)
{
waitfor (DelayMs(2000) || status==0);
for (i; i<7; i++)
{
printf("\n\n In for loop in run psi[i] = %d", psi[i]);
if (status == 0) return;
if (psi[i] < 0 && psi[i-1] >= 0) // if negative and previous number positive
{
digOut(1,0);
chamber = 1;
waitfor (DelayMs(2000));
digOut(1,1);
}
else if (psi[i] >= 0 && psi[i-1] < 0) // if positive and previous was negative
{
digOut(1,0);
chamber = 2;
waitfor (DelayMs(2000));
digOut(1,1);
}
output = abs(psi[i]);
output = output/7.23738; // converts PSI to voltage
if ((output) <= 5) // makes sure that output voltage wont exceed 5 volts
{
anaOutVolts(0, output);
waitfor (pressureb > (psi[i]*.9) && pressureb < (psi[i]*1.1));
waitfor (DelayMs(time[i]));
}
} // end for statement
return;
}
return;
}