PDA

View Full Version : broadening my scope



tobdec
08-18-2011, 07:04 PM
What do you guys think of the ATmega168 as a next step from the bs2? Not that theres nething wrong with my bs2 I just want to learn different languages and mcu's for a better understanding of it all.

Mike Green
08-18-2011, 07:19 PM
It depends on what you plan to do with the ATmega168. If you're just going to use the Arduino software or even just the C/C++ toolchain, you're not going to learn that much about the microcontroller itself. Frankly, I would suggest using the Propeller, perhaps getting one of the new QuickStart boards. You can use Catalina for a C compiler, plus there's Spin, Assembly, PropBasic, and Forth. You should look at 12Blocks too for an example of a graphical programming system. ViewPort is a good debugging and development tool.

Leon
08-18-2011, 07:37 PM
The ATmega168 is a nice chip to program in assembler and C, with good free tools and low-cost hardware. Plenty of support is available on the AVR Freaks forum. Get an AVR Dragon ($50) for programming and debugging.

rod1963
08-18-2011, 07:48 PM
The Atmega is a nice chip and you can't go wrong learning about it. There's C, Forth, assembler and compiled Basic available for it.

tobdec
08-18-2011, 08:02 PM
From what ive gathered the atmega's can use multiply languages as long as you use the correct compiler? My main goal i guess is to learn C. Ive got a solid background in electronics now and want to program more.

Leon
08-18-2011, 08:42 PM
C is generally used with AVR devices. There are one or two other languages but no one uses them for professional applications.

GordonMcComb
08-18-2011, 09:03 PM
If you can find a source the ATmega328P might be a better choice, simply as it has more memory. Otherwise, it's the same chip. The 328 is the one used in the latest Arduino Uno, so it's not quite as easy to find in stock. The two are more or less the same price.

Atmel offers their free coding tools, and there's the gcc toolchain, of course. There are some people that use the Arduino IDE (which extends gcc), but code in straight C. The IDE will create the hex files, which you then download via a programmer. For programmers there are a bunch in the $20 or $30 range. I have one from Pololu that's not bad.

It can be, er, um, a learning experience setting all this up. After doing it you get to appreciating the ease of getting started with something like the BS2.

-- Gordon

Duane Degn
08-18-2011, 10:08 PM
I agree with Mike Green (again).

The Propeller is a great chip for robots. I'm often frustrated reading Robot, Servo or Nuts & Nuts articles as the author struggles with keeping jitters out of their servos or they have some other timing problem that could have been easily solved with a Propeller.

I confess, I also plan to learn to use AVR's chips.

@Leon, Is "AVR Dragon" really needed for occasional programming? I'm willing to pay for programming tools if needed but I'd prefer free software if it's good enough.

Duane

Leon
08-18-2011, 10:33 PM
It makes things much easier, and doesn't cost much more than a programmer such as the AVRISP Mk2.

tobdec
08-18-2011, 10:35 PM
I found a great kit here http://www.nerdkits.com/kits/ at 75 bucks with the programming guide ill prob be able to jump right in. Plus ive got loads of c, c+ ,c# books just begging to be used!

Humanoido
08-19-2011, 10:48 AM
I agree with Mike Green and Duane Degn. The prop has 175 programming languages for ever conceivable project!

http://forums.parallax.com/showthread.php?113091-ULTIMATE-List-of-Propeller-Languages&highlight=ultimate

You can learn one language and move on to 174 others.

Leon
08-19-2011, 11:23 AM
How many of those languages are suitable for programming serious applications, though?

Erik Friesen
08-19-2011, 12:01 PM
The prop is a good bridge between some of the micro's that use C. It is so easy to run a program that a beginner doesn't have to fight it. Once you get the hang of it, the concepts are there enough to move on if needed. Just try configuring the oscillator for usb on a pic32, for example of diffcult, or the dspic33 series.

Ale
08-19-2011, 12:05 PM
If your goal is to learn C, then use your PC (or Mac or GNU/Linux powered machine, or whatever you have). I'd suggest you learn C first and then apply it to a uC. The ATMegas (any of them) are as easy to setup as the propeller and are very capable, have loads of peripherals and plenty of documentation.
I haven't used Catalina (for propeller programming) as I program the propeller only in assembler: the REAL only language that provides an alternative to a penitential robe ;-) :D :D :D. BTW, the propeller offers many advantages over an ATMega but they are really different beasts!
The AVR Dragon is an useful programming/debugging board, at some point you may need such capabilities.

Heater.
08-19-2011, 12:16 PM
As you want to learn C and this a Parallax forum, why not start with the Propeller and the Catalina C compiler?
Mind you with a Prop on the bench and the simplicity of programming in Spin/PASM with the Prop Tool or BST or PZST IDE's you may forget all about moving to C.
As for the AVRs I would get the biggest ones you can find and use the free avr-gcc C compiler. I have had good luck using a simple home made programming circuit and the free PonyProg download software.
You can even make a USB avr programmer out of a few resistors connected to a small avr and the avr-usb software.

tobdec
08-19-2011, 01:13 PM
wow i didn't know the prop was capable of soo many languages! Maybe I should go with a prop first and then move on to the more hardcore mcu's like atmega and straight pic's. From what I understand theyre alot more in depth to set up and configure. Not so "plug and play" like i'm used to with the bs2.

HollyMinkowski
08-19-2011, 11:48 PM
The ATmega168 is great! So is the propeller!
I suggest using them both. Sometimes they work well together as
well as separately. You might get more bang from the very similar
328p though...more flash.

I'd use WinAVR/GCC for the atmegas and Catalina for the Prop.
That way you will be learning C for both chips :-)

There are some very inexpensive USB programmers for the Atmel
chips available on ebay. We are talking 7-15 USD delivered.

I like combining the ATmega1284p and the Prop.
The 1284p has 128K of flash, 16K ram 4K eprom.
And runs at 20MIPS at 5v down to 4MIPS at 1.8v
costs 5.00 USD ea

Erik Friesen
08-20-2011, 01:59 AM
One problem I see with using avr is that you may become an avrfreak.

tobdec
08-20-2011, 02:36 AM
Even if i do become an avrfreak parallax always makes great acessories for ANY mcu. Im gona try a prop though just to see how I like them.

rod1963
08-20-2011, 05:21 PM
If you are new to C and need to learn it, learn it on a PC. It's easier that way than trying learn it on a on uC.

And yeah ATmega1284p is a good choice as well for a uC. Comes in a Dip40 package so it's hobbyist friendly.

tobdec
08-20-2011, 05:46 PM
What is uC? Is that a simulated C console on a linx or mac box?

Leon
08-20-2011, 05:48 PM
uC - micro-computer or micro-controller. MCU (micro-controller unit) is less confusing.

tobdec
08-20-2011, 05:58 PM
O lol its an mcu that runs on C. I have a nice stack of books on C#....is that similar to C? Can C# be used on the prop? What are the advantages of one language over another on an mcu? Sorry for all the questions Im just rly excited to dive into programming.

Leon
08-20-2011, 06:06 PM
C# isn't relevant to C used for embedded applications. I'd start with assembly language and then learn C.

tobdec
08-20-2011, 06:28 PM
Really? Why is that? Maybe i'm missing somthing but it seems like going from PBASIC-C-Assembly makes sense more than PBASIC-Assembly-C. Kinda like going from changing oil to making custom cam shafts. Maybe i'm missing somthing though.

Leon
08-20-2011, 06:37 PM
You can't use C effectively unless you know something about the architecture of the chip you are using. Programming in assembler is the best way to learn about the chip.

tobdec
08-20-2011, 06:49 PM
O so each chip uses a slightly different version of Assembly? Like amd, intel, motorola (tablets), or pic, etc... Then C will build upon that speicific version of assembly based on the chip?

Leon
08-20-2011, 06:56 PM
They have different architectures and instruction sets. Once you've used a couple you should be able to cope with new ones without any problems.

tobdec
08-20-2011, 06:58 PM
I bet its tricky to make apps for windows that can use both amd and intel then.

Leon
08-20-2011, 07:15 PM
They are usually written in C++, these days.

HollyMinkowski
08-20-2011, 10:39 PM
Leon is correct, there is a lot to be gained from knowing asm for
the particular uC you are working with. It is not an absolute must
though. Much good work can be done without low-level knowledge
of the uC. However, if you need to work near the limits of the uC a
working knowledge of asm can make the difference. C is very very
good but once in a while you must use asm to squeeze out that
last bit of goodness. I use C for probably 95%+ of my coding and
asm for the interrupt code that needs to do its job very quickly.

Once you know one flavor of asm then the skills quickly transfer
to any other uC. I learned asm on the 8 bit PIC uC. When I moved
to the Atmel chips it only took a few days to pick up that dialect
of asm. Asm on the Prop is really fun! there is a lot of power in each
32bit instruction...it's so versatile that you have to pay close attention
or you overlook ways to optimize your code.

For a beginner I have come to the conclusion that the best way to instruct
is to have a primer that starts from the very elementary steps of binary
math and logic and proceeds by giving simple and very detailed examples
of code and hardware using both C and asm to do the exact same tasks.
Learning C and asm side-by-side just makes sense to me. And if you already
know C or asm then the side-by-side examples make learning the other
language much easier.

The Prop1 and 2 could benefit from a primer that had examples of C, SPIN and
PASM for every exercise. For these uC's you really need a knowledge of all
three languages to do the best work possible.

tobdec
08-20-2011, 11:40 PM
Holly, do u think i should learn asm and C as a standalone first or start with a uC? Im fairly descent when it comes to hardware so that side is solid.

HollyMinkowski
08-21-2011, 12:46 AM
I advise you to learn C first since there exists no book
for beginners that teaches C and Asm at the same time.
You will need the AVRStudio IDE (free) and the free
WinAVR GCC compiler. You should be able to find quite
a bit of instructional material on the web. I know there is
some at hackaday and http://www.ladyada.net/learn/avr/
A quick google search will turn up more stuff and there are
a few books available for purchase.

Just search google using these terms ---> avr c tutorial

C for uC's is different that C on a PC because there are
lots of things you never really use when working with a uC.
Stuff like printf never really come up....

C is a small language but very powerful. You extend it by creating
functions and libraries. When I was just starting out in programming
and I discovered you could extend C by creating your own functions
and libraries it made me want to do a little happy dance...it seemed so
cool! (boy was I ever a newbie)

tobdec
08-21-2011, 01:44 AM
So the studio is where I write the code into files...and the gcc compiler is where its compiled into machie code correct? So I should probably start out with uC istead of going directly to PC C? My co-worker is very fluent in C and he has never even touched a mcu...as far as actualy programming one lol...God only knows he touches 100's a day!

HollyMinkowski
08-21-2011, 02:01 AM
Yup, install the WinAVR compiler and then install
studio 4.

Once you can write and compile a simple hello world
type program and send the program to the flash memory
on your uC and get it to run the hardest part is over with.

If you can find someone to walk you through that stuff in
person it will only take an hour at most. It will take longer
just working from online tutorials.

The IDE has a nice emulator so you can actually start off
running your code on a virtual uC.... all you really need to
begin is the WinAVR compiler and the Studio 4 IDE.\

The GCC compiler is integrated into studio 4 so everything
is done right inside the IDE. And if you have a compatible
USB programmer it too will be controlled from within the IDE.

tobdec
08-21-2011, 04:09 AM
What is soo difficult about flashing the first program?

Kevin Wood
08-21-2011, 04:26 AM
>>> What is soo difficult about flashing the first program?

Getting it to work...

IMO, the simplest way to get started with the ATMega 168/3268 is to get one of the socketed Arduino (currently the Uno) or one of the socketed clones. You can use it with both the Arduino IDE, or with AVR Studio if you have a programmer. No programmer is needed to use with the Arduino IDE... you program over USB.

The benefit here is that the Arduino IDE uses C/C++ syntax, while being very BS2-like in program structure. From there, you need to learn a handful of concepts to create a "proper" minimal C program that will compile with AVR Studio, and you can get as deep into the architecture as you like. The reason I suggest the socketed model is that you can then buy raw DIPs, pop then in the Arduino, program them, then use them in your projects.

Another option if you don't want to buy an Arduino is to use Virtual Breadboard (http://www.virtualbreadboard.net/HOME/tabid/166/Default.aspx), which has a built-in Arduino emulator. In fact, between that and the AVR Studio emulator that Holly mentioned, you can probably put off buying hardware until you actually want to build something.

tobdec
08-21-2011, 04:43 AM
Kevin thats pretty sweet! Your right I probably would need hardware with those. So the uno board can program any atmega? Hardware really isn't much of an issue to acquire cheap...and I mean cheap I have all sorts of connections lol but with this and the one holly mentioned I can hold off on hardware until I can determine what I actualy want/need. My bs2 is ok...I havn't even learned all of PBASIC yet..but i don't feel like I need to its just too easy to work with. I guess I need more of a challenge.

tobdec
08-21-2011, 04:45 AM
O btw kevin...what do u mean by "proper" C?

Leon
08-21-2011, 05:09 AM
Standard ANSI C.

Kevin Wood
08-21-2011, 07:30 AM
>>> So the uno board can program any atmega?

It can be used to program the ATmega168/328 DIPs, which is what you wanted to get started with. Rather than $75 for the kit you linked, get a socketed Arduino, which IMO is a better value.

>>> O btw kevin...what do u mean by "proper" C?

Arduino programs (called sketches) are built around two functions... setup() and loop()...


/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.

This example code is in the public domain.
*/

void setup() {
// initialize the digital pin as an output.
// Pin 13 has an LED connected on most Arduino boards:
pinMode(13, OUTPUT);
}

void loop() {
digitalWrite(13, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(13, LOW); // set the LED off
delay(1000); // wait for a second
}
This program won't compile with a C/C++ compiler, because it's missing, at a minimum, a main() function, plus header declarations that describe the library calls for other variables, data structures, and functions being used.

In order for this to be compiled by gcc, the Arduino IDE converts the sketch in to a compilable program, compiles it, and loads it to the ATmega. If you use AVR Studio for development, you're responsible for everything. So using the Arduino IDE let's somebody get comfortable using C/C++ syntax without having to immediately understand all of the lowest level details required to program the chip. When ready to graduate to AVR Studio, get a programmer to connect to the ICSP header and go from there.

tobdec
08-21-2011, 02:56 PM
Wow theres alot to this...I didn't realize how many little things made such a big difference just hardware wise. I agree on the arduino board now though. That way it's easier to start with and ive got an arduino uno to play around with.

HollyMinkowski
08-21-2011, 07:04 PM
http://www.ebay.com/sch/i.html?_nkw=AVR+USB&_armrs=1&_from=&_ipg=

tobdec
08-22-2011, 04:15 AM
Holly...I saw those earlier, that and a few dip packages Ill have literaly 20 bucks in it as opposed to 75 from that site I found. Only difference is that programming book. But from what i've saw soo far it looks stupid simple to get in to.

tobdec
08-25-2011, 12:17 AM
Any opinions on this high level assembly? http://www.amazon.com/Art-Assembly-Language-Randall-Hyde/dp/1593272073/ref=sr_1_1?ie=UTF8&qid=1314231025&sr=8-1
This was a pretty highly rated book. Just wanted to see what you guys thought about it before I go learning somthing that may be useless.

Leon
08-25-2011, 10:00 AM
I don't think that book is relevant to programming embedded systems in assembler.

Mark_T
08-25-2011, 02:36 PM
If you can find a source the ATmega328P might be a better choice, simply as it has more memory. Otherwise, it's the same chip. The 328 is the one used in the latest Arduino Uno, so it's not quite as easy to find in stock. The two are more or less the same price.
-- Gordon

Actually I find the 168 is much cheaper than the 328 (at least in TQFP) - partly because of the supply/demand equation. I've used these chips a lot both via Arduino libraries and direct hardware access (mainly for the flexible timer modules). The availability of 6 (or 8 on the TQFP version) ADC inputs is mighty useful even though they are rather slow and multiplexed.

Also the wide supply-voltage range is nice to have.

prof_braino
08-25-2011, 02:50 PM
Late to notice this discussion,


C is generally used with AVR devices. There are one or two other languages but no one uses them for professional applications.

http://amforth.sourceforge.net/

is a possible exception.

It seems you have already decided to use C., but consider that "appropriateness of tool".

Are you going to use C because you want to learn workstation OS and application programming, or do you still want to target micro controller embedded applications?

A workstation assumes a specifically large and growing set of resources for general applications.
An embedded application usually implies a much smaller set of resources purposely specific to the targeted application.

Consider the perspective that "the micro controller software looks toward the hardware, the workstation software looks away from the hardware and towards the OS".

This is an aspect to consider when "broadening your scope", as the focus of your scope should determine your tool selection (and not the popularity of a possibly inappropriate tool). Remember, software techniques, once learned correctly, can be applied to any tool environment, just as learning one assembler is applicable to learning any other assembler.

mindrobots
08-25-2011, 03:09 PM
Any opinions on this high level assembly? http://www.amazon.com/Art-Assembly-Language-Randall-Hyde/dp/1593272073/ref=sr_1_1?ie=UTF8&qid=1314231025&sr=8-1
This was a pretty highly rated book. Just wanted to see what you guys thought about it before I go learning somthing that may be useless.

I believe the text for that book is available online, for free, here:

http://www.arl.wustl.edu/~lockwood/class/cs306/books/artofasm/toc.html

Just to give you a flavor of what you're getting into with most any assembler programming.

wjsteele
08-25-2011, 03:42 PM
I have a nice stack of books on C#....is that similar to C? Can C# be used on the prop?

C# can only be used on the .NET Micro Framework based devices, like the Netduino and GHI boards. (It is syntactically similar to C, but vastly simplified.)

Bill

GordonMcComb
08-25-2011, 04:06 PM
IMO, the simplest way to get started with the ATMega 168/3268 is to get one of the socketed Arduino (currently the Uno) or one of the socketed clones. You can use it with both the Arduino IDE, or with AVR Studio if you have a programmer. No programmer is needed to use with the Arduino IDE... you program over USB.

I think it's simpler to get a board for 28-pin AVRs with a programmer, and skip the Arduino, especially if the dev board has a nice GUI for AVRDude. I've tried all the various incantations, and found the Arduino as a programmer sucks in a number of small ways that make the experience less than expected

First is that you can't program over USB unless the chip has a bootloader on it. So if you buy raw 168/328 chips, you'll still need a ICSP programmer. You can plug the programmer into the Arduino and then flash a bootloader onto it, but if your aim is to de-chip it and use the MCU outside of the board why not just program it via AVR Studio and a programmer. Arduino makes a nice dev platform, but a second-rate programmer.

Second is that if you try to load the Optiboot bootloader that ships with the current Uno it may not work, because of a silly bug they've never fixed (it's corrected in the very latest build of the bootloader available on GitHub, but this version isn't yet part of the IDE download). What happens is your Uno forever loops in bootload mode, and the sketch never starts. The problem doesn't exist if you pull the chip and use it externally, but it sure makes testing hard. All that plugging/unplugging wears out the socket on your Uno.

Third is, of course, the IDE doesn't have a way to generate a hex file in a specific location so you can easily fetch it and download it to your chip outside of the USB (bypassing the bootloader). You have to know where the Arduino stores its build files, grab the hex, etc. In all rather clumsy.

I could go on, but in the end this approach is a lot of work for not much extra benefit. Maybe 1.0 will change some of this, but as it stands, getting a separate programmer and dev board with AVRDude GUI is, I think, more appropriate for first-timers.

Granted, once you know what you're doing the process is repeatable and not difficult. The road to that point is not, IMO, nearly as smooth as the rest of the Arduino experience.

-- Gordon

GordonMcComb
08-25-2011, 04:22 PM
Actually I find the 168 is much cheaper than the 328 (at least in TQFP) - partly because of the supply/demand equation. I've used these chips a lot both via Arduino libraries and direct hardware access (mainly for the flexible timer modules). The availability of 6 (or 8 on the TQFP version) ADC inputs is mighty useful even though they are rather slow and multiplexed.

Also the wide supply-voltage range is nice to have.

Don't know about the TQFP package, but for a ATmega328P-PU, which has 6 or 8 ADC, and voltage down to 1.8V, the price difference for the DIPs is about 35 cents. Some part variations are more, some less, but in total, not a big hit. Of course, this all depends on availability. Digikey is low on 328Ps, but Mouser seems to have thousands of each.

Since the 168 and 328 are electrically identical it really comes down to whether you want or need the extra memory space. For 90%+ of jobs the 168 is still more than sufficient. However, if you have a choice, and if the price difference really only comes down to pennies, why not opt for the 8 seater van over the 4 seater SUV. (Ride comfort and gas mileage not part of the analogy!)

-- Gordon

tobdec
08-25-2011, 07:13 PM
At Braino...I guess my goal is both in all reality. I would definetly like to learn Workstation assembly and C but would also like to learn C for embedded applications. I think if I can get good at worksation C embedded C and asm should be easy to pick up. And as far as that book link goes i've allready got the book in my hands. I found a nice colection of e-books written for ASM on the piratebay it has like 10 books in it.

prof_braino
08-25-2011, 09:15 PM
Maybe, maybe not. If you get used to programming on a workstation with tons of memory (anything more than 32k) and tons of speed (anything faster than 80Mhz) and tons of overhead for things taken care of in the background automatically, you might have problems when these things are gone. Embedded is all about working within the constraints of the available equipment, workstations are all about filling the available memory until it breaks and you get to buy a bigger workstation. :)

Unless you want to put a laptop in your robot (and I've seen it done, some folks have too much money), embedded is a different kettle of fish, and your workstation experience can trip you up. Workstations are "maximum for a general solution", embedded is "minimum for a specific solution". While these can overlap, imagine in the extremes, like a Cadillac and a dune buggy; and driving from New York to LA vs driving on the sand.

Just something to consider.