Go Down

Topic: Maxbotix ultra sonic sensor and Baud rate (Read 880 times) previous topic - next topic

TeslaIaint

Mar 19, 2012, 12:17 am Last Edit: Mar 19, 2012, 12:29 am by TeslaIaint Reason: 1
I'm a little confused about baud rate in general. Does it only affect serial communication? I'm using two Maxbotix LV EZ 1's set at 9600 bps. According to what I have read, when i interface my bluetooth (bluetooth mate), it will require 57600 bps. I'm manually using the RX pin as a trigger to turn on and off the PWM pin of the sensor. My question is: Will changing the baud rate affect the delays needed for the sensors to read. For example...Does 50 milliseconds at 9600 bps = 50 milliseconds at 57600 bps within the code? Here's a snippet of the code for one of the sensors:

Code: [Select]
 for(int i = 0; i < arraysizeR; i++)
 {    
   digitalWrite(TriggerR, HIGH);
   delayMicroseconds(200);
   digitalWrite(TriggerR, LOW);
   pulseR = pulseIn(SonarR, HIGH);
   rangevalueR[i] = pulseR/147;
   delay(50);
   

robtillaart

Quote
I'm a little confused about baud rate in general. Does it only affect serial communication?


No, as serial communication takes time it can completely corrupt your sketch in theory as communication overhead can cost too much time. So you better use 115200 iso 1200 baud. You can even go higher (230400,345600) with the Arduino but the IDE serial monitor can only handle up to 115200.

Quote
Does 50 milliseconds at 9600 bps = 50 milliseconds at 57600 bps


50 millis == 50 millis

But the microdelay between two pulses at different baudrates differ substantially:
9600 baud => 1.000.000 micros / 9600 = 104.16 micros
57600 baud => 1.000.000 micros / 57600 = 17.36 micros


Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

TeslaIaint

#2
Mar 19, 2012, 08:42 pm Last Edit: Mar 19, 2012, 08:44 pm by TeslaIaint Reason: 1
does a delay of 1 second in my sketch at 9600 bps equal a delay of 1 second in my sketch at 57600 bps? Or at 115200 bps?

delay (1000);     //at 9600 bps    is this equal or not equal to      delay(1000);     // at 57600 bps

robtillaart


The baudrate as is will not affect the timing of the delay function in theory. But in practice there can be small differences even at the same baudrate, but these differences will be small.

Do a timing with micros() and print it to see the difference.

Code: [Select]

void setup()
{
Serial.begin(9600);
uint32_t start = micros();
delay(1000);
uint32_t stop = micros();
Serial.println(stop-start);
Serial.begin(57600);
start = micros();
delay(1000);
stop = micros();
Serial.println(stop-start);
Serial.begin(115200);
start = micros();
delay(1000);
stop = micros();
Serial.println(stop-start);
}

void loop()
{
}


mine printed:

1000004
1000008
1000004

QED.
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)


Go Up