dsPIC - PIC32 CANbus test

General discussion on mikroC PRO for dsPIC30/33 and PIC24.
Post Reply
Author
Message
mrpoons
Posts: 12
Joined: 18 Sep 2012 10:23

dsPIC - PIC32 CANbus test

#1 Post by mrpoons » 29 May 2013 03:21

I have a pair of easyPIC Fusion v7 boards. If I equip both boards with either dsPIC33EP512MU810 or PIC32MX795F512L MCU cards I have my own CAN examples working sucessfully. The dsPICs running at 140Mhz and the PIC32s running at 80Mhz.

I have used the CANculator program from libstock to configure the CANbus timing for the PIC32.

const unsigned int SJW = 1;
const unsigned int BRP = 4;
const unsigned int PHSEG1 = 5;
const unsigned int PHSEG2 = 6;
const unsigned int PROPSEG = 8;

Giving a CAN baudrate of 500Mhz

As the CANculator program does not support a 140Mhz clock I have calculated the following timing for the dsPIC

const unsigned int SJW = 1;
const unsigned int BRP = 7;
const unsigned int PHSEG1 = 5;
const unsigned int PHSEG2 = 6;
const unsigned int PROPSEG = 8;

Also giving a CAN baudrate of 500Mhz

If I try to connect a PIC32 and a dsPIC I don't receive any CAN messages.

Am I missing something fundamental?

Thanks for any help

Mike

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: dsPIC - PIC32 CANbus test

#2 Post by janko.kaljevic » 29 May 2013 09:49

Hello,

Your calculation is correct. It will generate 500 kbaud/s on CAN bus, when clock is 140MHz.

First you should check if the oscillator settings is correct on both controllers.
Also you can connect scope on CANH - CANL and check the real baud rate on the bus.

Best regards.

mrpoons
Posts: 12
Joined: 18 Sep 2012 10:23

Re: dsPIC - PIC32 CANbus test

#3 Post by mrpoons » 29 May 2013 10:31

Thanks Janko,

I finally worked it out!

The dsPIC with a 140Mhz oscillator can not create an exact 500 Kbaud CANbus rate. The best it can do is 500 Kbaud with a Baud rate deviation of about 1.5%.

Dropping the oscillator to 136 Mhz creates 500 Kbaud with a baud rate deviation of 0%. Now everything works.

For clarity... To get a 500 Kbaud CAN bus on a dsPICEP512MU810 wunning with an 8Mhz external oscillator I set...

PLL

M = 68, N1 = 2, N2 = 2

This means...

PLLPRE = N1 - 2 = 0
PLLPOST = (N2/2) - 1 = 0
PLLDIV = M - 2 = 66


And

const unsigned int SJW = 1;
const unsigned int BRP = 4;
const unsigned int PHSEG1 = 3;
const unsigned int PHSEG2 = 5;
const unsigned int PROPSEG = 8;

Thanks again for your help

Mike

Post Reply

Return to “mikroC PRO for dsPIC30/33 and PIC24 General”