You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to use a logic analyzer to measure the relevant timing parameters:
The time to initialize the DS18B20 and monitor the online information
The time to wait for the DS18B20 to release the bus
The time to trigger the temperature conversion
The time to send the read data command
The time to read the register value and obtain the temperature value
According to the datasheet, their units should be in microseconds (us), but my actual measurements are in milliseconds (ms).
How should I modify my measurement method?
Here is my code:
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DeviceAddress DS18B20_ID;
void setup() {
Serial.begin(9600);
unsigned long initStartTime = micros();
sensors.begin();
unsigned long initEndTime = micros();
Serial.print("Initialization Time: ");
Serial.print(initEndTime - initStartTime);
Serial.println(" us");
}
void loop() {
if (Serial.available() > 0) {
String command = Serial.readStringUntil('\n');
command.trim();
if (command == "GET") {
unsigned long waitStartTime = micros();
delayMicroseconds(550);
unsigned long waitEndTime = micros();
unsigned long convStartTime = micros();
sensors.requestTemperatures();
unsigned long convEndTime = micros();
unsigned long readCmdStartTime = micros();
float temperature = sensors.getTempCByIndex(0);
unsigned long readCmdEndTime = micros();
unsigned long readRegStartTime = micros();
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" C");
unsigned long readRegEndTime = micros();
Serial.print("Wait for Bus Release Time: ");
Serial.print(waitEndTime - waitStartTime);
Serial.println(" us");
Serial.print("Trigger Conversion Time: ");
Serial.print(convEndTime - convStartTime);
Serial.println(" us");
Serial.print("Send Read Command Time: ");
Serial.print(readCmdEndTime - readCmdStartTime);
Serial.println(" us");
Serial.print("Read Register Value Time: ");
Serial.print(readRegEndTime - readRegStartTime);
Serial.println(" us");
} else {
Serial.println("Unknown command.");
}
}
}
The text was updated successfully, but these errors were encountered:
I want to use a logic analyzer to measure the relevant timing parameters:
According to the datasheet, their units should be in microseconds (us), but my actual measurements are in milliseconds (ms).
How should I modify my measurement method?
Here is my code:
The text was updated successfully, but these errors were encountered: