CW and C beginners question

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

CW and C beginners question

3,142 Views
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
Labels (1)
0 Kudos
Reply
2 Replies

619 Views
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 Kudos
Reply

619 Views
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 Kudos
Reply