Reading TMP117 with ATmega4809 [solved]

Go To Last Post
12 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Greetings, folks -

 

Actually, the title is a bit of a smokescreen!

 

TMP117 is a pretty nice TI temperature sensor with 0.1C accuracy and 7.825 mC resolution. Value returned by the sensor is a 16-bit signed integer with LSB=7.825mC. Got it working nicely with the Microchip written Arduino TWI library for ATmega4808 "ported" to bare metal. No problem, there. 

 

The real question is how to convert the signed integer to decimal temperature? I've looked at several example programs and they blithely throw the whole mess at floating point, and charge ahead, with no apparent consideration of speed or code size. 

 

I am wondering if there is some way, which currently escapes me, that might use fixed point or other techniques to tame this beastie? My goal is to have something that can be transmitted as human readable ASCII with a single fractional decimal digit (e.g. 27.3 or  -7.9). In several other cases, I've used fixed point and inserted the decimal point "manually"; that works just fine and is quite fast. But, those cases were already scaled (e.g. LSB = 0.1C).

 

So, I am entertaining suggestions about how this might be approached.

 

Many thanks

Jim

This topic has a solution.

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

Last Edited: Fri. Mar 27, 2020 - 09:10 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A first thought suggests noting that the scaling is (nominally) from +/- 255 degrees... i.e. the top nine bits (signed) directly give you the unit temperature; the low seven bits handle the fractional part in 128 chunks...

 

Certainly there's no easy translation, unless you're going to multiply the count by 0.0078125 and keep an eye on the decimal point (i.e. multiply by 78125 and stick a decimal point in seven from the right). But if you only want to show say 0.5, 0.25, or 0.125 degree resolution, then just use bits 4-6 to index into a table of ascii.

 

I'd be inclined to keep an eye on the negative flag and convert everything to an unsigned positive value.

 

Neil

 

edit: I am assuming that there is a convenient 0x00-0xff to 0-255 routine available :) But that's simple!

Last Edited: Fri. Mar 27, 2020 - 07:42 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think Neil beat me to it, but that is 1C = 128 counts.... 

 

Jim

 

 

 

 

 

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2

 

 

Well, the bottom line is you just perform an integer multiplication.  Say you had binary number corresponding to a hypothetical sensor  value of 0.06234 and say fine, but it should read 973.45 on my display.

 

Well, there is certainly an integer multiplier such that   n*binaryvalue gives  97345 (rounded or truncated), where you manually position the decimal point to read 973.45

 

Once you determine that multiplier, just have at it.....multiply & it will work for all sensor values.

 

Say the 16 bit binary sensor value of 414 corresponds to 0.06234....then you'd need a multiplier of  97345/414 , or  235.1328 , use 235 and away you go.   235 & 235.1328 are % very close.

 

Or, to increase accuracy, 8*235.1328 is 1881.06   ...use 1881 (VERY close to 1881.06)  as the mult & divide your final result by 8  (watching out for 8x larger intermediate results).   

 

You want to shift things over enough to give a larger multiplier to minimize residual error down to the desired percentage.  Sometimes you get an "exact" matchup with little or no shifting needed (an exact fit, small multiplier) . 

Here, multiplying by 8 give a highly exact fit (99.997%) with no fuss. 

 

