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

I got a question about C code (PIC 16F877).

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







I got a question about C code (PIC 16F877).
PostPosted: Sat Jan 17, 2009 12:35 am     Reply with quote

Hello everyone,

I got a question about the CCS C compiler code.

I am using two temperature sensors. One is read from the PIN and the other is from USART. I wanna save these values which are from temperatrue sensors and to compare these two value. How should I do? I mean that these values keep changing and I need to keep comparing. I knew that I should save the data in somewhere and read them from there but I have no idea how to do that. Could you guys give me some hints?




Any help will be really really appreciated.



Thank you very much.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Jan 17, 2009 1:23 pm     Reply with quote

Do you want to compare the two current temperature values and then
display them on the PC screen immediately ?

Or, do you want to save a series of values (100's of them) over a period
of time (hours) and then compare and display the values later ?
If you want to do this one, then you could use an external eeprom chip
to store the values (24LC256). CCS has a driver for this chip in the
drivers directory.
Quote:
c:\program files\picc\drivers\24256.c
Brian
Guest







I got a question about C code (PIC 16F877).
PostPosted: Sat Jan 17, 2009 4:20 pm     Reply with quote

Hello,

Thank you for your replay.

Actually, I do not need to save all values. I just need to compare current temperature value and then my microcontroller will do some action. Because the value from Temperature sensor will come in one by one after delay_ms(3000) not at same time, I need to save this value. Could you tell me how to do that?

By the way, if I wanna use this chip, could you tell me how to do? I mean that do I just call this function or I just need to include it in the head-file?



Thank you very much.



Sincerely,



Brian
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Jan 17, 2009 5:30 pm     Reply with quote

Put the temperature values in two variables. Compare them with an if()
statement. Do something based on the result of that comparison.
Here's the basic outline of what you need to do:
Code:

void main()
{
signed int8 temp1;
signed int8 temp2;

initialize_sensor1();
initialize_sensor2();

while(1)
  {
   temp1 = get_temp_from_sensor1();
   temp2 = get_temp_from_sensor2();
   
   if(temp1 == temp2)
      printf("Temperatures are the same.\n\r");
   else
      printf("Temperatures are different.\n\r");

   delay_ms(3000);
  }

}
Ttelmah
Guest







PostPosted: Sun Jan 18, 2009 3:14 am     Reply with quote

To add one more comment. You will also need to realise, that even if the temperatures _are_exactly the same, the 'odds' are that the readings wll not be. So you will normally have to add a 'margin of error' to the readings, for comparison. So, to expand PCM's example:
Code:

#define MARGIN (3) //Adjust to suit the noise/accuracy of the sensors

void main()
{
signed int8 temp1;
signed int8 temp2;

initialize_sensor1();
initialize_sensor2();

while(1)
  {
   temp1 = get_temp_from_sensor1();
   temp2 = get_temp_from_sensor2();
   
   if (abs(temp1-temp2)<=MARGIN)
      printf("Temperatures are within the margin.\n\r");
   else
      printf("Temperatures are different.\n\r");

   delay_ms(3000);
  }

}

Here, I subtract one reading from the other. Take the 'absolute' value of this (gives a positive number only, corresponding to the difference between the values), and then if this is inside the 'margin', display the acceptance message.
In the 'real world', some slight form of margin, _will_ be needed...
Ideally (of course), you have the sensors returning a much 'finer' reading tha the acceptable difference (so perhaps temperature sensors reading in 1/10th degree steps), and 'accept' a temperature within half a degree of each other (+/-5 counts)). If the readings being returned are only giving figures to the same accuracy that you want to 'distinguish', getting reliable results, will become hard.

Best Wishes
Brian
Guest







I got a question about C code (PIC 16F877).
PostPosted: Tue Jan 20, 2009 3:14 am     Reply with quote

Hello,

I was out off town so I can not reply during pass two days.

Thank you guys' reply. I really appreciate it.

I will try you guys' suggestion and I will let you know the result.

Again. Thank you for you guys' reply.
Have a nice day.



Sincrely
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