I'm creating a setup to determine if a flowmeter being tested falls within design specifications. This is to processes returned merchandise by attempting to copy the test procedure used at the manufacturing plant, to verify whether the flowmeter is the problem with the returned unit. It is considered as passing if at 10psi of air input it is producing 30-50 pulses per second. The test specifications require waiting 10 seconds before calculating pulses per second.
I copied part of another program using a flowmeter I had gotten help writing a while ago, and tried to add in that it would display the pulses per second, as well as a pass/fail message, every 10 seconds. I think I am missing something with that part of it, since when I run the program it won't ever display the pulses per second or pass/fail messages, though it will display the reset messages. This is what I have right now:
You need to explain this statement! Do you mean to wait 10 seconds after the test is all done, then report? Or do you mean to not begin counting the pulses until 10 seconds after the beginning of the test?
What leads you to believe that there will be a pulse exactly 10000 milliseconds into the test? What if it is 10005 milliseconds, or 10023 milliseconds, or something like that?
Divide the number of pulses by ten thousand? What do you expect to get for a result when you divide the number of pulses by such a large number?
I'm using an Uno, should be able to use pins 2 or 3 for interrupts, at least according to the link you provided.
I didn't have anything plugged into pin 1. I started using an LCD screen plugged into the SDA/SCL pins, but switched to Serial to make sure it wasn't my screen that was the problem. Both the screen and Serial print out the reset message, just not the pulse per second message.
The procedure I was going to use is to activate the air flow to the flow meter, hit the reset button, then turn on the "Run" switch and observe for a pulse per second display/readout every 10 seconds. I wanted it to start counting pulses as soon as I turn the switch on, then calculate pulses per second every 10 seconds and display both the PPS and whether it is getting between 30 and 50 PPS. I wanted it to continue doing this until I turn the switch off after an indefinite period of time.
The Serial display will put up the reset message, but will not display anything 10 seconds after the On switch has been flipped.
is referring to 10000 milliseconds and not pulses, that was my intention at least. I want to stop counting pulses at 10 seconds, however many there have been by then. If the internal clock is prone to skipping milliseconds and going from 9999 to 10005 I was unaware of that, and that is a different problem I will have to consider how to address. But to your point, I also tried
if(elapsedTime - timeRun >= 10000)
And still didn't get a display of the PPS on the screen.
And the math on pulses per second should definitely have a few less zeros. I think it should be
pulsesPerSecond = pulses / 10;
Since I wanted to calculate pulses per second after 10 seconds, not pulses per millisecond. Not sure what I was thinking on that.
The usual way to do your project is to just do the pulse count in your interrupt function and not do any timing stuff.
Then in loop(), do all the timing stuff. When your timing is up, stop the interrupts, save the current pulse count to a separate variable, reset your pulse count and re-enable the interrupts. Then let code continue to work with the saved pulse count.
Ok, to isolate the issue I am attempting to solve, I set up a separate piece of code to just output a message every 5 seconds, to see if I can at least do that. This is what I tried:
I thought that's what I was doing. I tried a separate piece of code to just display a message every 5 seconds (without the pulse count part) and it still isn't displaying anything. I copied it on a reply to my original post. Please let me know if there is a better way to do just that part.
Seems to be working now, other than the first display of Pulses Per Second will pop up before 10 seconds has passed after turning on the switch. I can live with that though.