|
|
View previous topic :: View next topic |
Author |
Message |
Guest
|
Need help understanding some TC77 code..... |
Posted: Mon Feb 02, 2009 5:32 pm |
|
|
Hi All,
I'm using the following code to read temperature data from a TC77, and I'm trying to understand this code, and reconcile it with what I think the datasheet is saying:
Code: |
int8 iIndex;
int16 data = 0;
output_low(TC77_CS); //select the TC77
for(iIndex=13; iIndex>0; iIndex--)
{
output_high(TC77_SCK); //clock
delay_us(10);
output_low(TC77_SCK);
delay_us(10);
if (input(TC77_SIO))
bit_set(data,iIndex);
}
output_high(TC77_CS); //deselect the TC77
data >>= 6; //to get rid of the fraction of a degree
|
This code reads 13 bits of data from the TC77, and stuffs them into the variable 'data'. The datasheet says that the temperature data is stored in a 13 bit 2's compliment representation, however the lower three bits are NOT temperature related (13 data + 3 non-data =16). Thus, I think this routine is missing the upper 3 bits of temperature data. I think the above routine works because these values are always zero for positive temperatures anyway. Am I reading the data sheet correctly, and interpreting it right?
So, now to extend this routine to read both positive and negative temperatures, I'd have to read all 16 bits, and then look at the highest bit to determine if the temperature was positive or negative (bit 15 is the 'sign' bit)........
I'm also not clear on the line
Code: |
data >>= 6; //to get rid of the fraction of a degree
|
I can understand the shift to get rid of the lower three non-temperature bits, and some more shifting to get rid of the fractional part, but it seems to me the fractional part is contained in four bits, not three. Thus, I would think that a shift of 7 is correct, not 6. This has me perplexed because the code does work as written above.....
Tony |
|
|
Guest
|
|
Posted: Mon Feb 02, 2009 5:41 pm |
|
|
Hi All,
Argh!!! I see that the data is shifted out MSB first, so we always get the 13 temperature bits with this routine. The question remains, however, why is the shift right operation written the way it is?
Thanks!
Tony |
|
|
techdesign
Joined: 03 Feb 2009 Posts: 2 Location: Belgium
|
tc77 |
Posted: Tue Feb 03, 2009 6:50 am |
|
|
It depends on which fraction you want to get rid of.
Bit3 (LSB) of the TC77 represents 0.0625°C
Bit4 is 0.1250°C
etc...
Total sample value to be multiplied with LSB value for a temperature reading.
It's quite common to skip some LSBs to have a more stable readout.
An other approach would be to add up 10 full resolution samples and divide by 10 to have a more stable readout.
Bit16 (MSB) is the plus/minus sign, so a signed int16 is perfect for a 16-bit sample. Can be converted to a float if needed.
cheers,
Michel Bavin
www.techdesign.be
Last edited by techdesign on Wed Feb 04, 2009 1:18 am; edited 1 time in total |
|
|
Guest
|
|
Posted: Tue Feb 03, 2009 6:22 pm |
|
|
Hi Again,
Well, I'm still confused....... Here is the shift right line:
Does this line not say 'shift variable data 6 places to the right, and place the result in variable data'??
If so, the rightmost 6 bits are thrown out, correct? If that is true, by my read says that bits 2^1, 2^0, 2^-1, 2^-2, 2^-3, and 2^-4 are all lost. The confusion is that the upper two bits (2^1 and 2^0) contain whole data, not fractional data.
What am I missing???
Tony |
|
|
techdesign
Joined: 03 Feb 2009 Posts: 2 Location: Belgium
|
tc77 |
Posted: Wed Feb 04, 2009 2:49 am |
|
|
Yes, you'right to be confused.
First of all, the unsigned int16 "data" is filled from bit13 to bit0. This is a bit fishy, because of positive/negative values are best filled from bit15 to bit0.
Then the right shift >>=6 !! Even without the first problem above, this reduces the resolution to 4°C.
Best is to write your own routine i guess...
You might want to look at our TC77 code example in this project: http://www.techdesign.be/projects/012/012.htm
Look for the TC77 routine in the source code: http://www.techdesign.be/projects/012/012_v32_c.zip |
|
|
|
|
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
|