Hi
I'm dealing with time, applying the Arduino "millis" concept to Flowcode on a PIC uC .
From what I perceived, Flowcode sets Constants to " Z " domain ( - 32768 to 32767 ) by default .
That said and, until now, I'm creating Constants as they were variables, so they could assumed
as U Long ones, like here, with .CNT_msToWait :
msCurrent - .msPrevious >= .CNT_msToWait
All of the above are variables in the U Long domain, otherwise I could not obtain correct results from the inequation .
So, obviously, question is:
How to create a U Long Constant for dealing with time in a 32 bit "scale" ?
How to define a U Long Constant for dealing with time on a 32 bit "scale"
-
- Posts: 52
- http://meble-kuchenne.info.pl
- Joined: Mon Jan 04, 2021 8:08 pm
- Has thanked: 7 times
- Been thanked: 4 times
How to define a U Long Constant for dealing with time on a 32 bit "scale"
Many thanks in advance,
Miguel Garcia,
Electronic Systems Developer
-
- Matrix Staff
- Posts: 1922
- Joined: Wed Dec 02, 2020 11:07 pm
- Has thanked: 623 times
- Been thanked: 645 times
Re: How to define a U Long Constant for dealing with time on a 32 bit "scale"
Hi.
A constant will set the type automatically depending on the constant value.
For example if you set the constant to 1234567 it will automatically set as a long.
Enter 1234 it well set the constant will be automatically set as an integer.
123.45 the constant will be automatically set a float etc.
In the end the constant are evaluated at compiler time to make the actual calculation faster and consume less memory.
A constant will set the type automatically depending on the constant value.
For example if you set the constant to 1234567 it will automatically set as a long.
Enter 1234 it well set the constant will be automatically set as an integer.
123.45 the constant will be automatically set a float etc.
In the end the constant are evaluated at compiler time to make the actual calculation faster and consume less memory.
Martin
Re: How to define a U Long Constant for dealing with time on a 32 bit "scale"
H
So, if I define a Constant
CNT_msToWait = 1000
it will not give correct results on the inequation bellow, because msCurrent and
.msPrevious variables are U Long .
msCurrent - .msPrevious >=.CNT_msToWait
Can I force U Long, when creating the Constant, by putting zeros at the left of desired value ?
Or,
what must I need to write when editing C Constat icon to force it to be U Long ?
So, if I define a Constant
CNT_msToWait = 1000
it will not give correct results on the inequation bellow, because msCurrent and
.msPrevious variables are U Long .
msCurrent - .msPrevious >=.CNT_msToWait
Can I force U Long, when creating the Constant, by putting zeros at the left of desired value ?
Or,
what must I need to write when editing C Constat icon to force it to be U Long ?
Many thanks in advance,
Miguel Garcia,
Electronic Systems Developer
-
- Matrix Staff
- Posts: 1922
- Joined: Wed Dec 02, 2020 11:07 pm
- Has thanked: 623 times
- Been thanked: 645 times
Re: How to define a U Long Constant for dealing with time on a 32 bit "scale"
Hi
The first calculation needs to be Long variable = constant
That way the constant should be typecast to a long.
No that would work.
The first calculation needs to be Long variable = constant
That way the constant should be typecast to a long.
Martin
-
- Matrix Staff
- Posts: 1472
- Joined: Sat Dec 05, 2020 10:32 am
- Has thanked: 204 times
- Been thanked: 349 times
Re: How to define a U Long Constant for dealing with time on a 32 bit "scale"
Some more info on this that may be helpful...
In the generated code, a constant will be defined at the beginning of the generated C code using a "#define" directive. When the compilation occurs, the C compiler will first essentially replace any instances of the constant name in the code with the value given in the #define statement. So it does not matter what the type is.
For example, the generated C code might look like this:
The statement near the end of this code will get translated as a first step to:
At this point, the C compiler will perform any appropriate type casting.
The reason these constants are given a type (string, float or int) within Flowcode is so that Flowcode's simulation will work and also to ensure the code you generate will be valid for the C compiler.
In the generated code, a constant will be defined at the beginning of the generated C code using a "#define" directive. When the compilation occurs, the C compiler will first essentially replace any instances of the constant name in the code with the value given in the #define statement. So it does not matter what the type is.
For example, the generated C code might look like this:
Code: Select all
#define MY_CONSTANT (32323)
.
.
.
MY_VAR = MY_CONSTANT + 6;
Code: Select all
MY_VAR = (32323) + 6;
The reason these constants are given a type (string, float or int) within Flowcode is so that Flowcode's simulation will work and also to ensure the code you generate will be valid for the C compiler.
Re: How to define a U Long Constant for dealing with time on a 32 bit "scale"
Thanks for the explanation.
I will try it.
Anyway, both a U Long Variable and a
U Long Constant use the same amount of program space memory, doesn't they ?
I will try it.
Anyway, both a U Long Variable and a
U Long Constant use the same amount of program space memory, doesn't they ?
Many thanks in advance,
Miguel Garcia,
Electronic Systems Developer
-
- Matrix Staff
- Posts: 1472
- Joined: Sat Dec 05, 2020 10:32 am
- Has thanked: 204 times
- Been thanked: 349 times
Re: How to define a U Long Constant for dealing with time on a 32 bit "scale"
It is probably more complex that that and depends on the compiler implementation, but there should not be a large difference (if any).