pulling temp sensor data from 633 packet?

Dexter

New member
Hi,
I have a 633 and enabled the temperature reporting. I am getting the correct packet back, but the actual data does not correspond to the correct temperature. Any ideas why this is?

thru WinTest633, my temp sensor reads 25.875C.

I tried to calculate this value following the procedure outlined in the datasheet, and i kept getting numbers like 12.

here is my packet:


thanks!
Looking for additional LCD resources? Check out our LCD blog for the latest developments in LCD technology.
 

CF Tech

Administrator
633 WinTest does it like this:
Code:
  double
    degc;
  degc=(*(short *)&(packet->data[1]))/16.0;

  double
    degf;
  degf=(degc*9.0)/5.0+32.0;
  char
    deg_c_string[20];
  char
    deg_f_string[20];
  if(packet->data[3]==0)
    {
    strcpy(deg_c_string,"BAD");
    strcpy(deg_f_string,"CRC!");
    }
  else
    {
    sprintf(deg_c_string,"%9.4f",degc);
    sprintf(deg_f_string,"%9.4f",degf);
    }
What does your code look like?

Using hand calculations, the response you are getting in the above packet is:

0x1A6 = 422 (dec)

422/16 = 26.375 degrees Celsius

and

26.375 degrees Celsius = 79.475 degrees Fahrenheit
 

Dexter

New member
thanks for your reply.

i dont understand how you did the hand calcuations, i tried to do that too, but just on the A6 part. Where did you get the LSB from? Well, i mean, manually i understand where you get the LSB from, but what about in the code?

Code:
 private void TemperatureEventHandler(LCDPacket packet)
        {
            if (packet.Data[3] == 0)
            {
                return; //crc error
            }
            else
            {
                double degc;
                degc = (Convert.ToInt32(packet.Data[1]))/16.0;
                MessageBox.Show(degc.ToString());
            }
        }
that is my code, i think i understand now where you get teh LSB, you are taking Data[1] AND [2] at the same time but starting from data? or something?
 

Dexter

New member
okay, so short is 16 bit. what i need to do is get data[1] and data[2] into one variable and then divide by 16. thats what my problem is. i am not good with pointers and address references.

i think i get it, thank you for your help. i will experiment with it more but at least the packets are correct.
 

CF Tech

Administrator
The magic line is this:

degc=(*(short *)&(packet->data[1]))/16.0;

To do it with out typedefs, pointers, confusion (but laborious code):
Code:
short
  lsb_short;
short
  msb_short;
short
  temp_times_16;
double
  degreesc;

lsb_short=packet.Data[1];
msb_short=packet.Data[2];
temp_times_16=lsb_short+(msb_short*256);
degreesc=temp_times_16/16.0;
But this code does a bunch of labor you do not need to.

Instead, modify your code like this:
Code:
private void TemperatureEventHandler(LCDPacket packet)
    {
    if(!packet.Data[3])
      {
      return; //crc error
      }
    else
      {
      double
        degc;
      degc = (*(short *)&(packet->data[1]))/16.0;
      MessageBox.Show(degc.ToString());
      }
    }
Don't be afraid of the typedefs, pointers and stuff. They are what is really happening. The C++ stuff can hide the details until you have no idea what is going on--even when it is actually simple.
 

Dexter

New member
thanks for your post which explains the code. i would have no problem doing the pointers and stuff, but im using C# and it doesnt exactly play well with that stuff....

i will try your expanded code later, thanks so much for taking the time to explain it!
 
Top