I want to have my Toyota's engine RPM displayed in Max MSP. So, a rate which needs to be fairly instantaneous to be utilized for RPM-related operations such as servos which open/close variable intake runners etc. It also needs to be accurate and clean. I am using an LM1815 chip (zero crossing detector) which is receiving RPM information from my Toyota's ecu (NE wire). I have it going into one of my arduino digital inputs. For real-time and precision, the Ne signal from the distributor produces 24 pulses per cam revolution. It's a variable reluctor sensor, so the pulses are kinda ugly (among other things, the amplitude varies with RPM)... The LM1815 turns it into a nice square wave, and we can measure from edges (falling edge to falling edge). Time is equal to the time it just took the engine to travel 15 cam degrees or 30 crank degrees, or 12 pulses per revolution.
The problem is, it is meant to utilize ISR's on my arduino. As far as I know (please correct me if i am wrong), ISR's are not interpreted from maxuino into Max.
What I am getting in Max is a fast string of alternating zero's and ones, averaging about the same rate when compared (using the "route" object). I am using "counter" to give me a running tally of all events. At idle the tally comes in at about an event every 2.3 ms. At redline, this increases to an event every .23 ms. But according to the LM1815 application, at redline (7400 RPM) we should be getting about 1480 pulses per second, or a pulse every .676 ms. So obviously I am getting more "events" than just pulses, that are giving me a dirty signal.
My main questions are: 1) I am finding that the objects "timer" and "cpuclock" are not able to measure the time between events... it's too fast. I am using the method shown in "timer" help, the "Clever way to report time between events". I am using cpuclock in the same way. When I use the carry-count output of the counter to reduce the speed of the events (have it output a pulse every 50 or so events) I get some success but its very inconsistent. What is the best way in Max to measure the time between fast events? Is there a way?
2)How can I take a stream of numbers that fluctuates and changes constantly, discard the highest ones, discard the lowest ones, and just take the middle range? Using the "mean" object would include the highs and lows, which I don't want to do. For example, if I get a stream of numbers that average around 200, but I get some obviously out of range low numbers like in the teens, and then some obviously high out-of-range numbers like 600. Then as the RPM increases, the numbers now average around 2000, but i still get those occasional very low and high numbers that are just noise. What is a good way to clean up such data?
What I have tried is making a list and feeding it through "minimum" and "maximum" and mean, but this slows down the real-time response a lot. I have a feeling it is possible using the "route" object somehow, to keep it responsive, but have the route's arguments variable.
3) Some people have successfully been using the LM1815 chip and writing code to the arduino (not using Max/Maxuino at all), and getting the necessary timer information via ISR's. Is it possible to have Max running numerous activities through the arduino, and then having the arduino concurrently execute an additional code of instructions that has been loaded into it that has nothing to do with Max? Can this be done at the same time?
Any help would be much appreciated!