Teensy 4.1 baudrate

Status
Not open for further replies.

mark63

Active member
I have a question about the baud rate error for teensy 4.1
I found this table : https://www.pjrc.com/teensy/td_uart.html
But it is not up to date.
I would like to know how i can calculate the baud rate and the error i would get.
i tried with 1 Mbaud but that already gives an error. 2MB did not even work. i thought that using 600 MHz clock would be sufficient to get a high accurate baud rate.
When it has an offset i can compensate on the other end of the communication line.
where can i find the forumula for the baud calculation and the error?
I use teraterm with a windows virtual port driver. a normal rs232 port does not offer high baud rate.
of course the problem could be in my virtual com port too. But it is best to start with 1 thing first.
 
You can look at chapter 49 of the 1060 reference manual...
Section 49.3.2 Baud rate generation.

You might also look into the code: in <>/hardware/teensy/avr/cores/teensy4/HardwareSerial.cpp look at the ::begin method

You will see we are setup to use a fixed 24mhz clock.

Code:
#define UART_CLOCK 24000000
...
	float base = (float)UART_CLOCK / (float)baud;
	float besterr = 1e20;
	int bestdiv = 1;
	int bestosr = 4;
	for (int osr=4; osr <= 32; osr++) {
		float div = base / (float)osr;
		int divint = (int)(div + 0.5f);
		if (divint < 1) divint = 1;
		else if (divint > 8191) divint = 8191;
		float err = ((float)divint - div) / div;
		if (err < 0.0f) err = -err;
		if (err <= besterr) {
			besterr = err;
			bestdiv = divint;
			bestosr = osr;
		}
	}
	//printf(" baud %d: osr=%d, div=%d\n", baud, bestosr, bestdiv);
so if you pass in 1000000
base = 24
divint = 6
err = 0

I have baud rate for a long time driving servos at 1000000. I have also used it at 2mbs again divint = 3 err=0...
 
Status
Not open for further replies.
Back
Top