Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bus speed at 500 K #59

Open
Duke069 opened this issue May 2, 2023 · 10 comments
Open

Bus speed at 500 K #59

Duke069 opened this issue May 2, 2023 · 10 comments

Comments

@Duke069
Copy link

Duke069 commented May 2, 2023

I have no issues running my code at 125 K and all works great . The minute I run at 500 K my truck crashes .
I have all terminations done correctly and have termination resistors in place .

I was wondering if I had to play with TQ and sample points .
My truck seems to like 75 sample rate at 125 K speed .

It works perfect at 125K but i know the timing gets more critical the faster the bus speed .

Any help would be amazing .
Thanks

Here is my basic code .

//Reads all traffic on CAN0 and forwards it to CAN1 and modifies cluster frame first.
//Code based on samples provided by Thibaut Viard/Wilfredo Molina/Collin Kidder
//------------------------------------------------------------------------------------------------

// Required libraries
#include "variant.h"
#include <due_can.h>

//Leave defined if you use native port, comment if using programming port
//This sketch could provide a lot of traffic so it might be best to use the
//native port
#define Serial SerialUSB

void printFrame(CAN_FRAME *frame, int filter) {
Serial.print("Fltr: ");
if (filter > -1) Serial.print(filter);
else Serial.print("???");
Serial.print(" ID: 0x");
Serial.print(frame->id, HEX);
Serial.print(" Len: ");
Serial.print(frame->length);
Serial.print(" Data: 0x");
for (int count = 0; count < frame->length; count++) {
Serial.print(frame->data.bytes[count], HEX);
Serial.print(" ");
}
Serial.print("\r\n");
}

void gotFrame0(CAN_FRAME *frame)
{
//printFrame(frame, 1); //uncomment line to print frames that are going out
Can1.sendFrame(*frame);
}

void gotFrameCluster(CAN_FRAME *frame) //cluster
{
frame->data.byte[1]=0x08;
frame->data.byte[6]=0x01;
//printFrame(frame, 2); //uncomment line to print frames that are going out
Can1.sendFrame(*frame);
}

void gotFrame1(CAN_FRAME *frame)
{
//printFrame(frame, -1); //uncomment line to print frames that are going out
Can0.sendFrame(*frame);
}

void setup()
{

//Serial.begin(250000); //Uncomment for serial

// Initialize CAN0, Set the proper baud rates here
Can0.begin(CAN_BPS_500K);
// Initialize CAN1, Set the proper baud rates here
Can1.begin(CAN_BPS_500K);

//By default there are 7 RX mailboxes for each device - Standard frames
//Can0 Filters
Can0.setRXFilter(0, 0x372, 0x7FF, false); //Cluster

//Can1 Filters
Can1.setRXFilter(0, 0, false); //catch all mailbox - no mailbox ID specified

//now register all of the callback functions.
Can0.setCallback(0, gotFrameCluster);

//this function will get a callback for any mailbox that doesn't have a registered callback
Can0.setGeneralCallback(gotFrame0);
Can1.setGeneralCallback(gotFrame1);
}

void loop(){ //note the empty loop here. All work is done via callback as frames come in - no need to poll for them
}

@collin80
Copy link
Owner

The sketch seems fine. You seem to have covered your bases on how you've attempted to fix the problem. But, you're right, there could be problems with the sampling point. You can see in due_can.h that most sampling points are set around 65-75%. Sometimes upwards of 87% is best. Probably less than 65% isn't the best idea. But, usually the sampling point only has to be increased if you have really long bus wires. On vehicle scale wiring it shouldn't be so critical. But, there is another thing I suspect. You say it's properly terminated but sometimes things get over terminated and that can cause issues too. Make sure you aren't adding termination where it should not be. If you are doing MitM then check the resistance of the wiring on both sides. If it is already 60 ohms then don't add any more. If it is 120 ohms then go ahead and add a 120 ohm resistor on that side.

@Duke069
Copy link
Author

Duke069 commented Jul 25, 2023 via email

@Duke069
Copy link
Author

Duke069 commented Jul 25, 2023 via email

@Duke069
Copy link
Author

Duke069 commented Jul 25, 2023

I verified with an ohm meter just to make sure the resistance is correct and I am getting 60 or so ohms per can channel .
Polarity is correct for can H and can L on both busses .
Thanks again Collin for your time and expertise .
Always appreciate the efforts people put in to help others !
Cheers

@collin80
Copy link
Owner

It sounds like you've done everything correctly yet it still isn't working. There are a couple more things I can think to try:

  1. Put the CAN ports into listen only mode. This should case your board to not do anything to the CAN bus. If you can run the vehicle stock with the board attached and it doesn't fault then that's a good sign and might point to what to try next. If it faults even in listen only mode then something is wrong at a hardware level - termination (though you checked that), ground loop, etc.
  2. Uncomment the printFrame lines so you can see when traffic comes in. What you're hoping to see is that traffic is actually flowing in. Never seeing any traffic is a bad sign.

I guess it'd be possible that your CAN capture board is strange in some way or the transceiver is broken but you would certainly think that 4 would not all be bad and you'd also think that 125k wouldn't work then either.

@Duke069
Copy link
Author

Duke069 commented Jul 26, 2023

Thanks Collin I will do some playing this weekend with it and give it another solid go .
Thanks for all your help and I will keep you posted on my findings .
Cheers !

@Duke069
Copy link
Author

Duke069 commented Jul 27, 2023

Well I updated to IDE 2.1 and now it's working good
You can see me logging on can 1 and the code is working great .
image![Uploading 256652475...]

Collin thanks for all your help with this !
So glad it's working now !

@Duke069
Copy link
Author

Duke069 commented Jul 27, 2023

image
Can logger showing the code is working

@Duke069
Copy link
Author

Duke069 commented Apr 2, 2024 via email

@Duke069
Copy link
Author

Duke069 commented Apr 12, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants