200 likes | 805 Views
Atmega32 Microcontroller. This is a small computer with an RTOS, Real Time Operating System, running on it. Honestly, this is more powerful than you will ever need for any robot.
E N D
Atmega32 Microcontroller • This is a small computer with an RTOS, Real Time Operating System, running on it. Honestly, this is more powerful than you will ever need for any robot. • This chip along with most microcontrollers is made up of various types of I/O. With respect to robotics and art we can program these chips to do anything. Ask me, anything! • We will use them to: • Control servomotors (for dog legs and wheels) • Read and log data from sensors (for sensing toxins) • React to sonar for mobile guidance • Interface with other software (LabVIEW) for data analysis
Atmega32Specs • Review front page specs on Atmega32 Microcontroller at: http://www.atmel.com/dyn/resources/prod_documents/2503S.pdf • The Atmega32 is an 8 bit RISC microcontroller. • Pronounced risk, acronym for Reduced Instruction Set Computer, a type of microprocessor that recognizes a relatively limited number of instructions keeping it simple and yet fast. • 8 bit tells us how much information each register can support. It refers to information stored or processed; there are 256 different operations stored/processed per 8 bit register.
Hex/Binary/Decimal Conversion • Go to pg. 63 of the atmega32 manual to look at registers: http://www.atmel.com/dyn/resources/prod_documents/doc2503.pdf • In order to access registers, or turn things on and off you need to be able to convert between these numbering schemes. • Binary: 1s and 0s. • Decimal: 1, 2, 3, 4, 5…..100, 101…, base 10 • Hexidecimal: 0xc1, base 16 • Here’s a great source: http://www.stcsc.edu/OCL/hex_to_decimal_conversion.htm
Embedded C Programming in 1 Slide • Functions: main, void, int, return • Loops: If else, while, for, do while etc. • Commenting: //, /* • End commands with a semi-colon ; yourMom(void); • There are many ways to program an operation. The efficient way is preferred because it saves processor time.
Programming Order of Operations • Write pseudo code: basically a flowchart of the program, so you don’t immediately bog yourself down with code and syntax. • Write your program in a code editor (WinAVR, Emacs, etc.) • Compile (Gnu-GCC) and then debug if necessary. Compilers figure out if your code has errors; if it does, it will point them out and you can fix them; if it doesn’t, it will create machine code in the form of a *.hex file. • Send the *.hex file to the microcontroller using Hyperterminal or some other serial port terminal program. • Run your program!
Programming Example #include <avr/io.h> void delay(void) { volatile int i,j; for (j=0; j < 10; j++) for (i=0; i < 0xFFFF; i++) ; } int main(void) { DDRB = 0xFF; // set port B to outputs PORTB = 0x01; // write to PA0 on PORTB delay(); //delay for about 1 second PORTB = 0x00; // do not write anything return 0; }
Avr-libc Libraries • All microcontrollers have libraries of functions for use in your programs, so that you don’t always have to rewrite common algorithms. • Examples: timer.c, pwm.c, a2d.c, servo.c etc etc. • You can call use a library by including the header file at the top of your program: #include "timer.h“ // include timer function library (timing, PWM, etc)