Diecimila: unable to cope with digital inputs?

Dear mem and all Arduino Forum folks,

I am trying very long to input four digital inputs to Arduino Diecimila clon, from my diesel engine car.

It handles well two signals, but seems to be unable to cope with four.

Member “Mem” (knows a ton) has helped me a lot and suggested to INPUT two sensors vía DigitalRead() and two vía pulseIn() commands.
Clever solution. The first two work reasonable well. However, the last two aren´t working acceptably well for me.

There is more than 2 months I am working in this project. Should I throw away my Arduino board? Hope not. I like it. Much.

Here is the sketch:

/* ============= Millis per Pulse counter ============*/
// ---------------- using PulseIn ---------------------------
#include <DateTime.h>
#include <LiquidCrystal.h>

/* ------------- reset pins, define pins, variables ---------------- */
long rpm;
int resetPin = 3; // pin 3 resets the time
int pin = 3;
long duration;

/* ------- create object to control an LCD GMD1602K -------*/
LiquidCrystal lcd(12, 11, 6, 7, 8, 9, 10);

/* ============== SETUP ==================== */
void setup(){
lcd.clear(); //cleans display
pinMode(pin, INPUT); // a button on this pin resets the time
digitalWrite(resetPin, HIGH); // enables pull-up
DateTime.sync( 0 ); // set time to zero

}

void loop(){
/* ========= Execute program over and over ===========*/

duration = pulseIn(3,HIGH,1000); //counts milliseconds between two pulses
rpm = 200*(60000/duration); //converts milliseconds to rpm. The “200” figure is empirical.
lcd.setCursor(0,0);
lcd.print(“Millis”);
lcd.print(" “);
lcd.print(duration); // pints duration of pulse in millis
lcd.print(” “);
delay (500); // delay to allow printing
lcd.setCursor(0,1);
lcd.print(“rpm”);
lcd.print(” “);
lcd.print(rpm); // prints rpm
lcd.print(” ");
delay(500); // delay to allow printing
}

Results are printed on lcd. Both, millis and rpm.

However, the problems:

  1. Reasonable figures at idle (around 830 rpm), but not stable at all.
    The tachometer of the car with the same input, is very stable. However, it displays rpm figures in an analog gauge.

  2. If I accelerate, results may vary about 200% around “center values” but very unstable. Like dancing.

  3. Values for millis and rpm turn zero from time to time.

  4. Every time I plug the board in the car or in the PC, I have to reset Arduino manually, sometimes, repeatedly, to make it work.
    Otherwise, nothing is displayed.

Analog inputs are working well and stable.

I have a voltage dividers with a filtering capacitor to earth at the pin at entrance of each sensor signal.

I have tested several time lapsus for pulseIn(3, HIGH, 1000), like 500, 2000 milliseconds sample time lapsus.

I have tested several delay() commands to better seen results, have tested with no voltage divider at the entrance, but results are more or less unstable, not stable.

Anyone had succeded with more that 4 pulse input signals in Arduino diecimila?

If so, please help with this. Please try to run the sketch, enter a pulse signal, and tell me what you get.

Thank you folks in advance.

OldBeaver

  1. Reasonable figures at idle (around 830 rpm), but not stable at all

This could be due to the fact that it is not stable. You should try some averaging. That is taking say 8 samples and working out the average. This should be more stable.

The other thing this could be is noise on the input signal rather like contact bounce. You need an oscilloscope to see if this is happening and if it is you can use capacitors and filters to remove it.

If I accelerate, results may vary about 200% around "center values" but very unstable. Like dancing.

Again if you sort out the case above this will be sorted.

Values for millis and rpm turn zero from time to time.

Sounds like you have some hardware problems with contact bounce as mentioned above.

Every time I plug the board in the car or in the PC, I have to reset Arduino manually, sometimes, repeatedly, to make it work. Otherwise, nothing is displayed.

This sounds like the rise time on the input voltage on the LCD display is insufficient to trigger it's power on reset. Test if it is just the display by getting the LED to do something. If that works and the display doesn't then it is the LCD problem rather than an arduino problem.

Hey Grumpy_Mike,

Thank you for your suggestions.

I will check if it is a display problem. I think it is. It happens more in the car, than in the office. Could be voltage.

I need a lcd reset button, outside, on the cover box.

At the scope, signals look well.

By the way, how would you average? It is a good idea!

Ideas that come to my mind, as consequence of your comments:

Zeroes: what if voltage goes over 5VDC from time to time?

Maybe a voltage regulator with a zener diode may stabilize this?

Thank you much,

OldBeaver