MIDI and PICAXE again

oldjoe

Member
It would be nice to use the hser port on the X1 PICAXE for MIDI.

MIDI spec specifies a baud rate clock of 31.250+/-10% Kbaud, but 28.8 Kbaud is within +/-10%, so is 34Kbaud. Both the old PC and the Atari 800 spoke MIDI quite well and their UART could not do 31.250Kbaud?

An even bigger problem is the hser ports lack of a Start Bit, at least that is how it looks to me when I read Part 2 of the PICAXE User's Manual. There does not seem to be a way to set a Start Bit, nor set the number of Stop Bits, nor set any kind of Parity Bit, is something wrong with this UART?

Next, there needs to be a PICAXE Timer set up as a MIDI Clock, This has to be a programmable very low speed clock that can have its value changed in real time. The MIDI Clock has 24 pulses per Quarter Note, the number of Quarter notes per minute varies with Tempo. I have seen real music with Tempo as low as 30 and as high as 254, mostly Tempo stays around 74 to 96 and does not change for a whole song, but sometimes it does change. One of the reasons for MIDI Clock is when there are more than one instrument playing at a time, the "Note ON" command all need to come out during the same down beat.

Has anyone solved these problems?

I have found hippy's MIDI Music Box and it is a good starting point
"http://homepage.ntlworld.com/the.happy.hippy/picaxe/midiuart.txt"[!url] Can anyone provide me with URLs that are useful further reading? ********** UPDATE I just checked the ARATI 800. The Atari has been doing MIDI quite well since 1981 and the 800 is a 8-bit micro with a 4MHz system clock. The Midi doesn not go through the UART on the Atari, it goes in the high speed serial bus that connects to the Floppy Drives and the Printer, the circuit looks like a "bit-banger". UPDATE I have checked the studio PC and again the MIDI does not go through the serial port. The PC's MIDI goes through the joystick port. UPDATE, it looks like MIDI OUT is not a problem at 28.8Kbaud and it is possible from all these serial ports, it is the MIDI IN that is the problem! If the UART can not capture the incomming baud, then MIDI can not use the UART and one has to go to the "bit-banger" technique to do MIDI. oldjoe
 
Last edited:

oldjoe

Member
Update to using hser for MIDI

This is an update to my previsous post. This thread should be for using MIDI on the PICAXE especially using hser UART for MIDI.

I have a great interest in MIDI and anyone that wants to talk MIDI or music or music history or wooden music instrument building please e-mai me direcly.

I my PICAXE design is based on the PICAXE-40X1, see attached photo, this photo is jpg and 400Kbytes. I have checked the PIC 16F887 data sheet and the UART in the PIC will do 28.800Kbaud and can have all the Start-bit and Stop-bit and Parity-bit correct for MIDI!!! So there is no reason that the PICAXE-40X1 can not do MIDI OUT using hser or pins 24 and 25; one just has to use POKE to the 16F887 registers to set up the UART. Now I am looking at the problem of MIDI IN, for the 16F887 UART to frame the incomming baud, now that is the problem. hippy, if you read this I could use some help in POKEing to the PIC registers.

So anyone that has URLs that I could use don't hesitate to send them to me.

Thanks
oldjoe
bigjoe@valp.net
:eek:
Hope the photo stays attached!
 

Attachments

hippy

Ex-Staff (retired)
According to my official MIDI 1.0 Spec ( a genuine copy !!! ) that states 31.250kHz +/-1%

Once one gets to +/-6% the physical chip hardware starts mis-reading data.

The 16F887 should be able to do 32.250kHz, the 18X can because I've had that working. I'm a bit tied up at present but wil come back to you. In the meantime, read up on the SBRG register etc.
 

oldjoe

Member
:eek::eek: I am really bummed out to have misred the MIDI Spec.

When I read the MIDI Spec, I thought I read +/- 10% on the baud rate clock frequency. I get embarrassed when I mis-read a Spec.

Now after hippy pointed it out to me I went back and could not find anywhere it said +/- 10%, but did find page one of part 2 where it said 31,250 +/- 1% baud. 10 bits to the baud, with the byte between a Start and a Stop bit. The byte upside down and backwards :D

This is going to make me rethink my MIDI Project.

oldjoe
 

oldjoe

Member
Solving design problems for PICAXE and MIDI

Thanks hippy; thanks Technical.

Technical I appreciate the URL to the set-up for hsersetup. But now you should add these words to the Revolation PICAXE User Manual Section 2, page 62!!!

The biggie is the equation:

Desired Baud Rate = Fosc / (4(n+1))

So for the baud of 31.250 +/- 1% Kbaud required by the MIDI UART, the value of n=31 works exactly. n=31 -> 31.250kbaud :D

BTW, a little more on the use of: scratchpad , hserptr and hserflag would be a big help in the Tutorial.

I am still confused :confused: about using hsersetup!!!
On the User Manual page 62, it gives a list of bauds that are stored in the BASIC Editor/Compiler, but does not atate that the Compiler will take more values. Some of the baud values have B in front and some have T in front and some have no prefix at all! To me a B in front means convert to binary, I do not know what T signifies, but I assume that no prefix means don't conver to anything?

So I tried:
Code:
 hsersetup 31,0 'set hser to 31.250kbaud [!code]

and the Compiler took it and it seemed to do all right.

Next I have to work out the mode part of hsersetup to get the inversions and start and stop bits right!!!:eek:

Then this will finish one of the 2 clocks that I need to do MIDI on the PICAXE.

********

The part of MIDI that I am working on now is the baud clock and the MIDI clock.

********

This is the first hardware paragraph of page 1 of Section 2 of the MIDI Spec:
quote spec:
"The hardware MIDI interface operates at 31.25 (+/-1%) Kbaud asynchronus, with a start bit, 8 data bits (D0 to D7), and a stop bit.  This makes a total of 10 bits for a period of 320 microseconds per serial byte.  The start bit is a logical 0 (current on) and the stop bit is a logical 1 (current off).  Bytes are sent LSB first."

The last 2 sentences is why I say these bytes are upside-down and backwards :)

OK, PICAXE hsersetup value "mode" and the number of inverters in the hardware have to work together.  For my MIDI interface I use the schematic given on page 2 of section 2 of the MIDI Spec.  Anyone want me to post a copy just ask!!  Anyway my inverter is an 74HC04, so there are 6 inverters that can be used, right now I am only using 2.  Both the receive and transmit leg has to have the same number of inverters, but I have not decided how many that is.

I thought about using hserptr compared to a value to determain when to dump the scratchpad to external EEPROM, but this is not a good idea.  It is a better idea to creat a clock out of PIC Timer 0 and make this the MIDI Clock.  Every so many MIDI Clock pulses, reset the pointer and dump the scratchpad memory to external memory.

The MIDI Clock is reather Very Low Frequency.  Also the MIDI Clock is 24 clock pulses to a quarter note.  This causes a problem, as the period of a quarter note is a variable.  The MIDI Tempo Statement (Tempo is in the MIDI System Message), so the PICAXE has to be able to read the MIDI Messages as well as Receive and Transmit them.  Tempo states how many quarter notes per minute.  There is also a time signature involved, time is how many beats per measure and what note duration a beat is based on.

So my Receive code is to check hserptr and make sure it does not get to 127and if it does then dump scratch pad anyway, else wait for MIDI Clock to be at the start of a beat and then send a flag to external memory and following this flag with the contents of scratchpad.  If there is nothing in scratchpad, send the flag anyway and advance the pointers to be ready for the next chunck of data.

Hopefully the MIDI stream will be recorded in the exteranl EEPROM from which it can be clocked back to the hserout at temp with the MIDI Clock.

oldjoe
 

Technical

Technical Support
Staff member
On the User Manual page 62, it gives a list of bauds that are stored in the BASIC Editor/Compiler, but does not atate that the Compiler will take more values. Some of the baud values have B in front and some have T in front and some have no prefix at all!
Only b baud rates should be used with hsersetup. T and N baud rates are for serin/serout, which have completely different operation. b just stands for baud! Each bxxxx number is just a predefined constant for user convenience, you can also enter a number directly, as from your calculation.

with a start bit, 8 data bits (D0 to D7), and a stop bit. This makes a total of 10 bits for a period of 320 microseconds per serial byte. The start bit is a logical 0 (current on) and the stop bit is a logical 1 (current off). Bytes are sent LSB first.
This is normal 'true' RS232 - see section 4 of
http://www.beyondlogic.org/serial/serial1.htm

As the PICAXE also works with true data leave bit1 of mode as 0. And don't use any inverters in the hardware (or use two invertors to invert and then invert back again!). The following link shows some easy MIDI to (opto isolator)/from (two resistors) PIC interface circuits which can also be used with PICAXE.
http://tomscarff.tripod.com/
 
Last edited:

oldjoe

Member
One of the MIDI Clocks finished

Hi hippy, Hi technical, Hi anyother PICAXE fans that are interested in MIDI.

BTW technical, when is the BASIC Compiler/Editor going to be updated for the PICAXE-40X1?

Well one part of the PICAXE to MIDI design is now finished: the baud rate clock for use of hser for MIDI.

add
Code:
 hsersetup 31,0 'baus clock setup for 31.250Kbaud for MIDI [!code]  to initialization part of your MIDI program, also use the attached schematic and per technical's suggestion use either zero or an even number of inverters in both the receive and transmitter leg.

This finishes the first part of the MIDI design.

******
Now the part that is more music than programming
*******

What I have:
1) a studio
2) two MIDI Keyboards with built in Synthizers
3) three Sequencers; a Atari 800, a 486PC running Windows 95 and Print Music, and a Pentium III PC running Windows XP and Allegro.
4) a good amp and good speakers.

What I need for this part of the design is a clock to get the notes out on the beat.

What I can do is use the Sequencer to create a MIDI file with only one message in it and send it to the PICAXE and use the BASIC Compiler/Editor to look at what the PICAXE does.

I do not know right now what I want as far as the next clock.

I can create a one message file that only has the System/Program Change Message to set Tempo to 120, I can follow this through my code and see if it gets back to the Sequencer intack.

I can also create a one message MIDI file with only the Time Signature in it and do the same.

Now I still assume that the bytes in the scratch pad memory will be "up-sidedown and backwards" but I can still parse them to recover Tempo and Time Signature Data and store the 3 results in 3 variables.

The Tempo Clock will be very low frequency from about 10 cycles to 100 cycles per second, it has to be a variable clock with the clock divider a variable set by Tempo.  I will read Tempo, Tempo is how many quarter notes per minute, I will divide by 60 to get pulses per second and then multiply by 24 to get the number of MIDI clocks per second. 

The Beat Clock most likely will be a counter that will count MIDI Clock pulses and the clock dividers will come from the Time Signature: how many beats per measure and what note counts as a beat.

When I get a hserflag, I will do a compair on the latest byte in the Scratch Pad memory, if it is a Program Change Message I will further parse to see it it is for Tempo or Time.

When one of the Clocks times out, I will write a flag, most likely $FF to the external EEPROM and then dump all the bytes from Scratch Pad to external EEPROM.  When I play back I will dump all bytes from external EEPROM to hser transmit buffer until I reach the next $FF at which point I will stop sending to transmit buffer.  Also it is possible that there will be times that $FF will be encountered with no bytes to transmit.

Anyway the Interface Circuit is attached.  I am using 2 Inverters in each leg for buffering.

oldjoe
 
Last edited:

hippy

Ex-Staff (retired)
One problem you're going to have with using I2C Eeprom is the time it takes to write data; 5ms. 24 clock ticks at 60bpm is one clock tick every 40ms so that gives just 35ms to do everything in. The second problem is that if you update the Eeprom too often you're going to wear it out quite quickly. They usually have a nominal lifetime of 1,000,000 writes, but at one write per second it could be dead in a fortnight.
 

oldjoe

Member
MIDI INterface Schematic .....

Well the schematic got attached, but as a .jpg it is kinda poor.

