CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Calculation with fixed numbers.

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
bschriek



Joined: 18 Dec 2007
Posts: 82

View user's profile Send private message Send e-mail

Calculation with fixed numbers.
PostPosted: Mon Apr 14, 2025 1:40 am     Reply with quote

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: 9457
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Apr 14, 2025 4:47 am     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Mon Apr 14, 2025 5:53 am     Reply with quote

Yes, you are right.
Problem is reduced to 50%. Laughing
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group