Please adapt the code example in the OW library

Post your requests and ideas on the future development of mikroPascal.
Post Reply
Author
Message
Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Please adapt the code example in the OW library

#1 Post by Dany » 18 Aug 2008 19:19

Please adapt the code example in the OneWire library: now a delay of 120 microseconds to cover the DS1820 conversion time is in the code, while its maximum conversion time is 750 millisecs!
Current example:

Code: Select all

  repeat
       Ow_Reset(PORTA, 5);            // onewire reset signal
       Ow_Write(PORTA, 5, $CC);       // issue SKIP ROM command to DS1820
       Ow_Write(PORTA, 5, $44);       // issue CONVERT T command to DS1820
       Delay_us(120);                      // <-------- HERE -----------
       i  := Ow_Reset(PORTA, 5);
       Ow_Write(PORTA,5, $CC);        // issue SKIP ROM command to DS1820
       Ow_Write(PORTA,5, $BE);        // issue READ SCRATCHPAD command to DS1820
       j1 := Ow_Read(PORTA, 5);       // get result
       j2 := Ow_Read(PORTA, 5);       // get result
       ....
       ByteToStr(j2, text);           // decimal
       Lcd_Chr(2, 11, text[2]);

       Delay_ms(500);
 until false;
Tirst reading from the Ds1820 will always be wrong, since that is taken much too soon, without awaiting the conversion time. Normally the second reading will be ok due to the 500 ms delay present at the end of the endless loop (provided the DS1820 is capable of converting in 500 ms...).
New proposal:

Code: Select all

  repeat
       Ow_Reset(PORTA, 5);            // onewire reset signal
       Ow_Write(PORTA, 5, $CC);       // issue SKIP ROM command to DS1820
       Ow_Write(PORTA, 5, $44);       // issue CONVERT T command to DS1820
       Delay_ms(750);                     // <--- changed here
       i  := Ow_Reset(PORTA, 5);
       Ow_Write(PORTA,5, $CC);        // issue SKIP ROM command to DS1820
       Ow_Write(PORTA,5, $BE);        // issue READ SCRATCHPAD command to DS1820
       j1 := Ow_Read(PORTA, 5);       // get result
       j2 := Ow_Read(PORTA, 5);       // get result
       ....
       ByteToStr(j2, text);           // decimal
       Lcd_Chr(2, 11, text[2]);

       Delay_ms(500);               // <--- leave out this delay
 until false;
In above code the waiting time is inserted between "start conversion" and reading out the results, as it should be. The read values will be ok from the first reading onwards. Since there is now a rather massive delay in the DS1820 part, the delay at the end of the main loop can be left out.

p.s. I took the worst case max. conversion time here (750 ms for the DS18S20).

Thanks in advance and keep up the good work! :D
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

Post Reply

Return to “mikroPascal Wish List”