Beginning with microcontrollers

Thread Starter

MusicTech

Joined Apr 4, 2008
144
Hello, I am working on a keyboard (The musical kind) to embed into a piano belt. I was considering just using a simple 555/opamp circuit with buttons and resistors in parallel, but I figured a microcontroller would be better to avoid all the wiry messes of resistors. I decided to first write the program in a basic C as an outline for what the MCU program will look like. I figured it would save me thinking time when I get all my supplies. So I just have a couple questions:

1. What is the function and it's library for generating a tone in C (not ++)? I've looked on countless pages and can't find anything to generate a tone at x hertz. Also, is there a way to specify a type of wave?

2. What is the best Freeware (for mac) for programming, compiling and sending programs to the MCU.

3. Anybody know of the cheapest AVR connections, I believe they're called, to connect the MCU to a USB port? Or even an alternative, such as how to build a decent one yourself or a place where you could borrow one?

Thanks a lot!!!! in advance
 

roddefig

Joined Apr 29, 2008
149
1. What is the function and it's library for generating a tone in C (not ++)? I've looked on countless pages and can't find anything to generate a tone at x hertz. Also, is there a way to specify a type of wave?
The function would be hardware dependent so I don't believe there is one in the standard library. I would use pulse width modulation to create your tone.

2. What is the best Freeware (for mac) for programming, compiling and sending programs to the MCU.
avr-gcc appears to work on Macs. This page looks good but hasn't been updated in four years. Are you familiar with compiling software?

3. Anybody know of the cheapest AVR connections, I believe they're called, to connect the MCU to a USB port? Or even an alternative, such as how to build a decent one yourself or a place where you could borrow one?
What do you want this connection to do?
 

Thread Starter

MusicTech

Joined Apr 4, 2008
144
1. Well, what about the sound function? I was trying to use that, but I couldn't find the library it was in. I imagine it would probably have a default to whatever you've got, built in speakers, in my case. How do you do Pulse width mod?

2. That's a really good site, it must've been updated at least in the past year, as it mentions leopard, 10.5. Thanks. I am not familiar with programming/compiling methods for MCU's. Don't most take a standard C program that is just edited by the freeware? As for C though, I just use the standard gcc that comes with xcode.

3. I just need a connection that can take the program from the computer and put it into the MCU. Probably an IDE cable or AVR, but I am not sure what exactly it's called.
 

roddefig

Joined Apr 29, 2008
149
1. Well, what about the sound function? I was trying to use that, but I couldn't find the library it was in. I imagine it would probably have a default to whatever you've got, built in speakers, in my case. How do you do Pulse width mod?
I was unaware there was such a function. I can tell you with absolute certainty that there is no such function in the avr-gcc standard library. You can take a look at the Wikipedia article for PWM, but I think it is a bit confusing. Googling "pwm" or "pulse width modulation" pulls up some good articles. I'm pretty sure all of the AVRs have a PWM peripheral.

2. That's a really good site, it must've been updated at least in the past year, as it mentions leopard, 10.5. Thanks. I am not familiar with programming/compiling methods for MCU's. Don't most take a standard C program that is just edited by the freeware? As for C though, I just use the standard gcc that comes with xcode.
Sorry, I was referring to compiling avr-gcc. If you have the same OS as he does you could just use the pre-built binaries and not bother with building avr-gcc from source.

3. I just need a connection that can take the program from the computer and put it into the MCU. Probably an IDE cable or AVR, but I am not sure what exactly it's called.
That's what I thought you meant, but I try not to make assumptions. You'll need a programmer, which is a bit more complicated than a cable. If you haven't made any significant purchases yet, I would try and get a development board so you do not need to purchase/build a programmer and the support hardware for the microcontroller. I would highly recommend the AVR Butterfly (only $20!!). See the Wikipedia article: http://en.wikipedia.org/wiki/AVR_Butterfly. It should meet all of the requirements for your project and it only needs a standard RS-232 serial port for programming.
 

Thread Starter

MusicTech

Joined Apr 4, 2008
144
1. Is that a function in C though? I was going to do that anyway, with a simple 555 circuit. As in raw circuitry instead of programming. THe only reason I didn't like that is that it would be a mess of resistors, and with under a belt, there a greater chance something could break, short, rust etc. And you wouldn't be able to generate two tones at once.

2. So that program that he has on that site could function as the programmer you mention in 3?

3. So that can transfer info from comp to chip and it is not chip dependent, by which I mean you can use any size chip, any number of bits, i/o etc. And the screen is just an added feature? So you don't even need the screen, you can just use the butterfly for it's data transfer capabilities?

Thanks again, this very helpful!!!!
 
Last edited:

roddefig

