I need some help setting up my J1939 definition for CAN bit timing. I am using a PIC18LF26K80 microcontroller with an 8 MHz clock. I'm having trouble trying to figure out how to calculate the different bits for the CAN registers.
Right now in my J1939.def file I have this but it is for a 16 MHz clock
#define ECAN_RX_INTERRUPT_PRIORITY 0x00
#define ECAN_TX_INTERRUPT_PRIORITY 0x00
#define ECAN_INTERRUPT_PRIORITY (ECAN_RX_INTERRUPT_PRIORITY | ECAN_TX_INTERRUPT_PRIORITY)
#define ECAN_LEGACY_MODE J1939_TRUE
#define ECAN_EXTRA_RX_BUFFERS 3
#define ECAN_SJW 2
#define ECAN_BRP 1
#define ECAN_BRGCON1 (((ECAN_SJW-1)<<6) | (ECAN_BRP-1))
#define ECAN_SEG2PHTS 0x80
#define ECAN_SAM 0x00
#define ECAN_SEG1PH 6
#define ECAN_PRSEG 6
#define ECAN_BRGCON2 (ECAN_SEG2PHTS | ECAN_SAM | ((ECAN_SEG1PH-1)<<3) | (ECAN_PRSEG-1))
#define ECAN_WAKDIS 0x80
#define ECAN_WAKFIL 0x00
#define ECAN_SEG2PH 3
#define ECAN_BRGCON3 (ECAN_WAKDIS | ECAN_WAKFIL | (ECAN_SEG2PH-1))
I've looked in the documentation for my microcontroller and it shows how to set the bits but I still don't understand how to use that information to calculate for an 8 MHz clock.
Got it. With everything timing and rate wise supposed to be identical to when I was using a 16MHz clock, the 8MHz clock meant everything would take twice as long. So all I had to do was change the ECAN_BRP value from a 2 to a 1 because this represents the length of the time quantum (tq). By dividing the tq in half, it essentially doubles the timing, making the timing work the same as it did with the 16MHz clock.
My explanation may not actually make sense, but it's what makes sense to me in my head haha and it's the answer to my question so that's what I'm going with.