• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Frequency to Microprocessor input.

Status
Not open for further replies.

Huttojb1

Member
Hey.

Please see attached, this is the signal that goes into my RPM Gauge of my kitcar. I believe it dirives from the coil.

Obviously I cannot put this directly into my PIC (Microchip Micro) and need to condition it to a 5V max signal.

Once I have conditioned the signal I could then use the capture function on the PIC to capture edges to work out frequency or I would like to convert this frequency in to a 0v to 5v signal. Either way is good. Would probably prefer to convert signal to a voltage as it makes it easier.

It seems like it goes from approx 5hz to around 160hz. I only screenshot 3 examples but the large one (87hz) was about half throttle.

If anyone could help I would be very appreciative because I wouldn't even know where to start.

The simpler the better because I would need to source all the components

Jason.
 

Attachments

Huttojb1

Member
It would be pretty silly converting to a voltage, far easier to simply measure the pulses directly.

Just look for a rev counter circuit, here's one I found near the top of google:

https://www.quasarelectronics.co.uk/manuals/velleman/manual_k2625.pdf

Take the input circuit from that (or similar).
Thank s Nigel, I'm keeping the original gauge so don't need to display the signal just need to measure it via my PIC so I know electronically my RPM.

Why would it be silly converting to a voltage? It's pretty easy to read a voltage into the PIC and less code to read the ADC value.

If someone could help how to put a frequency to a voltage with my range I would be happy. If this isn't possible how would I condition the signal to ensure I get a nice 5v square wave frequency to read into a PIC.

Jason
 

Les Jones

Well-Known Member
Most Helpful Member
Hi Jason,
If the pulses come from the coil you can calculate the frequency coresponding to any particular number of RPM. For a 4 cylinder 4 stroke engine there will be 2 pulses per revolution. So for example 1500 RPM would be 3000 pulses per minute which is 50 HZ. (3000 /60 = 50 HZ ) You would just need a resistor and a 4.7 volt zener diode to clip the signal from the coil primary do a level that could be fed into a PIC or a frequency to voltage converter. If you want some code to get you started writing the code there is some here on my website. It includes the source code. This code is more complex than that needed for a car rev counter as it was designed to give accurate readings down to a low speed (60 RPM) It also includes code to alow it to be used with sensors the give between 1 and 99 pulses per rev.

Les
 

Huttojb1

Member
Hi Jason,
If the pulses come from the coil you can calculate the frequency coresponding to any particular number of RPM. For a 4 cylinder 4 stroke engine there will be 2 pulses per revolution. So for example 1500 RPM would be 3000 pulses per minute which is 50 HZ. (3000 /60 = 50 HZ ) You would just need a resistor and a 4.7 volt zener diode to clip the signal from the coil primary do a level that could be fed into a PIC or a frequency to voltage converter. If you want some code to get you started writing the code there is some here on my website. It includes the source code. This code is more complex than that needed for a car rev counter as it was designed to give accurate readings down to a low speed (60 RPM) It also includes code to alow it to be used with sensors the give between 1 and 99 pulses per rev.

Les
Thanks Les,

I see your working out but with the screen shot you can see I'm measuring 17hz, which with your equation equals 510rpm. I would question this because at idle it should read around 900rpm.

My engine is a cbr1000f.

The 4.7 zenor would remove the positive spikes but would allow the negative spikes through which may cause an incorrect trigger of a capture, would I also use a capacitor to smooth out the signal, what cap would I use without effecting the signals. Would the resistor be a current limiting resister?

Could I easily convert to a proportionant voltage?

Jason.
 

Huttojb1

Member
Also what zenor would I use, would it handle the voltage breakdown ?

Jason
 

Nigel Goodwin

Super Moderator
Most Helpful Member
Thank s Nigel, I'm keeping the original gauge so don't need to display the signal just need to measure it via my PIC so I know electronically my RPM.

Why would it be silly converting to a voltage? It's pretty easy to read a voltage into the PIC and less code to read the ADC value.
Because it's two extra conversions for no reason, plus the extra hardware to change it to a voltage.

If someone could help how to put a frequency to a voltage with my range I would be happy. If this isn't possible how would I condition the signal to ensure I get a nice 5v square wave frequency to read into a PIC.
A 555 timer rev counter circuit is all you need for that.

The square wave problem is already covered in the link I posted.
 

Les Jones

Well-Known Member
Most Helpful Member
Hi Jason,
I was assuming that your engine was a normal older type 4 cylinder car engine that had a contact breaker and distributer with a single coil. I Googled the type of engine you have and found that it was a motorcycle engine. You will have to look as and understand the ignition system. It could use 2 or 4 coils and may use the wasted spark system. A zener would also clip the negative spike to - 0.6 volts. I had not looked closely at your waveforms but now I see they are not what I would expect from the primary of a normal ignition coil. I would have expected a fast positive spike up to about 300 volts. If you use any sort of frequency to voltage converter (Other than a microproccesor measuring frequency and outputting the voltage via a DAC) it will need calibrating. Most microproccesor tachometers do not need calibration and the accuracy will be the same as the crystal used. (Which will be more than good enough for a 4 digit diapaly.)

Les.
 

Huttojb1

Member
Hi Jason,
I was assuming that your engine was a normal older type 4 cylinder car engine that had a contact breaker and distributer with a single coil. I Googled the type of engine you have and found that it was a motorcycle engine. You will have to look as and understand the ignition system. It could use 2 or 4 coils and may use the wasted spark system. A zener would also clip the negative spike to - 0.6 volts. I had not looked closely at your waveforms but now I see they are not what I would expect from the primary of a normal ignition coil. I would have expected a fast positive spike up to about 300 volts. If you use any sort of frequency to voltage converter (Other than a microproccesor measuring frequency and outputting the voltage via a DAC) it will need calibrating. Most microproccesor tachometers do not need calibration and the accuracy will be the same as the crystal used. (Which will be more than good enough for a 4 digit diapaly.)

Les.
Thanks les, I'm not too hot on the engine side of things, im looking at the resister and Zener circuit would you recommend a resistor value and zener.

I think I have accepted that I need to capture the edges and work out RPM on that via my micro.

I need to understand in more detail what Nigel's suggesting but think a zener, resistor combo is more my level.

Jason
 

Les Jones

Well-Known Member
Most Helpful Member
Hi Jason,
The zener would be a 4.7 volt 400mW or 1 watt model. the value of resistor can not be calculated until we know the amplitude of the input pulse. You do not give the volts per division setting of the oscilloscope displays (You need to give the actual values at the probe tip taking into account the divide by 10 of the scope probe.) you also need to say where the zero volt reference is on the display. The zener input will be exactly the same as on the kit that Nigel suggested.

Les.
 

Huttojb1

Member
Thanks les,

The v/div are in the bottom left corner of the scope, reading 10v.
 

spec

Well-Known Member
Most Helpful Member
Hey.

Please see attached, this is the signal that goes into my RPM Gauge of my kitcar. I believe it dirives from the coil.

Obviously I cannot put this directly into my PIC (Microchip Micro) and need to condition it to a 5V max signal.

Once I have conditioned the signal I could then use the capture function on the PIC to capture edges to work out frequency or I would like to convert this frequency in to a 0v to 5v signal. Either way is good. Would probably prefer to convert signal to a voltage as it makes it easier.

It seems like it goes from approx 5hz to around 160hz. I only screenshot 3 examples but the large one (87hz) was about half throttle.

If anyone could help I would be very appreciative because I wouldn't even know where to start.

The simpler the better because I would need to source all the components

Jason.
Hi HJB,

The circuit shown in the sketch below would provide a safe, reliable, and isolated way to interface the engine pulses to a microcontroller.

spec

2017_01_13_iss1_COUPLER_ENGINE_RPM.jpg
 
Last edited:

Huttojb1

Member
Hi HJB,

The circuit shown in the sketch below would provide a safe, reliable, and isolated way to interface the engine pulses to a microcontroller.

