I’m new to arduino and have only basic knowledge in programing. I’m now deep inside a project where I have bite off way more than I can chew, and now need some help.
My project is to convert an “old” electronic piano (Yamaha CP25) to play MIDI by an Arduino Uno Rev.3 with a “Musical Instrument Shield”. SparkFun Music Instrument Shield - DEV-10587 - SparkFun Electronics
So far I have managed to break out and convert the signal inside the piano into digital signals.
The 5 signal I getting out from the piano is ordered like this:
SY: Synchronization signal. Pulse positive 1us every 48us to sync all the signals (us=microsec.)
KC1/KC2/KC3/KC4: These simultaneously sends a 4-bit key code every 1us that contain all the information needed. 3 nibbles (=3us) is needed to represent a happening (for example a key is pressed down).
See http://ebookbrowse.com/yamaha-cp-35-service-manual-pdf-d426696899 page 14 (-15-)
1: I read that “Each machine instruction requires one clock cycle at 16MHz”. Does that mean I can write approx. 15 instructions in between every 1us reading? Is there any way to know now exactly how many machine instruction a specific loop takes? I gess I can put in a write to LedPin and measure the loop whith my osiloscope, or is it possible to compile the code into machine code and just look at it?
2: I know I probably need to prescale the arduino timer to get a higher resolution, but how will this affect the rest of the code, and how will it work with the MIDI serial protocol that operates at 31,250 bits per second? Or is there a better way getting the 1us sampling? Do I set booth the baud rate and the prescaler in the setup code?
3: This is how I think the program should be built up, but sins my lack of knowledge/ experience I would really appreciate some input on this, and maybe even get a better suggestion on how to structure the code.
Setup Prescale to 0.5us resolution Set MIDI baud rate: 31250 (for output onley?) Sync arduino clock to SY-signal loop if (SYpin == HIGH) Wait for SY-signal to trigger for (int i=0; i=16; ++1) Loop 16times (16*3=48us). for (int j=0; j=3; ++1) Loops for 3nibbles (3us) PORTD* Read KC1-4 simultaneously every 1us nop(delay) To make the for loop take 1us If.. else.. Some code to translate PORTDs data into MIDI-signal Write Send MIDI-command to shield
*Will the PORTD overwrite its own data every time it’s reading new values, or is there a way to avoid this?
Or is this code better sense it minimize the code in between the readings and avoid PORTD overwriting its data.
Setup Prescale to 0.5us resolution Set MIDI baud rate: 31250 Sync arduino clock to SY-signal loop if (SYpin == HIGH) Wait for SY-signal to trigger for (int i=0; i=16; ++1) Loop 16times (16*3=48us). PORTD Read the 1:th nibble If.. (translate) prepare MIDI code Store nop(delay) PORTD Read the 2:nd nibble If.. (translate) prepare MIDI code Store nop(delay) PORTD Read the 3:d nibble If.. (translate) prepare MIDI code Store Write Send MIDI-command to shield nop(delay)