Wrong baudrate flexcan demo "interrupt transfer" on FRDM-KV11Z SDK 2.7.0

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Wrong baudrate flexcan demo "interrupt transfer" on FRDM-KV11Z SDK 2.7.0

ソリューションへジャンプ
2,543件の閲覧回数
robertoquilez
Contributor III

Hello,

When run the flexcan driver demo (nterrupt transfer) out of the box, the baudrate is supposed to be 1Mbps but at the oscilloscope we "see" only  138.9 KHz

How can we set the baudrate properly? We would like to get 250Kbps, but we are unable to get that baudrate.

Here CAN Bit Time Calculation  we observe that no baud rate is compatible with 75MHz as core clock as configured  by default in the demo.

Thank you in advance for your support,

Roberto

ラベル(2)
1 解決策
2,380件の閲覧回数
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Roberto Quilez,

   Thanks for your question.

   Today, I check the SDK code on my side, frdmkv11z_flexcan_interrupt_transfer. SDK2.7.0.

   Find some code bugs, and I have modify it, it can transfer the 1Mbps and the 250Kbps now.

  1. 1Mbps Modification points: 

1)
/*#define PSEG1 5
#define PSEG2 2
#define PROPSEG 1
*/

#define PSEG1 4
#define PSEG2 1
#define PROPSEG 1

2) #define EXAMPLE_CAN_CLK_FREQ 10000000//CLOCK_GetFreq(kCLOCK_CoreSysClk)
or #define EXAMPLE_CAN_CLK_FREQ CLOCK_GetFreq(kCLOCK_Osc0ErClk)

Just select the external 10Mhz crystal as the clock source.

#define EXAMPLE_CAN_CLK_SOURCE (kFLEXCAN_ClkSrc0)

 flexcanConfig.clkSrc = EXAMPLE_CAN_CLK_SOURCE;

pastedImage_4.png

Test Result:

pastedImage_2.png

2. Your desired 250Kbps modified points:

  1) 

//250Kbps
#define PSEG1 4
#define PSEG2 1
#define PROPSEG 1

2) void FLEXCAN_GetDefaultConfig(flexcan_config_t *pConfig) in fsl_flexcan.c

void FLEXCAN_GetDefaultConfig(flexcan_config_t *pConfig)
{
/* Assertion. */
assert(NULL != pConfig);

/* Initializes the configure structure to zero. */
(void)memset(pConfig, 0, sizeof(*pConfig));

/* Initialize FlexCAN Module config struct with default value. */
pConfig->clkSrc = kFLEXCAN_ClkSrc0;
pConfig->baudRate = 250000U;//1000000U;

pastedImage_3.png

pastedImage_1.png

I also attach my modified project for your desired 250khz, it works Ok now.

Also provide the oscilloscope 250Kbps wave: 

pastedImage_1.png

  bit rate is correct!

  Test platform: FRDM-KV11Z

Wish it helps you!

If you still have questions about it, please kindly let me know.

Kerry

 

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

元の投稿で解決策を見る

7 返答(返信)
2,381件の閲覧回数
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Roberto Quilez,

   Thanks for your question.

   Today, I check the SDK code on my side, frdmkv11z_flexcan_interrupt_transfer. SDK2.7.0.

   Find some code bugs, and I have modify it, it can transfer the 1Mbps and the 250Kbps now.

  1. 1Mbps Modification points: 

1)
/*#define PSEG1 5
#define PSEG2 2
#define PROPSEG 1
*/

#define PSEG1 4
#define PSEG2 1
#define PROPSEG 1

2) #define EXAMPLE_CAN_CLK_FREQ 10000000//CLOCK_GetFreq(kCLOCK_CoreSysClk)
or #define EXAMPLE_CAN_CLK_FREQ CLOCK_GetFreq(kCLOCK_Osc0ErClk)

Just select the external 10Mhz crystal as the clock source.

#define EXAMPLE_CAN_CLK_SOURCE (kFLEXCAN_ClkSrc0)

 flexcanConfig.clkSrc = EXAMPLE_CAN_CLK_SOURCE;

pastedImage_4.png

Test Result:

pastedImage_2.png

2. Your desired 250Kbps modified points:

  1) 

//250Kbps
#define PSEG1 4
#define PSEG2 1
#define PROPSEG 1

2) void FLEXCAN_GetDefaultConfig(flexcan_config_t *pConfig) in fsl_flexcan.c

