每天进步一点点。
分类:
2008-01-22 22:39:48
Mscan08位时间计算
Step1:
决定PROP_SEG可允许的最小值
一、 从CAN收发器的数据手册中,获取发生器和接收器的最大传播延时时间。
二、 获取总线电缆的传播延时时间,计算最大总线长度上的传播延时时间。
三、 利用一下公式计算:
其中:
——最长总线传播延时
——发送器传播延时
——接收器传播延时
Step2:
选择CAN系统时钟频率
由于CAN系统时钟是从MCU时钟或者晶振上得到的,CAN时钟频率是在MCU或者晶振的频率限制上通过预分频得到的。选择好CAN总线时钟后,CAN总线的显性位时间(NBT)将是CAN总线周期()的8到25倍。
Step3:
计算PROP_SEG段
利用以下公式,
(2)
计算PROP_SEG段的需要的的数量。如果计算结果大于8,回到step2,选择一个低一些的CAN系统时钟频率。
Step4:
分配PHSAE_SEG1喝PHASE_SEG2
用step2中获得的每一位的的数量,见去step3中的PROP_SEG,减轻SYNC_SEG的一个。如果计算结果小于3,回到step2,选择一个高一些的时钟频率。如果计算结果是一个大于3的奇数,将结果加1,重新计算。如果计算机结果等于3,那么PHASE_SEG1 = 1,PHASE_SEG2 = 2,且每位只采样一次。否则,将剩余的数量平分为,分别分配给PHASE_SEG1和PHASE_SEG2。
Step5:
计算晶振的误差,公式如下:
(3)
(4)
假如PHASE_SEG1 > 4 tQ,,建议重复step2到step6。选一个更大的分频值。
如果PHASE_SEG1 < 4 tQ,,建议重复step2到step6。选一个更小的分频值,直到PROP_SEG=8。如果预分频器已经等于1,但是还要降低晶振误差,那就只能选择一个更高的时钟频率了。
范例:
l Bit rate = 125k bit per second
l Bus length = 50m
l Bus propagation delay = 5 x 10-9 sm-1
l Physical Interface (PCA82C250) transmitter plus receiver
propagation delay = 150ns at 85C
l MCU oscillator frequency = 8MHz
Step 1: Physical delay of bus = 50 x 5 x 10-9 = 250ns
tPROP_SEG=2(250ns + 150ns)=800ns
Step 2: A prescaler value of 4 gives a CAN system clock of 2MHz and
a Time Quantum of 500ns. This will give 8000 / 500 = 16 time
quanta per bit.
Step 3:
Step4:
From 16 time quanta per bit, subtract 2 for PROP_SEG and 1
for SYNC_SEG. This leaves 13. Therefore PHASE_SEG1 = 6
and PHASE_SEG2 = 6 and the remaining bit is added to
PROP_SEG, i.e. PROP_SEG = 3.
Step 5: RJW is the lesser of 4 and PHASE_SEG1, in this case 4
Step 6: From equation (3):
公式(4):
需要的晶振误差要比这两个值低。
As PHASE_SEG1 > 4, repeat Steps 2 to 6 with a larger
prescaler value:
Step 2: A prescaler value of 8 gives a CAN system clock of 1MHz and
a Time Quantum of 1000ns. This will give 8000 / 1000 = 8 time
quanta per bit.
Step 3:
Step 4: From 8 time quanta per bit, subtract 1 for PROP_SEG and 1
for SYNC_SEG. This leaves 6. Therefore PHASE_SEG1 = 3
and PHASE_SEG2 = 3.
Step 5: RJW is the smaller of 4 and PHASE_SEG1, in this case 3
Step 6: From equation (3):
公式(4):
The required oscillator tolerance is the smaller of these values,
i.e. 0.01485 (1.485%) over 101μs (12.625 bit times). This is a
significant increase in the oscillator tolerance requirement, so
the chosen values are:
Prescaler = 8
Nominal Bit Time = 8
PROP_SEG = 1
PHASE_SEG1 = 3
PHASE_SEG2 = 3
RJW = 3
Oscillator tolerance = 1.485%