For negative values, you can first convert to positive (2's compliment) & keep track of the final sign.

 

Below you can see that the displayed value gets closer/better with more shifting (larger multipliers)...after a point there is no improvement.

So you pick, by determining how many counts off you care to tolerate.  Or pick a % & be happy with that.

 

Note that while 235 as a multiplier is close % wise, it is gives 55 delta counts on the display (97345-97290).  That's the law of big numbers!

Of course shifts by 256 allow easy shifting by simply toss out full bytes from the result (grabbing the high bytes)

 

 

 

 

 

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Last Edited: Fri. Mar 27, 2020 - 09:16 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

BINGO (not the Freaks contributor!)

 

avrcandies got the  prize!

 

Thanks

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Here is an Excel file you can use...just enter your numbers in the TWO yellow boxes...the desired INTEGER value & the originating integer binary value...it will figure out possible best-case multipliers for you

 

https://www.dropbox.com/s/7lo58y...

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Got it. Thank you.

 

Would have never thought of using a spread sheet. Does make it easy, however.

'

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

bookmarking this, thanks @avrcandies

my projects: https://github.com/epccs

Debugging is harder than programming - don’t write code you can’t debug! https://www.avrfreaks.net/forum/help-it-doesnt-work

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Interesting...I wrote a script to find the min multiplier needed for zero error, with the needed shifts:

Here, I want to get 10000, starting with various numbers I want to scale.   

For example, if I had 134 max and wanted to linearly scale to 10000 max , just mult by 597 & divide by 8 (shift by 3 bits)

This is the minimum solution that will scale 134 exactly to 10000 (with rounding).  I suspect that this 597 scaling is minimal for all numbers ranging 0-134  giving 0-10000, but need to verify whether that is the case.

  In the next post I verified it is NOT the case.

[had: 1 mul: 10000 divide: 1 ][had: 2 mul: 5000 divide: 1 ][had: 3 mul: 13333 divide: 4 ][had: 4 mul: 2500 divide: 1 ][had: 5 mul: 2000 divide: 1 ]
[had: 6 mul: 13333 divide: 8 ][had: 7 mul: 2857 divide: 2 ][had: 8 mul: 1250 divide: 1 ][had: 9 mul: 8889 divide: 8 ][had: 10 mul: 1000 divide: 1 ]
[had: 11 mul: 7273 divide: 8 ][had: 12 mul: 13333 divide: 16 ][had: 13 mul: 3077 divide: 4 ][had: 14 mul: 2857 divide: 4 ][had: 15 mul: 10667 divide: 16 ]
[had: 16 mul: 625 divide: 1 ][had: 17 mul: 2353 divide: 4 ][had: 18 mul: 8889 divide: 16 ][had: 19 mul: 8421 divide: 16 ][had: 20 mul: 500 divide: 1 ]
[had: 21 mul: 7619 divide: 16 ][had: 22 mul: 7273 divide: 16 ][had: 23 mul: 13913 divide: 32 ][had: 24 mul: 13333 divide: 32 ][had: 25 mul: 400 divide: 1 ]
[had: 26 mul: 3077 divide: 8 ][had: 27 mul: 2963 divide: 8 ][had: 28 mul: 2857 divide: 8 ][had: 29 mul: 5517 divide: 16 ][had: 30 mul: 10667 divide: 32 ]
[had: 31 mul: 10323 divide: 32 ][had: 32 mul: 625 divide: 2 ][had: 33 mul: 9697 divide: 32 ][had: 34 mul: 2353 divide: 8 ][had: 35 mul: 9143 divide: 32 ]
[had: 36 mul: 8889 divide: 32 ][had: 37 mul: 8649 divide: 32 ][had: 38 mul: 8421 divide: 32 ][had: 39 mul: 8205 divide: 32 ][had: 40 mul: 250 divide: 1 ]
[had: 41 mul: 7805 divide: 32 ][had: 42 mul: 7619 divide: 32 ][had: 43 mul: 3721 divide: 16 ][had: 44 mul: 7273 divide: 32 ][had: 45 mul: 7111 divide: 32 ]
[had: 46 mul: 13913 divide: 64 ][had: 47 mul: 13617 divide: 64 ][had: 48 mul: 13333 divide: 64 ][had: 49 mul: 13061 divide: 64 ][had: 50 mul: 200 divide: 1 ]
[had: 51 mul: 12549 divide: 64 ][had: 52 mul: 3077 divide: 16 ][had: 53 mul: 3019 divide: 16 ][had: 54 mul: 2963 divide: 16 ][had: 55 mul: 2909 divide: 16 ]
[had: 56 mul: 2857 divide: 16 ][had: 57 mul: 2807 divide: 16 ][had: 58 mul: 5517 divide: 32 ][had: 59 mul: 10847 divide: 64 ][had: 60 mul: 10667 divide: 64 ]
[had: 61 mul: 2623 divide: 16 ][had: 62 mul: 10323 divide: 64 ][had: 63 mul: 10159 divide: 64 ][had: 64 mul: 625 divide: 4 ][had: 65 mul: 4923 divide: 32 ]
[had: 66 mul: 9697 divide: 64 ][had: 67 mul: 597 divide: 4 ][had: 68 mul: 2353 divide: 16 ][had: 69 mul: 9275 divide: 64 ][had: 70 mul: 9143 divide: 64 ]
[had: 71 mul: 4507 divide: 32 ][had: 72 mul: 8889 divide: 64 ][had: 73 mul: 8767 divide: 64 ][had: 74 mul: 8649 divide: 64 ][had: 75 mul: 8533 divide: 64 ]
[had: 76 mul: 8421 divide: 64 ][had: 77 mul: 1039 divide: 8 ][had: 78 mul: 8205 divide: 64 ][had: 79 mul: 8101 divide: 64 ][had: 80 mul: 125 divide: 1 ]
[had: 81 mul: 7901 divide: 64 ][had: 82 mul: 7805 divide: 64 ][had: 83 mul: 7711 divide: 64 ][had: 84 mul: 7619 divide: 64 ][had: 85 mul: 15059 divide: 128 ]
[had: 86 mul: 3721 divide: 32 ][had: 87 mul: 1839 divide: 16 ][had: 88 mul: 7273 divide: 64 ][had: 89 mul: 7191 divide: 64 ][had: 90 mul: 7111 divide: 64 ]
[had: 91 mul: 7033 divide: 64 ][had: 92 mul: 13913 divide: 128 ][had: 93 mul: 3441 divide: 32 ][had: 94 mul: 13617 divide: 128 ][had: 95 mul: 6737 divide: 64 ]
[had: 96 mul: 13333 divide: 128 ][had: 97 mul: 3299 divide: 32 ][had: 98 mul: 13061 divide: 128 ][had: 99 mul: 12929 divide: 128 ][had: 100 mul: 100 divide: 1 ]
[had: 101 mul: 12673 divide: 128 ][had: 102 mul: 12549 divide: 128 ][had: 103 mul: 12427 divide: 128 ][had: 104 mul: 3077 divide: 32 ][had: 105 mul: 6095 divide: 64 ]
[had: 106 mul: 3019 divide: 32 ][had: 107 mul: 11963 divide: 128 ][had: 108 mul: 2963 divide: 32 ][had: 109 mul: 11743 divide: 128 ][had: 110 mul: 2909 divide: 32 ]
[had: 111 mul: 2883 divide: 32 ][had: 112 mul: 2857 divide: 32 ][had: 113 mul: 11327 divide: 128 ][had: 114 mul: 2807 divide: 32 ][had: 115 mul: 5565 divide: 64 ]
[had: 116 mul: 5517 divide: 64 ][had: 117 mul: 2735 divide: 32 ][had: 118 mul: 10847 divide: 128 ][had: 119 mul: 2689 divide: 32 ][had: 120 mul: 10667 divide: 128 ]
[had: 121 mul: 5289 divide: 64 ][had: 122 mul: 2623 divide: 32 ][had: 123 mul: 5203 divide: 64 ][had: 124 mul: 10323 divide: 128 ][had: 125 mul: 80 divide: 1 ]
[had: 126 mul: 10159 divide: 128 ][had: 127 mul: 10079 divide: 128 ][had: 128 mul: 625 divide: 8 ][had: 129 mul: 4961 divide: 64 ][had: 130 mul: 4923 divide: 64 ]
[had: 131 mul: 9771 divide: 128 ][had: 132 mul: 9697 divide: 128 ][had: 133 mul: 1203 divide: 16 ][had: 134 mul: 597 divide: 8 ][had: 135 mul: 18963 divide: 256 ]
[had: 136 mul: 2353 divide: 32 ][had: 137 mul: 9343 divide: 128 ][had: 138 mul: 9275 divide: 128 ][had: 139 mul: 9209 divide: 128 ][had: 140 mul: 9143 divide: 128 ]
[had: 141 mul: 4539 divide: 64 ][had: 142 mul: 4507 divide: 64 ][had: 143 mul: 8951 divide: 128 ][had: 144 mul: 8889 divide: 128 ][had: 145 mul: 2207 divide: 32 ]
[had: 146 mul: 8767 divide: 128 ][had: 147 mul: 17415 divide: 256 ][had: 148 mul: 8649 divide: 128 ][had: 149 mul: 8591 divide: 128 ][had: 150 mul: 8533 divide: 128 ]
[had: 151 mul: 8477 divide: 128 ][had: 152 mul: 8421 divide: 128 ][had: 153 mul: 4183 divide: 64 ][had: 154 mul: 1039 divide: 16 ][had: 155 mul: 4129 divide: 64 ]
[had: 156 mul: 8205 divide: 128 ][had: 157 mul: 8153 divide: 128 ][had: 158 mul: 8101 divide: 128 ][had: 159 mul: 4025 divide: 64 ][had: 160 mul: 125 divide: 2 ]
[had: 161 mul: 3975 divide: 64 ][had: 162 mul: 7901 divide: 128 ][had: 163 mul: 7853 divide: 128 ][had: 164 mul: 7805 divide: 128 ][had: 165 mul: 15515 divide: 256 ]
[had: 166 mul: 7711 divide: 128 ][had: 167 mul: 7665 divide: 128 ][had: 168 mul: 7619 divide: 128 ][had: 169 mul: 3787 divide: 64 ][had: 170 mul: 15059 divide: 256 ]
[had: 171 mul: 14971 divide: 256 ][had: 172 mul: 3721 divide: 64 ][had: 173 mul: 7399 divide: 128 ][had: 174 mul: 1839 divide: 32 ][had: 175 mul: 3657 divide: 64 ]
[had: 176 mul: 7273 divide: 128 ][had: 177 mul: 14463 divide: 256 ][had: 178 mul: 7191 divide: 128 ][had: 179 mul: 7151 divide: 128 ][had: 180 mul: 7111 divide: 128 ]
[had: 181 mul: 221 divide: 4 ][had: 182 mul: 7033 divide: 128 ][had: 183 mul: 13989 divide: 256 ][had: 184 mul: 13913 divide: 256 ][had: 185 mul: 6919 divide: 128 ]
[had: 186 mul: 3441 divide: 64 ][had: 187 mul: 6845 divide: 128 ][had: 188 mul: 13617 divide: 256 ][had: 189 mul: 13545 divide: 256 ][had: 190 mul: 6737 divide: 128 ]
[had: 191 mul: 13403 divide: 256 ][had: 192 mul: 13333 divide: 256 ][had: 193 mul: 829 divide: 16 ][had: 194 mul: 3299 divide: 64 ][had: 195 mul: 1641 divide: 32 ]
[had: 196 mul: 13061 divide: 256 ][had: 197 mul: 12995 divide: 256 ][had: 198 mul: 12929 divide: 256 ][had: 199 mul: 201 divide: 4 ][had: 200 mul: 50 divide: 1 ]
[had: 201 mul: 199 divide: 4 ][had: 202 mul: 12673 divide: 256 ][had: 203 mul: 12611 divide: 256 ][had: 204 mul: 12549 divide: 256 ][had: 205 mul: 1561 divide: 32 ]
[had: 206 mul: 12427 divide: 256 ][had: 207 mul: 12367 divide: 256 ][had: 208 mul: 3077 divide: 64 ][had: 209 mul: 12249 divide: 256 ][had: 210 mul: 6095 divide: 128 ]
[had: 211 mul: 12133 divide: 256 ][had: 212 mul: 3019 divide: 64 ][had: 213 mul: 12019 divide: 256 ][had: 214 mul: 11963 divide: 256 ][had: 215 mul: 11907 divide: 256 ]
[had: 216 mul: 2963 divide: 64 ][had: 217 mul: 11797 divide: 256 ][had: 218 mul: 11743 divide: 256 ][had: 219 mul: 5845 divide: 128 ][had: 220 mul: 2909 divide: 64 ]
[had: 221 mul: 181 divide: 4 ][had: 222 mul: 2883 divide: 64 ][had: 223 mul: 1435 divide: 32 ][had: 224 mul: 2857 divide: 64 ][had: 225 mul: 5689 divide: 128 ]
[had: 226 mul: 11327 divide: 256 ][had: 227 mul: 5639 divide: 128 ][had: 228 mul: 2807 divide: 64 ][had: 229 mul: 11179 divide: 256 ][had: 230 mul: 5565 divide: 128 ]
[had: 231 mul: 5541 divide: 128 ][had: 232 mul: 5517 divide: 128 ][had: 233 mul: 10987 divide: 256 ][had: 234 mul: 2735 divide: 64 ][had: 235 mul: 5447 divide: 128 ]
[had: 236 mul: 10847 divide: 256 ][had: 237 mul: 5401 divide: 128 ][had: 238 mul: 2689 divide: 64 ][had: 239 mul: 10711 divide: 256 ][had: 240 mul: 10667 divide: 256 ]
[had: 241 mul: 5311 divide: 128 ][had: 242 mul: 5289 divide: 128 ][had: 243 mul: 10535 divide: 256 ][had: 244 mul: 2623 divide: 64 ][had: 245 mul: 10449 divide: 256 ]
[had: 246 mul: 5203 divide: 128 ][had: 247 mul: 2591 divide: 64 ][had: 248 mul: 10323 divide: 256 ][had: 249 mul: 10281 divide: 256 ][had: 250 mul: 40 divide: 1 ]
[had: 251 mul: 10199 divide: 256 ][had: 252 mul: 10159 divide: 256 ][had: 253 mul: 10119 divide: 256 ][had: 254 mul: 10079 divide: 256 ][had: 255 mul: 10039 divide: 256 ]
[had: 256 mul: 625 divide: 16 ][had: 257 mul: 9961 divide: 256 ][had: 258 mul: 4961 divide: 128 ][had: 259 mul: 2471 divide: 64 ][had: 260 mul: 4923 divide: 128 ]
[had: 261 mul: 613 divide: 16 ][had: 262 mul: 9771 divide: 256 ][had: 263 mul: 4867 divide: 128 ][had: 264 mul: 9697 divide: 256 ][had: 265 mul: 2415 divide: 64 ]
[had: 266 mul: 1203 divide: 32 ][had: 267 mul: 2397 divide: 64 ][had: 268 mul: 597 divide: 16 ][had: 269 mul: 9517 divide: 256 ][had: 270 mul: 18963 divide: 512 ]
[had: 271 mul: 18893 divide: 512 ][had: 272 mul: 2353 divide: 64 ][had: 273 mul: 9377 divide: 256 ][had: 274 mul: 9343 divide: 256 ][had: 275 mul: 9309 divide: 256 ]
[had: 276 mul: 9275 divide: 256 ][had: 277 mul: 4621 divide: 128 ][had: 278 mul: 9209 divide: 256 ][had: 279 mul: 1147 divide: 32 ][had: 280 mul: 9143 divide: 256 ]
[had: 281 mul: 4555 divide: 128 ][had: 282 mul: 4539 divide: 128 ][had: 283 mul: 4523 divide: 128 ][had: 284 mul: 4507 divide: 128 ][had: 285 mul: 17965 divide: 512 ]
[had: 286 mul: 8951 divide: 256 ][had: 287 mul: 1115 divide: 32 ][had: 288 mul: 8889 divide: 256 ][had: 289 mul: 4429 divide: 128 ][had: 290 mul: 2207 divide: 64 ]
[had: 291 mul: 8797 divide: 256 ][had: 292 mul: 8767 divide: 256 ][had: 293 mul: 8737 divide: 256 ][had: 294 mul: 17415 divide: 512 ][had: 295 mul: 4339 divide: 128 ]
[had: 296 mul: 8649 divide: 256 ][had: 297 mul: 17239 divide: 512 ][had: 298 mul: 8591 divide: 256 ][had: 299 mul: 4281 divide: 128 ][had: 300 mul: 8533 divide: 256 ]
[had: 301 mul: 8505 divide: 256 ][had: 302 mul: 8477 divide: 256 ][had: 303 mul: 8449 divide: 256 ][had: 304 mul: 8421 divide: 256 ][had: 305 mul: 16787 divide: 512 ]
[had: 306 mul: 4183 divide: 128 ][had: 307 mul: 8339 divide: 256 ][had: 308 mul: 1039 divide: 32 ][had: 309 mul: 8285 divide: 256 ][had: 310 mul: 4129 divide: 128 ]
[had: 311 mul: 16463

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Last Edited: Sat. Mar 28, 2020 - 02:35 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Interesting...while the above scales the endpoints to match exactly (after rounding), due to number's stair stepping of both the input (unscaled)  and output (scaled) numbers, a few intermediate points along some lines can be off by one count (meaning to make EVERY point along the line give an exact rounded count, you can double the multiplier & perform 1 additional shift.  Example:

 

[had: 38 mul: 8421 divide: 32 ]
ERR had 38 mul 8421 div 32 where 35 delt 1

 

[had: 39 mul: 8205 divide: 32 ]
ERR had 39 mul 8205 div 32 where 11 delt 1
ERR had 39 mul 8205 div 32 where 33 delt 1
ERR had 39 mul 8205 div 32 where 38 delt 1
[had: 40 mul: 250 divide: 1 ]

 

Here a max value of 38 is scaled to 10000 by multiplying by 8421 & dividing by 32.....this works perfectly everywhere  from 0 to 38 EXCEPT  at 35 where the rounded result will be off by 1 count, everywhere else it will be zero counts.

10000*35/38=9210.53 (9211)   35*8421/32=9210.468 (9210)  so for 35, instead of showing 9211, it will show 9210.   All other points will round exactly.

 

 

for the cases 133 and 134,    133 is perfect over range 0  to 133.

 134 has 8 points (71,79,87,95,103,111,119,127) with a delta of 1 count

 

[had: 133 mul: 1203 divide: 16 ]
[had: 134 mul: 597 divide: 8 ]
ERR had 134 mul 597 div 8 where 71 delt 1
ERR had 134 mul 597 div 8 where 79 delt 1
ERR had 134 mul 597 div 8 where 87 delt 1
ERR had 134 mul 597 div 8 where 95 delt 1
ERR had 134 mul 597 div 8 where 103 delt 1
ERR had 134 mul 597 div 8 where 111 delt 1
ERR had 134 mul 597 div 8 where 119 delt 1
ERR had 134 mul 597 div 8 where 127 delt 1
[had: 135 mul: 18963 divide: 256 ]

 

 

 

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Last Edited: Sat. May 16, 2020 - 09:23 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

note :  THIS IS THE END OF MY INVESTIGATION---enough is enough...it has been interesting

 

I went and made a routine that checked when the minimum scaling is made for the endpoints, which lines are perfect their entire length (perfectly matching rounded numbers).  Any imperfection is within 1 count.

Surprisingly, not many lines past the test their entire length, due to stairstepping:

These are various max input ranges, when minimally scaled for a max output of 10000:

good entire line, when minimally scaled for max input of 1
good entire line, when minimally scaled for max input of 2
good entire line, when minimally scaled for max input of 3
good entire line, when minimally scaled for max input of 4
good entire line, when minimally scaled for max input of 5
good entire line, when minimally scaled for max input of 6
good entire line, when minimally scaled for max input of 7
good entire line, when minimally scaled for max input of 8
good entire line, when minimally scaled for max input of 10
good entire line, when minimally scaled for max input of 16
good entire line, when minimally scaled for max input of 19
good entire line, when minimally scaled for max input of 20
good entire line, when minimally scaled for max input of 21
good entire line, when minimally scaled for max input of 23
good entire line, when minimally scaled for max input of 25
good entire line, when minimally scaled for max input of 32
good entire line, when minimally scaled for max input of 40
good entire line, when minimally scaled for max input of 46
good entire line, when minimally scaled for max input of 47
good entire line, when minimally scaled for max input of 50
good entire line, when minimally scaled for max input of 51
good entire line, when minimally scaled for max input of 57
good entire line, when minimally scaled for max input of 64
good entire line, when minimally scaled for max input of 67
good entire line, when minimally scaled for max input of 80
good entire line, when minimally scaled for max input of 89
good entire line, when minimally scaled for max input of 94
good entire line, when minimally scaled for max input of 100
good entire line, when minimally scaled for max input of 102
good entire line, when minimally scaled for max input of 125
good entire line, when minimally scaled for max input of 128
good entire line, when minimally scaled for max input of 133
good entire line, when minimally scaled for max input of 141
good entire line, when minimally scaled for max input of 153
good entire line, when minimally scaled for max input of 160
good entire line, when minimally scaled for max input of 199
good entire line, when minimally scaled for max input of 200
good entire line, when minimally scaled for max input of 201
good entire line, when minimally scaled for max input of 250
good entire line, when minimally scaled for max input of 256
good entire line, when minimally scaled for max input of 267
good entire line, when minimally scaled for max input of 320
good entire line, when minimally scaled for max input of 399
good entire line, when minimally scaled for max input of 400
good entire line, when minimally scaled for max input of 401
good entire line, when minimally scaled for max input of 423
good entire line, when minimally scaled for max input of 500
good entire line, when minimally scaled for max input of 512
good entire line, when minimally scaled for max input of 533
good entire line, when minimally scaled for max input of 597
good entire line, when minimally scaled for max input of 625
good entire line, when minimally scaled for max input of 640
good entire line, when minimally scaled for max input of 679
good entire line, when minimally scaled for max input of 719
good entire line, when minimally scaled for max input of 799
good entire line, when minimally scaled for max input of 800
good entire line, when minimally scaled for max input of 801
good entire line, when minimally scaled for max input of 1000
good entire line, when minimally scaled for max input of 1024
good entire line, when minimally scaled for max input of 1067
good entire line, when minimally scaled for max input of 1203
good entire line, when minimally scaled for max input of 1250
good entire line, when minimally scaled for max input of 1280
good entire line, when minimally scaled for max input of 1358
good entire line, when minimally scaled for max input of 1371
good entire line, when minimally scaled for max input of 1513
good entire line, when minimally scaled for max input of 1599
good entire line, when minimally scaled for max input of 1600
good entire line, when minimally scaled for max input of 1601
good entire line, when minimally scaled for max input of 2000
good entire line, when minimally scaled for max input of 2037
good entire line, when minimally scaled for max input of 2048
good entire line, when minimally scaled for max input of 2133
good entire line, when minimally scaled for max input of 2397
good entire line, when minimally scaled for max input of 2500
good entire line, when minimally scaled for max input of 2560
good entire line, when minimally scaled for max input of 2716
good entire line, when minimally scaled for max input of 2807
good entire line, when minimally scaled for max input of 2857
good entire line, when minimally scaled for max input of 2923
good entire line, when minimally scaled for max input of 2997
good entire line, when minimally scaled for max input of 3199
good entire line, when minimally scaled for max input of 3200
good entire line, when minimally scaled for max input of 3201
good entire line, when minimally scaled for max input of 4000
good entire line, when minimally scaled for max input of 4096
good entire line, when minimally scaled for max input of 4183
good entire line, when minimally scaled for max input of 4266
good entire line, when minimally scaled for max input of 4539
good entire line, when minimally scaled for max input of 4671
good entire line, when minimally scaled for max input of 4803
good entire line, when minimally scaled for max input of 5000
good entire line, when minimally scaled for max input of 5027
good entire line, when minimally scaled for max input of 5120
good entire line, when minimally scaled for max input of 5846
good entire line, when minimally scaled for max input of 5994
good entire line, when minimally scaled for max input of 6399
good entire line, when minimally scaled for max input of 6400
good entire line, when minimally scaled for max input of 6401
good entire line, when minimally scaled for max input of 7121
good entire line, when minimally scaled for max input of 7191
good entire line, when minimally scaled for max input of 7231
good entire line, when minimally scaled for max input of 7469
good entire line, when minimally scaled for max input of 7619
good entire line, when minimally scaled for max input of 8000
good entire line, when minimally scaled for max input of 8192
good entire line, when minimally scaled for max input of 8421
good entire line, when minimally scaled for max input of 8532
good entire line, when minimally scaled for max input of 8769
good entire line, when minimally scaled for max input of 9597

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Last Edited: Sat. Mar 28, 2020 - 03:08 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thread has a little age to it, but I was creating a twi driver and needed a target. I had an lcd with i2c interface, but that turned out to be not a great target as it is write only and bit-banging was easy, although I eventually did get twi working with it also. I also had a failed 'project' with a TMP117 mounted on a pcb (probably the smallest device I have soldered/hotplated), so soldered up some wires so I could try to use it as a test target. I'm not sure how I ended up with a TMP117, but most likely drilling down a mouser search led me there.

 

I remembered a thread about tmp117, so here I am and maybe the following numbers may be useful although if I can come up with them can't be too complicated. I also timed various versions, like simply doing multiplication/division-  x100F(int16_t){ return v*140625L/100000; }, and the bitshift is of course faster- ~88 clocks vs ~684 clocks. One thing to watch for is the compiler may or may not turn a divide into a shift (/64 into a >>6), so you can think you are being clever and the compiler still defeats you. Of course there is still divides used in the print when splitting up the value, and a printing of a value is not going to be done at a fast rate, so not sure if it is worth the trouble of figuring out clever bit-shifts in this case. Its still ~600 unused clocks if power is important, I guess.

 

The tmp117 is quite sensitive, you can put your finger maybe 1/4 inch away and start watching the temp climb.

 

// 0.0078125*1.8 (0.0140625) degree F per count (without 32 degree offset)
// x10 = 9/64 = .140625, x100 = 45/32 = 1.40625, x1000 = 225/16 = 14.0625 (x1 = x10()/10 :) )
static constexpr int16_t x10F  (int16_t v){ return ((v * 9L)>>6) + 320; }
static constexpr int16_t x100F (int16_t v){ return ((v * 45L)>>5) + 3200; }

//static constexpr int16_t x100F (int16_t v){ return v * 140625L / 100000 + 3200; } //a 'normal' version
static constexpr int32_t x1000F(int16_t v){ return ((v * 225L)>>4) + 32000; }

 

// 0.0078125 degree C per count (1/128 degree)
// x10 = 5/64 = .078125, x100 = 25/32 = 0.78125, x1000 = 125/16 = 7.8125 (x1 = raw>>7)
static constexpr int16_t x10C  (int16_t v){ return (v * 5L)>>6; }
static constexpr int16_t x100C (int16_t v){ return (v * 25L)>>5; }
static constexpr int32_t x1000C(int16_t v){ return (v * 125L)>>4; }

 

 

Tmp117<Twi0,0x48,PC2> tmp117; //twi, address, optional power pin

void tmp117Display(){
    uint16_t id = 0;
    if( not tmp117.id(id) or
        not tmp117.refresh() ){
        Print( lcd, "TMP117 error\r\r" );

        return;
    }
    int16_t temp = tmp117.tempRaw();
    int16_t tC = tmp117.tempX100C();
    int16_t tF = tmp117.tempX100F();

 

    bool tCminus = false; //'manual' minus sign

    bool tFminus = false;

    if( tC < 0 ){ tCminus = true; tC = -tC; }
    if( tF < 0 ){ tFminus = true; tF = -tF; }

    Print( lcd, "ID: %X  %d\r%s%u.%02u\xDF" "C %s%u.%02u\xDF" "F\r",
        id, temp,
        tCminus?"-":"", tC/100, tC%100,
        tFminus?"-":"", tF/100, tF%100 );
}

 

Some (not great) photos of the test board w/tiny3217-

https://photos.app.goo.gl/cE45mE...

Last Edited: Sat. May 16, 2020 - 08:32 PM