For anyone that can go to http://www.expresspcb.com and download their free CAD program I will post a better copy of the MIDI Interface Schematic. But it can only be read by expresspcb's CAD program.

Bummer, once again the Forum will not let me upload the schematic, so you are going to have to e-mail me if you want a better copy:bigjoe@valp.net I will attach a copy and reply back to you.

See you

oldjoe
 

Mycroft2152

Senior Member
Well the schematic got attached, but as a .jpg it is kinda poor.

For anyone that can go to http://www.expresspcb.com and download their free CAD program I will post a better copy of the MIDI Interface Schematic. But it can only be read by expresspcb's CAD program.

Bummer, once again the Forum will not let me upload the schematic, so you are going to have to e-mail me if you want a better copy:bigjoe@valp.net I will attach a copy and reply back to you.

See you

oldjoe
OJ,

The trick to get "non-approved" formats posted on the forum is to manually change the extension to ".txt" and include a note to change them back io view.

For example myboard.pcb becomes myboard.txt

Myc
 

oldjoe

Member
PICAXE and MIDI again, trying to post the schematic of the PICAXE to MIDI Interface

Hi hippy, Hi technical, Hi Texy and all PICAXE owners that are interested in MIDI

Texy, sorry on the attachment, sometimes the Forum will not let me attach, I will try again!

hippy, I will try to address your concerns in this post.

For the PICAXE owners that haven't used MIDI yet, this is how I do it:

1. The keyboards are my main input devices, both keyboards are polyphonic/multi-timberal, that is they can sound like a lot of different instruments at the same time.

2. I play on the keyboard to get music into the MIDI program fastest and easiest. The MIDI OUT of the keyboard connects to the MIDI IN of the Sequencer. In my case, the Sequencer is most often the PC that is running the Print Music program.

3. The MIDI OUT of the PC connects to the MIDI IN of the keyboard and I can use the Sequencer to Record and Playback the MIDI file, and I do.

4. I listen and use the Sequencer to edit the music until I get it how I want it.

5. So with all this working, why do I want to fool with a PICAXE to do the same thing? :D Simple the studio gear is too big, too heavy and too many cables to take to a Proformance.

6. I want to put my Play List in the PICAXE. I want to put my back-up in the EEPROM.

7. When I succeed in attaching the schematic for my MIDI Interface Board, you will see. In addition to whats on this schematic, I have 3 NO Pushbuttons and 6 LED. Why 3 PB? Because that is the most I can package, my Circuit Boards are 3.8 X 2.5 inches. A bunch of post earlier, I posted a picture of my PICAXE Board.

8. The first PB is marked Record/Play, the second is marked Pause/Continue and the third PB is marked Stop/Start. At 3.8 by 2.5, I can easily get the two boards into a Foot Switch.

9. The Foot Switch contacts connect to the Pause PB, the MIDI out of the MIDI Interface Board is cabled to the keyboard MIDI IN and the Audio Out of the keyboard connects to the house amp.

10. Now I can set up with no more than carrying my Harp, the keyboard and I can have the footswitch in my pocket and the MIDI Cable and Mic Cable over my sholder.

So back at the studio, I spend hours getting my playlist recorded and edited with all the back-up just the way I want it; then I turn on my PICAXE with my MIDI software running and pulse the record/playback PB until the Record LED comes ON; next I pulse the Stop/Start PB until the Start LED comes on; finally I reach over to the Sequencer and push Play. So an hour later all the songs have been downloaded to the EEPROMs.

OK, Can the PICAXE at 4MHz do the work fast enough? I do not know, but if it can't then I will use setfreq to go to 8MHz or 16MHz, I am using a PICAXE-40X1.

How about the EEPROM, will they be worn-out? I don't know yet. In MIDI speak the burst of bytes is called a Chunk. Before the music starts there is a chunk of about 10 bytes that are the System messages and Program Change messages that sets up the Synthizer. Then on the first Beat there is about 10 bytes of "Note-On" command bytes.

Right now I am still experimenting and do not know the answers yet, but I am leaning toware doing the PICAXE software this way: in the initialization set Tempo equat to 120, Beat per measure equal to 4 and Note to count as a Beat equal to 4. Also set up the baud clock with hsersetup 31,0 . Then go to the branch that leads to either the Record or Playback code. In Record everytime there is a hserflag, check the byte to see if it is changing Temp or Time Signature (most often NOT, lot of songs do not make any changes once they start). When the Start PB is pressed, clear all pointers and turn on the UART to the MIDI stream. Now each MIDI Clock, write $FF to the EEPROM, advance pointer and then start dumping whatever is in the Scratch Pad Memory, maybe as much as 10 bytes, then sometime nothing, then wait for next MIDI Clock pulse, continue for a long time until the Stop PB is pressed at which time the code stops writing to the EEPROM. Now if each song goes for 3.5 minutes on average and there are 3 instruments playing: a harp, a lute and either a budoram, flute or mandolin; how many bytes of Note-On and Note-Off is this? The good part is if I get it right, then I can save the EEPROM and use it over and over again, as it will keep my recording.

Still cannot get the schematic to attach correctly. I guess that anyone that wants it to just e-mail me an I will e-mail them back with the schematic attached. Note that the schematic is just the one given in the MIDI Spec Section 2 on page 2, with a few additions.

hippy, BTW I did Amazing Grace last night and it took 639 bytes, a MIDI file is not very large.

oldjoe
 

oldjoe

Member
Schematic and layout for MIDI Interface Board

Hi Mycroft2152 and everyone interested in MIDI and PICAXE:D

Hopfully attached is two files that have their extensions changed to .txt Immediantly after downloading then change the first extension to .sch and the second extension to .pcb

Also you are going to have to get the CAD software to read these files from http://www.expresspcb.com the software should be free:)

OK here goes, hope it works!!!
 

Attachments

oldjoe

Member
Schematic and layout for other half of PICAXR/MIDI Project

Hi Mycroft2152 and everyone interested in MIDI and PICAXE :D

