We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi, I want to create a Function to approximate a custom Baudrate. The Function depends on two Variables: Baudrate = f(x,y) = (FDV * 40) / (8192 * (BG + 1)), FDV = 1..511, BG = 1..8192 Unfortunately I am not that good in maths so anyone who has an idea how to solve this ? One could do it iterative but that will be too time consuming. Best Regards, Marcus
It's not time-consuming at all if you don't try to run the code on the microcontroller itself. And even if you do run it there, it's not much of a problem --- you're not going to be changing the baudrate once per second, or are you? The plan would be to loop over one variable and calculate the best possible solution for the other, i.e.:
for (FDV=0; FDV<512; FDV++) { short BG = round(8192.0 * BaudRate / 40 / FDV) - 1; float BaudRateError = 40.0 * FDV / 8192 / (BG + 1) - BaudRate; if (BaudRateError < 0) BaudRateError = -BaudRateError; if (BaudRateError < OptimalBaudRateError) updateOptimalBaudRate(FDV,BG,BaudRateError); }