Confirm calculations - please someone !

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
ksor
Posts: 126
Joined: Mon Oct 23, 2006 3:50 pm

Confirm calculations - please someone !

Post by ksor »

I have made a program for RPM and COUNTING revolutions with 4 digits LED.

The RB0INT is counting incomming pulses and is used in both parts - in the RPM part it counts for a periode of time by TRM0 and a prolonging variable - RPMUpdateInit.

In the counting part of it I have some problems in the HW witch I'll have to investigate more - so never mind that for now.

In the RPM, I count incomming pulses for a periode of time calculated like this:

RPM = InCommingPuls / PulsPrRevolution * 60 / ( 13 * RPMUpdateInit )

where I did these calculations on TMR0 interrupts:

External ressonator: 20 MHz
System clock: 5 MHz
Prescaler 256 19531,25 Hz
Overflow at 256: 76,29394531 Hz
Counting periode: 13,1072 mSec INT_TMR0

with these numbers I try to investegate my "limits" = MAX RPM I can measure:

InCommingPuls 32767 because it's an INT
PulsPrRevolution 1 in the first place just 1
RPMUpdateInit 15 If I want a longer 'Counting periode' for more stable display
Counting periode 196,608 mSec

RPM calculates to 10000

With my 4 digits I can measure max 9999 with 1 pulse pr revolution.

Unfortunately I have 80 pulses pr revolution on my lathe and this gives this calculation:

InCommingPuls 32767 because it's an INT
PulsPrRevolution 80 on my lathe
RPMUpdateInit 15 If I want a longer 'Counting periode' for more stable display
Counting periode 196,608 mSec

RPM calculates to 125 !!!!!!!!!!

Then I can measure max 125 RPM and that's NOT god !

I maybe then HAVE to shorten my "counting periode", but it's can't do it and I think the "error reading" becomes bigger this way - right ?

Is my calculations correct ?

How should I else do it to measure max 9999 RPM ?
Best regards
KSor, Denmark

ksor
Posts: 126
Joined: Mon Oct 23, 2006 3:50 pm

Re: Confirm calculations - please someone !

Post by ksor »

I have made an Excel sheet witch do the calculations - and I beleave the right ones this time.

With the shown numbers I should be able to measure RPM <= 6666 - can someone confirm - please !
Attachments
Tidsberegninger.xls
(17 KiB) Downloaded 302 times
Best regards
KSor, Denmark

User avatar
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: Confirm calculations - please someone !

Post by Benj »

Hello Ksor,

Sorry for the delay.

Yes the value of 0.4096 mSeconds is correct for the timer timeout period.

I do not get the same result for the RPM however. Please could you add some brackets to the equasion so I can correctly interpret the order of events. Eg divide then multiply or multiply then divide.

ksor
Posts: 126
Joined: Mon Oct 23, 2006 3:50 pm

Re: Confirm calculations - please someone !

Post by ksor »

Hi again !

It was NOT a prompt to you - I beleave other users could answer too :)

Oh, I'm sorry - there's still an error in the calculation of the RPM !

Calculation are ALWAYS done
1) first inner ()'s,
2) * and /
3) + and -
If no ()'s then 2) and then 3) from left to right !

- fortunately to my best !
- now I can go up to 9999 RPM and
- even get a longer counting periode !

Do you agree ?

(Here is a new Excel sheet - no password is used in the protection !)
Attachments
Tidsberegninger.xls
(17 KiB) Downloaded 277 times
Best regards
KSor, Denmark

User avatar
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: Confirm calculations - please someone !

Post by Benj »

I'm a bit rusty when you take the old brackets away it seems :)

Yes your calculations check out and look good. Nice job of reaching near 1000. You will need to use the floating point for the last multiply by 2.46.

Calculation came out as 9989.9380 when I did them by hand so you could probably simply round up to 9990 and then convert back to an integer for outputting to LCD or over a bus etc.

You would just have to keep track of the number of interrupts in your program to allow you to reset the counter after every 3 cycles.

ksor
Posts: 126
Joined: Mon Oct 23, 2006 3:50 pm

Re: Confirm calculations - please someone !

Post by ksor »

:D - very nice - I'll try it out now - thx !
Best regards
KSor, Denmark

ksor
Posts: 126
Joined: Mon Oct 23, 2006 3:50 pm

Re: Confirm calculations - please someone !

Post by ksor »

I leave the re-using of TMR0 interrupt for the RPM mode - it too spooky to find out I think - I'll take TMR2 for the RPM mode instead and leave TRM0 for use in COUNTING mode.

My formula for the RPM is:

RPM = InCommingPuls / PulsPrRevolution * 60 / CountingPeriode

I use this formula in Flowcode:

DisplayThis = float2int(InCommingPuls/PulsPrOmdr*60/24576*10000)

and 0 < InCommingPuls <=32767
and 1 <= PulsPrOmdr <=100

DisplayThis, IncommingPuls and PulsPrOmdr are declared as INT, but I get this error message in compilation:

error: arguments of 'float32_to_int32' don't match the parameters of call - for more, see the attached file !

How can I calculate this formula ?

Oh, I forgot - the HELP file has NO help for the Float2Int() - it looks like a very, very old help file !!!!!!!!!!!
Attachments
07 - RPM og Counter.msg.txt
(1.98 KiB) Downloaded 311 times
Best regards
KSor, Denmark

User avatar
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: Confirm calculations - please someone !

Post by Benj »

Hello Ksor,

It looks like the float function is not being alled quite correctly. Can you post up your .FCF flowcode file and I will see if I can sort this out for you.

ksor
Posts: 126
Joined: Mon Oct 23, 2006 3:50 pm

Re: Confirm calculations - please someone !

Post by ksor »

In tried a little - this simple formula goes wrong !

Any comment on the old help file - Float2Int() (and more) is NOT documented in my help file.
Attachments
TEST_FLOAT.msg.txt
(1.88 KiB) Downloaded 310 times
TEST_FLOAT.fcf
(4 KiB) Downloaded 311 times
Best regards
KSor, Denmark

User avatar
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: Confirm calculations - please someone !

Post by Benj »

Hello Ksor

The float functions are detailed on the calculation icon page of the Flowcode help file.

I have changed your code to perform the calculation correctly and this should now compile and run correctly on the device.
Attachments
TEST_FLOAT.fcf
(4.5 KiB) Downloaded 340 times

ksor
Posts: 126
Joined: Mon Oct 23, 2006 3:50 pm

Re: Confirm calculations - please someone !

Post by ksor »

Oh - what a calculation !

Please tell me where the documention is - here is what I see:
Attachments
Help.jpg
Help.jpg (206.36 KiB) Viewed 8038 times
Best regards
KSor, Denmark

User avatar
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: Confirm calculations - please someone !

Post by Benj »

Hello Ksor

Sorry you'r right the FloatToInt and the IntToFloat functions have been missed off the help file.

They are very basic and simply look like this.

int = float2int ( float ) - Convert floating point number to integer
float = int2float ( int ) - Convert integer number to floating point

ksor
Posts: 126
Joined: Mon Oct 23, 2006 3:50 pm

Re: Confirm calculations - please someone !

Post by ksor »

Yeah - often things are in fact very simple - but the point is that that the help "file" or "what-ever-you-call-it" is NOT updated - and it should be.
Best regards
KSor, Denmark

Post Reply