Shop OBEX P1 Docs P2 Docs Learn Events
broadening my scope - Page 2 — Parallax Forums

broadening my scope

2»

Comments

  • tobdectobdec Posts: 267
    edited 2011-08-20 16:40
    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.
  • HollyMinkowskiHollyMinkowski Posts: 1,398
    edited 2011-08-20 17:46
    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)
  • tobdectobdec Posts: 267
    edited 2011-08-20 18:44
    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!
  • HollyMinkowskiHollyMinkowski Posts: 1,398
    edited 2011-08-20 19:01
    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.
  • tobdectobdec Posts: 267
    edited 2011-08-20 21:09
    What is soo difficult about flashing the first program?
  • Kevin WoodKevin Wood Posts: 1,266
    edited 2011-08-20 21:26
    >>> 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, 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.
  • tobdectobdec Posts: 267
    edited 2011-08-20 21:43
    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.
  • tobdectobdec Posts: 267
    edited 2011-08-20 21:45
    O btw kevin...what do u mean by "proper" C?
  • LeonLeon Posts: 7,620
    edited 2011-08-20 22:09
    Standard ANSI C.
  • Kevin WoodKevin Wood Posts: 1,266
    edited 2011-08-21 00:30
    >>> 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.
  • tobdectobdec Posts: 267
    edited 2011-08-21 07:56
    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.
  • tobdectobdec Posts: 267
    edited 2011-08-21 21:15
    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.
  • tobdectobdec Posts: 267
    edited 2011-08-24 17:17
    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.
  • LeonLeon Posts: 7,620
    edited 2011-08-25 03:00
    I don't think that book is relevant to programming embedded systems in assembler.
  • Mark_TMark_T Posts: 1,981
    edited 2011-08-25 07:36
    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_brainoprof_braino Posts: 4,313
    edited 2011-08-25 07:50
    Late to notice this discussion,
    Leon wrote: »
    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.
  • mindrobotsmindrobots Posts: 6,506
    edited 2011-08-25 08:09
    tobdec wrote: »
    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.
  • wjsteelewjsteele Posts: 697
    edited 2011-08-25 08:42
    tobdec wrote: »
    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
  • GordonMcCombGordonMcComb Posts: 3,366
    edited 2011-08-25 09:06
    Kevin Wood wrote: »
    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
  • GordonMcCombGordonMcComb Posts: 3,366
    edited 2011-08-25 09:22
    Mark_T wrote: »
    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
  • tobdectobdec Posts: 267
    edited 2011-08-25 12:13
    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_brainoprof_braino Posts: 4,313
    edited 2011-08-25 14:15
    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.
Sign In or Register to comment.