:eek: Well this is the third try to post Processor Board schematic and layout, it is the other half of the MIDI Project.

Once again you have to change the first extension to .sch and the second to .pcb and further get the CAD reader from http://www.expresspcb.com it should be for free :)

Maybe this will work, BTW I have already posted a photo of this board board is 3.8 " by 2.5 " and if anyone wants a parts list just ask.
 

Attachments

Wrenow

Senior Member
I, too, am terribly interested in MIDI, and have been cogitating the best solution(s) for my particular issue(s), in case you have already dealt with it and have ready solution(s).

At our church, we have an organ with a MIDI interface. I have several hundred MIDI files in my repertoire (keyed in, note by note, with mouse clicks from the sheet music - if I could read music, it would have gone far faster ;-) ) that I can put on floppy disks and play on the organ through a floppy to MIDI interface, but it has a high latency on startup, and screws up timing if you are not extremely careful. A couple of things I would like to do to make things easier for others to pinch-hit:

1) A box with the 5 or 6 pieces of standard service music that you just press one button for (a button for each selection and an emergency stop button to cancel). As in, you press the "Gloria" button, and the Gloria begins playing. This should be pretty easy with a Picaxe, methinks, but I have not gotten around to cobbling it together. Thus I am watching this particular discussion with great interest. Being able to access the songs from an SD card would be a plus, but is not required.

2) One where you can pick from a list, a la an Ipod or Zune. Sadly I have not found a media player that offers MIDI output (you would think that Creative, which is big into MIDI and media players would include this). There is a Palm-based solution, the IttiMIDI, but it is not quite what I am looking for, but the ASUS EEEPC line is starting to look interesting for this application.

What would be really nice is to be able to set up a playlist for the day's music so that the operator just has to hit Play at the appropriate time, but to be able to break out of the playlist to the master list for another selection (so, in case communion runs long, for instance, you can drop in another background piece, like and Ave Maria or Panis Angelicus).

By the way, a little rural church of about 25 families at best. Not a lot of tech depth here, many more near luddites when it comes to technical stuff. :-D

Cheers,

Wreno
 
Last edited:

oldjoe

Member
Reply to Wrenow MIDI request

Hi Wrenow and anyother PICAXE users that is interested in MIDI

Have you been successful in getting to http://www.expresspcb.com ?

Now can you get into http://www.finalemusic.com ?

Did you read the two posts where I stated how I use MID?

OK, the project that I have described will give you what you have asked for :D

If you make a MIDI Recorder, whatever you record will come back each time you push the "continue" button on my MIDI Recorder. You will still need a Synthizer to change the MID into music, but a $100 MIDI Keyboard from Radio Shack can do this quite well. Or maybe your Church Organ has the Synthizer built into it's MIDI Interface.

So this only leaves, the need for a better way to get the MIDI into the PICAXE.

Now there are lots of copies of the "PICAXE EEPROM Memory Expansion Project". The software for this Project from David Lincoln's book Programming and Customizing the PICAXE is my starting place. On my Enhanced Processor Board, see prior post ;), I have eight DIP Sockets for these EEPROMs. Each socket is already hard wired with the right address, so that up to 8 EEPROMs can be uniquely addresses, this gives lot of memory for MIDI things, and BTW I did measure that 20 bars of Amazing Grace only took 639 bytes of MIDI, including the triplets :D So the better way is a MIDI software program! Do you have a PC that can run MS Windows 98 or XP? If you do, then go to the Finale web site and download Note Pad, it is a free MIDI Program. ( I like the Finale stuff better than Cakewalk).

Note Pad is easy to use and if you buy a MIDI Keyboard for the Synthizer, then you will also have the MIDI Keys or if you can get a PC to your Church Organ, you can use the Organ's keyboard, let me know what you will find the most easy to do.

Anyway buy a MIDI Interface for your PC. The MIDI Interface goes for about$25 new and cheaper on e-Bay. It plugs into the PC's joystick connector.

When you download Note Pad, be sure to registerwith Finale!!! This is a Big Deal, because you want them to send you their e-mail!!! The next upgrades to the Finale MIDI Software line is tooooooo expensive for the Hobbyest, well there is a Music Teacher's Discount, but the best deal is to wait until around Christmas time when Finale does a big discount for "upgrades". So for a price that is reasonable for the hobbyest, on can upgrade Note Pad to the next level; which is Print Music. A year later, you can up grade Print Music to Allegro!! There is one higher level, but I haven't even got there yet myself.

Anyway right now, I sit down on the MIDI Keyboard and play. It all goes into the PC via the MIDI Interface and the PC using Print Music, does: 1) turns it into sheet music score; 2) saves it as a .mus file; and 3) saves it as a .mid file. Also any time I want, I can play these files back. Any time I want I can record these files to a CD that I can play back on any CD player.

I will post my software for my MIDI Recorder, the core of this software is the I2C EEPROM Memory Expansion Project that is in many books and the PICAXE User's Manual. Be advised that this software is still "a work in progress".

Wrenow, reply and let me know how you are doing on your MIDI Project.

oldjoe
 

Wrenow

Senior Member
Right now, I am primarily cogitating and lurking/waiting on several projects. One attractive implementation (using a different microprocessor) is the http://www.sdmidicontroller.com/default.htm, which is an offshoot of this open-source project - http://www.lehmayr.de/e_mrmidi.htm. Sadly, in C and for Atmel. Still considering getting the kit and building one, but it is a tad pricey with the current exchange rates. I have considered asking a friend with C and circuit board experience if he would be interested in helping me cobble it together, but I am a bit swamped with a wedding in a few weeks and two other major events the next month to prepare for.

I have also suggested to Creative that they add a MIDI output interface to their Zune series (seems it should be a pretty easy thing for them since they already do a lot of MIDI stuff).

Cheers,

Wreno
 

oldjoe

Member
Answer to Wrenow and the posting of improved schematic for MIDI Interface

Hi Wrenow and any other PICAXE ouwner interested in MIDI

Yep, I looked at the URL that you posted, impressive and a polished product but kinda expensive.

My approach is different but can cover all the same features at half the price.

