Skip to content

CAN bit rate enhancement #297

Open
Open
@fastbike

Description

@fastbike

Following on from #295

Here's another small code change to the CAN baud rate calculation to support the allowable error between the theoretical bit rate and the calculated bit rate to be an absolute value.

Current behaviour for a theoretical bus speed of 16,666.666' shows the following states:

  • CAN.begin(16666) succeeds - the absolute error is 0.003200128
  • CAN.begin(16667) fails - even though the absolute error is smaller at 0.001599968

Code change is required in CanUtil.cpp ...

    /* If the fractional part is sufficiently close to zero, we have
     * found a valid prescaler configuration.
     */
    if (brp_fract < 0.01)

... it should be checking either side of the desired rate

    /* If the fractional part is sufficiently close to zero, we have
     * found a valid prescaler configuration.
     */
    if (brp_fract < 0.01 || brp_fract > 0.99)

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: codeRelated to content of the project itselftype: imperfectionPerceived defect in any part of project

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions