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

demo_blink_led_asm bugfix #639

Merged
merged 7 commits into from
Jun 27, 2023
Merged

Conversation

vivi202
Copy link
Contributor

@vivi202 vivi202 commented Jun 26, 2023

This PR fix a bug that make demo_blink_led_asm not work as intended.

Example of the wrong behavior

bug
This behavior is caused by the delay subroutine which sometimes doesn't work as it should.
The instruction add t1, t1, t0 can cause an overflow when mcycle is sufficiently large.
These overflows then leads to the delay_loop being skipped multiple times.

solution

I have solved this bug by using the MTIME module instead of mcycle, ensuring that every time the delay subroutine is called, the MTIME.TIME_LOW register is resetted back to zero, thereby avoiding overflows.

@stnolting
Copy link
Owner

stnolting commented Jun 27, 2023

Hey there!

I never thought about this overflow issue (and it seems like I did not run the problem long enough...) - so thanks for discovering this! 👍

I like your simple fix, but this requires that the MTIME machine timer is present in the system. Furthermore, MTIME is expected to show "wall clock" time so altering the MTIME counter during operation might not be a good thing (but that is not relevant for this minimal demo anyway).

However, what do you think about going back to the mcycle variant and clear that counter in the delay loop?

By the way, thumbs up for the illustrating video! 😉

@stnolting stnolting self-assigned this Jun 27, 2023
@stnolting stnolting added bug Something isn't working SW software-related labels Jun 27, 2023
@vivi202
Copy link
Contributor Author

vivi202 commented Jun 27, 2023

I agree with you, MTIME should not be altered, so i went back to the mcycle variant.

@stnolting
Copy link
Owner

Looks good to me! 👍
Were you able to test your new version? Is the overflow issue resolved?

@vivi202
Copy link
Contributor Author

vivi202 commented Jun 27, 2023

Yes i have tested it, and the issue is now resolved, i also finded a typo in the datasheet i can fix it here or i need to open another PR?

@stnolting
Copy link
Owner

Yes i have tested it, and the issue is now resolved

Great, thank you!

i also finded a typo in the datasheet i can fix it here or i need to open another PR?

If that is just a typo then just add it to this PR. 😉

@vivi202
Copy link
Contributor Author

vivi202 commented Jun 27, 2023

Great, thank you!

you'r welcome, thank you so much for making this awesome opensource project!

@stnolting
Copy link
Owner

Thank you very much 😉

Ready to merge?

@vivi202
Copy link
Contributor Author

vivi202 commented Jun 27, 2023

Ready to merge?

Yes.

@stnolting stnolting merged commit 33cc6ff into stnolting:main Jun 27, 2023
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working SW software-related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants