Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
This translates into a sample point as shown in this table - all values <75% are ignored (previous options ringed in blue).
This means that we can limit
BS2
to values between 1 and 5, andBS1
may then start from(BS2 * 3) - 1
.