Hi there!
I'm having issues with setting the baudrate/frequency in bitbang mode.
First a general question on `ftdi_set_baudrate`. I wonder what the reason is
that libftdi multiplies the baudrate by 4 in bitbang mode. I couldn't find any
reasons for that in the datasheet, but I might have just missed something.
For my actual issue, let's have a look at some code:
```
// usual ftdi open and setup
// ...
// bitbang buffer generation
uint8_t *wave = malloc(10000);
for (int i = 0; i < 10000; i++) {
wave[i++] = 0x00;
wave[i++] = 0x01;
}
ftdi_set_bitmode(ftdi, 0xff, BITMODE_RESET);
ftdi_set_baudrate(ftdi, 200000);
ftdi_set_bitmode(ftdi, 0x01, BITMODE_BITBANG);
ftdi_write_data(ftdi, wave, 10000);
```
The resulting waveform should have a frequency of 100kHz (200000 baud / 2 bits
per full cycle). However, my logic analyzer shows 500kHz. Setting the baudrate
after mode setup, leads to 2 MHz - that's what I described in my initial
question (freq * 4). Still, the frequency is 5 times higher than expected.
For comparison, I have tested this with pyftdi:
```
from pyftdi.gpio import GpioAsyncController
g = GpioAsyncController()
g.configure("ftdi://ftdi:4232/2", direction=0xff)
g.ftdi.reset()
g.set_frequency(200000)
g.write(b'\x00\x01' * 5000)
```
This time I measure 100kHz!
I had a look at the different implementations for divisor calculations. One
difference is, that pyftdi makes use of the /5 divisor in -H ftdis. Also, I get
different divisor values but I have not yet compared the calculation yet (but I
saw that they differ):
baudrate libftdi1 pyftdi
1000 b= 1000, v=12000, i=514 b= 992, v=64771, i= 2
40000 b= 40000, v= 300, i=514 b= 40000, v= 1500, i=514
100000 b=100000, v= 120, i=514 b=100000, v= 600, i=514
200000 b=200000, v= 60, i=514 b=200000, v= 300, i=514
800000 b=800000, v= 15, i=514 b=800000, v= 75, i=514
b = resulting baudrate
v = value
i = index
In most cases (except 1000 Hz for example, that could be optimized in pyftdi),
the `value` is 5 times higher for pyftdi. I'm not yet sure, what that means
exactly, since I haven't fully understood the calculations, yet.
Any ideas, what could be wrong here?
Michael
--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx
|