spec

Hey Spec, that's seems very reasonable, and easy. I also think I have a 6N139 aswell.

Just a couple of questions if you don't mind so I improve my understanding. 6n139.2 (input), would this handle the voltage in seeing 10v with transistion noise of 60v+. What is IN400X doing?

Would this also switch on the transistion spikes, I'm looking to filter the transistion spikes out?

Thanks again.

Jason.
 

spec

Well-Known Member
Most Helpful Member
Hi HJB,

6n139.2 (input), would this handle the voltage in seeing 10v with transistion noise of 60v+.
Yes to both questions
What is IN400x doing?
The 1N400x (where x is any number 2 to 7) is just a power diode that protects the input LED of the 6N139 from any reverse voltage on the input.
Would this also switch on the transition spikes, I'm looking to filter the transition spikes out
It depends how fast the transition spikes are but let us assume that the coupler does pass the spikes.

It would be a relatively simple to add effective filtering.

The circuit I posted is only a skeleton circuit- sometime I sped hours producing a fully toleranced design, with decoupling filters, fuses etc, only to have the OP say it is too complicated and go for some half-arsed design from the net.

If you are interested in this approach I will do a full design and then we can tailor it to match your application- this will include pulse shaping and filtering as necessary. :)

spec
 
Last edited:

Huttojb1

Member
If you are interested in this approach I will do a full design and then we can tailor it to match your application- this will include pulse shaping and filtering as necessary. :)
spec
Hey Spec, where you been all my life. Lol.

Thank you for your help and I really appreciate it. Although your help would be welcomed I don't want you to spend hours from your busy life doing this. I am looking for a solution and because Les offered a Zener / Resistor solution I have been to RS components today and brought the required components to attempt the solution over the weekend.

Perhaps I use the solution you gave me to condition the circuit before going to the PIC after the zener.

So if you have time, I would appreciate your help.

I'll go into the garage later today and see what optocouplers I have. Maybe I can use one.

Jason
 

spec

Well-Known Member
Most Helpful Member
Hey Spec, where you been all my life. Lol.

Thank you for your help and I really appreciate it. Although your help would be welcomed I don't want you to spend hours from your busy life doing this. I am looking for a solution and because Les offered a Zener / Resistor solution I have been to RS components today and brought the required components to attempt the solution over the weekend.

Perhaps I use the solution you gave me to condition the circuit before going to the PIC after the zener.

So if you have time, I would appreciate your help.

I'll go into the garage later today and see what optocouplers I have. Maybe I can use one.

Jason
Hi HJB,

That is fine it will take as long as it takes.

On ETO you will get quite a few suggestions for doing things and it is totally up to you which approach you go for- that is not the problem.

I will do a prettier schematic for you to consider alongside the other designs.:)

spec
 
Last edited:

MikeMl

Well-Known Member
Most Helpful Member
To implement a tach, you have two choices: count events per unit time, or measure the period between events using a high frequency clock (like the cpu clock of a microprocessor). Doing the former with any significant resolution means waiting a relatively long time between updates (like a second per update). Doing the latter means you can get higher resolution in a shorter time (like the interval between successive power strokes). Doing the latter, however, requires that you do a division to get the RPM:

f=k/period, where k is a constant.
 

Les Jones

Well-Known Member
Most Helpful Member
Hi MikeMl,
You might be interested in a variation of that method in the link I put in post #4 of this thread. If you read the software description it describes how it works.

Les.
 

Huttojb1

Member
POST Issue 2 of 2017_01_14

Hi HJB,

Below is the schematic for the isolated pulse coupler as promised.

spec


DATASHEETS
(1) 6N139; http://www.vishay.com/docs/83605/6n138.pdf

Hey Spec,

Sorry the diagram wasn't viewable on my phone last night so didn't see you had posted it.

Thanks ever so much, I will need to source the 6N139, but will definitely try the design for my solution.

Will definitely get back to you with the results.

Thanks again, Jason.
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top