In my case, no display except for 6 status LED's.

I require 2 boards about 2-1/2 X 2-1/2 inches, the first board cost about $40 to make with some soldering that is right up there for a hobbyest with a pencile iron and the second board is wire-wrapped and will only last about 10 years.

:D But mostly my design is just a MIDI Recorder Design. I plan to use it like I said on prior posts. I do all the controller and composing functions elsewhere on other equipment, and if the cost of the PC is already sunk, then no more than another $25 to get the rest of the functions.

Another shortcomming of my design is it is not finished yet, still a work in progress. I am still changing the design.

But one advantage of my design is it uses the PICAXE and the PICAXE's BASIC Compiler.

So I am uploading a revision to the MIDI Interface Schematic, once again you have to change the extension from .dsn to .sch and use the Express PCB CAD Program to view it. Up to Rev B now for the Interface Board.

BTW, I would like to do a MIDI Synthizer Board, but I do not know where to get a MIDI Wave Table ROM.

oldjoe
 

Attachments

oldjoe

Member
Start of Software for the MIDI Recorder Project

HI all PICAXE owners that are interested in MIDI

OK I am putting together the software "boiler plate" for the MIDI Recorder Project, it uses the I2C Memory Expansion code from David Lincoln's book Programming and Customizing the PICAXE page 297, as its starting point.

I am using the Revolation PICAXE BASIC Compiler to enter and test code.

My pholosophy is to write a few lines of code then use the Compiler to check for errors. If everything compiles OK and the Simulation RUNs and I get expected results, then I write a few more lines of code.

HI Technical ... when is the BASIC Compiler going to have a PICAXE-40 radio button? :D

Now my environemnt is the PICAXE-40X1 and I an using the PICAXE-28X1 radio button on the Compiler/Simulator for testing. I note that the PICAXE that the original memory expansion code was written for is not compatable with the 28X1, This is about as simple software code as it is going to get, future releases will get more complicated fast.

Anyway here is the start of the software:

oldjoe
 

Attachments

Last edited:

oldjoe

Member
Next level of Software aned request for help

:eek: help technical help :eek:

I am reading the PICAXE User's Manual, the PIC 16F887 Data Sheet and David Lincoln's Book as fast as I can and I need help because I am not finding what I need.

Also this is another post of Software, the "Boiler Plate" is a little more fleshed out.

My environment is the PICAXE-40X1, I am using Revolation's BASIC Compiler.

Question: is it hserinflag and hserinptr or hserflag and hserptr?

ASSUMPTION/Question: the hserinflag occures when a new byte is received by the hser-UART?

ASSUMPTION/Question: the hserinptr occures when a new byte is received by the hser-UART and it points to the address of this new byte? If I use hserinptr, it does not reset the memory pointer like using hserin? There seems to be a lack of User Manual information of how to use this function.

Question: how many interrupts can one use with the PICAXE-40X1? What is the syntax, also see how I used interrupt in my attached code. Can I use the "do not care" operator?

Question: can I use hserinflag as a interrupt? What is the syntax?

For the rest of the PICAXE owners and thoes interested in MIDI:

here is todays' copy of the Software "Boiler Plate"; notice it is a little more filled out than yesterdays. This code is free of syntax errors, will Compile and Run. It is just not there yet, I would like to be able to use 5 Interrupts if it is possible.

oldjoe
 

Attachments

Technical

Technical Support
Staff member
hserinflag and hserptr
This is historical and, we admit, a bit confusing! The next release of the compilers will support both hserinptr and hserptr etc.

yes - the hserinflag occurs when a new background byte is received

hserptr is a pointer (to the scratchpad), it does not 'occur'. When you use the hsersetup command the pointer is reset to 0. Every time a byte is received the pointer increments to the next scratchpad address.

This means hserptr value is three things:
1) The total number of bytes already received.
2) The next address that will be written to when the next byte is received
3) 1 more than the last address written to.

1 interrupt, called 'interrupt:'
 

oldjoe

Member
Thank you technical and help me again, more questions.

Thanks technical, I appreciate your answers :D


Question: can I use hserinflag to trigger an interrupt? Can anything trigger an interrupt on a PICAXE, besides a pin going HIGH or LOW?

Question: what is the syntax to transfer the number in hserptr to a variable, say like w6? Just use an equal sign? I take it that hserptr is a word. I am not finding much infoabout the Scratch Pad Memory, can I use hserptr to PEEK its contents?


Reason is that I have only 300 microseconds to compare (and parse if necessary) the incomming byte, if it is a Program Change Command changing TEMPO, so I want to do this in a ISR.

Question: I want to use Timer1 to make a clock that has the Range of 15 to 120 Hertz, do you think this is possible? Also, I need to change the frequency of this clock on the fly. Can I use Timer1 overflow to do anything? Using the BASIC Compiler? Syntax?

oldjoe
 
Last edited:

Technical

Technical Support
Staff member
Yes, hserinflag can trigger the interupt. Use setintflags command.

hserptr is a word value, but can only contain the number 0-127 (the scratchpad on X1 is 128 bytes) and hence can be treated as a byte on the X1 parts.

It can be used as any other variable e.g. let w6 = hserptr

To access the actual scratchpad data (remember hserptr is a pointer, not the actual data) use get/put or @ptr,@ptrinc,@ptrdec)

This will get you the last byte received into b2 and then reset the pointer:
b6 = hserptr - 1
get b6,b2
hserptr = 0

300us is probably too small a time to do much processing.

By clock do you mean a pulsing output pin?
 

oldjoe

Member
Thanks to technical again

Thanks technical :D

technical wrote:

This will get you the last byte received into b2 and then reset the pointer:
b6 = hserptr - 1
get b6,b2
hserptr = 0

300us is probably too small a time to do much processing.

By clock do you mean a pulsing output pin?
OK, the first part rises another question: what is the difference between the first block of code and hserin? BTW, I want to read this byte into b2 without changing anything in the Scratch Pad Memory nor changing hserptr.

