summaryrefslogtreecommitdiff
path: root/cantiming.py
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@diac24.net>2011-08-21 14:56:43 +0200
committerDavid Lamparter <equinox@diac24.net>2011-08-21 14:56:43 +0200
commitaa0a617f957de3c42a217283b8cc35db669d270c (patch)
treea04f6e7ed604abfc0dad81d1230158aba9070528 /cantiming.py
initial commit
Diffstat (limited to 'cantiming.py')
-rw-r--r--cantiming.py78
1 files changed, 78 insertions, 0 deletions
diff --git a/cantiming.py b/cantiming.py
new file mode 100644
index 0000000..1eb7fe2
--- /dev/null
+++ b/cantiming.py
@@ -0,0 +1,78 @@
+# -*- coding: utf-8 -*-
+from math import ceil
+def eng(val):
+ if val < 1e-6:
+ return '%.3fn' % (val * 1e9)
+ if val < 1e-3:
+ return '%.3fµ' % (val * 1e6)
+ if val < 1e-0:
+ return '%.3fm' % (val * 1e3)
+ if val < 1e3:
+ return '%.3f' % (val)
+ if val < 1e6:
+ return '%.3fk' % (val / 1e3)
+ if val < 1e9:
+ return '%.3fM' % (val / 1e6)
+ return '%f' % (val)
+
+fosc = 16e6
+
+brp = 12
+print 'BRP: %d' % (brp)
+tdrvcmp = 130e-9
+
+tq = 2 * brp / fosc
+print 'Tq: %ss (= %sHz)' % (eng(tq), eng(1./tq))
+
+print ''
+
+print 'bus properties:'
+print '\tTdrv + Tcmp = %ss' % (eng(tdrvcmp))
+buslen = 100.
+tbus = buslen / 177. * 1e-6
+print '\tTbus = %ss' % (eng(tbus))
+tprop = 2 * (tbus + tdrvcmp)
+print '\tTprop = %ss, / Tq = %.2f' % (eng(tprop), tprop / tq)
+print ''
+
+s_sync = 1
+s_prop = 2
+s_ps1 = 1
+s_ps2 = 2
+print ' <%s%d%s><%s%d%s><%s%d%s><%s%d%s>' % (
+ '-' * (s_sync * 2 - 1), s_sync,
+ '-' * (s_sync * 2 - 1),
+ '-' * (s_prop * 2 - 1), s_prop,
+ '-' * (s_prop * 2 - 1),
+ '-' * (s_ps1 * 2 - 1), s_ps1,
+ '-' * (s_ps1 * 2 - 1),
+ '-' * (s_ps2 * 2 - 1), s_ps2,
+ '-' * (s_ps2 * 2 - 1))
+print (' %%-%ds%%-%ds%%-%ds%%-%ds' % (s_sync * 5, s_prop * 5, s_ps1 * 5, s_ps2 * 5)) % ('sync', 'prop', 'PS1', 'PS2')
+print ''
+tqperbit = s_sync + s_prop + s_ps1 + s_ps2
+bittime = tq * tqperbit
+print '\tTbit = %ss' % (eng(bittime))
+print ''
+
+print 'system properties:'
+osctol = 0.001
+print '\toscillator tolerance: %dppm' % (osctol / 0.000001)
+
+
+tbitmin, tbitmax = bittime * (1 - osctol), bittime * (1 + osctol)
+print '\tTbit \in (%ss, %ss)' % (eng(tbitmin), eng(tbitmax))
+tsjwmin = 10 * tbitmax - 10 * tbitmin
+print '\tTsjwmin = %ss, / Tq = %.6f' % (eng(tsjwmin), tsjwmin / (tq * (1 - osctol)))
+sjw = int(ceil(tsjwmin / (tq * (1 - osctol))))
+print '\tSJW = %d' % (sjw)
+print ''
+
+print 'conditions'
+print '\tprop + PS1 >= PS2 ', str(s_prop + s_ps1 >= s_ps2)
+print '\tprop + PS1 >= Tprop ', str(s_prop + s_ps1 >= tprop / tq)
+print '\tPS2 > SJW ', str(s_ps2 > sjw)
+print ''
+
+print 'result'
+print '\t%sbit/s' % (eng(1. / bittime))