CW and C beginners question

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

CW and C beginners question

3,140 次查看
ernestsnaith
Contributor I
How do you know how many processor calculations are used for particular C instructions? I think that a part of my code should be running a little faster than it is and would like to know whats slowing it down. I cant really step by step it as it relies on a complicated waveform from another MC.
 
Cheers
标签 (1)
0 项奖励
回复
2 回复数

617 次查看
ernestsnaith
Contributor I
Found the answer. However could somone give me a little advise, i have the following calculation which seems to take 50 cpu cycles.
 
Angle = ((390 - (ToothNo * 30)) - ((TCNT - Tooth1) / Gapdeg));
 
I also have 4
 
    if ((C1START <= 360) && (ANGLE <= C1START))    // COIL1 START PULSE
 
Which combine to use around 90 cpu cycles.
 
Are there far more efficient ways to write such things? if so how do i find them out? Are there any good books etc?
0 项奖励
回复

617 次查看
Lundin
Senior Contributor IV
Not much you can improve. Perhaps use some maths and rewrite the equation with just one integer constant instead of two (390 and 30) since they will always be the same. And avoid division if possible.
0 项奖励
回复