Go Down

Topic: Frequency input issue for tachometer (Read 3102 times) previous topic - next topic

M4vrick

Hi all :)

I want to use my arduino for some kind of tachometer.

My car has a tachometer output, with square 0-12V signal (verified with an oscilloscope), frequency is from 20Hz to 500Hz.
I've made a small input adaptor to have a square 0-5V input for the arduino, which is working as far I can see on my DSO Nano V2 (low cost oscilloscope).

The problem is: the frequency measured by the arduino is moving continuously. It's never stable.

I've tried with a square signal generated from the DSO Nano and the measure is stable.

My opinion is: there is some noise on the input signal in the car which is measured by the arduino. The library I use is simply counting the rises on the input regarding the time, and noise could make some rises.

Here is the adaptor circuit for the input. I'm using the ULN2803 as a driver for LEDs, and there was 2 network unused, so I've take one to do the trick.



And the code:

Code: [Select]
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <FreqMeasure.h>

#define OLED_DC 11
#define OLED_CS 12
#define OLED_CLK 10
#define OLED_MOSI 9
#define OLED_RESET 13
Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);

#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2

#if (SSD1306_LCDHEIGHT != 32)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif

//Input Pin 8

double sum=0;
int count=0;

void setup(){
  display.begin(SSD1306_SWITCHCAPVCC);
  FreqMeasure.begin();
}

void loop(){
  if (FreqMeasure.available()) {
    // average several reading together
    sum = sum + FreqMeasure.read();
    count = count + 1;
    if (count > 50) {
      double frequency = F_CPU / (sum / count);
      display.clearDisplay();
      display.setTextSize(2);
      display.setTextColor(WHITE);
      display.setCursor(0,0);
      display.print("8 Frq: ");
      display.println(frequency);
      display.display();
      sum = 0;
      count = 0;
    }
  }
}
   


Do you think I need to use a low pass filter to keep only frequency under 1KHz ?

Or any other ideas about a better way to do it ?

MarkT

You need to condition the noisy signal better.  I'd propose a low-pass RC stage with a cut-off around 1 to 2 kHz, followed
by a schmitt-trigger to generate clean logic signals.

You should also filter out really high frequencies with a 100pF capacitor directly across the incoming cable (always
worth doing for slow signal sources, such as audio, to cut out most of the radio-frequency interference).

A suitable RC stage would be 10k in series to 10nF to ground - cutoff around 1600Hz.  You also need to reduce to 5V
signal level and feed to a schmitt trigger stage such as a 74HC14 inverter.

Now for the theory:

Logic signals need to transition from LOW to HIGH (or vice versa) very fast (millions of volts per second) - this is
essential for correct circuit operation.  Anything can happen if the signal changes too slowly (many multiple pulses
may be registered, the circuit may temporarily go into a high-current-dissipation state, it may oscillate at radio
frequencies).

Thus a schmitt-trigger gate is needed to clean up the unknown noisy signal before the Arduino.  Schmitt-triggers
clean up any slow transition with positive feedback and guarantee fast transitions (and reject noise spikes completely
below a threshold amplitude).

But you likely have noise spikes from the car ignition all over your signal - low pass filtering can knock the amplitude
of these right down to below the level the schmitt-trigger will recognise.
[ I won't respond to messages, use the forum please ]

M4vrick

Reducing to 5V is already done with the ULN2803.

I'll try with the low-pass RC stage, capacitor and schmitt-trigger logic.

Thank you :)

Papa G

You are really overdriving the darlington if your input level is 12V. You could put the filter in place of the 1k resistor and kill two birds with one stone.

M4vrick

What do you mean by 'overdriving the darlington' ? My english is not so good  :smiley-red:

Put the filter in place of the resistor was already in my plan :)

Papa G


What do you mean by 'overdriving the darlington' ? My english is not so good  :smiley-red:

Put the filter in place of the resistor was already in my plan :)


Sorry, I mean you are supplying its input with many times more current than necessary. It probably has an Hfe of greater than 1000 at the collector current you will get with a 10k collector resistor.

M4vrick



Sorry, I mean you are supplying its input with many times more current than necessary. It probably has an Hfe of greater than 1000 at the collector current you will get with a 10k collector resistor.


Ok, much clear for me now :)

Thank you. I'll let you know if it's working after modifying it.

Papa G




Sorry, I mean you are supplying its input with many times more current than necessary. It probably has an Hfe of greater than 1000 at the collector current you will get with a 10k collector resistor.


Ok, much clear for me now :)

Thank you. I'll let you know if it's working after modifying it.


You're welcome.
Definitely, keep us informed.

M4vrick

Everything is good now !

Just with the RC network before the darlington, no more bad ready, the frequency measure is steady :D

I need to improve the speed now, my tachometer has a refresh rate of 1sample/second, it's really too slow  :smiley-sweat:

Thank you for your help :)

Papa G


Everything is good now !

Just with the RC network before the darlington, no more bad ready, the frequency measure is steady :D

I need to improve the speed now, my tachometer has a refresh rate of 1sample/second, it's really too slow  :smiley-sweat:

Thank you for your help :)

I'm glad it works.

One of the difficult decisions with a digital tachometer is what to use for an update speed. I prefer an analog tachometer for that reason. You could  consider using a digital bar graph or if possible a sort of "pie chart" to simulate the good things about an analog readout. Keep the digital for "cruising".

M4vrick

My final goal is a sequential shiftlight not a tachometer, and it's working good :D

Papa G


My final goal is a sequential shiftlight not a tachometer, and it's working good :D


Ah, okay, I didn't realize that from your initial posts. I see now that a faster update makes sense in that context. You'll be able to update pretty quickly, especially if you use integer math.

Go Up