CW and C beginners question

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

CW and C beginners question

3,152件の閲覧回数
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 返答(返信)

629件の閲覧回数
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 件の賞賛
返信

629件の閲覧回数
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 件の賞賛
返信