{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# 8051 Calculations for Baud Rate Generator\n", "\n", "Desired baud rate is 9600. What oscillator frequencies and timer settings can we use in order to generate that baud rate with acceptable error?\n", "\n", "$BaudRate = \\frac{K \\;\\times\\; OscillatorFreq}{32 \\;\\times\\; 12 \\;\\times\\; (256 - TH1)}$\n", "\n", "$TH1 = 256 - \\frac{K \\;\\times\\; OscillatorFreq}{32 \\;\\times\\; 12 \\;\\times\\; BaudRate}$\n" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
F (MHz)KTH1Baud% Error
01.84320022559600.0000000.000000
13.57954512559321.731771-2.898627
23.57954522549321.731771-2.898627
33.68640012559600.0000000.000000
43.68640022549600.0000000.000000
57.37280012549600.0000000.000000
67.37280022529600.0000000.000000
711.05920012539600.0000000.000000
811.05920022509600.0000000.000000
\n", "
" ], "text/plain": [ " F (MHz) K TH1 Baud % Error\n", "0 1.843200 2 255 9600.000000 0.000000\n", "1 3.579545 1 255 9321.731771 -2.898627\n", "2 3.579545 2 254 9321.731771 -2.898627\n", "3 3.686400 1 255 9600.000000 0.000000\n", "4 3.686400 2 254 9600.000000 0.000000\n", "5 7.372800 1 254 9600.000000 0.000000\n", "6 7.372800 2 252 9600.000000 0.000000\n", "7 11.059200 1 253 9600.000000 0.000000\n", "8 11.059200 2 250 9600.000000 0.000000" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import pandas as pd\n", "\n", "# Available oscillator frequencies <= 12 MHz\n", "Flist = [\n", " 1.0E6,\n", " 1.2288E6,\n", " 1.544E6,\n", " 1.8432E6,\n", " 2.0E6,\n", " 2.5476E6,\n", " 2.2768E6,\n", " 3.579545E6,\n", " 3.6864E6,\n", " 4.0E6,\n", " 4.096E6,\n", " 4.9152E6,\n", " 5.0E6,\n", " 5.0688E6,\n", " 6.0E6,\n", " 6.144E6,\n", " 7.3728E6,\n", " 8.0E6,\n", " 9.8304E6,\n", " 10.0E6,\n", " 11.0592E6,\n", " 12.0E6\n", "]\n", "\n", "# Multipliers for SMOD = (0,1)\n", "Klist = [1, 2]\n", "\n", "# Target baud rate\n", "Btarget = 9600\n", "\n", "# Calculate TH1 setting, actual baud rate, and error\n", "tbl = []\n", "for F in Flist:\n", " for K in Klist:\n", " TH1 = int(256 - (K * F)/(32 * 12 * Btarget))\n", " if TH1 > 0:\n", " Bactual = (K * F)/(32 * 12 * (256 - TH1))\n", " Berror = 100.0*(Bactual - Btarget)/Btarget\n", " if abs(Berror) <= 5.0:\n", " tbl.append([F/1.0E6, K, TH1, Bactual, Berror])\n", "pd.DataFrame(tbl, columns=['F (MHz)', 'K', 'TH1', 'Baud', '% Error'])\n", "\n", " " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.7" } }, "nbformat": 4, "nbformat_minor": 4 }