How to make a variable float to const float
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-12-02 12:37 PM
Dear All,
I compile a program with cube ide and would like to know how the float variable is const float.
sample is.
float a
const float b
b = a;
BR,
Methee
Solved! Go to Solution.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-12-03 10:45 AM
And I can't edit or pull code from a screen shot/bitmap.
Make a structure you're configuration items live in.
Create routines to read, write and validate this structure you can place in FLASH or EEPROM
FOO foo = { 0 };
void InitFoo(FOO *foo, EEPROM *eeprom)
{
...
foo->donkeys = 12;
foo->freqHz = eeprom->freqHz;
foo->speedRPM = eeprom->speedRPM;
...
}
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-12-02 1:37 PM
Const (constant) variables cannot be changed after they are initialized. This means you can and must initialize them only once.
It's a compiler flag more than anything that lets the compiler know that variable won't be changing and it can optimize things as if that variable will always be the same value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-12-02 1:45 PM
Dear TDK,
You can help me for this solution?
float a =10;
const float b=a;
BR,
Methee
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-12-02 1:52 PM
That code is valid and will compile just fine. What help is needed?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-12-02 1:55 PM
To what end?
const float b = 10.0f;
Or pass it to a function that has const float x as a parameter?
The optimizer should try to fold constant values, perhaps use define?
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-12-03 2:15 AM
Dear Tesla DeLorean,
I need to read data from eeprom for change information in parameters of MotorControl Workbench 6.2.0 project.
But function parameters need to be const float or #define only.
Please help advise.
BR,
Methee
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-12-03 6:47 AM
That is not a function, but a structure initialization. You need to learn the C programming language first before trying to deal with complex software development.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-12-03 8:10 AM
The compiler can't initialize the structure with a variable.
You should start with an empty structure, and write a subroutine to do the initial fill from your EEPROM, or whatever.
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-12-03 9:40 AM
I can use it for Aruino ide but cube ide is very difficult to use. Can you make an inverter to sell if you are good at it? It didn't help me at all. It's better not to answer.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-12-03 9:41 AM
I'm just stuck here. Otherwise, I have no problem. Let's try to find another way. It doesn't seem to help me at all.
