Hi everyone,
I am currently working on eTPU - AN4907 Engine Control demo. In the etpuc_crank.c (CRANK function), I saw the below function.
mertk_1-1641805517450.png
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.
mertk_2-1641805706163.png
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";
- tooth_period / crank_local.tcr2_ticks_per_tooth = 272024 / 100 = 2720 (rounding down - MACH register will be equal to the 24 which is called as remainder)
- After the division in order to put the 2720 (integer part) to related bit field in the TRR register we should shift it left by 9. => 2720 << 9 = 1392640 (0x154000 in hex)
Secondly, we should process the "fractional part of TRR";
- mach (which is equal to the 24) << 9 = 12288
- After the shifting mach register, in order to convert the remainder to the fraction we divide the shifted mach with crank_local.tcr2_ticks_per_tooth => 12288 / 100 = 122 (0x7A in hex - rounding down)
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.