cancel
Showing results for 
Search instead for 
Did you mean: 

Advice, measure RPM?

sima2
Associate III
Posted on June 19, 2010 at 17:15

Advice, measure RPM?

3 REPLIES 3
picguy2
Associate II
Posted on May 17, 2011 at 13:55

Start by thinking about the signal you will be getting from the engine.  How many pulses per rev?  I would use SysTick (0xE000E018) loading it in an ISR connected to your engine signal. Do a little arithmetic saving the time between interrupts.  

Note: SysTick counts down.  And it would not hurt to assure that the “:SysTick Reload Value Register�? is set the way you want it to be set.

In your mainline convert delta time into RPM.

Depending on the engine pulse rate and update rate needed a $1.00 PIC might work as well.  But with STM32 you would not have to write or find an appropriate divide subroutine.
darcy23
Associate II
Posted on May 17, 2011 at 13:55

I'd recommend using TIM2 (as you've suggested) and use it in Input Capture mode.  But in saying that...  there are numerous ways you could use the timers to achieve what you're trying to do.  Here's one way

Let's make a few assumptions... 

RPM min: 500/2 = 250 Hz (4.0 ms)

RPM max: 10000/2 = 5000 Hz (0.2ms)

Pick your TIM2 prescaler to give you the biggest value possible yet still not overflow 0xFFFF before 4.0ms has expired.  You can then capture every rising or falling edge (measuring the period between edges) and calculate the RPM on a pulse by pulse basis - assuming you actually need/want that kind of accuracy

e.g.

72MHz, prescaler 8 = 9MHz

9M / 250 = 36000 (where 36K counts would be the period at 500 RPM)

9M / 5000 = 1800 (period equals 1800 counts at 10000 RPM)

If you measure a period of 8571 (for example) that's 9M/8571 = 1050Hz = 2100 RPM.

Personally, I'd reserve the use of SysTick for software ticks (generating 0.1 - 10ms ticks etc)

Set the timer to reset with each update event (See SMS in SMCR register), and generate an interrupt (or use DMA).

raptorhal2
Lead
Posted on May 17, 2011 at 13:55

Systick will result in a noisy answer. Darcy's answer is a better technique.

Check the RPM pulse signal characteristics. If it is a standard tach input signal for a 4 cycle engine, you will get 4 pulses per revolution.

Cheers, Hal