I have a problem with a calculated value. I have to calculate CPM (CountsPerMinute). And i want to have different measurement cycles (10s,5s,2s and so). So i have to calculate the conversion factor
If mesCycle is 5
CPM = counts * x
x = (60/mesCycle)
60/5 is 12, so Counts * 12 becomes CPM
if mes Cycle is 10, then its 60/10
and so on
to test the conversion, i made a serial.print for x.
X remains stable when counts is 0.
if counts are high like, 20 or so, then strange values appear... like 450, 192, 500...
Post the entire sketch... The problem is somewhere in it, but you are likely to guess wrongly
where it is if you cannot identify the nature of the problem.
For a start you are seem to be using integer division which is probably inappropriate.
Detaching and reattaching the interrupt handler is silly.
I took this from an existing code, they say in the case when another interrupt happens, while the interrupt function is still doing some work, the function will not be finished properly.
Is that false? Could i just delete the detach/attach in the function?
PaulS:
cpm = count * (60/mesCycle);
Integer arithmetic is being performed. Is that what you want?
PS. Do yourself, and us, a favor, and learn to use Tools + Auto Format.
I want that the number 60 (for 60seconds) is divied by the value that is stored in mesCycle, it can be 1 to 255.