Quick and dirty RPM meter

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
Docara
Posts: 315
Joined: Sun Jun 23, 2013 1:29 pm
Has thanked: 28 times
Been thanked: 61 times
Contact:

Quick and dirty RPM meter

Post by Docara »

Hello everyone,

I need to knock up a quick RPM indicator to help calibrate a tacho gauge on a diesel engine, derived from the alternator.

I have a Arduino UNO R3 and an LCD available, as well as a photo transistor and UV LED emittor.

All I want is to put one white mark on the crank for detection.

Now, I asume the way to do this is count the number of pulses in a given time - say 10sec and multiple by 6 to give minutes. The trouble is when you look at the timer interrupts there's not really a suitable time base/prescaler to use.

Any thoughts on how best to procede?

Thanks
Matt

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Quick and dirty RPM meter

Post by Benj »

Hi Matt,

I might do it like this.

Use a C icon to reset the timer 1 count registers

Code: Select all

TMR1L = 0;
TMR1H = 0;
Start Timer 1 running based on an external T1CKI signal and a prescaler of 1:1. The T1CKI pin must be connected to the digital output of your white mark detector.

Start another timer running with a count to monitor the passing of time, for example 10 seconds. You could simply use a delay instead but a timer will probably be a bit more accurate.

When the time period is over disable the timer 1 and collect the value from the count registers into a 16-bit variable using a C icon.

Code: Select all

FCV_COUNT = TMR1L;
FCV_COUNT = FCV_COUNT | (TMR1H  << 8)
This will give you the number of revs that have happened within the measurement time period.

Docara
Posts: 315
Joined: Sun Jun 23, 2013 1:29 pm
Has thanked: 28 times
Been thanked: 61 times
Contact:

Re: Quick and dirty RPM meter

Post by Docara »

Thanks Ben,

Just to make your suggestion clear in my mind - you are saying that you would count internal timer pulses based on the rotation time and not counting he crank pulses in a given time. (As I wastrying to do.

If this is indeed the case and assuming a 10sec timebase, when you multiple the timer count by 6 you then would need to divide thus count by, what, the timer frequency to get rev per minute value.?

Also, guessing the "<< 8" mean shift left by 8 places so your dividing by 8 but what does rhe | (pipe)character mean, and how does this give a meanimgful reault.

Oh the isle RPM I think is only about 850rpm

Thanks

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Quick and dirty RPM meter

Post by Benj »

Hello,

In my suggestion timer 2 would monitor the passing of time, e.g. up to 10 seconds.

Timer 1 would count the number of pulses (revs) that have happened within the time frame using the external input. You would multiply this count value by 6 to give revs per min.

The | character is a binary OR. So the Low count byte at bits 0-7 ORed with the high count byte at bits 8-15. You could also use + but | makes more sense from a binary point of view.

Post Reply