µTasker Forum
µTasker Forum => NXPTM M522XX, KINETIS and i.MX RT => Topic started by: tr111 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????????
-
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
-
Thanks you!
I do that a day!I can sure that now!