Second the 300microseconds, that is why I want a ISR with only a couple of statements in it. In the ISR, first to get the MIDI byte in b2, then second, compare b2 with a bit mask which will fail and then to enable interrupts again, and exit or return or goto main. If the bit mask passes, it appears that the only choice I have is to jump to a label, now a I do not know about the time duration to do the jump. I will have to re-think on this ISR. :(

Third, no to clock pulsing a pin. I want this Clock to be able to overflow at a 16 to 120 Hertz rate and the overflow to do something that I can make into something like a interrupt. I see how I can do it by POKEing the PIC registers and PEEKing the PIC interrupt Flag Register, I will post a longer answer and you can tell me it there is a easier way.

and thanks again, can't wait to try some of these things.
oldjoe

Ther rest of your answers were good and I have no further questions about them.
 

oldjoe

Member
Reply for technical on the MIDI Clock

:) Hi technical

This is the long answer to your question:
Code:
By clock do you mean a pulsing output pin?
short answer NO. Long answer as follows:

To me MIDI is a bursting stream of bytes and these bytes have to be put in "time bins" so that when multiple instruments play they all sound right.

These burst of bytes are called in MIDI speak CHUNKS.

The largest number of bytes in a CHUNK that I have observed so far is 17.

Most "time bins" do not have any bytes in them at all. Bytes in CHUNK=0.

50 years ago the MIDI community desided that a "time bin" of 1/24 of a quarter note was enough. "Time bin" does not have to be exact because live musicians are not on time within a few hundred milliseconds anyway!!! :eek:

SO I am going to make a MIDI Clock that is going to run at 24 times a quarter note. But a quarter note is not a CONSTANT, it is a VARIABLE!!! :eek: In music speak, Tempo states how many quarter notes per minute, and Tempo is one of the MIDI Program Change Messages.

SO if I can find the Tempo Program Change Message in the MIDI Stream, then I can recover the value of tempo! I do NOT expect more than one of these messages in the whole piece of music, but I have to look.

NOW suppose that I have extracted the value of tempo. Further suppose that I am going to use a 16-bit Timer like Timer1 for my clock. OK, I set the clock to count JIFFIES and on roll-over to set flag in the TMR1IF Register of the PIC 16F887.

FURTHER A JIFFIE can have lots of different values, but I choose it simple. I poke to T1CON Register and POKE TMR1CS=0 for fosc/4 so now the jiffie is down to 1microsecond, next I POKE T1CKPS to 11 to prescale divide by 8, so now the jiffie is down to 8 microseconds. Now, I calculate how many jiffie to preload Registers TMR1H and TMR1L to give my desired MIDI Clock. The algorythm is 312,000/tempo=number jiffie to roll-over.

I have to keep PEEKing TMR1IF for the overflow flag and when I see it, I POKE T1CON bit 0 to stop Timer1, then I move any MIDI bytes, POKE a new preload value into TMR1H and TMR1L and POKE T1CON bit 0 HIGH and wait for the next overflow.

When tempo equals 34, MIDI Clock is 13.6 Hertz, period is 73.5 milliseconds and Timer1 has to count 9187 jiffie to roll-over, when tempo is 254, MIDI Clock is 101.6 Hertz, period is 9.8 milliseconds and Timer1 has to count 1225 jiffies. These are the extreams! real music never gets here, because it sounds bad, real tempo stays around 76 to 98.

Anyway hope this clearifies what I am trying for. What help I could use from you is letting me know if there is a simpler way to use Timer1 from the Revolation BASIC Compiler.

oldjoe
 

Jeremy Leach

Senior Member
OldJoe, I'm interested in Midi myself - use it a lot but have never got down to how it works.

What I'm wondering is: Do the chunks have defined start and stop bytes? If you are just recording then why do you need to process the incoming tempo in real time? I'd have thought the only receive job to do would be to dump the data into memory as fast as possible as it's coming in. Then only on playback (at which point you could have done all sorts of processing) make sure you send the chunks at the right tempo. I'm assuming between chunks no data is sent??

I can't see how the tempo of the incoming data chunks is important as far as just storing the data is concerned. It's only on playback you need to spew out the data chunks at the right tempo(s)??

I'm probably not getting this though !
 
Last edited:

oldjoe

Member
Answer to Jeremy Leach

Hi Jeremy

As best I can tell, the baud/bytes have stop and start bits, but the CHUNKs do NOT have stop and start bytes.

So there is nothing to tell one which CHUNK any byte should belong to. That is why I am making flags or book-marks to seperate CHUNKS when I record them.

BTW, for anyone trying to make sense of what is happening in MIDI there are two ways: 1) Buy a copy (expensive) of The Complete MIDI 1.0 Detailed Specification from the MIDI Manufacturers Association; or 2) get a logic analyzer or a PC that can look at data streams and look at a MIDI Data Stream. I am doing both. I have also used my MIDI Editor to create MIDI Files with very little in them, like only the Message that Tempo is 96.

The way it looks to me is that when the Sequencer starts a MIDI Playback a CHUNK of Channel and System Messages go out, the most I have seen so far is 17 bytes, one after the other. Then the MIDI files settles down to just sending "Note ON" and "Note OFF" bytes. These bytes are tricky, the Sequencer can use a "shorthand" usualy the first nibble is the header that contains the channel address and the secomd nibble is the pitch and velocity.

On the "beat" a lot of note-ON bytes go out and then a few "time bins" later the companion note-OFF go out. There are lots of time-bins where not a single byte goes out.

Plus at any time a Program Change Message type can go out, a Program Change Message can change Tempo as well as lots of other things.

To make the music sound right, especially when more than one voice is sounding, all the notes have to be on time with each other. So during playback all the bytes have to stay in their proper CHUNK. For me to get them right, I have to put Flags or Book-Marks between CHUNKs when I record these bytes, so I can know which bytes to send as a group on Playback.

Hope this helps.

Please reply, I am getting pretty lonesome, I did not think very many PICAXE owners were interested in MIDI. Just: me, hippy, Wrenow and now you. ;)

oldjoe
 

Jeremy Leach

