Can I make midi music with a PIC16F873a


Closed Thread
Results 1 to 14 of 14
  1. #1

    Exclamation Can I make midi music with a PIC16F873a

    Hi Everyone,

    I'm new here. I'm looking for a way to make music with my PIC16F873a. And I don't mean the beep beep sound, but real midisound. I have a casio synthesiser and I would like to copy a short tune into my pic, to play it over and over again. I know that I need PWM to make a "natural" sound, and I looked at some schematics for use with a little loudspeaker.

    Along with the music some lights have to flash, but that part works allready.

    Is there anyone who knows how this works? I would love to hear from you.

    Thanks,
    Mathy

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Mathy Knaapen View Post
    Hi Everyone,
    I'm new here. I'm looking for a way to make music with my PIC16F873a. And I don't mean the beep beep sound, but real midisound. I have a casio synthesiser and I would like to copy a short tune into my pic, to play it over and over again. I know that I need PWM to make a "natural" sound, and I looked at some schematics for use with a little loudspeaker.
    Along with the music some lights have to flash, but that part works allready.
    Is there anyone who knows how this works? I would love to hear from you.
    Thanks,
    Mathy
    A) double posting isn't going to get you anywhere any faster

    B) A PIC isn't made for making music. The SOUND command in PBP works, not very well, but it works. Run this thru a decent filter on the output, and you might have something. I'd think your best bet is a melody generator IC. The first few links aren't too bad, kinda rudimentary, but they might work...
    http://www.google.com/search?num=100...y+generator+IC
    Show us some code. I'm sure we can help.
    Last edited by skimask; - 17th May 2007 at 20:53.

  3. #3


    Did you find this post helpful? Yes | No

    Default I don't have code yet

    Hi skymask,

    I'm quite new in this PIC an BASIC world. I can put some LEDs on now and that took a week for me to program. I have to learn a lot, I know....

    The sound command generates the BEEP BEEP sound on one sertain frequency. Midi is playing more notes at the same time.

    I searched a melody generator on the web. But in Holland there's no reseller for less than 1000 IC's!!! So I tought that PBP and a PCI could do the job. I want to play Brahms Lullaby for 5 minutes and fade out the music.

    And about the double posting, there are more forums. I was looking for my first posting, but could not find it back..... Yep, I know....

    There must be a way to play music with a PIC. It's just a matter of programming, right?


    Mathy

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Mathy Knaapen View Post
    There must be a way to play music with a PIC. It's just a matter of programming, right?
    Mathy
    MIDI programming with a PIC, sure...
    MIDI-like generation with a PIC only, without an external MIDI-source?
    Not without a good, relatively high speed A/D converter, and enough memory in the PIC, or attached to it, to send out to the A/D converter at a decent sampling rate to sound like decent music.
    The key here is being able to transfer in/out of the external memory and shoot the data out to the A/D converter.

    My advice...
    Break it down to the lowest level you can possibly break it down to. Sure, you can light some LEDs, can you do any PWM with them? Can you create a variable duty cycle, variable frequency output on a pin? Can you make and use an interrupt driven program (something you'll need to send out audio at a specific sample rate).

    Yes, (and this is the way I'd do it) you can record MP3 data to a file on a flash card and funnel that data thru a PIC out to a STA013 or VS1001k. But, I get the feeling that accessing flash cards and I2C control of a STA013 is a bit above your knowledge at the moment.

    And there aren't any Melody Generator's here in North Dakota either, but I can sure get them from here:
    http://www.maplin.co.uk/Search.aspx?...source=15&SD=Y
    and that's across 2,500 miles of land and Xx,xxx miles of ocean.
    Last edited by skimask; - 17th May 2007 at 21:30.

  5. #5


    Did you find this post helpful? Yes | No

    Angry

    I'll gues I'll have to buy 1000 melody generators.......

    Mathy

  6. #6
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Mathy Knaapen View Post
    I'll gues I'll have to buy 1000 melody generators.......

    Mathy
    Or you could do as suggested...learn PBP, learn the PIC, learn a bit of electronics, sprinkle in some other components, and eventually have exactly what you want, built by YOU, with YOUR name on it.
    Nothing better than that...

  7. #7
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Depending what type of sound you want to produce... but that's nothing a PIC would be able to do.

    Just record a sound you like on you computer with a decent Sound Editor software, then zoom in to see how it's made....

    PIC are way too limited for complicated and rich sound, Maybe DsPIC would be enough.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  8. #8
    Join Date
    Mar 2007
    Location
    Boston, MA USA
    Posts
    12


    Did you find this post helpful? Yes | No

    Default

    You want the PIC to send MIDI messages to control/play the casio synthesizer.

    The MIDI signal is just control data, not audio (a serial control signal that sends note value on/off and other commands).

    The signal is organized into 10 bits (start bit, 8 data bits and one stop) running at 31,250 bits per second.

    Here is a link that describes the specifications and command set for the signal:

    http://en.wikipedia.org/wiki/The_MIDI_1.0_Protocol

    I am not sure if your PIC has a UART, it could be used to produce the serial signal. Then you would need space for the storage of the song data, and a way to enter it.

  9. #9
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,807


    Did you find this post helpful? Yes | No

    Default

    Hmm, I am a little confused as to what really Mathy wants to do.

    1. Control the Casio Synthesizer with a PIC to make some music, or

    2. Reproduce the music from the PIC in whole?

    The second is a big-big project as other members described above.

    The first is easy done in software only.

    Ioannis

  10. #10
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Default One time recording or multiple

    Hi,

    If I have understood correctly then you want a custom melody to be reproduced by a standalone circuit. You would play/sequence the number on your casio keyboard.

    There is an application of a PIC playing 1bit audio available here http://members.home.nl/b.vandam/lonely/pagina47.html This may be interesting for you.

    There are OTP (One Time Programmable) Voice chip available from APLUS INC. http://www.aplusinc.com.tw I have checked their Indian website and found that a chip capable of recording about 341 seconds audio costs around $2.5 USD. They sale in low quantities too. But I have no idea if they would ship international. Beware these OTP chips may need a dedicated programmer (costs around $200 USD). Do not expect great sound quality. Because it uses a maximum of 8KHz sampling rate and uses 4bit ADPCM compression. It can also record PCM but that will reduce the playback time. These can be controlled by a PIC to playback multiple segments . I have seen one application here by charudatt who uses a PIC clock to enchant digital mantras. I am not sure if he uses one of these. But they are available in his hometown Mumbai in India. I am attaching one datasheet for your reference.

    Aplus also makes melody generators (sort of a MIDI playback engine mainly targeted as bells/ringers) . You don't get enough polyphony or rich sound due to the limited fm synthesis (May be there are some which uses a ROM table).

    There are chips from Aplus which can record/re-record audio standalone or controlled by a micro. But they are more expensive.Price is directly proportional to the maximum recording time.

    I think I have seen a post by Melanie producing tunes. Why not post your sample tune here ?! In MP3/Wave/Midi whatever.

    Please describe your application in details. May be someone from here has done before.
    Last edited by sougata; - 18th May 2007 at 08:25.
    Regards

    Sougata

  11. #11
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Default Ooops I forgot the attachment.

    Sorry guys. Here is the pdf datasheet. Its split into two parts by Winrar available from www.rarlabs.com . Remove the ".txt"

    I tried ".bak" but didn't work. I should have gone through the entire list which files are allowed by the vbulletin admin.

    You can also have look at the PICLIST here http://www.piclist.com/techref/microchip/io/audio.htm

    P.S. - Original author's site is working . http://www.romanblack.com/picsound.htm
    Attached Files Attached Files
    Last edited by sougata; - 18th May 2007 at 08:22.
    Regards

    Sougata

  12. #12
    Join Date
    May 2007
    Posts
    26


    Did you find this post helpful? Yes | No

    Wink

    Quote Originally Posted by Mathy Knaapen View Post
    I'll gues I'll have to buy 1000 melody generators.......

    Mathy

    Gotta take it one step at a time. I suggest "beep beep"ing for a little bit. Then use FREQOUT command which CAN use multiple frequencies.

    There are lots of ways of doing it, and not all of them are tooo complicated, and some of them wont cost you anything but time.

    Experiment with FREQOUT. When I have time maybe I can give you a starting point. But for now, I have got to go to work ^^

  13. #13


    Did you find this post helpful? Yes | No

    Smile Many Thanks!

    Hi Everyone,

    Thanks for the tons of input you gave on my question. I tried several of them and I'm still not to happy, but al things has to start from scrats.

    I'm going to play with the FREQOUT command to see what happens. after that I give up for a little while.

    Other question:
    normaly the speaker is on one pin and the other on VDD (or VSS depending...)
    But if I put the speaker on two pins, and invert those two pins at the same time( so 1 = + the other -), would that improve the sound quality? It's a kind of pushpulling the speakercone.... Just a wild gues.

    Mathy

  14. #14
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Mathy Knaapen View Post
    Other question:
    normaly the speaker is on one pin and the other on VDD (or VSS depending...)
    But if I put the speaker on two pins, and invert those two pins at the same time( so 1 = + the other -), would that improve the sound quality? It's a kind of pushpulling the speakercone.... Just a wild gues.
    Mathy
    It'll only be louder. A bit of info...
    A square wave is comprised of a sine wave at frequency 'X' plus all odd harmonics on either side of the primary frequency. So, a square wave is fundamentally a whole lot of frequencies all rolled up into one.
    Also, how do you get decent distortion from an electric guitar? You 'clip' the sine waves coming out of it, that is, flatten out the tops of the sine wave. What does the top of a square wave look like? Yep, flat, just like that clipped sine wave.
    So, if you listen to a pure sine wave vs. a pure square wave, the square wave will sound more R2D2-ish, and the sine wave more pleasing.

    By push-pulling a speaker vs. just pulling it...same result...crap.
    Yes, you could filter the output thru a filter network and make those square waves a bit more rounded off and resemble a sine wave. It won't be pretty, but it'll work, and it'll seem a bit louder (and more annoying).

    You still want to do what you said back in post #3? And that's it?

Similar Threads

  1. Change On Interrupt, PIC16F884
    By elec_mech in forum mel PIC BASIC Pro
    Replies: 17
    Last Post: - 14th November 2008, 17:25
  2. Midi, Interrupts and Pic better than SX28?
    By Lajko in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 27th September 2008, 00:26
  3. Replies: 3
    Last Post: - 10th April 2008, 10:02
  4. How come they make electronics hard as poss
    By George in forum Off Topic
    Replies: 9
    Last Post: - 13th July 2007, 23:54
  5. Play Music (MP3, WAV,...) for greeting card
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 10th January 2007, 15:14

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts