View previous topic :: View next topic |
Author |
Message |
tony Guest
|
runtime |
Posted: Thu Mar 11, 2004 9:49 am |
|
|
Hello,
i need to run a program for a specfic amount of time. e.g 5 secs, so i can calculate speed.
does anybody know the easiest way to do this,
will my counter still oerate when the counter is running or will it stop count to 5 and then move on to the next bit of code.
i'm using ccs, 16f877 and microchips ide board.
Thanks. |
|
![](templates/subSilver/images/spacer.gif) |
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Thu Mar 11, 2004 10:28 am |
|
|
What does your program do?
If you have any serial output and you record it with something like something like terminal by Br@y++ that can timestamp the incomming data, you can use the timestamps to check the speed of your program. Note that adding print statements to your program may slow it down a lot. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
|
Posted: Thu Mar 11, 2004 10:43 am |
|
|
its a speedo,
it counts the revolutions,
then there is a sum, but time is one of the factors in the sum |
|
![](templates/subSilver/images/spacer.gif) |
Thomas Blake
Joined: 18 Jan 2004 Posts: 22 Location: Burbank CA
|
time |
Posted: Thu Mar 11, 2004 11:30 am |
|
|
Don't "run the program" for 5 seconds, run the counter/accumulator for 5 seconds.
Calculate the ints/second for the timer and clock speed you're using.
Compare it to the constant that equals 5 sec for that timer/clock.
If it's <, then continue to count and accumulate, else jump to an infinite loop or wait-for-switch loop.
Put thecounter/accumulator code in the main loop, not the timer interrupt handler. Use the timer/interrupt handler to set a go/stop flag instead.
Hope this helps. |
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
|
Posted: Thu Mar 11, 2004 11:41 am |
|
|
you'll have to excuse my ignorance here i'm new enought pics.
i'm using a 20Mhz crytals,
so how would i calculate int ints/second.
by any chace would you have some examples of the code needed |
|
![](templates/subSilver/images/spacer.gif) |
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
|
Posted: Thu Mar 11, 2004 1:52 pm |
|
|
time=seconds;
While(time==seconds);
time=seconds;
while(time+5>seconds)
{ On_Now=Input(pin);
if(On_Now && Was_Off) ++pulse count;
Was_Off=!On_Now;
}
Take this and add an interupt driven time keeper. |
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
|
Posted: Fri Mar 12, 2004 10:28 am |
|
|
using the speed.c example i think i have solved my problem
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
long time;
set_timer1(0); // start counting
time=get_timer1();
now the only problem i have is trying to figure ou the follwoing line:
mph = 0.000009929*(float)time/3600.0; // calculate the time in hours
mph = distance/(63360.0*mph);
what is 0.000009929?
distance is a distance in inches and 63360=no of inches in a mile |
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
|
Posted: Thu Apr 08, 2004 3:20 pm |
|
|
anybody??
i'm still having problems |
|
![](templates/subSilver/images/spacer.gif) |
|