How to Determine Elapsed Time of a Loop
in Propeller 1
Hello,
Is there a way to determine the elapsed time of a loop in Propeller C?
Thank you.
Is there a way to determine the elapsed time of a loop in Propeller C?
Thank you.

Comments
#include <propeller.h> int tryTiming(void) { int startTime; int i, j, k; startTime = CNT; // remember starting time for (i=1;i<=100;i++) for (j=1;j<=100;j++) k = i * 12345 / j; // multiply and divide return CNT - startTime; // return time difference in system clocksWe have 10,000 multiplies and divides plus assorted other operations. The system counter rolls over after 2^32 clock cycles so you need to keep the total loop time under roughly 53 seconds (2^32 / 80000000) using the normal 80MHz system clock. In this case, the values are signed, so the maximum loop time is 26 seconds.#include propeller.h float startTime; float delta; // Do Prediction Step, note: filter is not using accel measurements at this point, only gyro, so it drifts startTime = CNT; // Remember starting time int N = 3; for(int i = 0; i < N; i++){ //////////////////// // State derivatives float f[2] = { {gy+gx*sin(phi)*tan(theta)+gz*cos(phi)*tan(theta)}, {gx*cos(phi)-gz*sin(phi)} }; ////////////////////// // Calculate xhat // xhat = xhat + (Ts/N)*f xhat[0]=xhat[0]+(delta/N)*f[0]; xhat[1]=xhat[1]+(delta/N)*f[1]; phi=xhat[0]; theta=xhat[1]; print("%f delta = %f\n",theta*180/PI, delta); } delta = (CNT-startTime)/80000000;Have I implemented this correctly by dividing by 80,000,000 to get the elapsed time in seconds?
David
// Calculate xhat // xhat = xhat + (Ts/N)*f xhat[0]=xhat[0]+(delta/N)*f[0]; xhat[1]=xhat[1]+(delta/N)*f[1];Thanks. I have now initialized delta to an estimated value. Before it was assuming delta is zero.
Mike,
Thanks so much for your help. I have not changed anything with the clock so I'm assuming it is still set to 80 MHz.
David