SPEED CAN-BUS inernal external
Moderator: Benj
-
- Posts: 59
- Joined: Mon Aug 04, 2014 12:59 pm
- Has thanked: 8 times
- Been thanked: 4 times
- Contact:
SPEED CAN-BUS inernal external
Hello!
I have a PIC18F2580 with internal (only MCP2551) and one external (MCP2515 and MCP2551) CAN-Buses.
I have a simple program (CAN-retranslator). From the first channel to the second. It loses some frames. Like not enough speed. I increased Osc. from 16 to 40 MHz? but almost nothing was changed.
Was the speed of SPI channel (to external CAN) been increased with Osc?
How can I increase speed of traffic between PIC and CAN transceivers?
I have a PIC18F2580 with internal (only MCP2551) and one external (MCP2515 and MCP2551) CAN-Buses.
I have a simple program (CAN-retranslator). From the first channel to the second. It loses some frames. Like not enough speed. I increased Osc. from 16 to 40 MHz? but almost nothing was changed.
Was the speed of SPI channel (to external CAN) been increased with Osc?
How can I increase speed of traffic between PIC and CAN transceivers?
- QMESAR
- Valued Contributor
- Posts: 1287
- Joined: Sun Oct 05, 2014 3:20 pm
- Location: Russia
- Has thanked: 384 times
- Been thanked: 614 times
- Contact:
Re: SPEED CAN-BUS inernal external
Hi.
As CAN is time based communication it is simply not just a question of speeding up the SPI there are a few important information regarding your CAN translator missing.
1 What is the bus load you are trying to connect too(how many messages are on this bus per second)
2 What is the cycle time of the fastest message on the bus
3 are you setting the MASK and filters to mask out the messages of interest
we need a bit more information to help you will some sensible advise
As CAN is time based communication it is simply not just a question of speeding up the SPI there are a few important information regarding your CAN translator missing.
1 What is the bus load you are trying to connect too(how many messages are on this bus per second)
2 What is the cycle time of the fastest message on the bus
3 are you setting the MASK and filters to mask out the messages of interest
we need a bit more information to help you will some sensible advise
https://www.flowcodexchange.com/
Regards QMESAR
Regards QMESAR
-
- Posts: 59
- Joined: Mon Aug 04, 2014 12:59 pm
- Has thanked: 8 times
- Been thanked: 4 times
- Contact:
Re: SPEED CAN-BUS inernal external
Thanks for your answer!
1. It is very different. I'll put an example of track.
2.Sometime it less then 1 ms (see str. 7-8)
3.Yes and no. I use mask 0 and filter 0 because I don't know the protocol fully, and I have to exclude some frames with exact IDs.
But the speed of CAN-bus isn't so big (95kbps) and I'm sure there are enough resources of this PIC for this task.
And I have one additional question: how I can enable
for both CAN channels?
?
1. It is very different. I'll put an example of track.
2.Sometime it less then 1 ms (see str. 7-8)
3.Yes and no. I use mask 0 and filter 0 because I don't know the protocol fully, and I have to exclude some frames with exact IDs.
But the speed of CAN-bus isn't so big (95kbps) and I'm sure there are enough resources of this PIC for this task.
And I have one additional question: how I can enable
Code: Select all
RXB0DBEN: Receive Buffer 0 Double-Buffer Enable bit
1 = Receive Buffer 0 overflow will write to Receive Buffer 1
Code: Select all
Time Frame ID DLC Data
16:14:48:007 Data frame Standard frame 000004e8 7 46 0f 0b a4 00 00 01
16:14:48:007 Data frame Standard frame 00000188 6 46 02 00 00 00 00
16:14:48:022 Data frame Standard frame 00000506 8 16 00 42 16 84 00 00 03
16:14:48:038 Data frame Standard frame 000004e8 7 46 0f 0b bf 00 00 01
16:14:48:085 Data frame Standard frame 000004e8 7 46 0f 0b f6 00 00 01
16:14:48:116 Data frame Standard frame 00000188 6 46 02 00 00 00 00
16:14:48:132 Data frame Standard frame 00000501 8 61 00 42 16 01 00 40 01
16:14:48:132 Data frame Standard frame 000004e8 7 46 0f 0c 06 00 00 01
16:14:48:178 Data frame Standard frame 000004e8 7 46 0f 0b b5 00 00 01
16:14:48:210 Data frame Standard frame 00000188 6 46 02 00 00 00 00
16:14:48:225 Data frame Standard frame 00000506 8 16 00 42 16 81 00 02 00
16:14:48:241 Data frame Standard frame 000004e8 7 46 0f 0b 34 00 00 01
16:14:48:288 Data frame Standard frame 000004e8 7 46 0f 0b 8c 00 00 01
16:14:48:303 Data frame Standard frame 00000501 8 61 00 42 16 01 00 40 01
Code: Select all
FC_CAN_SPI_CAN_Write_2(FCV_0e702_can2__CAN_RXB0CTRL, 0x24);
FC_CAN_SPI_CAN_Write_1(FCV_0e701_can1__CAN_RXB0CTRL, 0x24
- LeighM
- Matrix Staff
- Posts: 2178
- Joined: Tue Jan 17, 2012 10:07 am
- Has thanked: 481 times
- Been thanked: 699 times
- Contact:
Re: SPEED CAN-BUS inernal external
Hi,
Would it be possible to attach your Flowcode project (.fcfx) file?
This would help answer a few questions about your setup.
Would it be possible to attach your Flowcode project (.fcfx) file?
This would help answer a few questions about your setup.
-
- Posts: 59
- Joined: Mon Aug 04, 2014 12:59 pm
- Has thanked: 8 times
- Been thanked: 4 times
- Contact:
- LeighM
- Matrix Staff
- Posts: 2178
- Joined: Tue Jan 17, 2012 10:07 am
- Has thanked: 481 times
- Been thanked: 699 times
- Contact:
Re: SPEED CAN-BUS inernal external
Hi,
Not sure if this is the complete answer, but I noticed a missing check of CAN2 Buffer 1 ... edit: To set the rollover
CAN1...
CAN2...
Not sure if this is the complete answer, but I noticed a missing check of CAN2 Buffer 1 ... edit: To set the rollover
CAN1...
Code: Select all
// Request config mode.
cancon = MX_CAN_REQOP_CONFIG;
while( (canstat & MX_CAN_OP_MODE_BITS) != MX_CAN_REQOP_CONFIG );
rxb0con = 0x24;
Code: Select all
//setup CNF and control registers
FC_CAN_SPI_CAN_Config_2(FCV_0e702_can2__CAN_REQOP_CONFIG);
FC_CAN_SPI_CAN_Write_2(FCV_0e702_can2__CAN_RXB0CTRL, 0x24);
Last edited by LeighM on Thu Oct 12, 2017 11:49 am, edited 1 time in total.
-
- Posts: 59
- Joined: Mon Aug 04, 2014 12:59 pm
- Has thanked: 8 times
- Been thanked: 4 times
- Contact:
Re: SPEED CAN-BUS inernal external
Yes!
I see it. I rebuilt it many times and made this mistake.
But it doesn't resolve the main problem. I have tried correct variant.
I suppose the problem of missing frames can be in slow speed in communications of PIC and MCP2515. And it can be solved by increasing speed or use the RX(1) buffers when the RX0 is full and new message is receiving.
I see it. I rebuilt it many times and made this mistake.
But it doesn't resolve the main problem. I have tried correct variant.
I suppose the problem of missing frames can be in slow speed in communications of PIC and MCP2515. And it can be solved by increasing speed or use the RX(1) buffers when the RX0 is full and new message is receiving.
- LeighM
- Matrix Staff
- Posts: 2178
- Joined: Tue Jan 17, 2012 10:07 am
- Has thanked: 481 times
- Been thanked: 699 times
- Contact:
Re: SPEED CAN-BUS inernal external
OK. I've just done an edit to my previous post, with code for setting the rollover mode, see if that helps.
btw, the code is to add the rxb0con line into the existing initialization code.
Does the problem happen in any particular direction, CAN1->CAN2, CAN2->CAN1?
btw, the code is to add the rxb0con line into the existing initialization code.
Does the problem happen in any particular direction, CAN1->CAN2, CAN2->CAN1?
Last edited by LeighM on Thu Oct 12, 2017 11:54 am, edited 1 time in total.
-
- Posts: 59
- Joined: Mon Aug 04, 2014 12:59 pm
- Has thanked: 8 times
- Been thanked: 4 times
- Contact:
Re: SPEED CAN-BUS inernal external
Yes. I tried to remove any excludes for any IDs and just resend them. I sow many mistakes. And they was different (added - it was protocol crashing, I think) . But I didn't catch exact differences. And there was a few changes on the hardware board (resistance terminators and some other) because of including scheme differences.Does the problem happen in any particular direction, CAN1->CAN2, CAN2->CAN1?
Thanks I'll try your code soon.
Last edited by Barmaley_GMN on Fri Oct 13, 2017 6:34 am, edited 1 time in total.
-
- Posts: 59
- Joined: Mon Aug 04, 2014 12:59 pm
- Has thanked: 8 times
- Been thanked: 4 times
- Contact:
Re: SPEED CAN-BUS inernal external
Your code works good, thanks!
My program steel have problem. I checked it works without mistakes from Can2(ext) to Can1(int) and in reverse (1 to 2) it looses frames, and
I didn't see any frame from RX buffer(1) (I marked them).
I swapped all MCPs, resolder all wires, but it didn't help.
It looses about 10% Every time quantity of lost frames is different.
I made variable. It counts received frames and writes sum to eeprom. I see it receive all of them. So, I think, the problem is in sending from Can2 (external).
Any ideas?
My program steel have problem. I checked it works without mistakes from Can2(ext) to Can1(int) and in reverse (1 to 2) it looses frames, and
I didn't see any frame from RX buffer(1) (I marked them).
I swapped all MCPs, resolder all wires, but it didn't help.
It looses about 10% Every time quantity of lost frames is different.
I made variable. It counts received frames and writes sum to eeprom. I see it receive all of them. So, I think, the problem is in sending from Can2 (external).
Any ideas?
- LeighM
- Matrix Staff
- Posts: 2178
- Joined: Tue Jan 17, 2012 10:07 am
- Has thanked: 481 times
- Been thanked: 699 times
- Contact:
Re: SPEED CAN-BUS inernal external
They were good tests.
Maybe something to try is changing the CAN2 SPI speed and seeing what difference, if any, that makes.
Just after the can2::Initialise(), add a C icon with the following code
Add the following line for faster (x4) SPI
Or add the following lines for slower (/4) SPI
Maybe something to try is changing the CAN2 SPI speed and seeing what difference, if any, that makes.
Just after the can2::Initialise(), add a C icon with the following code
Add the following line for faster (x4) SPI
Code: Select all
sspcon = sspcon & 0xFC;
Code: Select all
sspcon = sspcon & 0xFC;
sspcon = sspcon | 2;
-
- Posts: 59
- Joined: Mon Aug 04, 2014 12:59 pm
- Has thanked: 8 times
- Been thanked: 4 times
- Contact:
- LeighM
- Matrix Staff
- Posts: 2178
- Joined: Tue Jan 17, 2012 10:07 am
- Has thanked: 481 times
- Been thanked: 699 times
- Contact:
Re: SPEED CAN-BUS inernal external
Yes, on this device it is sspcon1, but our generic CAL code redefines sspcon as sspcon1, so either will work
-
- Posts: 59
- Joined: Mon Aug 04, 2014 12:59 pm
- Has thanked: 8 times
- Been thanked: 4 times
- Contact:
Re: SPEED CAN-BUS inernal external
Thanks again!
Your code works, but doesn't help.
I made some new experiments and catch regularity. If I make simple program with cycle for 3000 and macro:
CAN2 Set TX ID simple
CAN2 Set TX data
CAN2 sendBuffer
It didn't send half of the all frames.
It sends all of them if I put delay to cycle more then 1200us and it is veeeery bad for my program, but decreases mistakes to 0,075%
This delay can be less more then 2 times if I use only one macros (SendBuffer).
If I choose software mode for CAN2 - it works slowly but the same way.
And CAN1 send everything without any delays. It works perfect!
So I think the main problem in external CAN component. Maybe it doesn't have some checks if the registers ready. And of course maybe I am again on a wrong way)))
Your code works, but doesn't help.
I made some new experiments and catch regularity. If I make simple program with cycle for 3000 and macro:
CAN2 Set TX ID simple
CAN2 Set TX data
CAN2 sendBuffer
It didn't send half of the all frames.
It sends all of them if I put delay to cycle more then 1200us and it is veeeery bad for my program, but decreases mistakes to 0,075%
This delay can be less more then 2 times if I use only one macros (SendBuffer).
If I choose software mode for CAN2 - it works slowly but the same way.
And CAN1 send everything without any delays. It works perfect!
So I think the main problem in external CAN component. Maybe it doesn't have some checks if the registers ready. And of course maybe I am again on a wrong way)))
Last edited by Barmaley_GMN on Sat Oct 14, 2017 7:27 am, edited 3 times in total.
-
- Posts: 59
- Joined: Mon Aug 04, 2014 12:59 pm
- Has thanked: 8 times
- Been thanked: 4 times
- Contact:
- LeighM
- Matrix Staff
- Posts: 2178
- Joined: Tue Jan 17, 2012 10:07 am
- Has thanked: 481 times
- Been thanked: 699 times
- Contact:
Re: SPEED CAN-BUS inernal external
You could be right. I'll check on Monday.Maybe it doesn't have some checks if the registers ready.
Thanks,
- LeighM
- Matrix Staff
- Posts: 2178
- Joined: Tue Jan 17, 2012 10:07 am
- Has thanked: 481 times
- Been thanked: 699 times
- Contact:
Re: SPEED CAN-BUS inernal external
Hi,
I've done a quick macro CheckTx, attached, that you can import into your project.
This can be used to check if the Tx buffer is busy, maybe test buffer 0 and if busy use 1 or 2?
I've done a quick macro CheckTx, attached, that you can import into your project.
This can be used to check if the Tx buffer is busy, maybe test buffer 0 and if busy use 1 or 2?
- Attachments
-
- CheckTx.fcm
- (704 Bytes) Downloaded 154 times
-
- Posts: 59
- Joined: Mon Aug 04, 2014 12:59 pm
- Has thanked: 8 times
- Been thanked: 4 times
- Contact:
Re: SPEED CAN-BUS inernal external
Thanks!
I'll be able to check it close to next weekend.
I tried to change TX buffers in cycle (0-1-0-1...) it didn't help.
And now, there are rollover RX0->RX1 works in my program. It uses TX0 and TX1 and has delays after every sending buffer 1200us. It isn't enough. And I see near 4 lost messages from 5450 sample from real CAN-BUS. If I remove or just make delays shorter I see more mistakes. I can try to use var. and use 3 TX buffers, but I think there is should be more smart solution.
I'll be able to check it close to next weekend.
I tried to change TX buffers in cycle (0-1-0-1...) it didn't help.
And now, there are rollover RX0->RX1 works in my program. It uses TX0 and TX1 and has delays after every sending buffer 1200us. It isn't enough. And I see near 4 lost messages from 5450 sample from real CAN-BUS. If I remove or just make delays shorter I see more mistakes. I can try to use var. and use 3 TX buffers, but I think there is should be more smart solution.
- LeighM
- Matrix Staff
- Posts: 2178
- Joined: Tue Jan 17, 2012 10:07 am
- Has thanked: 481 times
- Been thanked: 699 times
- Contact:
Re: SPEED CAN-BUS inernal external
Oh, that sounds like we might be barking up the wrong tree then.And I try to change TX buffers in cycle (0-1-0-1...) it didn't help.
Are both CAN buses running at the same speed?
On the CAN2 transmit, are there any gaps between transmissions?
Are messages being acknowledged by a receiver?
I just wonder if there are auto re-transmissions going on?
-
- Posts: 59
- Joined: Mon Aug 04, 2014 12:59 pm
- Has thanked: 8 times
- Been thanked: 4 times
- Contact:
Re: SPEED CAN-BUS inernal external
There can be some language barriers.
If I understand You:
1. Both CAN-BUSes work on the same speed (95,238kbps). They work with different resonators (40MHz CAN1 and 20Mhz CAN2), but it doesn't matter. Microchip CAN Bit Timing Calculator got data for CNFn/BRGCONn registers.
2. I didn't catch gaps. But if delay not enough program skips some of messages.
3. I 'm not sure about acknowledging but both CAN have the same components since MCP2551 and their's surroundings, and as I said before CAN1 sent everything without delays and losses (skips).
If I understand You:
1. Both CAN-BUSes work on the same speed (95,238kbps). They work with different resonators (40MHz CAN1 and 20Mhz CAN2), but it doesn't matter. Microchip CAN Bit Timing Calculator got data for CNFn/BRGCONn registers.
2. I didn't catch gaps. But if delay not enough program skips some of messages.
3. I 'm not sure about acknowledging but both CAN have the same components since MCP2551 and their's surroundings, and as I said before CAN1 sent everything without delays and losses (skips).
- LeighM
- Matrix Staff
- Posts: 2178
- Joined: Tue Jan 17, 2012 10:07 am
- Has thanked: 481 times
- Been thanked: 699 times
- Contact:
Re: SPEED CAN-BUS inernal external
I noticed that in the MCP code there is a very small delay between setting up the data and sending.
Might be worth trying adding a very short delay between can2::SetTxData() and can2::SendBuffer()
Also might be worth setting an output port at the start of the can2 setup, then clear just after the send so that you can see (on an oscilloscope) how long the processes takes relative to the incoming CAN messages.
Might be worth trying adding a very short delay between can2::SetTxData() and can2::SendBuffer()
Also might be worth setting an output port at the start of the can2 setup, then clear just after the send so that you can see (on an oscilloscope) how long the processes takes relative to the incoming CAN messages.
-
- Posts: 59
- Joined: Mon Aug 04, 2014 12:59 pm
- Has thanked: 8 times
- Been thanked: 4 times
- Contact:
Re: SPEED CAN-BUS inernal external
I did it. And didn't catch the difference. If sum of delays less then 1200us - I see lost frames.LeighM wrote:I noticed that in the MCP code there is a very small delay between setting up the data and sending.
Might be worth trying adding a very short delay between can2::SetTxData() and can2::SendBuffer()
I have one port for LED. I can connect my logic analyzer and catch the period. But I don't understand you: which exact process I need to check: setup (macro initialisation or set TX_Data... buffer). Or I can check it by ChipSelect pin...LeighM wrote:Also might be worth setting an output port at the start of the can2 setup, then clear just after the send so that you can see (on an oscilloscope) how long the processes takes relative to the incoming CAN messages.
-
- Posts: 59
- Joined: Mon Aug 04, 2014 12:59 pm
- Has thanked: 8 times
- Been thanked: 4 times
- Contact:
-
- Posts: 59
- Joined: Mon Aug 04, 2014 12:59 pm
- Has thanked: 8 times
- Been thanked: 4 times
- Contact:
Re: SPEED CAN-BUS inernal external
Some new experiments
The first image for internal CAN1 Next for external CAN2 - used 3 TX buffers 1->2->0->1...
The first image for internal CAN1 Next for external CAN2 - used 3 TX buffers 1->2->0->1...
Last edited by Barmaley_GMN on Wed Oct 25, 2017 2:19 pm, edited 1 time in total.
-
- Posts: 59
- Joined: Mon Aug 04, 2014 12:59 pm
- Has thanked: 8 times
- Been thanked: 4 times
- Contact:
Re: SPEED CAN-BUS inernal external
Next with one TX buffer (1-1-1)
I made some tests for every variant I have seen different periods but the same Count of received frames.
Next one like previous but added faster SPI (x4)
If I add 2us delays after every CAN macros - it doesn't matter the result on the screen is the same.I made some tests for every variant I have seen different periods but the same Count of received frames.