Senior Member
I'll have to browse up about it all - I've seen some detailed stuff out there before about midi. I know for a fact that you can get huge SysEx messages transferring all sorts of data, plus lots of data to do with pitch bend and aftertouch - which makes me think you could get a LOT more than 17 bytes per chunk.

My gut feeling here is that you're up against processing speed, and the picaxe just might not be able to do this. I'd say it's best to find this out before you put too much more effort into your design.

I like your idea though - I've started playing keyboards in a band and the thought of a small unit to playback midi tracks is appealing. Actually what I'd like is a unit that can play short sequences at the touch of a button, or keypress. So, for instance, I can be playing piano lead and then quickly press a button so I can get a synth riff playing at the same time. I've done a lot of surfing over the last couple of days - inspired by this thread - to see what's out there. There is very little that can do what I want.
 

oldjoe

Member
Second Reply to Jermy on MIDI/PICAXE

Hi Jermy

OK to answer your prior post !!!

My gut feeling here is that you're up against processing speed, and the picaxe just might not be able to do this. I'd say it's best to find this out before you put too much more effort into your design.
Know what? hippy feels the same way as you do, and maybe technical as well. I wish I knew how many clock cycles each BASIC statement took, or if I could get a listing of the Assembly code that the BACIC Compiler generated, but I have two answers for your concern that offer a ray of hope:
1) I do a full MIDI with an ATARI 800 with a 8-bit micrprocessor with a 4MHz Clock. It does it all the MIDI, lots of bytes.
2)the PICAXE-40X1 that I use has lots of capacity that I haven't tapped, I haven't moved it off of 4MHz yet, but I can do a setfreq 8m or a setfreq 16m, then recalculate the frequency dependent constants all over again. :)


that you can get huge SysEx messages transferring all sorts of data, plus lots of data to do with pitch bend and aftertouch
Jermy, you are probably right, maybe it is just that my MIDI composing uses just simple music and I am not very demanding. But my MIDI back-up files while backing me up are not big nor complex, the largest CHUNK is measured at 17 bytes and for the whole 3-1/2 minute song only 637 bytes with all the ormentation.


the thought of a small unit to playback midi tracks is appealing. Actually what I'd like is a unit that can play short sequences at the touch of a button, or keypress. So, for instance, I can be playing piano lead and then quickly press a button so I can get a synth riff playing at the same time.
yeah, yeah, yeah :D Someone finally understands!!! That I what I am after as well: SMALL two boards 2.5 by 2.8 inches that will fit into a foot pedal. PRE_RECORDRD "whatever", riffs for you , back-up for me. One of the push buttons on the MIDI Interface Board is labled: Pause Continue and it does. For my back-up I use 10 second leader between songs, if I hear 3 seconds of silence I stomp the foot switch. back-up for my whole play list is in the EEPROM. After I finish talking, I stomp the foot switch again and in a few seconds the back-up starts and I join in.

I would like to do a "Sampling" Synthizer with the PICAXE but can not figure out how yet. Why the Sampling part? Well I haven't found anyone selling a MIDI Wave Table :eek: Besides, I am a woodworker and I make all my musical instruments and some like a Lute are not part of General MIDI ;) I have read the MIDI Standard and have learned how they did it. I have enough memory on my PICAXE Processor Board to do it a lot simpling and do a Sampling of every note, my Paraguayan Harp is only 36 notes, my Gaelic Irish Harp is only 22 notes, the Lute is only 24 notes and the flute is 24 notes; I am not sure of the Booderam but it maybe only one note. Anyway this is for the far future.

I would like to do a Samplig Synthizer where I could define the pitch or frequency of each note !!!! Jermy have you ever heard of "micro tonal" ???

oldjoe
 

Jeremy Leach

Senior Member
Well, I'm with you on the requirements, it's just knowing how to deliver them ;)

Seriously though, I don't want to dampen your enthusiasm, but I think the midi idea is unlikely to be possible with a picaxe. And a sampler completely out of the question, because it would need very fast processing using very low level code.

If (and it's a bit IF) there is some chip out there that could handle the midi side of things, then perhaps there would be scope for designing a unit with a picaxe controlling the user interface / display parts.
 

oldjoe

Member
Third reply to Jermy

Hi Jermy :eek:

Yes speed is the question with the PICAXE.

Jermy wrote:
Seriously though, I don't want to dampen your enthusiasm, but I think the midi idea is unlikely to be possible with a picaxe. And a sampler completely out of the question, because it would need very fast processing using very low level code.
also in another PICAXE thread:
http://www.picaxeforum.co.uk/showthread.php?t=10458 they are descussing the PICAXE being too slow to capture a USB stream at 12 Mbit a sec.

My only answer on the MIDI at a baud every 350 microseconds ... if if my ATARI 800 running at 3.75 MHz can do all the MIDI things, then a PICAXE at 4MHz can do some of the MIDI things :) also hippy has alrady done MIDI Musicbox on the PICAXE with kinda bit banding on pin5 of a 08, his project is on his web site and in the forum archive.

I am not ready to give up on the PICAXE yet :D

I will let you know about my progress.

oldjoe
 

oldjoe

Member
Help technical help

:confused: Confused again and need help :confused:

Basically I am confused with the Revolation BASIC Conpiler use of timer and timer offset and toflag . Plus the proper syntax to POKE and PEEK a PIC Register !!! A 16F887 PIC Register, since I am using a PICAXE-40X1.


First my confusion on the PICAXE BASIC Compiler timer . In the PICAXE User's Manual it says Timer0 and also says it is a 16 bit timer and in another place it implies it is an 8-bit counter feeding a 16-bit counter.

Well I was going to make my own variable speed clock by using the PIC's Timer1 which is a 16-bit counter/timer. Also I was going to make a 8microsecond jiffy by setting PIC Timer1 clock first to fosc/4 then divide by 8. So this is the first thing I need to know is what is the proper thing to say to the PICAXE BASIC Compiler to POKE into the PIC's T1CON Register? Also, I am having a little trouble finding just what is the physical address of this T1CON Register.

