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

Revise baudrate calculations #41

Merged
merged 3 commits into from
Aug 21, 2024
Merged

Conversation

attie-argentum
Copy link
Contributor

As discussed in #40, the baudrate calculations should not consider SJW as part of the bit time.

This PR revises the timing calculations to exclude SJW, performance is also improved while maintaining a sample point between 75-95%.

Out-of-bounds SJW values are clamped, and the value is kept as high as possible for improved interoperability.
The lookup of pre-calculated timing configuration is also improved.


During calculation, all prescaler values that are unable to achieve the desired baudrate are immediately skipped, and restricting BS1/BS2 values as below allows us to also discard a large number of iterations that would produce inferior configurations.

Compared to the previous code, we gain 15x potential configuration options per prescaler value, and also discard 3x inferior options (early sample point)... this is 45x total vs 33x previously.

The number of time quanta for each BS1 / BS2 value is shown below:
image

This translates into a sample point as shown in this table - all values <75% are ignored (previous options ringed in blue).
image

This means that we can limit BS2 to values between 1 and 5, and BS1 may then start from (BS2 * 3) - 1.
image

@pazi88
Copy link
Owner

pazi88 commented Aug 20, 2024

Sorry for delay. This looks very good. I will test this little bit first.

@attie-argentum
Copy link
Contributor Author

No problem!

We've actually had further issues related to small BS1 and/or BS2 values (limiting the efficacy of SJW) and remote nodes starting their ACKs too early (causing an Error Frames)... I think it will be quite difficult to build this into a generic "calculate the parameters" function at runtime, so we have opted for a patch with manually selected timing configuration that works for our system... I wonder if it might be useful to consider a formal API for setting custom timings as well?

@pazi88 pazi88 merged commit a662adf into pazi88:main Aug 21, 2024
8 checks passed
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

Successfully merging this pull request may close these issues.

2 participants