Page 1 of 1
Frequency Counter
Posted: Tue Feb 07, 2012 12:52 pm
by Will643
Hi
I am trying to program a 16f88 PIC using Flowcode v4 to display a frequency to 4 decimal points. I am using an interrupt and tmr0 and can get a result displayed on an LCD as a whole number but not with decimal points as the counter result is an integer. Any help would be appreciated to get the result as a string or a float so i can display the result with a decimal point.
Thanks
Will
Re: Frequency Counter
Posted: Tue Feb 07, 2012 1:14 pm
by JonnyW
Hello. How are you storing the frequency - as an integer?
An integer is always a whole number - there is never any need to add a decimal point. If this is a particular requirement you can do:
Code: Select all
buffer = IntToString$(frequency)
buffer = buffer + "."
To add a '.' after the number.
If you are dividing by another number to get a fractional value, you can do this to a floating point result:
Code: Select all
freq = fdiv(int2float(multiplier), int2float(divisor))
Then you can use a float and use FloatToString$() in a string calculation box to display this. I would not do this in an interrupt though as floating point calculations and string conversions are slow.
Note in v5 this code can all be done in a single calculation box as:
Code: Select all
freq = int2float(multiplier) / divisor
buffer = FloatToString$(freq)
I hope this is what you are after or is something to go on.
Jonny
Re: Frequency Counter
Posted: Tue Mar 20, 2012 5:20 pm
by jadiflow
Johnny, if I may:
I have a problem with the FloatToString$ function.
It seems to work OK until the argument to FloatToString$ is larger than 32k.
Above a value of 32k, incorrect values are printed.
Is there a limit to the FloatToString$ function preventing it to convert values above 32k?
jan
Re: Frequency Counter
Posted: Tue Mar 20, 2012 6:28 pm
by Benj
Hi Jan,
Replied to you here.
http://www.matrixmultimedia.com/mmforum ... =7&t=10457
Please don't multi post if you can help it.
