Converting milliseconds to frequency
I have code written to measure the time period of a square waveform using pulsin . I measure the low time and the high time and add them together and send it to an LCD. It is quite accurate (comparing to scope) and the refresh time is fast as the frequency varies. Knowing that frequency is 1/time, how can one go about doing the math in PBP to calculate the frequency of this waveform? Thanks.
This is either very easy or a bigger problem than it seems.
Here is the main loop: I found that I needed to do the 4/5ths thing to get the time more accurate.
loop: pulsin PORTA.1,0,x
x = x / 100
pulsin PORTA.1,1,y
y = y / 100
z = x + y
z = z * 4
z = z / 5
LCDOUT $fe, $C0
LCDOUT " "
LCDOUT $fe, $C0
LCDOUT #z
Goto loop
Then, when should we use lookup ???
All this thread bring back a question that I had in mind for a while. I was wondering at which point is that better (faster) to use lookup instead of calculated values?
I know that I can find thread like "Sine wave power inverter" where a lookup table was used to increase calculation's speed. But is this only a trial an error process or can someone bring up guidelines that will lead to use one solution or the other?
J-P