Hi everyone,
I am currently working on eTPU - AN4907 Engine Control demo. In the etpuc_crank.c (CRANK function), I saw the below function.
I understand the purpose of the function and I know we should set TRR for every tooth after the synchronization. However, I am struggling the understanding why we are shifting the mach register left by 9.
The below image shows the TRR register of the eTPU for MPC5644A microcontroller.
In order to make clear everything, I want to give an example which the values are taken from the random point of the demo.
tooth_period = 272024 (in TCR1)
crank_local.tcr2_ticks_per_tooth = 100 (default value in demo)
First, we should process the "integer part of TRR";
Secondly, we should process the "fractional part of TRR";
Lastly, add them to get TRR value => 0x154000 + 0x7A = 0x15407A
Normally, if we do NOT work on bits, I should expect the presentation of the fraction part of TRR is 24/100 where it means that mach / crank_local.tcr2_ticks_per_tooth. As you can notice, there is no shifting in the mach! However in aspect of bits, if divide 24 to 100, we will get 0 (zero). So, this is not gonna be work.
So, why we are shifting mach (remainder) by 9 where I mark it with red color? Is this related with the design of the eTPU?
I tried to explain more clearly, hope you understand what I ask. Also, I read 24.5.7.4.1 Calculating the angle tick period integer and fraction section in RM of MPC5644A.
Best regards,
Mert.
Solved! Go to Solution.
Oh, I've struggle that question for 2-3 days and when I checking my question. I noticed something
Again, we assume that, tooth_period = 272024 and crank_local.tcr2_ticks_per_tooth = 100. In the integer part, we are shifting the division result left by 9. But, what is the result value of division? It is 2720 (tooth_period / crank_local.tcr2_ticks_per_tooth). This number can be found also if the tooth_period = 272000. I mean, we are losing the effect of the last two digit (two digit beucase we divide with 100) of the tooth period. Because we didn't shift the tooth_period, we shift the result of the division!
Therefore, in order to preserve the importance of the value of 24 (actually it's remainder right
I hope it is understandable. If I am true, I would like to know that, so I am still looking forward for your helps friends.
Best regards,
Mert.
Hi @mertk ,
Can you please let me know where to obtain "etpuc_crank.c" file. all i can find in AN4907SW is "etpu_crank.c".
Thanks,
Arjun
Hi @arjunraveendran,
You can download the example project (NXP AN4907 Engine Control Library) from the below link;
https://www.ashware.com/Software
Best regards,
Mert.
hello @mertk ,
Thanks for the resources.
Hi John, thank you for your answer.
Mert.
Oh, I've struggle that question for 2-3 days and when I checking my question. I noticed something
Again, we assume that, tooth_period = 272024 and crank_local.tcr2_ticks_per_tooth = 100. In the integer part, we are shifting the division result left by 9. But, what is the result value of division? It is 2720 (tooth_period / crank_local.tcr2_ticks_per_tooth). This number can be found also if the tooth_period = 272000. I mean, we are losing the effect of the last two digit (two digit beucase we divide with 100) of the tooth period. Because we didn't shift the tooth_period, we shift the result of the division!
Therefore, in order to preserve the importance of the value of 24 (actually it's remainder right
I hope it is understandable. If I am true, I would like to know that, so I am still looking forward for your helps friends.
Best regards,
Mert.
I believe your description is accurate. The initial tooth period cannot be shifted left before the first division because in many cases (slower engine speeds) overflow would result, thus the decomposition into two divides.