Page 1 of 1

PIC18F2685 CAN with wrong BAUD Rate

Posted: Thu Oct 15, 2020 6:40 am
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

Re: PIC18F2685 CAN with wrong BAUD Rate

Posted: Mon Oct 19, 2020 10:53 pm
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?

Re: PIC18F2685 CAN with wrong BAUD Rate

Posted: Tue Oct 20, 2020 6:41 am
by QMESAR
As Ben said use a higher Clock Frequency ,4MHZ clock for a CAN application is not desired :D

Re: PIC18F2685 CAN with wrong BAUD Rate

Posted: Tue Oct 20, 2020 12:45 pm
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

Re: PIC18F2685 CAN with wrong BAUD Rate

Posted: Tue Oct 20, 2020 1:33 pm
by medelec35
With the 4MHz you can enable PLL which will give you 16MHz.
Just change clock frequency to 16000000

Re: PIC18F2685 CAN with wrong BAUD Rate

Posted: Thu Oct 22, 2020 9:21 am
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

Re: PIC18F2685 CAN with wrong BAUD Rate

Posted: Thu Oct 22, 2020 3:52 pm
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