Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Programming for Atmel AVR microcontroller

Options
  • 04-04-2005 11:32am
    #1
    Closed Accounts Posts: 820 ✭✭✭


    Hi there,

    I am currently doing a one year thought masters and I am required to program a number of compression algorithms onto an AVR chip as part of my theses. Sounds easy, but I have no prior experience with coding a micro-controllers. I come from a computer science background. What I need to be able to is

    1. Open a file & read contents
    2. Compress it using desired algorithm (Huffman)
    3. Write results to a file.

    I am more than capable with step 2 but it's step 1 & 3 that are catching me. I have no idea how this is done using a microcontroller. The Gnu avr C compiler is the compiler i'm using along with AVR Studio as my IDE. I don't have a project board as i've been instructed to do it using emulation. Of course with my background i would assume you would use the open() and close() c functions but of course because there is no underlying OS this it is more difficult to do. Could someone with a knowledge of programming a microcontroller using C please help me out.

    All I really need is parts 1 & 2 above to get started. Once I have this i can concentrate my efforts on writing the algorithm into c code and optimising it. Bear in mind that i'm completely clueless when it comes to microcontrollers so don't assume anything in your response. I've tried loads of searches on google and have already posted on www.avrfreaks.com with no luck.

    Thanks in advance.

    Brian


Comments

  • Closed Accounts Posts: 7 MDMA


    ok as for writing to a micro controller there is a little kit u can by on the net called BASIC Stamp 1 its manufactured by http://www.parallax.com u can buy this kit for as little as €70 it is designed for those who wish to learn how to program a micro-controller so i figured its right up ur ally.here is the link to the article on howstuffworks..they refer the above link at the end of one of there guides...http://electronics.howstuffworks.com/microcontroller.htm

    now i know u say u want to program the controller in c well i dont know a whole lot about micro_controller programming but if i were doing any micro programming id use asm thats assembley ...if u do decide to use asm there is a really cool tool for asm simulation called http://www.emu8086.com/ its a good tool anyway even if u dont use asm cos they deal with micro-controlers is a Visual Microprocessor Emulator..now it should not be very hard to google a book or tut on c programming a microcontroller if u cant find anything well i give a look but thats my suggested answer...

    let me know if this helps at all....

    MDMA


  • Registered Users Posts: 2,426 ✭✭✭ressem


    What sort of storage. Are you connecting to flash/eeprom, ide controller, storage through uart?

    From the avr doc (avr-libc-user-manual-1.2.3.pdf) under standard IO chapter
    "
    The standard streams stdin, stdout, and stderr are provided, but contrary to the C standard, since avr-libc has no knowledge about applicable devices, these streams are not already pre-initialized at application startup. Also, since there is no notion of "file" whatsoever to avr-libc, there is no function fopen() that could be used to associate a stream to some device. (See note 1.) Instead, the function fdevopen() is provided to associate a stream to a device, where the device needs to provide a function to send a character, to receive a character, or both.
    "

    Don't know thether you need it but
    http://www.robs-projects.com/filelib.html
    provides
    FAT32 File IO Library for AVR.


  • Closed Accounts Posts: 820 ✭✭✭qBot


    Thanks for all your replies

    @ressem I haven't made any decision as to what device i will connect. Mainly cause i don't really know what u can connect. Based on the spec given to me by my supervisor my thesis should take input, compress it and output it. It is most likely a continuos stream. I felt that if i were able to read and write to files it would make development and debuging so much easier as I could set up a test environment with text files and make sure they were compressed properly. I did see the reference to fdevopen() in avr-libc however i don't know how to use it. I've tried looking for tutorials online but there are none so simple that i can follow. You seem to know what your talking about and i would appreciate any ideas u would have on the subject. Do u know of anyy better ideas i could use for test environments and stuff like that.
    .


  • Registered Users Posts: 2,426 ✭✭✭ressem


    You seem to know what your talking about
    :eek:
    first time...

    Warning, I don't work with this hw or IDE, I'm going on what I glanced at here.
    http://www.atmel.com/dyn/products/app_notes.asp?family_id=607 and the user doc.


    Ok, we're not going to deal with files and file systems to start with, just raw data that can be inspected in the IDE.

    the thing about fdevopen is that you provide the functions to read and write bytes to the particular device. The doc shows a very simplistic way of dealing with data being received from the uart.

    If you want to deal with addressable data blocks then check whether your device is compatible with avr/eeprom.h, in which case the eeprom_getchar function you create might be little more than a

    eeprom_is_ready()
    eeprom_read_byte( address)

    with a little address counter handling.

    If you need to read/write stream data over a serial connection then you'd use the UART a bit like
    http://voodooz.no-ip.org/robotics/srx1/source/serialio.c

    but I have no idea how easy this is with your emulator package and looking at "setup and use of the spi" it doesn't look trivial


  • Closed Accounts Posts: 820 ✭✭✭qBot


    Ya, what your saying seems to make sense. I had heard of fdevopen() before, but i have no idea to set it up. I'll take a look at the source of serialio.c. The emulation is still a problem though. How would i send test data to the ide channel through emulation. Even if i had a test board, I think once i had set up my emulation environment properly it would be a lot easier to develop with. Me being a computer scientist and all.


  • Advertisement
  • Registered Users Posts: 1,745 ✭✭✭swiss


    I haven't worked with that particular processor but I do recall programming another microprocessor (the PIC16F877 if anyone is interested) in C.

    As has already been mentioned, your first port of call should be to the datasheet of the microprocessor. You haven't mentioned the specific microprocessor that you'll be using, so I took the liberty of selecting a typical one in the mould of what you probably be dealing with.

    This is the direct link to the PDF.

    If you're unfamiliar with microprocessor coding, it may seem daunting at first, but you will often find inbuilt routines such as ISR (interrupt service routines), as well as timers, counters etc to help you along the way.

    I don't know what kind of emulation software is available for this particular microprocessor, but if you're doing a masters I think you should set up a circuit board with an RS232 connection on the board to your PC. You can then upload programs using telnet through the COM ports. It will avoid the expense of a Stamp board and should allow for faster program development/deployment.


  • Registered Users Posts: 2,426 ✭✭✭ressem


    Sorry, I wasn't clear.

    The IDE reference in the last post was Integrated development environment. I assumed that you were using avr studio in simulation mode without any hardware emulators.

    I believe that you won't work with a real windows formatted IDE drive. As then you have to worry about trashing the file system, virtual IDE controller etc.

    At best you would be dealing with a virtual eeprom, as is meant to be supported by the atmel studio emulator.
    Whether you want to implement a routine to format the virtual drive with a file allocation table, or just treat the entire eeprom as one or more fixed size files is up to you.

    It may be possible to use a file on the windows filesystem as a virtual eeprom device, the same way that you use an ISO file with a loopback device in linux or vmware. Depends on the emulator. Then you could edit it with any byte friendly programming editor under windows.

    Otherwise you might require a test routine to populate the virtual eeprom with your data, or to use the debugger to fill that area of storage, before running your load routine under emulation.

    In short, need more info.
    Eg documentation for Studio to determine best way to setup and fill the virtual eeprom/flash. See if you can have a file under windows that is used as an eeprom.
    Whether Studio supports other virtual hardware like uart or ide controller if you must. UART might be preferred if you switch to using a development board on a developmemt board.

    At the bare minimum you could "load" and "save" data by using interrupts to catch and send bytes on particular pins, which would be educational for you.

    What microprocessor you intend to use, what emulator you use and whether you are going to need to download and run this from real hardware as part of your project. In which case knowing what development boards are available to you might focus you on a particular processor and setup.

    -- edit --
    Apparently some of the microprocessors have UARTs built in. If you choose this method of data transfer, the bits at http://www.siwawi.arubi.uni-kl.de/avr_projects/#bf_logger
    might be of use, like uart data logger.

    Also there is meant to be support for filling the virtual eeprom with a windows .eep file in Studio.


  • Closed Accounts Posts: 820 ✭✭✭qBot


    @ressem Thank your for a great reply. I never acknowledged it back in April. Sorry bout that, diverted attention to my exams and assignments. But you have been a great help. I probably will have more questions from time to time which ill post here. Thanks to every one who replied to this thread.


Advertisement