PIC18F2685 CAN with wrong BAUD Rate

Moderator: Benj

Post Reply
maridd
Posts: 11
Joined: Fri Sep 18, 2020 12:13 pm
Contact:

PIC18F2685 CAN with wrong BAUD Rate

Post by maridd »

Hi,

i have two circuits with PIC18F2685 communicating via CAN. Both PICs work with a 4MHz crystal. The PICs have internal CAN controllers. As a transceiver i use the TJA1050. In the CAN component properties i configured the internal use and a BAUD rate of 125KBaud. The circuit works fine, one circuit is sending CAN Messages and the other one is receiving.

I tried to see the CAN Messages with a PEAK Dongle on my screen but i couldn`t get any messages. Next, i looked at the width of a bit and so i figured out, that both circuits are working with a real BAUD Rate of 100kBaud.

So to summarize, configuring the circuit via the CAN component properties for 125kBaud gives a real BAUD rate of 100kBaud.

best regards

maridd

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: PIC18F2685 CAN with wrong BAUD Rate

Post by Benj »

Hello,

That's curious, I wonder if it's something to do with the 4MHz clock speed? Maybe 125KHz was not available from the divider ratio and hence 100KHz was the closest? Might be worth trying at 20MHz and see if this gives a better result?

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 1287
Joined: Sun Oct 05, 2014 3:20 pm
Location: Russia
Has thanked: 384 times
Been thanked: 614 times
Contact:

Re: PIC18F2685 CAN with wrong BAUD Rate

Post by QMESAR »

As Ben said use a higher Clock Frequency ,4MHZ clock for a CAN application is not desired :D

maridd
Posts: 11
Joined: Fri Sep 18, 2020 12:13 pm
Contact:

Re: PIC18F2685 CAN with wrong BAUD Rate

Post by maridd »

Hi,

i can try a higher clock frequency. However, i have a running project with this PIC and a 4Mhz crystal and i used 50kHz. 50kHz is not available in the properties setting so i took the first available, which is 125kHz.

According to several timing calculators 125kHz should work with this clock frequency. But anyway, most probably i will switch to a higher clock frequency.

Thanks a lot

maridd

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: PIC18F2685 CAN with wrong BAUD Rate

Post by medelec35 »

With the 4MHz you can enable PLL which will give you 16MHz.
Just change clock frequency to 16000000
Martin

maridd
Posts: 11
Joined: Fri Sep 18, 2020 12:13 pm
Contact:

Re: PIC18F2685 CAN with wrong BAUD Rate

Post by maridd »

Hi,

i tried your idea to enable PLL and this sets the internal frequency to 16MHz. The strange thing is that despite the fact that i still have set 125kBaud in the CAN properties this gives me now a CAN frequency of 400kHz, so exactly 4 times the frequency i have without enabling PLL.

Because datatransfer via CAN works fine with clockfrequeny 4MHz and 100kBaud or even 16MHz internal (by PLL) and 400kBaud i will work with this result but i never get the transfer rates given in the properties.

maridd

maridd
Posts: 11
Joined: Fri Sep 18, 2020 12:13 pm
Contact:

Re: PIC18F2685 CAN with wrong BAUD Rate

Post by maridd »

Hi again,

to bring this post to an end... I calculated the CAN timing with a BIT calculator and wrote this values directly into the BRGCON register after the initialization icon for the CAN component, so my own values override the flowcode values. And this works with a clock frequency of 4MHz and a bitrate of 125kbps and of course with higher clock frequencies. Just wanted to let you know.

best regards

maridd

Post Reply