Joined Apr 29, 2008
149
1. Is that a function in C though? I was going to do that anyway, with a simple 555 circuit. As in raw circuitry instead of programming. THe only reason I didn't like that is that it would be a mess of resistors, and with under a belt, there a greater chance something could break, short, rust etc. And you wouldn't be able to generate two tones at once.
I looked through the C libraries and I was unable to find anything like a sound function that you mentioned. The only thing that is remotely similar would be the "bell" character in the ASCII character set, which will make the computer beep if it has a speaker.

You'll have to forgive me, I'm not familiar with generating PWM using the 555. That would be a better question to post in the general forum, because there are quite a few folks there who know quite a bit about it and would be able to make a recommendation as which would be the better solution.

2. So that program that he has on that site could function as the programmer you mention in 3?
Yes, provided you have the correct hardware as well.

3. So that can transfer info from comp to chip and it is not chip dependent, by which I mean you can use any size chip, any number of bits, i/o etc.
Not really. The Butterfly is a development kit with a microcontroller included. It's not a programmer, you can't program other microcontrollers with it. I think you should look into it because it is already built, works, and doesn't require a seperate hardware programmer (which you will have to build or purchase). There's heaps of documentation on the internet on that specific board, lots of example projects and code, and I saw a few pages that covered using it with Macs. Finally, for only $20, it's a great starting point that doesn't empty your wallet.

So you don't even need the screen, you can just use the butterfly for it's data transfer capabilities?
You don't need to use the screen if you don't want to.

I'm really pushing the Butterfly because from the questions you are asking, and forgive me if I'm wrong, you don't have any prior experience with microcontrollers. The Butterfly is already built (so you don't have to troubleshoot something you don't understand), is self contained (all you need to do is plug it in), and has a large amount of documentation available for free, some of which is specifically for beginners. Finally, for the price, if something happens to it or it turns out to be something you don't need, you're not out a lot of money.

If you start from a chip you will have to build a circuit with the proper support components, find a power supply that supplies the voltage you need, and build/buy a programmer that will work with the microcontroller you have chosen. Chances are that you will mistake somewhere in the process and have to spend a significant amount of time troubleshooting. The Butterfly will save you a lot of time and effort and allow you to concentrate on building your keyboard, rather than getting the microcontroller to work.
 

Thread Starter

MusicTech

Joined Apr 4, 2008
144
1. OK, unlike the MCU, I have way more confidence in my ability to do that, the only problem is that there would be wires all over, make for a very delicate project.

2. Thanks, that's all my question for that.

3. OK, I will look into that more, and hopefully scrape together enough dough for it, like you sad, at least it won't cripple me financially.

That sparkfun link looks good too.

http://www.cytron.com.my/listProductCategory.asp?cid=81#2965 (see product 1 and 2)

I found that on a long chain of links I found on youtube tutorials. Do these look like it would suit my need a little later down the road? If I understand correctly, All I should need is a physical hookup to my computer and the program (Do I have to use the programmer they offer, or can I use the one you showed me?) and I will be able to use those two parts to program a PIC of the mentioned pin counts, correct?

Thanks again for all your help. I would love to say I please feel free to ask me about anything, but you are probably way better at me at everything electronics than I am. Nevertheless though, if there is something you think I would know or be able to assist you in researching, please feel free to ask.
 
Last edited:

roddefig

Joined Apr 29, 2008
149
http://www.cytron.com.my/listProduct...sp?cid=81#2965 (see product 1 and 2)

I found that on a long chain of links I found on youtube tutorials. Do these look like it would suit my need a little later down the road? If I understand correctly, All I should need is a physical hookup to my computer and the program (Do I have to use the programmer they offer, or can I use the one you showed me?) and I will be able to use those two parts to program a PIC of the mentioned pin counts, correct?
Well, sort of. That's a PIC programmer, we have been discussing AVRs. These are two different microcontrollers made by two different companies. I prefer the AVR over the PIC, mostly because the AVR has a great, free compiler available. I haven't used the PIC very much. However, there are plenty of other people on this forum who are PIC fans and would help you if you go with PICs.

I don't want to discourage you from trying out microcontrollers! Here's some links about the Butterfly that you can read.

Butterfly manual from Atmel: http://www.atmel.com/dyn/resources/prod_documents/doc4271.pdf
Excellent projects page: http://www.siwawi.arubi.uni-kl.de/avr_projects/index.html
MP3 Player: http://www.brokentoaster.com/butterflymp3/index.html
ATMega169 datasheet: http://www.atmel.com/dyn/resources/prod_documents/doc8018.pdf

Thanks again for all your help. I would love to say I please feel free to ask me about anything, but you are probably way better at me at everything electronics than I am.
No worries! Everyone has to start somewhere. Let me know what you end up going with and if you need any help getting started.
 

Thread Starter

MusicTech

Joined Apr 4, 2008
144
OK thanks, that was confusing me.

I can't wait to get the butterfly, that looks like a lot of fun.

AS far as that keyboard proect goes, considering I do need exactly 25 i/o, I was considering this chip:

http://ww1.microchip.com/downloads/en/DeviceDoc/41291C.pdf (The 28 pin one)

wheras 24 would be connected to the actual buttons, waiting for one to be pushed, and the other would be outputing a tone to the speaker. Would this work? Also, does it matter which i/o is attached where, as long as the programming and polarity is ok, or does that big table after the graphic mean big restrictions?
 

RiJoRI

Joined Aug 15, 2007
536
... 24 [I/O pins] would be connected to the actual buttons, waiting for one to be pushed, ...
Quick question: will you have a total of 24 keys, or are you doing a matrix with up to 144 keys? (24 keys can be put into a 6x4 matrix, needing only 6+4 I/O pins.)

--Rich
 

roddefig

Joined Apr 29, 2008
149
Question, do you want to work with AVRs or PICs? The Butterfly is based off the AVR but if you want to work with PICs you should go with something different.

In regards to your question about pin functions, it does matter which pin your speaker is connected to (it will need to be one of the CCPx pins), but as far as the keys are concerned, any of the I/O ports will do. You're cutting it pretty close with the 28 pin chip though, I'd make absolutely sure there won't be any conflicts.
 

Thread Starter

MusicTech

Joined Apr 4, 2008
144
Well, I really don't have a preference, in my original post I really didn't understand the difference, so I just said AVR. It's just that, so far, I haven't found anything as helpful as that programmer and movable socket for AVR. most of the stuff for AVR was only for one chip size and that's it, which I have stated is a very big problem considering my very small budget.

What do you think, maybe get the 40 pin one? That has like 36 i/o give or take a couple.

Also, what are the differences between CCP pins and the other pin types?

Thanks again
 
Last edited:

hgmjr

Joined Jan 28, 2005
9,027
most of the stuff for AVR was only for one chip size and that's it, which I have stated is a very big problem considering my very small budget.
I'm not sure where you got the idea that "most of the stuff for AVR was only for one chip size".

If by "stuff" you mean the hardware development board, then you need to take a look at the STK500 board available from several sources most notably Digi-key. This board cost around $80 US. Another $15 US gets you a "wall wart" power supply. The STK500 can handle the 8-pin, 20-pin, 28-pin, and 40-pin AVR through-hole packages nicely. I own two of them and they are well worth the money (IMHO).

The nice thing about the STK500 board is that it not only serves as the programmer for the device used on the board but it is also useable to program your AVR based designs once you decide to breadboard your own circuit. All that you need to do is provide an ISP6PIN or ISP10PIN ISP header on your prototype board.

hgmjr
 

John Luciani

Joined Apr 3, 2007
475
3. Anybody know of the cheapest AVR connections, I believe they're called, to connect the MCU to a USB port? Or even an alternative, such as how to build a decent one yourself or a place where you could borrow one?
I would use an ATmega168 and FT232RL to get to the USB port. There are probably enough lines to do a matrix scan otherwise get I2C or SPI logic. As was mentioned
there is a GCC for linux, mac and windows.

The ATmega168 is around $3 the FT232RL is around $4. In the datasheet for
my ATmega168 board (ZB1) there is a schematic and parts list.
See http://www.wiblocks.com.

(* jcl *)
 

Thread Starter

MusicTech

Joined Apr 4, 2008
144
mmmm, hehehe I don't know what a matrix scan or SPI logic are.... sorry

When I wrote AVR I wasn't really sure what it meant, just trying to get a point across. Now, I am looking into PIC (mainly because there is a VERY cheap programmer and socket for multiple sizes) There is a Really nice one for AVR that I would LOVE that hgmjr suggested, but at this point the beggars pay me when I walk by. My parents recently have been very generous to me recently musically, and now are done buying me stuff for quite a while. The only bad part is that the only programmer I know is MacrocASM keeps immediately crashing when I open and I have reinstalled it many times. Anyone know why?
 

Arm_n_Legs

Joined Mar 7, 2007
186
Have not come across any C library for tone generation. However, you can control the timer in the microcontroller to pulse a I/O to generate tone of a precise frequency. A sample is shown below for the 8051. Case 1 to 7 represent the notes from "C" to "C". SpkPort is defined as a I/O.


void music_table(unsigned char notes, unsigned int length)
{
unsigned int x;

TR1=1;
LED = 0;
for(x=0;x<length;x++)
{
switch(notes)
{
case 1: TH1= 0xf8; TL1=0x87; break;
case 2: TH1= 0xf9; TL1=0x58; break;
case 3: TH1= 0xfa; TL1=0x12; break;
case 4: TH1= 0xfa; TL1=0x67; break;
case 5: TH1= 0xfb; TL1=0x02; break;
case 6: TH1= 0xfb; TL1=0x8f; break;
case 7: TH1= 0xfc; TL1=0x0a; break;

}
while (TF1==0);
TF1=0;
SpkPort = !SpkPort;
}
TR1=0;
LED=1;

}
 
Top