arduino / arduino/ArduinoCore-renesas

CAN bit rate enhancement

Open
#297 0 comments 0 reactions 0 assignees View on GitHub
topic: code type: imperfection
Dominant language
C
Stars
193
Forks
112
PR merge metrics
No merged PRs in 30d

Description

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)
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Open CanUtil.cpp and inspect the CAN baud-rate calculation around the fractional prescaler check. Verify the theoretical rates described in the issue, then update the check so valid fractional values on either side are accepted. Confirm that CAN.begin(16666) and CAN.begin(16667) both behave as described.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
embedded-iot
Issue type
Feature
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.