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 support@ccsinfo.com

Vdrive2 and 16f1824
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
mvanvliet



Joined: 02 Jun 2009
Posts: 123
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Mar 05, 2013 9:25 am     Reply with quote

Dear Ttelmah,

at this moment I don't change the code. I don't need more than 255 characters in the sending string. But when I need it I will try your idea.

Next question about strings:

I will calculate the mean of 51 int16 samples. I did it like this:

Code:
int16 Verlies_ber = 0;
float Verlies_kort = 0;
int teller = 0;
int16 Totaal = 0;
int16 Verlies_array[52];
     
Verlies_ber = Verlies_kort * 10;                               //convert float to int16 without losing much resolution
      Verlies_array[Minuut_teller] = Verlies_ber;                               //put the int16 into an array
     
      for(teller = 0; teller <= 51; teller++)
      {
      Totaal = Totaal + verlies_array[teller];                                  //calculate the total of the numbers in the array
      }
     
      Verlies_lang = Totaal /512;                                               //Totaal / 10 * 5 / 256


I did the /512 because I read that /256 is an easy thing for the micro. Is /512 also an easy value?
Ttelmah



Joined: 11 Mar 2010
Posts: 19260

View user's profile Send private message

PostPosted: Tue Mar 05, 2013 10:58 am     Reply with quote

Any fixed binary division, can be done using rotation. /256 is 'particularly easy', since it only involves fetching the high byte.

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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