Eficiency

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

Eficiency

1,106 Views
ernestsnaith
Contributor I
I was wondering why my code cycle repeated itselft so slowly and decided to see what part of it took so long. In the end i got the down to;
 
Code:
void main(void) {  EnableInterrupts;  TSCR1 = 0x80;               //ENABLE TIMER  TSCR2 = 0x04;        //PRESCALER SET TO 16  for(;;)   {    Marker9 = Marker8;    Marker8 = Marker7;    Marker7 = Marker6;    Marker6 = Marker5;    Marker5 = Marker4;    Marker4 = Marker3;    Marker3 = Marker2;    Marker2 = Marker1;    Marker1 = TCNT;                       }}

 
 
I then looked at the marker values and was amazed to see that each differed by 3-4 increments of the timer. with a timer prescaler of 16 thats 45-60 bus cycles is it not? Why is such a simple operation taking so long?
0 Kudos
1 Reply

262 Views
rocco
Senior Contributor II
Hi, Ernest:

Not much information to go on, but here are a few things to look at.

What type are Marker1 through Marker9? If they were floats, 60 cycles sound reasonable, but certainly to long if they were 16-bit integers.

Where are they allocated? In page-zero? On the stack?

Could there be interrupts enabled that may be sapping all of your CPU bandwidth?

Have you looked at the assembly code that was generated?

I don't know what timer you are using, so are you sure it's running on the same clock as the CPU?
0 Kudos