I am finding the information in the User's Manual not sufficient to do what I want to do in BASIC. I would really like to stay in BASIC as the software code would be cleaner and easier to understand.

Next I need to preload the PIC's T1 Timer/Counter with the number of Jiffies that I want to count until roll-over. It should be possible as I need less than 60,000 Jiffies to do what I want to do. I just need to make sure my math statements deal with numbers between +0 and +64K, I think I can do this.

Finially I need to PEEK the PIC's interrupt flag register and clear it; so what is the BASIC Compilers syntax to PEEK a PIC Register? I can not use toflag if I an not using the PICAXE BASIC Compiler's timer. At least I do not think I can, also I am already using interrupt elsewhere in the code.




Another question: do you know of any programming trick to swap bits in a byte? I think that in a MIDI baud, the baud is shifted out LSB first and I want to parse the baud to a byte and then swap bits to get MSB first.


thanks
oldjoe
 

Jeremy Leach

Senior Member
This site might help ...

http://www.audiomulch.com/midipic/

It's got a lot of links and info about Stamps, Pics, Midi etc.

if if my ATARI 800 running at 3.75 MHz can do all the MIDI things, then a PICAXE at 4MHz can do some of the MIDI things
This isn't necessarily true OJ, because your Atari is probably using low level language to process the midi data. Picaxe Basic is a high level language with no inbuilt commands specifically designed for midi, and it's unlikely you can manipulate the data quickly enough. My guess is that any processing of incoming midi data beyond just storing it, will take too long using a picaxe. I'd love to be proved wrong, and be able to solder up your design in a months time ;)
 
Last edited:

hippy

Ex-Staff (retired)
My only answer on the MIDI at a baud every 350 microseconds ... if if my ATARI 800 running at 3.75 MHz can do all the MIDI things, then a PICAXE at 4MHz can do some of the MIDI things :) also hippy has alrady done MIDI Musicbox on the PICAXE with kinda bit banding on pin5 of a 08, his project is on his web site and in the forum archive.
As Jeremy says, although a PICAXE runs at 4MHz ( even 8MHz or 16MHz ) the PICAXE Basic program itself runs far slower. At 4MHz that's probably in the region of 40kHz, about 100 times slower.

Using HSERIN takes a load off the processor by using background hardware but there's still a considerable amount of processing which may need to be done. It then comes down to how much data comes in and how quickly you have to move it somewhere else.

Simple MIDI, especially throwing Note On and Note Off out with no real care about accurate timing is one thing, but the more it needs to do and the more accurate it needs to be the harder it gets, and that's even more critical when it comes to receiving.

DMX-512 is a similar case - That runs at 250K baud; it's entirely possible to send DMX from an 18X but impossible to receive it.

I can't say if what you're trying to achieve is possible or not but I'm sure you will gain valuable experience whichever way it goes.
 

oldjoe

Member
PICAXE?MIDI Recorder Schematic and software

Hi everyone interested in MIDI

Well this project is going and I soon hope to post in the Finished Project Thread.

BTW, I would like to be able to post more files at a time. It would make a more organized post if I could post: a photo, a schematic, a parts list and a layout. Also I would like to see more extensions were allowed, I am partial to using the free CAD program from Express PCB for my schematic (.sch) and my artwork (.pcb); also I like a formated tabular parts list (.doc). Oh well I am going to post the schematic of my MIDI Interface Board as a .dsn file and anyone that wants to look at it will have to rename it a .sch file; the software file is OK, it is a standard PICAXE BASIC Compiler file .bas

Hardware I did it in two 2.5 X 2.8 printed wiring boards. Hardware design is complete. I do not expect any further changes to hardware.

Software still a work in progress. The "boiler plate" is finished, the finished program will look the same as this one that is posted. The program flow should stay the same. I still have polishing left to do. The program is small 383 bytes of 4096 and fast. I did not use anything other than what is in the PICAXE User's Manual.

BTW, I like the Revolation PICAXE BASIC Compiler, I find it easy to use.

oldjoe
 

Attachments

oldjoe

Member
Complain Something did not work right on the Relolation PICAXE BASIC Editor/Compiler/

Hi technical :mad:

Need help.

I finally found something in the PICAXE BASIC Editor/Compiler?Simulator that did not work right.

In trying for a simple and concise program statement to convert the MIDI Byte that is upside-down and Backwards into a binary byte that I can use in a calculation, I used the following subroutine code:


Code:
convert_byte: 'this sub is only called from main_branch4 and requires that temp contain the MIDI tempo byte
' the MIDI byte to be converted is upside down and backwards, When done put converted value in tempo,
' nothing else.
tempo = ~ tempo        'take the ones compliment of tempo, make it upsidedown
tempo = tempo rev 8    'reverse bit order, make it backwards.
if tempo < 34 then gosub fix_low_tempo  'look at using MAX and MIN for this.
if tempo >254 then gosub fix_hi_tempo
return                        'return tempo with the right value in it for calculations
Acording to Revolation PICAXE Users Manual Section 2; pages 19 and 21 it should have worked. :eek: but it did not. The INV and REV function did not work.

OH well, I have an algorythm for INV and can use that; but REV needs something, I have forgotten the trick for REV and was looking forward to the BASIC Compilers routine doing it for me.

oldjoe
 

Jeremy Leach

Senior Member
OJ, if you are manipulating bytes the fastest method might be to use a lookup for all 256 possibilities. For instance Read b0,b0 to translate b0. It's just an idea and I know it's wasteful of memory - but it might improve speed (not sure though how speed of read compares to executing maths functions).
 

oldjoe

Member
Thanks Jeremy

Hi Jeremy, thanks :)

I will use your suggestion, I have plenty of unused PICAXE Memory, so memory use is not a problem.

My first hope is that technical will come to the rescue :D

MY bigger hope is that the folks at Revolation will fix the PICAXE BASIC Editor/Programmer/Simulator software, so it will properly take REV and INV, I can hope because I read in the PICAXE Users Manual :eek: that the PICAXE -X1 will do these things.

oldjoe
 
Top