Reading multiple frequency

Hi all,
Apologies if this is a very basic question as I am a complete noob to the microprocessor world. I am looking at a project to measure turbo speed. I have always used Garrett or borgwarner gauges off the shelf but I am doing my own installation this time and want to do it a little differently.

The installation will see me have twin VNT turbos on a Nissan TD42 engine. Being variable nozzle turbos, I need to make sure they are boosting the same as I can’t have any cavitation which will cause cartridge damage. The turbo controls will be all mechanical and the Arduino will just be for tuning/monitoring.

I plan to monitor a maf sensor on the intake of each turbo and that seems fairly simple and achievable but I would also like to measure turbine speed as well and that’s where I get a bit lost.

I know that the commercial units use an induction sensor on the compressor wheel and it pulses every time a vane passes the sensor and I plan to use the exact same inducers on my project. I also know that the maximum turbine speed will be around 130,000 rpm for that size turbo and that means I will be trying to read 130,000x9vanes is 1,170,000pulses per minute or 19,500per second (19.5khz). Keep in mind I need to read 2 of these at the same time and refresh the display probably every second.

I want to learn how to do it on my own but I would really like to know if it is possible and the best direction to start researching. Thanks in advance for all the help.

Neglecting the potential need to condition the inductor outputs to a suitable range for the microcontroller (5V or 3.3V) and maybe square the signal.
A couple of options would be to either use the inductors connected to a couple of external interrupt pins that have code to count rising/falling signal edges. Or have the inductor inputs connected to timer counter pins so you use a hardware timer to count edges.

Hi Riva,
I believe that the signal is a 5v (almost) square wave and the power to the sensor is 12vdc and common ground for shielding and negative. I will test this with a scope before I hook it up obviously but in case it’s 12v signal, would a simple voltage bridge work for a signal at that speed??

As for the interrupts, is it possible to run two interrupts on the same board without affecting each other?? I will do some research on interrupts as it sounds like I should be heading in that direction anyways.

Cheers

Justscary:
Hi Riva,
I believe that the signal is a 5v (almost) square wave and the power to the sensor is 12vdc and common ground for shielding and negative. I will test this with a scope before I hook it up obviously but in case it’s 12v signal, would a simple voltage bridge work for a signal at that speed??

19.5 kHz is quite slow - a voltage divider made of two resistors will do just fine. Pull-up resistors are routinely used for much higher frequencies.

As for the interrupts, is it possible to run two interrupts on the same board without affecting each other?? I will do some research on interrupts as it sounds like I should be heading in that direction anyways.

Yes... an ATmega328 has two "external interrupts" on specific pins, plus pin change interrupts on all of them. It also has three timer/counter registers which may be an even easier option for this application.

Hi wvmarle,
Wow, you make it sound simple. 19.5khz is SLOW??? How fast can you go with these things??

On the timer registers, is there a specific way that you access these registers and do you know where can I get a tutorial on doing this kind of design. I am looking for other posts on measuring pulses but I get a little lost on the sketch side of things. I suppose it doesn’t help that I have a “mechanical” type brain ha ha ha

I wouldn't call 19KHz "slow" but it's not pushing the limits of the slowest Arduino.

I've tried to do the timer-counter thing myself and failed. I spent a lot of hours going through the datasheet and never fully understood what codes correspond to the datasheet register names. For the gurus that actually memorize this stuff, it seems easy. Maybe you can find a tutorial online. Search for "timer counter mode".

For your project it may not be necessary. It depends on how much other work the Arduino has to do in between counting turbo vanes. A simple external interrupt can count the vanes like any other RPM counter. Try to find an example online which doesn't simply count the time taken for one revolution but counts for several revolutions or several milliseconds.

For testing, you are going to have to create two independent 19kHz signals to feed both into your Arduino and check it doesn't get overloaded. Using delayMilliseconds() you can create pretty much any square wave you want. Buy a few smaller Arduinos (Nano or Micro) to use as your test signal generators, if you don't already have a lab full of test equipment.

That is a good idea about making the test equipment and reading counts/time. Should I average the readings over a few to smooth the display reading? I only plan to read both signals, average, and then write to a single lcd to try and simplify it as much as possible. I plan to use another board for the maf sensors etc. as the timing won’t be as critical and I feel I’ll have enough to deal with on this sketch as it is a learning project

Can't say I memorise the register names at all - but with the data sheet in hand have been able to measure frequencies of up to 1.5 MHz. One timer used as counter, to count the pulses, another as timer to give me the measurement period. The limit should be 8 MHz for a 16 MHz clock (can't try it out, my 555 can't do more than 2.7 MHz).

For up to 19.5 kHz I'd consider to connect it to the T1 pin to have the counter take care of the counting in the background, and then in loop() a millis() based timer to read the register every 1000 ms and use the actual time passed (may be a little more than 1000 ms) to do the calculations.

Otherwise connect it to one of the external interrupt pins, or even just a pin change interrupt (and get two counts per cycle: both falling and rising edges), and again have a 1000 ms timer loop do the calculations.

If you do use Timers as counters then probably best to use a Mega instead of an UNO as it has more timers so you won't lose core timing functions (Timer0) when setting one up as a counter. Have a look at this thread for a nice explanation of timer counters.

As long as you use timer1 and timer2 there's no conflict. OP didn't talk about servos or other peripherals that use timers.

wvmarle:
As long as you use timer1 and timer2 there's no conflict. OP didn't talk about servos or other peripherals that use timers.

IIRC the UNO has usable clock counter sources to Timer0 and Timer1 only, to use Timer2 in counter mode you need to use the pins the 16MHz crystal is connected to so would need to hack (or use bare-bones).

True.
That limits you to timer1 as counter which is enough for this single RPM signal, leaving timer2 to do other things. Anyway, timer1 is the only 16-bit timer on the ATmega328p, and OP most likely doesn't want to deal with 8-bit timers which overflow at 255 (I did that on an ATtiny84a as I needed two 16-bit timers... one as counter, the other to count processor cycles, so in the end I combined two 8-bit timers for that).