Hi, I am using the standard ETPU engine control library (AN4907SW or NXP etpu function generator site) decoding a 35-1 teeth with no CAM function and therefore engine cycle is 36 teeth (1 revolution). The engine is 2-stroke engine and no need for CAM function. I have changed macros in MCU application as below. I couldn't understand the tooth period (TCR1) and RPM conversion. Can you express where does it come from?
#define SYS_FREQ_HZ 150E6
#define TCR1_FREQ_HZ (SYS_FREQ_HZ/2)
#define TEETH_TILL_GAP 35
#define TEETH_IN_GAP 1
#define TEETH_PER_CYCLE 36
#define TCR2_TICKS_PER_TOOTH 1000
#define TCR2_TICKS_PER_CYCLE ((TEETH_PER_CYCLE)*(TCR2_TICKS_PER_TOOTH))
#define MSEC2TCR1(x) (TCR1_FREQ_HZ/1E3*(x)/1E0)
#define USEC2TCR1(x) (TCR1_FREQ_HZ/1E3*(x)/1E3)
#define DEG2TCR2(x) ((x)*TCR2_TICKS_PER_CYCLE/360)
#define UFRACT24(x) ((x)*0xFFFFFF)
#define TCR12USEC(x) (x / ( TCR1_FREQ_HZ / 1E6 ))
#define TCR2DEG(x) (360*(x)/TCR2_TICKS_PER_CYCLE)
/* Tooth Period [TCR1] and RPM */
#define RPM2TP(x) (TCR1_FREQ_HZ/(x)*60/(TEETH_PER_CYCLE))
#define TP2RPM(x) (TCR1_FREQ_HZ/(x)*60/(TEETH_PER_CYCLE))
-------------------------------------------------------------------------------------------------------------------------------------------------
In NXP AN4908 Engine control demo application document page 6, the conversion is below for a 4-stroke engine;
Regards,
Solved! Go to Solution.
It's algebra. The CRANK routine gives you a log of the number of TCR1 cycles (documented in AN4907 as "• The measured tooth periods can optionally be logged to an array.") that were observed during the previous tooth. You are inferring the engine speed by figuring out how long it took for a single tooth to fly by your crank wheel detector. The slower the engine, the more time, the faster the engine, the faster the teeth fly by.
TCR1 is a free running clock, so you get TCR1_FREQ_HZ or in your case 1,000,000 pulses per second.
x is your measured number of pulses during the previous tooth in pulses per tooth.
60 is the number of seconds in a minute.
TEETH_PER_CYCLE relates to your tone wheel with 36 teeth. Since you are using a 2-cycle, this gives you 36 teeth per revolution.
So, as each tooth gets detected, CRANK will sample TCR1 to figure out what time it is and subtract that number from the time of the previous tooth. That tells you how many TCR1 counts went by for that tooth. Now that you know how much time it took for a tooth to go by, work the math backwards to figure out what engine speed gives you that time.
so:
(TCR1_FREQ_HZ /(x)*60/(TEETH_PER_CYCLE))
Substituting the stuff above:
(1,000,000 pulses/second / (x pulses/tooth) * 60 seconds/minute / (36 tooth/rotation))
1,000,000 pulses * tooth * 60 seconds * rotation
= _____________________________________________
second * x pulses * minute * 36 tooth
= 1,000,000 * 60
________________ rotations/minute
x * 36
So if your tooth log[0] gives you a number like 850, plop 850 into the x term of the equation and that would be 1960 RPM.
A log value of 1666 would give you 1000 RPM, a nice idle.
Is this what you were looking for?
Andrei
The code looks something like this:
ENGINE_RPM_T TPUGetRPM(void) {
uint32_t tcr1_ticks;
tcr1_ticks = crank_instance.cpba_tooth_period_log[0];
return (TP2RPM(tcr1_ticks));
}
Andrei
Andrei hi,
The point I couldn't understand is where the formulation comes from;
#define TP2RPM(x) (TCR1_FREQ_HZ /(x)*60/(TEETH_PER_CYCLE))
Regards,
It's algebra. The CRANK routine gives you a log of the number of TCR1 cycles (documented in AN4907 as "• The measured tooth periods can optionally be logged to an array.") that were observed during the previous tooth. You are inferring the engine speed by figuring out how long it took for a single tooth to fly by your crank wheel detector. The slower the engine, the more time, the faster the engine, the faster the teeth fly by.
TCR1 is a free running clock, so you get TCR1_FREQ_HZ or in your case 1,000,000 pulses per second.
x is your measured number of pulses during the previous tooth in pulses per tooth.
60 is the number of seconds in a minute.
TEETH_PER_CYCLE relates to your tone wheel with 36 teeth. Since you are using a 2-cycle, this gives you 36 teeth per revolution.
So, as each tooth gets detected, CRANK will sample TCR1 to figure out what time it is and subtract that number from the time of the previous tooth. That tells you how many TCR1 counts went by for that tooth. Now that you know how much time it took for a tooth to go by, work the math backwards to figure out what engine speed gives you that time.
so:
(TCR1_FREQ_HZ /(x)*60/(TEETH_PER_CYCLE))
Substituting the stuff above:
(1,000,000 pulses/second / (x pulses/tooth) * 60 seconds/minute / (36 tooth/rotation))
1,000,000 pulses * tooth * 60 seconds * rotation
= _____________________________________________
second * x pulses * minute * 36 tooth
= 1,000,000 * 60
________________ rotations/minute
x * 36
So if your tooth log[0] gives you a number like 850, plop 850 into the x term of the equation and that would be 1960 RPM.
A log value of 1666 would give you 1000 RPM, a nice idle.
Is this what you were looking for?
Andrei
Hi Andrei,
many thanks for stepping in and providing explanation! But just a small correction to your calculations:
Turgay has a configuration of eTPU system clock for 150 MHz so in his case TCR1_FREQ_HZ will be half of that it means 75 000 000 ticks per second, not 1 000 000 as you are stating in your example. I believe this is just a typo. So to make it clear for his case the calculations for crank log of value 850 would be as follows:
75,000,000 * 60
________________ rotations/minute = 147,058 RPM
850 * 36
Thanks again
Regards
Marketa
Ah yes, I see what I did. I took the frequencies from the code quoted from the app note, not Turgay's code. And mine is broken as well, I should have had 100,000,000 in my broken example.
I won't fix it. That way the thread still makes sense.
A
Andrei hi,
Thank you for your detailed explanation. Appreciated.
Regards,