完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我正在研究一个老的硬件+固件。需要将CAN波特率改变为250KBPS,假设当前是1MBPS。它是一个10MHz的外部晶体,所以PLL系统时钟:40MHz(?)现在,在ecan.defI内部,虽然浏览了数据表的CAN部分,但是找不到找到波特率的简单方法。以上值为1MbPs?2。如何更改为250kbps,我假设通过改变BrpayVal= 16?提前感谢任何帮助
以上来自于百度翻译 以下为原文 I am working on an old hardware + firmware. Need to change CAN baudrate to 250KBPS, assuming presently at 1MBPS. It is an external crystal of 10MHz, so with PLL sysClock: 40MHz (?) //settings #pragma config WDT = OFF #pragma config OSC = HSPLL #pragma config LVP = OFF #pragma config IESO = ON #pragma config BOREN = BOHW #pragma config BORV = 1 //0=4.5V, 1=4.2V, 2= 2.7V, 3= 2.0V #pragma config WDTPS = 1 #pragma config STVREN = OFF #pragma config MCLRE = ON CAN settings now, inside ecan.def #define ECAN_SJW_VAL 2 #define ECAN_BRP_VAL 4 #define ECAN_PHSEG1_VAL 8 #define ECAN_PHSEG2_VAL 8 #define ECAN_PROPSEG_VAL 8 I could not find a simple way of finding the baudrate, though gone through CAN section of data sheet. 1. The above values correct for 1MBPS? 2. How to change that to 250KBPS, I assume by changing BRP_VAL = 16? Thanks in advance for any help Cheers Joy |
|
相关推荐
1个回答
|
|
喜悦,CAN比特率比PIC上的大多数通信模块要复杂一些,因为每个比特被分解成单个时间量子(TQ),在这个特定的代码中由ECAN_BRP_VAL控制。40MHz的FoSC和4的BRP值给出了TQ宽度:(2×(BRP+1))/FoCC=2(2×(4 +1))/40=25.比特时间是TQ宽度乘以由代码指定的每比特的时间量子数。这似乎由ECAN_PHSEG1_VAL、ECAN_PHSEG2_VAL和ECAN_PROPSEG_VAL值以及传播段在您的特定代码中指定,它们是相位段1和2。除了那些,还有同步段,它总是1 TQ。因此,由提供的代码给出的比特时间是:1+8+8+8=25TQ给定先前计算的TQ的.25uS时间,它给我们这个CAN模块的6.25uS比特时间。这应该给出一个160 kb/s的CAN频率,假设所有的x定义语句都符合我所相信的。如果这个代码输出一个1Mb/s的CAN信号,那么代码中的其他地方就有别的事情发生。有几种方法可以达到250kb/s的速率,这取决于你的其他需要。从所提供的代码中的当前设置出发,一种可能的选择是保持ECAN_BRP_VAL相同,并改变相位段,使得比特时间为16TQ,使得比特时间为4uS,频率为250kb/s。其他的BRP为4的组合,将给出总共16TQ,还有BRP为3的组合,以及给出总共20TQ的任何组合,以及BRP/Time Quanta值的其他几个组合。ATE在数据表的第24.9节中
以上来自于百度翻译 以下为原文 Joy, CAN bitrate is a bit more complicated than most communications modules on the PIC, as each bit is broken into individual time quanta (TQ), which are controlled by ECAN_BRP_VAL in this particular code. 40MHz FOSC and a BRP value of 4 gives a TQ width of: (2*(BRP+1))/FOSC = 2(2*(4+1))/40 = .25uS. The bit time is then the TQ width multiplied by the number of time quanta per bit specified by code. This appears to be specified in your particular code by the ECAN_PHSEG1_VAL, ECAN_PHSEG2_VAL and ECAN_PROPSEG_VAL values, which are phase segment 1 and 2, and the propagation segment. In addition to those there is the synchronization segment, which is always 1 TQ. Thus, the bit time given by the code provided is: 1+8+8+8=25 TQ Given the previously calculated .25uS time for TQ it gives us a 6.25uS bit time for this CAN module. This should give a CAN frequency of 160 kb/s assuming that all of the #define statements do what I believe them to do. If this code is outputting a 1Mb/s CAN signal then there is something else going on elsewhere in the code. There are several ways to achieve the desired 250kb/s rate, depending on your other needs. Going off of the current settings you have in the code provided, one possible option is to keep ECAN_BRP_VAL the same and change the phase segments so that the bit time is 16 TQ, making the bit time 4uS and the frequency 250kb/s. One possibility for this is: #define ECAN_SJW_VAL 2 #define ECAN_BRP_VAL 4 #define ECAN_PHSEG1_VAL 3 #define ECAN_PSHEG2_VAL 4 #define ECAN_PROPSEG_VAL 8 Giving a bit time of 1+3+4+8=16 TQ. Other combinations with BRP of 4 that will give a total of 16 TQ will also work, as will a BRP of 3 and any combination that gives a total of 20 TQ, as well as several other combinations of BRP/Time Quanta values. All equations I used here, as well as further information on setting up the CAN baud rate, are in section 24.9 of the datasheet |
|
|
|
只有小组成员才能发言,加入小组>>
5253 浏览 9 评论
2038 浏览 8 评论
1958 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3219 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2267 浏览 5 评论
792浏览 1评论
686浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
617浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
686浏览 0评论
586浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-30 09:51 , Processed in 1.478489 second(s), Total 77, Slave 62 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号