void FLEXCAN_GetDefaultConfig(flexcan_config_t *pConfig)
{
/* Assertion. */
assert(NULL != pConfig);

/* Initializes the configure structure to zero. */
(void)memset(pConfig, 0, sizeof(*pConfig));

/* Initialize FlexCAN Module config struct with default value. */
pConfig->clkSrc = kFLEXCAN_ClkSrc0;
pConfig->baudRate = 250000U;//1000000U;

pastedImage_3.png

pastedImage_1.png

I also attach my modified project for your desired 250khz, it works Ok now.

Also provide the oscilloscope 250Kbps wave: 

pastedImage_1.png

  bit rate is correct!

  Test platform: FRDM-KV11Z

Wish it helps you!

If you still have questions about it, please kindly let me know.

Kerry

 

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

2,380件の閲覧回数
robertoquilez
Contributor III

Thank you very much Kerry. It works!

Really valuable, I was stuck for a while.

Nevertheless I have difficulties understanding how I might had found the same values that you got following this step by step example:

pastedImage_1.png

 

Let's assume Baurate is 250Kbps and MCU clock is 10MHz
NBT x Prescaler = 40 (NBT = 8, Prescaler = 5)
Let's assume PROP_SEG is 1 because the CAN bus is really short.
NBT - 1Tq - PROP_SEG = 6
So PHASE_SEG1 and PHASE_SEG2 = 3

I don't know how do you get
#define PSEG1 4
#define PSEG2 1
#define PROPSEG 1

Can you explain your calculation please ?

Moreover in your previous post, baudrate 250K or 1M do not have any impact on PSEG1, PSEG2 or PROPSEG.

0 件の賞賛
返信
2,380件の閲覧回数
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Roberto Quilez

   Please read the KV11Z reference manual:

https://www.nxp.com/webapp/Download?colCode=KV11P64M75RM 

  Chapter  39.4.8.4 Protocol timing

pastedImage_2.png

pastedImage_4.png

pastedImage_3.png

  You will find my configuration details.

 1. 1Mbps, my configuration is 

#define PSEG1 4
#define PSEG2 1
#define PROPSEG 1

Please note, Time segment 1= PSEG1+1, Time Segment 2= PSEG2+1

So, if you want to get 1Mbps, but your fCANCLK is external crystal 10Mhz.

What does it mean?

1Mbps= (10M/(PRESDIV+1))/(4+PROPSEG+PROPSEG+PSEG1).

If choose PRESDIV =0, no divide clock.

Then it means your 4+PROPSEG+PROPSEG+PSEG1= 10, then you need to check table 39-14, find item 1 is the proper one.

That's why I choose:

#define PSEG1 4
#define PSEG2 1
#define PROPSEG 1

2. 250Kbps

  Now, why I don't modify the PSEG1, PSEG2, PROPSEG1?

 Because my PRESDIV set the other data, if you debug the code and check the CAN_CTRL1[PRESDIV], you will find it is 3.

250Kbps=(10M/(PRESDIV+1))/(4+PROPSEG+PROPSEG+PSEG1).

=>250Kbps=(10M/(PRESDIV(3)+1))/(4+PROPSEG+PROPSEG+PSEG1).

Wish it helps you!

If you still have questions about it, please kindly let me know.

Kerry

 

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 件の賞賛
返信
2,380件の閲覧回数
robertoquilez
Contributor III

Kerry, thank you again for your rapide response.

I think there are some things in your post that do not match with what I see in the doct:

You wrote Time Segment 1 = PSEG1 + 1 but according to the reference manual it's PROPSEG + PSEG1 + 2
after you wrote (4+PROPSEG+PROPSEG+PSEG1) but I think you meant (4+PROPSEG+PSEG2+PSEG1)

With the formula:
4+PROPSEG+PSEG2+PSEG1 = 10
==> TS1 + TS2 = 9

How do you choose between line 1 or 2 of Table 39-14 ?
I mean TS1(7) + TS2(2) = TS1(6) + TS2(3) = 9

0 件の賞賛
返信
2,380件の閲覧回数
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Roberto Quilez,

   Your understanding is wrong, seems you didn't check my picture which is from the KV11 RM:

pastedImage_1.png

  bit time after clock divide is : SYNC_SEG+PROPSEG+PSEG1+2+PSEG2+1.

  SYNC_SEG=1.

Then, you will know it is 4+PROPSEG+PSEG1+PSEG2

Please note PROPSEG,PSEG1,PSEG2 are the register value.

Time segment 1= PSEG1+1, Time Segment 2= PSEG2+1

The following picture is after +1

pastedImage_2.png

So 4+PROPSEG+PSEG2+PSEG1 = 10, it is 1+(Time segment 1=PSEG1+1)+(Time segment2=PSEG2+1)+(jump width=PSEG1 +1)

If  PROPSEG=1 ,jump width=2, I want PSEG2+PSEG1+2 = 7, it is Time segment 1+ Time segment2=7.

So, if Time segment1 =5, Timesegment 2=2, it is 7, meet the demand.

Wish it really helps you to understand it.

Maybe you also need to double read the KV11 RM carefully.

If you still have questions about it, please kindly let me know.

Kerry

 

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 件の賞賛
返信
2,380件の閲覧回数
robertoquilez
Contributor III

Ok, you are right, thank you very much.

My misunderstanding was due to the first picture where we see: 

 Timer segment 1 = PROPSEG + PSEG1 + 2

When the formula to apply is:

Time segment 1= PSEG1+1.

Thank you very much for your support, again.

0 件の賞賛
返信
2,380件の閲覧回数
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Roberto Quilez,

   You are using this code:

SDK_2.7.0_FRDM-KV11Z\boards\frdmkv11z\driver_examples\flexcan\interrupt_transfer

Right?

If the tool don't have the related 250Kbps, you can calculate by yourself, just find the proper PSEG1, PSEG2 and PROPSEG.

You can refer to the example to calculate it:

for e.g. 84M clock and 1M baud rate, the
quantum should be .e.g 14=(6+3+1)+4, so prescaler is 6. By default, quantum
is set to 10=(3+2+1)+4, because for most platforms e.g. 120M source clock/(1M
baud rate * 10) is an integer.

Anyway, tomorrow, I will help you to test it.

Kerry

 

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 件の賞賛
返信