Harmony 3, PIC32MX795F512H
Couldn't get the baudrate right with Harmony's settings; set to 125kHz in Harmony but meaured 135kHz on scope.
Eventually set the numbers by editing the generated code and re-checking on the scope. Got the 125kHz, but the numbers don't make sense... (plib_can1.c line 114)
/* Set the Bitrate to 125 Kbps */
C1CFG = ((20 << _C1CFG_BRP_POSITION) & _C1CFG_BRP_MASK)
| ((3 << _C1CFG_SJW_POSITION) & _C1CFG_SJW_MASK)
| ((6 << _C1CFG_SEG2PH_POSITION) & _C1CFG_SEG2PH_MASK)
| ((12 << _C1CFG_SEG1PH_POSITION) & _C1CFG_SEG1PH_MASK)
| ((1 << _C1CFG_PRSEG_POSITION) & _C1CFG_PRSEG_MASK)
I think that should give a bitrate of 80M (clock) / 20 (BRP) / 2 (built in postscaler)
/ ( 1 (PRSEG) + 12 (SEG1PH) + 6 (SEG2PH)
or 2MHz / (19) = 105kHz.
But it gives 125kHz bit times on scope.
Harmony's original numbers were
| ((3 << _C1CFG_SEG2PH_POSITION) & _C1CFG_SEG2PH_MASK)
| ((7 << _C1CFG_SEG1PH_POSITION) & _C1CFG_SEG1PH_MASK)
| ((0 << _C1CFG_PRSEG_POSITION) & _C1CFG_PRSEG_MASK)
Which I think should give 2MHz / (3 + 7 + 0) = 200kHz. But actually gives about 136kHz on the scope.
Which seems more wrong.
Don't know if it makes any difference, but I'm sending data onto a canbus of two Microchip MCP2515DM-BM demo boards (and also monitoring with Microchip's Can Bus Analyzer) and seems to be fine when the bitrate is correct.
I've clearly missed an important point somewhere, can anyone enlighten me?
Obviously, just after I post... numbers are only 0-7 so my 6, 12, 1 was actually 6,4,1. So 3,7,1 also works properly.
Looks like Harmony did get most of the numbers right, except PRSEG set to 0 instead of 1. Also, BRP rate divider should be 19 to divide by 20. And I'm still clearly calculating the numbers wrongly. 4 'time quanta' out somewhere.
Edit 2: - yes, I missed one time quanta of Sync Seg, plus the other segments are specified as (quanta - 1) - so the sum I should have been doing is 2M / (1 + 2 + 8 + 5) = 125kHz.
post edited by domble - 2020/08/07 09:31:04