1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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))
|