Author Topic: Simple Microcontroller for a beginner  (Read 30384 times)

0 Members and 1 Guest are viewing this topic.

alm

  • Guest
Re: Simple Microcontroller for a beginner
« Reply #50 on: February 23, 2012, 08:54:22 pm »
If you need an 8-bit MCU, AVR is a much better choice. For 16-bit, the MSP430 has a very elegant architecture, and is very low power too. PIC-16 is also nice (it's a totally new architecture and not like its retarded 8-bit brother).
To keep things simple, the PIC16 does not use a 16-bit architecture, that's the PIC24 and dsPIC series. The PIC32 series is 32-bit. The architecture is less important if you program in C, but the low end (PIC10, 12, 16) PICs aren't very well suited to C either.
 

Online Sal Ammoniac

  • Super Contributor
  • ***
  • Posts: 1673
  • Country: us
Re: Simple Microcontroller for a beginner
« Reply #51 on: February 23, 2012, 09:05:10 pm »
To keep things simple, the PIC16 does not use a 16-bit architecture, that's the PIC24 and dsPIC series.

Yep, I meant 16-bit PIC. Even their naming convention is brain-dead.  ;)
Complexity is the number-one enemy of high-quality code.
 

Offline harnon

  • Regular Contributor
  • *
  • Posts: 215
  • Country: au
  • Is this thing on?
    • My Personal Website
Re: Simple Microcontroller for a beginner
« Reply #52 on: February 24, 2012, 08:46:00 am »
Given the op was asking about a chip for a beginner, is there a similar level of online support for ARM M3 as pic/'duino/avr? (eg https://www.eevblog.com/forum/microcontrollers/beginning-cortex-m3-but-so-lost!!/ seems like a good starting point)  The chips certainly sound promising for some projects i have in mind.
« Last Edit: February 24, 2012, 09:32:03 am by harnon »
 

Offline LukeW

  • Frequent Contributor
  • **
  • Posts: 686
Re: Simple Microcontroller for a beginner
« Reply #53 on: February 24, 2012, 10:07:39 am »
Don't get a PIC.

Get an Arduino, at least to start. Then you can build on your Arduino experience to more complex AVR systems, either with different hardware, different software, or both.

Start with simple Arduino projects, and move to more and more complex Arduino projects as you learn more and as you want to learn more.

You can do very complex hardware and software systems based around an Arduino.

As you want to interface more and more complex electronic devices and I/Os and sensors and power supplies and communications to the Arduino, you'll want to and need to learn more about general electronics. And more about programming C.

If you want a serious embedded programming challenge, you can always write "real" C for the AVR, compile it with avr-gcc, and run it on an Arduino board.

If you want to design and build a bespoke PCB, you can always design and build a bespoke PCB that includes an ATmega328 etc. AVR, a crystal, power supplies, a serial interface, and all your appropriate I/O hardware for your project, and you can still use the Arduino bootloader, the Arduino C language and the Arduino IDE to develop code on the AVR - or you can use something like avr-gcc if you wish.
 

Offline markus_b

  • Regular Contributor
  • *
  • Posts: 115
  • Country: ch
Re: Simple Microcontroller for a beginner
« Reply #54 on: February 24, 2012, 09:13:51 pm »
Here's a good example of how you can program one with nothing more than a few wires and a PC.
http://www.instructables.com/id/Ghetto-Programming%3A-Getting-started-with-AVR-micro/

Can you program any chip like PIC 16F690 or ATMEGA16 or does it have to be the attiny 2313 chip?
And is it any harder to program software wise?
That circuit can program all AVRs, programmable by ISP and running at 5V (the same voltage as the parallelport). These are the large majority of AVRs. It will not work for the large xMegas and the 5-pin Tinys. It is using the open source avrdude programming software, which can program all AVR chips. It supports about everything, from a direct parallel/serial port connection to the expensive Atmel gear.

I've started out the same, by using a simple (1 transistor) serial port programmer. This works well also in-circuit in homegrown gear. Makes development easy as you just leave everything connected and push new versions to the device to test.
Markus

A good scientist is a person with original ideas. A good engineer is a person who makes a design that works with as few original ideas as possible.
 

Offline amyk

  • Super Contributor
  • ***
  • Posts: 8276
Re: Simple Microcontroller for a beginner
« Reply #55 on: February 25, 2012, 09:11:45 am »
Some of the newer parallel ports are only 3.3V so they won't work with 5V-only chips.

The ones that require 12V are a little more complex, but you can get that from a PC power supply too. I recommend putting a current limiting resistor on the 12V because it needs <1mA and a 12V to ground short can be a bit exciting.
 

Offline Psi

  • Super Contributor
  • ***
  • Posts: 9953
  • Country: nz
Re: Simple Microcontroller for a beginner
« Reply #56 on: February 25, 2012, 10:40:57 am »
Some of the newer parallel ports are only 3.3V so they won't work with 5V-only chips.

The ones that require 12V are a little more complex, but you can get that from a PC power supply too. I recommend putting a current limiting resistor on the 12V because it needs <1mA and a 12V to ground short can be a bit exciting.
You can get massive sparks even at 12V . I had that .

heh yeah, when i play around with my ultracaps i sometimes short out 15V @ 600A for fun. That produces sparks up to ~70cm
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline markus_b

  • Regular Contributor
  • *
  • Posts: 115
  • Country: ch
Re: Simple Microcontroller for a beginner
« Reply #57 on: February 25, 2012, 11:01:05 am »
Some of the newer parallel ports are only 3.3V so they won't work with 5V-only chips.

The ones that require 12V are a little more complex, but you can get that from a PC power supply too. I recommend putting a current limiting resistor on the 12V because it needs <1mA and a 12V to ground short can be a bit exciting.
There are no 5V-only chips, I think. But I always felt that connecting to a parallel port is more risky than connecting to a serial port as you connect directly to a multifuntional chip on the motherboard. If you blow it you blow the motherboard. If you use the serial port you connect to the serial level converter (max232, etc), so if you blow it you may well just have blown the serial port, not the complete PC. This is even more the case if you use a USB-serial cable.

The 12V high-voltage programming is not something I would attempt lightly with a home-grown device. If you need that, then get a AVR-dragon for $50.
Markus

A good scientist is a person with original ideas. A good engineer is a person who makes a design that works with as few original ideas as possible.
 

Offline Andy

  • Contributor
  • Posts: 26
Re: Simple Microcontroller for a beginner
« Reply #58 on: February 25, 2012, 12:39:32 pm »
Some of the newer parallel ports are only 3.3V so they won't work with 5V-only chips.

The ones that require 12V are a little more complex, but you can get that from a PC power supply too. I recommend putting a current limiting resistor on the 12V because it needs <1mA and a 12V to ground short can be a bit exciting.
There are no 5V-only chips, I think. But I always felt that connecting to a parallel port is more risky than connecting to a serial port as you connect directly to a multifuntional chip on the motherboard. If you blow it you blow the motherboard. If you use the serial port you connect to the serial level converter (max232, etc), so if you blow it you may well just have blown the serial port, not the complete PC. This is even more the case if you use a USB-serial cable.

The 12V high-voltage programming is not something I would attempt lightly with a home-grown device. If you need that, then get a AVR-dragon for $50.

How about using a USB-parallel cable then :)
 

Offline wkb

  • Frequent Contributor
  • **
  • Posts: 910
  • Country: nl
Re: Simple Microcontroller for a beginner
« Reply #59 on: February 25, 2012, 01:48:43 pm »
 

Offline markus_b

  • Regular Contributor
  • *
  • Posts: 115
  • Country: ch
Re: Simple Microcontroller for a beginner
« Reply #60 on: February 25, 2012, 02:19:25 pm »
How about using a USB-parallel cable then :)
In theory an USB parallel cable would be fine to protect the PC. But, as far as I know, the parallel programming software requires direct access to the parallel port chip, so it would not work with a parallel cable. This would apply to serial cables too, but there are generic (but slow) ways to toggle pins and avrdude knows about those. In addition avrdude has special support for FTDI-chips (USB/serial) and can use high speed with those.

However, from this thread: https://www.eevblog.com/forum/beginners/which-rotary-encoder-for-pwm-project/msg93075/ I gather that the OP has made his choice (MSP430).
Markus

A good scientist is a person with original ideas. A good engineer is a person who makes a design that works with as few original ideas as possible.
 

Offline Tony R

  • Regular Contributor
  • *
  • Posts: 117
  • Country: 00
Re: Simple Microcontroller for a beginner
« Reply #61 on: February 25, 2012, 05:17:46 pm »
And don't be persuaded by people (and I used to be guilty of this) that tell you that you have to learn Assembler to truly program a microcontroller. Learn C, all embedded development is headed that way now, and you can still use assembler later once you are used to the concepts of programming.

I agree with you, to a point. Programming in assembly really gets you to think about every C instruction you write. When you program in C you don't really understand what all the registers actually do. If you want to set up a PWM, you need to set at least two registers and most likely a couple more to enable it, set the pull up/pull down resistors. But doing it in assembly really gives you a good idea of what is going on behind the scene.

Now, If you are doing it as a hobby do you really need to know assembly? of course not... Do you really need to make the most of your high level code? No.
Tony R.
Computer Engineering Student
Focus: Embedded Assembly Programming, Realtime Systems,  IEEE Student Member
 

Online Sal Ammoniac

  • Super Contributor
  • ***
  • Posts: 1673
  • Country: us
Re: Simple Microcontroller for a beginner
« Reply #62 on: February 25, 2012, 06:00:02 pm »
Don't get a PIC.


Why not?

Because there are much better, more modern architectures around. Since this thread is titled "simple microcontroller for a beginner", the original poster is not likely to have an investment in Pic development tools and hardware, so no reason to be locked into the ancient 8-bit Pic. Better to start out with something more modern and easy to understand at the architectural level. (The 16-bit and 32-bit Pics are more modern designs and I wouldn't hesitate to recommend them to someone with a little experience.)

Given the vast amount of software and hardware coming out of the Arduino juggernaut, the AVR is probably a better choice for a beginner, even if he doesn't want to use Arduino hardware.
Complexity is the number-one enemy of high-quality code.
 

Offline Bored@Work

  • Super Contributor
  • ***
  • Posts: 3932
  • Country: 00
Re: Simple Microcontroller for a beginner
« Reply #63 on: February 25, 2012, 06:45:39 pm »
When you program in C you don't really understand what all the registers actually do. If you want to set up a PWM, you need to set at least two registers and most likely a couple more to enable it, set the pull up/pull down resistors. But doing it in assembly really gives you a good idea of what is going on behind the scene.

If you program it in raw C, you see exactly what you do with the registers. Only I you use one of those typically very stupid "driver libraries", or heaven forbit an Arduino, you obscure things.

Randomly picked from an AVR example (including syntax and other errors Atmel likes to show in their examples):

Assembler:
Code: [Select]
WriteTCNT1:
    in r18,SREG        ; Save global interrupt flag
    cli                ; Disable interrupts
    out TCNT1H,r17     ; Set TCNT1 to r17:r16
    out TCNT1L,r16
    out SREG,r18       ; Restore global interrupt flag
    ret

C:
Code: [Select]
void WriteTCNT1(unsigned int val)
{
    unsigned char sreg = SREG;    // Save global interrupt flag
    cli();                        // Disable interrupts
    TCNT1 = val;                  // Set TCNT1 to val
    SREG = sreg;                  // Restore global interrupt flag
}

Hardly any difference.
I delete PMs unread. If you have something to say, say it in public.
For all else: Profile->[Modify Profile]Buddies/Ignore List->Edit Ignore List
 

Offline wkb

  • Frequent Contributor
  • **
  • Posts: 910
  • Country: nl
Re: Simple Microcontroller for a beginner
« Reply #64 on: February 25, 2012, 10:43:42 pm »
Don't get a PIC.


Why not?

Because there are much better, more modern architectures around. Since this thread is titled "simple microcontroller for a beginner", the original poster is not likely to have an investment in Pic development tools and hardware, so no reason to be locked into the ancient 8-bit Pic. Better to start out with something more modern and easy to understand at the architectural level. (The 16-bit and 32-bit Pics are more modern designs and I wouldn't hesitate to recommend them to someone with a little experience.)

Given the vast amount of software and hardware coming out of the Arduino juggernaut, the AVR is probably a better choice for a beginner, even if he doesn't want to use Arduino hardware.

Ok, could be.  I'd go ARM for that reason though.  Heck, you might be hired by Apple to do their iSomethingOrOther if you get really proficient programming ARM CPUs  ::)
 

Offline cowboy303Topic starter

  • Regular Contributor
  • *
  • Posts: 82
  • Country: us
Re: Simple Microcontroller for a beginner
« Reply #65 on: February 26, 2012, 12:26:40 am »
Quote
However, from this thread: https://www.eevblog.com/forum/beginners/which-rotary-encoder-for-pwm-project/msg93075/ I gather that the OP has made his choice (MSP430).

Since most of this stuff (like code C ???) is Over my head.  I thought I'd get something for $4.30 that I can plow up or throw out the window and not care.  And that way I know what I'm buying for $30 And if I even want one.  I was putting in a digikey order anyway thought what the heck.
 

Offline IanB

  • Super Contributor
  • ***
  • Posts: 11892
  • Country: us
Re: Simple Microcontroller for a beginner
« Reply #66 on: February 26, 2012, 12:44:15 am »
Since most of this stuff (like code C ???) is Over my head.  I thought I'd get something for $4.30 that I can plow up or throw out the window and not care.  And that way I know what I'm buying for $30 And if I even want one.  I was putting in a digikey order anyway thought what the heck.

If coding in C is over your head then you should definitely be thinking in terms of Arduino as a starting point. Programming computers is not hard to get the hang of, but working with microcontrollers is definitely programming computers. If you have never programmed before, the Arduino would be an excellent place to begin. Let me put it this way--I am a very capable computer programmer who thinks programming C is like a walk in the park--but looking at some microcontroller C code for the first time made my brain hurt. If I spent a couple of hours figuring out how the code maps to the hardware I would be OK, but if you are a beginner I can't honestly recommend you go this way. If you want a gentle introduction to the world of microcontrollers and you are new to programming, then the Arduino is the place to begin. Really. Don't let people tell you anything different.
 

Offline markus_b

  • Regular Contributor
  • *
  • Posts: 115
  • Country: ch
Re: Simple Microcontroller for a beginner
« Reply #67 on: February 26, 2012, 09:36:20 am »
Since most of this stuff (like code C ???) is Over my head.  I thought I'd get something for $4.30 that I can plow up or throw out the window and not care.  And that way I know what I'm buying for $30 And if I even want one.  I was putting in a digikey order anyway thought what the heck.
If coding in C is over your head then you should definitely be thinking in terms of Arduino as a starting point.
I agree with this point of view. As said before, easy programming is the strong point of arduino. You could just have added another $3.5 for a mega168PU and the used the Arduino software to program it. Very much the same as Dave in the power-supply project. Here a link to a tutorial on the subject: Arduino standalone on breadboard
Markus

A good scientist is a person with original ideas. A good engineer is a person who makes a design that works with as few original ideas as possible.
 

Offline cowboy303Topic starter

  • Regular Contributor
  • *
  • Posts: 82
  • Country: us
Re: Simple Microcontroller for a beginner
« Reply #68 on: February 26, 2012, 03:32:13 pm »
Since most of this stuff (like code C ???) is Over my head.  I thought I'd get something for $4.30 that I can plow up or throw out the window and not care.  And that way I know what I'm buying for $30 And if I even want one.  I was putting in a digikey order anyway thought what the heck.
If coding in C is over your head then you should definitely be thinking in terms of Arduino as a starting point.
I agree with this point of view. As said before, easy programming is the strong point of arduino. You could just have added another $3.5 for a mega168PU and the used the Arduino software to program it. Very much the same as Dave in the power-supply project. Here a link to a tutorial on the subject: Arduino standalone on breadboard

I was looking at your link (Please tell me if I'm wrong) looks like you need to have this little guy http://www.sparkfun.com/products/718

I have no idea about what I'm doing but if you go on Ebay and look up atmega8 you get this guy http://www.ebay.com/itm/USBASP-ISP-Programmer-adapter-10-Pin-Cable-f-ATMega8-AVRDude-Tiny-CAN-PWM-Series-/260867187214?_trksid=p5197.m7&_trkparms=algo%3DLVI%26itu%3DUCI%26otn%3D5%26po%3DLVI%26ps%3D63%26clkid%3D6603437073072637844
Is it any good?  I really don't want to plug anything straight in to my laptop.
I've seen a web page that tells you how to connect it up but can't find it know I somebody can help that would be great.
« Last Edit: February 26, 2012, 03:34:40 pm by cowboy303 »
 

Offline TerminalJack505

  • Super Contributor
  • ***
  • Posts: 1310
  • Country: 00
Re: Simple Microcontroller for a beginner
« Reply #69 on: February 26, 2012, 04:34:42 pm »
Quote
I was looking at your link (Please tell me if I'm wrong) looks like you need to have this little guy http://www.sparkfun.com/products/718

I have no idea about what I'm doing but if you go on Ebay and look up atmega8 you get this guy http://www.ebay.com/itm/USBASP-ISP-Programmer-adapter-10-Pin-Cable-f-ATMega8-AVRDude-Tiny-CAN-PWM-Series-/260867187214?_trksid=p5197.m7&_trkparms=algo%3DLVI%26itu%3DUCI%26otn%3D5%26po%3DLVI%26ps%3D63%26clkid%3D6603437073072637844
Is it any good?  I really don't want to plug anything straight in to my laptop.
I've seen a web page that tells you how to connect it up but can't find it know I somebody can help that would be great.

That $5 programmer doesn't look too bad.  Apparently it's based on a proven open hardware design.  It will only work with 5V systems, however.  That is, your circuit (the MCU, specifically) has to be powered at 5V.

It looks like they left an option to use a couple of the pins for serial communication via USB as well.  This must by why they used the 10-pin ISP connector instead of the more compact 6-pin.  According to the site, this isn't implemented yet.  When, and if, it ever is then you would likely need to upgrade the firmware on the programmer.

For 5 bucks you probably can't go wrong.

Edited to add:

I just took a closer look at the pictures.  Apparently there's a resistor that can be removed to support 3.3V systems.  Also, that particular programmer likely won't ever support the serial communication feature since it looks like those pins are permanently connected to GND.  (Or the silkscreen is just mislabeled.)
« Last Edit: February 26, 2012, 04:40:34 pm by TerminalJack505 »
 

Offline markus_b

  • Regular Contributor
  • *
  • Posts: 115
  • Country: ch
Re: Simple Microcontroller for a beginner
« Reply #70 on: February 26, 2012, 05:05:43 pm »
Is it any good?  I really don't want to plug anything straight in to my laptop.
I've seen a web page that tells you how to connect it up but can't find it know I somebody can help that would be great.
The USBASP is certainly *much* better than a direct connection to a parallel or serial port. If you want competent information I'd scan the avrfreaks.net forum: Google 'usbasp site:avrfreaks.net' and you'll have plenty of reported experiences.

If you want to be able to use the Arduino tools to program you'll need a serial or USB/serial interface (your sparkfun link). There are indications that USBASP support was added recently to the Arduino, but I don't know.
Markus

A good scientist is a person with original ideas. A good engineer is a person who makes a design that works with as few original ideas as possible.
 

Offline electrode

  • Regular Contributor
  • *
  • Posts: 141
  • Country: au
Re: Simple Microcontroller for a beginner
« Reply #71 on: February 27, 2012, 12:00:01 am »
If you want to be able to use the Arduino tools to program you'll need a serial or USB/serial interface (your sparkfun link).

You can program via ISP too. Just hold shift when clicking compile and upload (version 1.0 onwards).

USBASP isn't in my programmer list in the Arduino tools menu, so you may need to add it yourself (unless it has been added in the newest version). It's probably as simple as a line or two in the preferences file, eg:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1282243271
(note that this thread is for adding it as a burning bootloader programmer, not a sketch uploading programmer, but it should be similar)
 

Offline cowboy303Topic starter

  • Regular Contributor
  • *
  • Posts: 82
  • Country: us
Re: Simple Microcontroller for a beginner
« Reply #72 on: February 27, 2012, 01:00:29 am »
Quote
However, from this thread: https://www.eevblog.com/forum/beginners/which-rotary-encoder-for-pwm-project/msg93075/ I gather that the OP has made his choice (MSP430).

Since most of this stuff (like code C ???) is Over my head.  I thought I'd get something for $4.30 that I can plow up or throw out the window and not care.  And that way I know what I'm buying for $30 And if I even want one.  I was putting in a digikey order anyway thought what the heck.

Before when I said code C is over my head ???.  I meant I have only heard of it and don't know anything about it. And I think it would help everybody if I told you about my self so here it go's.
I'm 15 years old and and started with electronics 4 months ago my first circuit was a full wave rectifier with 4 1n4002 diodes I got from an old TV with 4 nails on a 1 X 4  non of my family member fave any electrical knowledge and mine is very limeted.  I have  designed simple stuff like a charge controller etc so now I'm working on a power supply (very similar to Dave's) and since I learn best by doing I thought I'd try my hand at Microcontrollers to control the thing and that was what the Thread was about I probably should have said this at the beginning but better now then never. 
 

Offline IanB

  • Super Contributor
  • ***
  • Posts: 11892
  • Country: us
Re: Simple Microcontroller for a beginner
« Reply #73 on: February 27, 2012, 01:25:03 am »
The thing is when you are 15 there is a whole world of knowledge ahead of you to learn about. You don't need to feel any pressure to do advanced things right away. There will plenty of time to come to learn everything you could ever want to learn.

When I was 15 we had things like the Commodore PET to learn basic computer functions and programming with. They have gone away now, and the Arduino is probably the spiritual successor to those early home computers.

I would still suggest you start out with the Arduino and move on to more advanced topics with low level programming of microcontrollers later on. It depends a little on how much programming you have already done on desktop computers. If you are new to the whole programming thing then raw programming of micros is going to be a steep learning curve.
 

Offline Psi

  • Super Contributor
  • ***
  • Posts: 9953
  • Country: nz
Re: Simple Microcontroller for a beginner
« Reply #74 on: February 27, 2012, 01:37:05 am »
Before when I said code C is over my head ???.  I meant I have only heard of it and don't know anything about it. And I think it would help everybody if I told you about my self so here it go's.
I'm 15 years old and and started with electronics 4 months ago my first circuit was a full wave rectifier with 4 1n4002 diodes I got from an old TV with 4 nails on a 1 X 4  non of my family member fave any electrical knowledge and mine is very limeted.  I have  designed simple stuff like a charge controller etc so now I'm working on a power supply (very similar to Dave's) and since I learn best by doing I thought I'd try my hand at Microcontrollers to control the thing and that was what the Thread was about I probably should have said this at the beginning but better now then never.

The cool thing about Arduino C and micro controllers is you don't have to have any knowlodge to get an LED to flash (or lots of other basic stuff).

There is a huge number of Arduino examples you can just download, build and try without needing to understand the code.
Which is awesome because when getting into microcontrollers for the first time that's half the battle :)
Once you have something that works, even if its just flashing an led, it's easy to play around changing code and seeing what it does.
If you stuff something up you can just copy the original code back in.

And i bet there are tutorials on youtube where people not only show their Arduino code but also explain how it works, which you will find very useful.
Greek letter 'Psi' (not Pounds per Square Inch)
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf