Page 14 of 17

Re: Tacho options for a petrol dash?

Posted: 09 Aug 2018, 22:34
by CJH
bigbadbob76 wrote:hmmmm.... not easy. I'm no programmer but I think you have to do it with interupts.

Yes, it would be nice for the main code loop to do all the maths and the display updates, and for the device to wait for an interrupt to signal that a pulse has started, instead of having to watch the analogue input the whole time. But as far as I can tell, interrupts only work on the digital input pins.

But I think an alternative could be to have a routine that runs for an undisturbed (I was going to say 'uninterrupted') period, say 100ms, to sample the analogue input pin, then returns to the main code with an RPM value. This could then be used to update the display, and when that and any other loop activities are complete the RPM routine would be called again. 100ms would give me plenty of time get an accurate RPM value, and even if it only updated once per second due to slow LCD updates, that would probably be enough to make a reasonable tacho display. Something to work on.


bigbadbob76 wrote:Here's the scope plots anyway-

5v/division, x10 probe, so 375V pk-pk.
no wonder it tingles. :lol:
Image
Thank you. What kind of resistor is needed to deal with that?

Re: Tacho options for a petrol dash?

Posted: 10 Aug 2018, 12:18
by bigbadbob76
375v - say 5v for the zener= 370v.
370v/say 20mA (current limit through the zener)= 18.5K ohm.
You do the power maths. :wink:
put the zener between your arduino input pin and ground, and the resistor in series with the signal.

Re: Tacho options for a petrol dash?

Posted: 10 Aug 2018, 13:10
by CJH
Thank you. Just to be sure - do you mean like this?

Image

I'm puzzled about the zener now - this is how I understand it should be oriented to achieve a voltage input to the Arduino that will not exceed 5.6V, but it seems to be in a different place/orientation to the one in the tacho circuit that I copied. How does it work in that tacho circuit? And in the Arduino circuit, should I perhaps have two of them, anode-to-anode, to ensure the voltage stays between +5.6V and -5.6V, because the negative spike in your scope photo looks quite big too (~50V)?

Image

Re: Tacho options for a petrol dash?

Posted: 10 Aug 2018, 13:27
by bigbadbob76
Top picture is right for the arduino. :ok
It clamps the input to the arduino to no greater than the zener voltage. so you want a zener voltage less than 5V to be safe.
The rest of the volts are dropped across the resistor.

Yes you can use two back to back but make sure you use a zener that is 0.7v less than 5V as the forward biased diode will add to the zener voltage.
To do it really nicely, use an optoisolator instead of the zener.
Drive the led of the optoisolator from the tacho signal via the 18K resistor.
This will keep the high voltages off your sensitive arduino.


The SAK takes up to 20V input, the zener in that circuit is dropping say 5.6V from the voltage that's left after the 33k/3k3 potential divider has divided it by 11.
so for example...
375V input / 11= 34V
34V- 5.6V= 28V

hmmmm..... that zener is probably not 5.6V, it's not marked so whoever drew that ciruit just drew it as a diode.

Re: Tacho options for a petrol dash?

Posted: 10 Aug 2018, 13:31
by CJH
Thank you. Supplementary questions:

1) Any idea why I seem to be seeing ~0.25V on pin 2 of the SAK215?
2) Would anode-to-anode, or cathode-to-cathode, zeners be a good idea in the Arduino circuit?

Re: Tacho options for a petrol dash?

Posted: 10 Aug 2018, 13:41
by bigbadbob76
edited above to include optoisolator.
back to back or front to front makes no difference to sheep.... errr.... sorry..

Re: Tacho options for a petrol dash?

Posted: 10 Aug 2018, 13:45
by CJH
bigbadbob76 wrote:edited above to include optoisolator.

Thank you. You're doing a fine job of introducing me to new components one by one.

Re: Tacho options for a petrol dash?

Posted: 10 Aug 2018, 14:25
by bigbadbob76
CJH wrote:1) Any idea why I seem to be seeing ~0.25V on pin 2 of the SAK215?

With what input? is this in the van? and what measuring instrument?
A multimeter will try and show you an average voltage. if the duty cycle of the tacho input pulses is low (see my scope plot above) then your meter will show a very low reading.
Scope is the tool for looking at pulses. :wink:

Re: Tacho options for a petrol dash?

Posted: 10 Aug 2018, 14:43
by CJH
bigbadbob76 wrote:
CJH wrote:1) Any idea why I seem to be seeing ~0.25V on pin 2 of the SAK215?

With what input? is this in the van? and what measuring instrument?
A multimeter will try and show you an average voltage. if the duty cycle of the tacho input pulses is low (see my scope plot above) then your meter will show a very low reading.
Scope is the tool for looking at pulses. :wink:

Coil pulse inputs, measured in the van using an Arduino nano connected to pin2 and gnd. In this plot, the y-axis scale goes from 0-1023 to represent 0-5V, so a value of ~50 is ~0.25V. It's quite possible that I did something wrong, so I'm planning to have another go over the weekend.

Image

Re: Tacho options for a petrol dash?

Posted: 10 Aug 2018, 17:26
by bigbadbob76
Looking at my scope plot, theres some noisy crap after the main spike. Maybe you sampled that.
I'm out of my comfort zone with digital sampling.


Sent from my iPhone using Tapatalk

Re: Tacho options for a petrol dash?

Posted: 10 Aug 2018, 19:56
by CJH
bigbadbob76 wrote:Looking at my scope plot, theres some noisy crap after the main spike. Maybe you sampled that.
I'm out of my comfort zone with digital sampling.

I don't think that's it - that plot shows several complete pulse cycles. I'm not going to worry about that until I've repeated the process and checked for blunders.

In the meantime I now have a nice little RPM calculation in its own little routine - I call the routine with a parameter to specify how many samples should be averaged, and while it's in that routine it does nothing else - no screen updating, no printing to the serial port - and it returns after the specified number of samples with an RPM value. In my main loop, if I simply call that routine successively and print the results to the serial port, the results are extremely accurate (testing against my signal generator it matches very closely - so that settles the argument over whether to trust the signal generator or my Draper multimeter).

The problem comes when I attempt to write the RPM value to my LCD screen. Even though the write happens only after the RPM routine has returned with a value, somehow the screen writing affects the results. Makes no sense. In fact, if I replace the screen write with a simple 'delay(100)', after the RPM routine, it STILL affects the RPM calculation. There's something I'm not getting. Maybe it's to do with external interrupts happening while I'm in the RPM routine, but I can't disable them because then the clock timer doesn't work. I think I need to join an Arduino forum and post code there to see if someone can explain what I'm missing.

Re: Tacho options for a petrol dash?

Posted: 10 Aug 2018, 21:42
by bigbadbob76
I'll watch from the sidelines. :)
Sorry I can't help any further, i've done some basic (excuse the pun) "read a value, write it to display" arduino programming but nothing like this.

Re: Tacho options for a petrol dash?

Posted: 11 Aug 2018, 06:49
by bigherb
bigbadbob76 wrote:
5v/division, x10 probe, so 375V pk-pk.
no wonder it tingles. :lol:
Image


That is good coil switching.
Yes, the back emf from the coil is high 300+ volts
You need a scope to check ignition problems gives you a nice window into the system.

This is what it means from my handheld scope.

Image

Re: Tacho options for a petrol dash?

Posted: 11 Aug 2018, 11:37
by CJH
The main spike seems to be sufficiently higher than the bounces to allow some sort of threshold to be set in a digital pulse counter/tacho. I need to have another play.

In the meantime, I've got a digital tacho that works with my signal generator, and can now also display to a screen! The secret was to put the pulse detection into a timer interrupt routine, where it seems to be safe from other interrupts. I've set it to fire 1000 times a second, which should ensure it catches every pulse, and times them to sufficient accuracy.

Image

Right - this flywheel isn't going to sleeve itself....

Re: Tacho options for a petrol dash?

Posted: 11 Aug 2018, 17:19
by Cobra88
Well done Chris

I knew you would crack it :ok