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
Frequency Counter
Moderator: Benj
- JonnyW
- Posts: 1230
- Joined: Fri Oct 29, 2010 9:13 am
- Location: Matrix Multimedia Ltd
- Has thanked: 63 times
- Been thanked: 290 times
- Contact:
Re: Frequency Counter
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:
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:
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:
I hope this is what you are after or is something to go on.
Jonny
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 + "."
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))
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)
Jonny
-
jadiflow
- Flowcode v5 User
- Posts: 273
- Joined: Thu Apr 17, 2008 9:59 am
- Has thanked: 19 times
- Been thanked: 16 times
Re: Frequency Counter
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
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
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Frequency Counter
Hi Jan,
Replied to you here.
http://www.matrixmultimedia.com/mmforum ... =7&t=10457
Please don't multi post if you can help it.
Replied to you here.
http://www.matrixmultimedia.com/mmforum ... =7&t=10457
Please don't multi post if you can help it.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel