Author Topic: also set the Bit rate of 52235evb'CAN?  (Read 8643 times)

Offline tr111

  • Jr. Member
  • **
  • Posts: 72
    • View Profile
also set the Bit rate of 52235evb'CAN?
« on: November 15, 2007, 04:57:29 AM »
case 1000000:

CANCTRL = ((3 << 24) | RJW_2 | EXTAL_CLK_SOURCE | PROPSEG_BIT_TIME2 | PHASE_BUF_SEG1_LEN3 | PHASE_BUF_SEG2_LEN2);

PRESDIV=3;
RJW_2=2,
EXTAL_CLK_SOURCE =0;
PROPSEG_BIT_TIME2   (1)       =1;
PHASE_BUF_SEG1_LEN3 (2<<19)           =2;
 PHASE_BUF_SEG2_LEN2 (1<<16)   =1;
because the EXTAL_CLK=25000000;
so  Ftq = 25000000/(3+1);
Sync_Seg + Prop_Seg +Phase_Seg1 + Phase_Seg2=1+(1+1)+(2+1)+(1+1)=8
BIT RATE= Ftq /(1+1+1+2+1+1+1)!=1000000;???????ERROR????????

BUT THE
default:                                                             // 40 KHz
        CANCTRL = ((24 << 24) | RJW_2 | EXTAL_CLK_SOURCE | PROPSEG_BIT_TIME8 | PHASE_BUF_SEG1_LEN8 | PHASE_BUF_SEG2_LEN8); // Initialise the CAN controller with the required speed and parameters// Initialise the CAN controller with the required speed and parameters
PRESDIV=24;
so  Ftq = 25000000/(24+1);
Sync_Seg + Prop_Seg +Phase_Seg1 + Phase_Seg2=1+(7+1)+(7+1)+(7+1)=25
BIT RATE= Ftq /(25)=40000=40kHZ!

WHY???????make sure????which is RIGHT????????






       

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: also set the Bit rate of 52235evb'CAN?
« Reply #1 on: November 15, 2007, 01:12:37 PM »
Hi

I have checked and you are right - the speed is proabably about 781kHz instead of 1MHz.

After some pondering I think that I can explain the error. Origianally the CAN interface was developed with the 5213 and an 8MHz crystal - the crystal is used rather than the PLL since it has less jitter and is thus more accurate. The implementation was successfully tested in a system using different CAN controllers at 1MHz - and the speed is exact when the define for this processor is set.

The M5223X has a 25MHz crystal and the setting is not correct for this (if using only M5223X in a system this error will not necessarily be noticed since all are working with the same speed). I suggest the following change which seems to be the only method of generating the exact 1MHz speed from the 25MHz crystal:

        CANCTRL = (((1-1) << 24) | RJW_2 | EXTAL_CLK_SOURCE | PROPSEG_BIT_TIME8 | PHASE_BUF_SEG1_LEN8 | PHASE_BUF_SEG2_LEN8); // Initialise the CAN controller with the required speed and parameters

For 100kHz simply divide the clock by 10:

        CANCTRL = (((10-1) << 24) | RJW_2 | EXTAL_CLK_SOURCE | PROPSEG_BIT_TIME8 | PHASE_BUF_SEG1_LEN8 | PHASE_BUF_SEG2_LEN8); // Initialise the CAN controller with the required speed and parameters

Regards

Mark



« Last Edit: November 15, 2007, 04:19:11 PM by mark »

Offline tr111

  • Jr. Member
  • **
  • Posts: 72
    • View Profile
Re: also set the Bit rate of 52235evb'CAN?
« Reply #2 on: November 15, 2007, 03:39:14 PM »
     Thanks you!
     I do that a day!I can sure that now!