Hi Steve,
I'm sure there are probably several ways to do something like this, but I would use the StopWatch in MPLAB to see how many clock cycles my sub-routines require.
Then use a variable (or several depending on the osc frequency) to keep track of how many times my code has run from start to return to start.
This variable (or variables) would tell me how long I had been accumulating counts on RA4/T0CKI during normal execution of my routines.
Code:
COUNTER VAR WORD ' # of passes through routines
MAX_COUNTS CON ? ' # of passes required for my time period
COUNTER = 0
Main:
COUNTER = COUNTER + 1
IF COUNTER = MAX_COUNTS THEN GOSUB COMPUTE
Do something
Display:
Refresh display, etc,,
GOTO Main
Compute:
Read TMR0
Compute result, etc,,
Clear COUNTER, timer0, etc,,
Return
Just loop through your program waiting for the variable/s to reach a value that is equal to the time period you need to accumulate your counts in. Then read TMR0, and do the math.
You can insert pauses all over the place as long as they don't interfere with the display refresh rate required.
The problem with using something like;
> count porta.3,1000,pulsos
with hundreds (or thousands) of interrupts before the BASIC command can execute is that even if you do manage to save & restore context, you'll never get a reliable count returned. Especially with all the pause statements & BASIC comands in the int handler.
The period for your counts returned is no longer valid which introduces a HUGE error factor in the final result.
Bookmarks