Go Down

Topic: DS18x20_Temperature module (Read 1 time) previous topic - next topic

Reinderien

The TeensyDuino One Wire library website contains this description:

Quote

The DS18x20_Temperature does not properly handle lower resolution (faster) modes on some chips. Thanks to Pete Hardie for this fix. Replace this:

Code: [Select]

  } else {
    byte cfg = (data[4] & 0x60);
    if (cfg == 0x00) raw = raw << 3;  // 9 bit resolution, 93.75 ms
    else if (cfg == 0x20) raw = raw << 2; // 10 bit res, 187.5 ms
    else if (cfg == 0x40) raw = raw << 1; // 11 bit res, 375 ms
    // default is 12 bit resolution, 750 ms conversion time
  }


With this:

Code: [Select]

  } else {
    unsigned char t_mask[4] = {0x7, 0x3, 0x1, 0x0};
    byte cfg = (data[4] & 0x60) >> 5;
    raw &= ~t_mask[cfg];
  }



I would like to know: is the following code equivalent? Would it be more performant since it has no addressing operations?

Code: [Select]

raw &= ~0 << (3 - ((data[4] >> 5) & 3));


Does anyone have an applicable DS18x20_Temperature device to check this?

Thanks!

el_supremo

Quote
I would like to know: is the following code equivalent?

It looks like it is.

Quote
Would it be more performant since it has no addressing operations?

What's the rush? The DS18B20 takes nearly 100 milliseconds to do a 9-bit conversion, so shaving off a few microseconds isn't going to make any difference.

Pete
Don't send me technical questions via Private Message.

Docedison

Certainly a conversion could be done before the temperature lag of the device would come into play... and be either displayed or used... AN LCD takes longer than that and relays usually have 40 to 100 ms pull in time. I shudder at coding a PID loop around the latency of a DS18B20. Perhaps for serial comm but again what of the response time?

Doc
--> WA7EMS <--
"The solution of every problem is another problem." -Johann Wolfgang von Goethe
I do answer technical questions PM'd to me with whatever is in my clipboard

Reinderien

From the sounds of it you're right that speed isn't an important factor here. I was more curious than anything. Anyway, thanks.

Go Up