Sammy1Am / MoppyClassic

Moppy has been replaced with Moppy 2.0!
569 stars 190 forks source link

mbed Port #40

Closed twagler closed 9 years ago

twagler commented 10 years ago

If anyone is interested, I'll be porting this to mbed as an open library. The extra speed should allow us to clean things up a bit using a "floppy_drive" class instead of looping through ports and skipping even/odd indices.

I'll also be porting the java app to QT 5.1.1

Sammy1Am commented 10 years ago

Cool!

Out of curiosity, what are some of the major differences between using Arduino chips and mbed chips for prototyping? Obviously the ARM processor opens up more options, but development-wise are there many differences for writing code? Finding libraries?

twagler commented 10 years ago

The main reason for the port is that i have an mbed and not an Arduino, however, with the additional processing speed, RAM, ROM space, etc, we may be able to expand this project along with cleaning it up a bit. The mbed libraries are coded such that anyone with any of the mbed supported devices can use the exact same code. The home-grown, user-provided libraries also help out quite a bit when it comes to connecting to other peripherals.

The QT port is also simply because I have more experience with QT than with Java. Both are completely cross-platform and the conversation of pros/cons of Java/C++ could go on for ages.

twagler commented 10 years ago

What was the driving factor in the 40usec resolution?

Sammy1Am commented 10 years ago

I chose the Arduino and Java for much the same reasons (I got one for Christmas, and I already knew Java). If possible, it would be cool to keep the serial communications protocol the same so that users could use your QT port with an Arduino if they wanted to (or the Java app with an mbed board, but my Java app's nothing to sneeze at).

Regarding the 40usec resolution: I originally had the Arduino in a tight while(true) loop, that would just use a modulus operator on the current Arduino's microsecond tick counter and the period of the desired note(s). Obviously, depending on how long other operations took, it wouldn't always land on 0, so I basically checked that tick % noteperiod < 100 or something like that, which got me close.

There were still inconsistencies though. Especially as I started to ramp up the number of drives I was using, the drives would sort of start to move in little bursts and get really jerky, partially because the % operator was really slow. I came upon interrupts as a solution for consistent timing that still allowed the Arduino some free cycles to do stuff like read from the serial port. This also meant that rather than tracking a microsecond tick from the Arduino, I could do 40microsecond ticks more precisely.

The 40usec value was sort of arbitrarily chosen as being small enough that notes would be relatively accurate, but large enough that there's plenty of time for the Arduino to complete what it needs to between loops. It could probably be adjusted as necessary, but I don't think there's any need to make it too much smaller since the frequency would deviate at most by about 1.8% at the upper range of the floppy drives (440Hz). That's enough to sound a little bit out of tune, but floppy drives are not exactly precision musical instruments to start with. =P

I did make it a variable in the code so it could be adjusted though.

twagler commented 10 years ago

Fair enough. I don't have an Arduino, nor do I know much about their limits, however, if you speed up that baud rate a bit to say 115200, you'll be spending a lot less time in the UART reading. I tested the resolution at settings of 20 and 10. I couldn't perceive a difference. Back to 40 it is.

The mbed port is working completely now with the java application (other than the reset command. Haven't fiddled with it yet) I planned on making everything cross compatible so one could use a the QT app with Arduino or the Java app with the mbed just as you said above. I'll keep you updated.

AmEv7Fam commented 10 years ago

Now, to get the Android port done... haha...

twagler commented 10 years ago

Actually with Qt 5.2 all i have to do is change the target to Android. I'm working on writing a MIDI parser from scratch right now. I believe there's a few of them written in C++ out there, but it's more of a learning experience anyway.

Sammy1Am commented 9 years ago

I'm closing this issue as it's not really an "issue" so to speak. Feel free to continue to use this area to comment and discuss the ports though.