View previous topic :: View next topic |
Author |
Message |
bschriek
Joined: 18 Dec 2007 Posts: 82
|
Calculation with fixed numbers. |
Posted: Mon Apr 14, 2025 1:40 am |
|
|
PCW Compiler, IDE 5.118, 16F18124
I use the "NCO_FIXED_DUTY_MODE" and "CWG_MODE_HALF_BRIDGE" to control a half-bridge. This works fine!
To set the frequency at 55kHz I need to fill the NCO varible with 7256d.
Code: | Freq = 7256; // int16
set_nco_inc_value(Freq); // = 55kHz |
But for better understanding I like to use a simple calculation/description.
Code: | Freq = (55000 / 7.58); // Here I can see immediately the frequency is 55kHz.
set_nco_inc_value(Freq); // = 55kHz |
I also have a simple while loop as you can see underneath:
Code: | Freq = (75000 / 7.58); // Here I can see immediately the frequency is 75kHz.
while (Freq > (55000/7.58)) // And here it's 55kHz
{
......... code
set_nco_inc_value(Freq);
delay_us(50);
} |
I thought the compiler does this calculation and converts to a constant but it's not.
When I open the .LST file this calculation is fully performed in the program and uses a lot of memory and time.
Probably a silly question but any help is welcome. |
|
 |
temtronic
Joined: 01 Jul 2010 Posts: 9465 Location: Greensville,Ontario
|
|
Posted: Mon Apr 14, 2025 4:47 am |
|
|
my gut is saying that 'freq=..' will be calculated during compile BUT the 'while(........) 'test' will be calculated every time ?? |
|
 |
bschriek
Joined: 18 Dec 2007 Posts: 82
|
|
Posted: Mon Apr 14, 2025 5:53 am |
|
|
Yes, you are right.
Problem is reduced to 50%.  |
|
 |
|