Closed gfeun closed 4 years ago
Thanks for taking the time to create this pull-request Glenn! This seems to be a simple yet clever way to improve the performance of the simulator, a sort of quick-win.
Have you tried comparing the speed of actual code (such as the blink example from the demo project)? What speed did you get and what browser/device have you used?
Yes, i was just editing my PR to add that, you're too fast :smile:
So i observed a ~7% difference using the demo after 5s of simulation time on Firefox 74
Without PR: Simulation time: 00:05.093 (27%)
With PR: Simulation time: 00:05.218 (34%)
Oh, I wasn't expecting such a massive difference between Firefox and Chromium performance.
Just tested on Chromium 80
Without PR: Simulation time: 00:10.218 (83%)
With PR: Simulation time: 00:10.375 (137%)
Good job Glenn! I just released this as part of 0.6.1.
Where do you teach embedded systems?
I am not too familiar with hardware simulators but my guess would be that use of a map of opcodes or switch statements would provide even greater benefits.
Yeah, that's the purpose of the benchmark
folder - I have started it in effort to figure out how to further improve performance. If you look at benchmark/index.ts
, it checks exactly that - comparing the performance of avrInstruction
v.s. using a map / UInt16Array to decode the instructions in one go.
If you are interested in further looking in these directions let me know, we can brainstorm together.
Thank you for your reactivity !
I teach at a French university called Université de Bretagne Occidentale. It is not my main job, I only intervene as a substitute teacher for practical work on an introductory course. Practical work include teaching assembly basics, C and the use of some µController peripherals (GPIO, ADC, 7-segment display, LED, timers, buzzer). We teach using AVR libraries without Arduino abstractions to give an understanding of the low level interactions with the hardware.
What is of interest to me is that we have custom boards with all our peripherals and an atmega 2560 sitting in the middle. Since school has gone full remote we have to find ways to teach these concepts to students at home. I stumble upon your project and saw the great potential to be able to create a virtual board, or at least part of it (Button and LED would be a good starting point).
So I'm not an expert but I'll be glad to help !
I see that you have some interesting issues awaiting that may be easier for me to begin with than performance optimization :smile: I'll take a few days to familiarize with Typescript and the codebase and will keep you updated.
Thanks for the explanation, that's great to hear!
Any help with the open issues will be blessed. Which peripherals do you have on your atmega2560 board?
Our board look like this (this is our old one but peripherals are the same)
So we make use of GPIO for leds, buttons, 7-seg and switches ADC for potentiometer and temperature sensor (Upper left) Timers to generate signals for the buzzer Usart for communication with a PC Interupts for keypad
ADC would be a great next step and interesting to implement.
👍 for the ADC!
As far as the other hardware, here is some stuff we already have: LEDs are there, 7-seg, push buttons, USART, and I also see that you have an LCD there, which we have too.
So apart from ADC, the missing pieces are the keypad, buzzer , and switches.
If you want to check out the 7-seg, for instance, I created a small programming challenge that uses it, and would love to get your feedback on it:
Keypad is not necessary, switches shoudn't be hard and I saw that you have an early buzzer implementation in your simon game example. I'll dabble with some components and try to create an initial board webpage.
That's a good challenge and a great website. I couldn't wrap my head around the 7-seg pinout, I'll try again tomorrow.
Thanks for the feedback!
What do you think about building this board page on top of the wokwi.com platform?
I have just released a beta editor that actually allows you to tinker with both the code and the hardware / explanations in the page, you can get it to by adding ?beta-editor=yeah
to any playground/challenge URL, e.g.:
https://wokwi.com/playground/blink?beta-editor=yeah
This editor allows you to preview your change immediately, but it currently does not support saving the code. Once if have some code you are happy with, you can send a pull-request to the playgrounds repo, and it will go live shortly after being merged.
I like the possibility to write lessons using markdown while including electronic components using html ! That's super neat. The dynamic reload is great too.
I don't understand however how you link the components to specific pins ? (found, with the label attribute, feels like magic :smile: )
I'd like to know, do you own wokwi ? Is it intended to be a commercial platform in the future ?
For the board I imagined an horizontally split window to fit the real board orientation. But this could be changed, i'll try to build a prototype.
A little feedback, I don't personally feel that the "comment section" is useful for this type of content. Imagining lots of comments here would distract from the lesson i think.
It's a massive ecosystem of tools you built here, that's amazing.
Great!
Yes, Wokwi is a project I started together with @AriellaE. The idea is to provide a platform where people can create Arduino, Electronics and IoT courses, both paid and free, and share them with the community.
Good call about the comments section. We actually added it pretty early in the project, and so far it has only been used by a single person to report about an issue. We'll probably remove it or make it optional (so that they playground owner can decide if they want to have comments or not).
Thanks :-)
Hello,
First I'd like to thank you for this great project. I am teaching the basics of embedded systems and this could be a great resource for me in the future !
While I was taking a look at the source code I came along this quick optimization in the instruction code. I hope I didn't miss something obvious.
Simply replacing
if
withelse if
provides a welcomed performance boost. All theseif
on every opcode adds up, so addingelse if
reduces the amount of checks per opcode.However I liked the clear opcode separation by a line but the prettier doesn't allow this with
else if
so it is a bit ugly and condensed now.I am not too familiar with hardware simulators but my guess would be that use of a map of opcodes or switch statements would provide even greater benefits.
With this PR the last instruction still requires evaluation of all the preceding
if
andelse if
.Benchmarks
Before this PR:
With this PR: