Hi,
In the library for DS18B20 (ds18b20.h) there is something about polling,
although I don't know what polling is, I think it might be the solution to my problem.
Can someone explain to me how to do it?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Any read of any device ( internal or external to the microcontroller ) takes time., so, to better understand and potentially resolve, I’d greatly appreciate your insights on the following:
Could you explain what "polling" means in the context of the DS18B20 library and how it operates in your mind?
Are there specific use cases or scenarios where polling is especially useful with DS18B20 sensors?
How does polling compare to other methods, such as interrupt-based approaches, or a straight read operation?
Is there any particular setup or configuration required to enable polling in the ds18b20.h library? Are there examples or resources you’d recommend to help implement polling effectively with DS18B20 sensors?
I need more guidance, resources, or examples you can provide to help me better grasp the concept and its application.
I just use the DS1bB20 library.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The DS18B20 operates on the 1-Wire protocol, which requires precise timing for reliable communication. These timing values are important when implementing communication with the sensor, especially as we are bit-banging the protocol rather than using a dedicated 1-Wire interface.
See ..demos\Temperature_Sensor_Solutions\DS18B20_Sensor_Solutions\MultiPort_Sensors_to_Hardware_Serial_Terminal\DS18X20 ID Search with Multidrop and Serial Output ATMega.gcb
This looks like it is using the ConvertT and it has lots of optmised operations.
Or, you adapt the library to give you full control of the timings. This would not break the existing use of the library. With the adaption you can work out exactly where each delay is.
Or, you use the I2C to OneWire converter. The DS2482 is the most commonly used I²C to 1-Wire bridge chip. It allows you to connect 1-Wire devices (like the DS18B20 temperature sensor) to an I²C bus.
I adopted the library into my code.
And in the loop below from the DS18B20 library where pin DQ is checked to be high for complete acquisition. I have inserted my code to retrieve data from the a/d converter and reach my goal of a maximum of 20 milliseconds between samples.
OWoutConvertT' Instruct ds18b20 to begin temperature conversion to digital Do dir DQ out Set DQ Off wait 4 us Dir DQ In wait 7 us If DQ = 1 Then Exit Do SetTemp = Scale (ReadAD(AN0), 0, 254, 10, 40) ;Read AN0 while waiting wait60us'minimum 60 us time slots between reads Loop
In my main program I read the temperature to the GLCD display and right after a new ReadTemp command is send.
I hope I have explained myself so that it can be understood.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
In the library for DS18B20 (ds18b20.h) there is something about polling,
although I don't know what polling is, I think it might be the solution to my problem.
Can someone explain to me how to do it?
Can you explain what you mean by 'my problem' ?
Any read of any device ( internal or external to the microcontroller ) takes time., so, to better understand and potentially resolve, I’d greatly appreciate your insights on the following:
Could you explain what "polling" means in the context of the DS18B20 library and how it operates in your mind?
Are there specific use cases or scenarios where polling is especially useful with DS18B20 sensors?
How does polling compare to other methods, such as interrupt-based approaches, or a straight read operation?
Is there any particular setup or configuration required to enable polling in the ds18b20.h library? Are there examples or resources you’d recommend to help implement polling effectively with DS18B20 sensors?
I need more guidance, resources, or examples you can provide to help me better grasp the concept and its application.
I just use the DS1bB20 library.
Sorry, I can see that my problem is poorly formulated.
I'll try to see if I can do it better.
My problem is the time it takes to get a measurement from my DS18B20 sensor.
When I run this program fragment and measure with my scope on pin B.3
It takes 850 ms to get a measurement.
So my main program "stops" for 850 ms every time I need to get a measurement from my DS18B20.
How can I get a measurement from my DS18B20 without my main program "stopping" for more than max. 20 ms?
The DS18B20 operates on the 1-Wire protocol, which requires precise timing for reliable communication. These timing values are important when implementing communication with the sensor, especially as we are bit-banging the protocol rather than using a dedicated 1-Wire interface.
The current library is based on https://www.analog.com/media/en/technical-documentation/tech-articles/1wire-communication-with-a-microchip-picmicro-microcontroller.pdf
See ..demos\Temperature_Sensor_Solutions\DS18B20_Sensor_Solutions\MultiPort_Sensors_to_Hardware_Serial_Terminal\DS18X20 ID Search with Multidrop and Serial Output ATMega.gcb
This looks like it is using the ConvertT and it has lots of optmised operations.
Or, you adapt the library to give you full control of the timings. This would not break the existing use of the library. With the adaption you can work out exactly where each delay is.
Or, you use the I2C to OneWire converter. The DS2482 is the most commonly used I²C to 1-Wire bridge chip. It allows you to connect 1-Wire devices (like the DS18B20 temperature sensor) to an I²C bus.
Key features of the DS2482:
So, you can read via I2C. I use this one on of the test beds. Not sure of the conversion timing.
@Anobium
Thank you very much for the good advice. I don't know DS2482 but I need to look into it more.
I have solved my problem. I looked at the library for DS18B20 repeatedly and suddenly I saw the light.
I adopted the library into my code and it gave me full control over the times as you suggested.
My question was poorly formulated and not elaborated enough. I will try to do better next time.
Well done.
My pleasure to help.
What was the exact solution?
Thanks!
I adopted the library into my code.
And in the loop below from the DS18B20 library where pin DQ is checked to be high for complete acquisition. I have inserted my code to retrieve data from the a/d converter and reach my goal of a maximum of 20 milliseconds between samples.
In my main program I read the temperature to the GLCD display and right after a new ReadTemp command is send.
I hope I have explained myself so that it can be understood.
I would move the adapted function in the library to your main program.
Rename the function, then use #DEFINE
oldfunction
newfunction
. Else you will lose you work.Good advice thanks a lot!