Mark -
I think I am closer to understanding what you are saying.
I was assuming that since all of the code Felix wrote does, in fact, work the way it is written that having the XMIT function where it is currently located is was not actually a problem. Is that because of the interrupts() here in the XMIT function that re-enables the interrupts so it is not an issue with millis()?:
void XMIT()
{
noInterrupts();
PulseCounter = PulseCounterVolatile;
interrupts(); <--------------------
if (millis() - TIMESTAMP_pulse_curr >= 5000)
{
ledState = !ledState;
digitalWrite(LED, ledState);
}
I appreciate the time you are investing in trying to help me understand. I am working on understanding how the interrupt/noInterrupts works in relation to attachInterrupt. From what I am gathering from you, the transmit function should not work at all if it is in an ISR or at least it's not a good idea to place it there, is that correct?
If that is correct, does the inclusion of the noInterrupts/interrupts functions in the XMIT function alleviate the issues caused by using it there?
On to your recommendation of using a volatile flag/variable. I assume that in my code where the actual transmit happens:
if (water.GPM!=GPMlast || water.GAL!=GALlast || water.GLM!=GLMlast) //Check and see if we used any water.....
{
if (debug)
{
Serial.println("Time to transmit.......");
}
radio.send(0, &water, sizeof water);
I would instead set a variable there indicating that we
should transmit and then create a function in my loop that looks at that variable and transmits the information if the variable has been set, then reset the variable (and the WDT). Is that correct?
I guess thanks to my ignorance, I was assuming that as long as my water was running and hence the interrupt driven part of the code was in control, everything stopped until the water stopped, it just stays right there and does not execute anything else (like the loop()) until it is done. Since I think that is not correct, how often (in general) does the loop() run while the water is flowing? Is it once per pulse of the water meter, once per ms or