http://students.iitk.ac.in/roboclub MICRO-CONTROLLER: A microcontroller is the brain of the robot: These are: 1. Integrated Circuits (ICs) Programmable – You can define what they do. This is what makes them different from other simpler ICs, such as AND gates, inverters, etc Logic tables relating Input and Output can be defined by you Many useful features built in to the uC itself 2. 3. ATMEGA 16 16 KB Flash Memory… 40 pin UC… 32 I/O Pins These pins have other functions like UART, ADC, SPI, LCD, Interrupt, TIMERS, etc… But we will now focus on I/O and TIMER… Maximum Voltage 5V, current rating about 10 milliamperes Atmega8 I/O Pins: Setting Data Direction (I/O?): DDRX Register PORTX Register PINX Register I/O Registers Input / Output is controlled through special variables called “registers”. Registers are actual hardware memory locations inside the μCs with predefined names and sizes. Assigning a value to these registers in the program changes the corresponding hardware configuration. And, these values can be altered multiple number of time at any point in the program. There are 3 registers that control the I/O pins: DDR, PORT and PIN. Each port has it’s own registers. Hence, DDRA, PORTA, PINA registers for port A; DDRB, PORTB, PINB for port B and likewise. DDR(Data Direction Register) Decides whether the pin is Input or Output. DDR is an 8 bit register. Each bit corresponds to a particular pin on the associated port. If a bit on the DDR register is 0, then the corresponding pin on the associated port is set as input. Similarly, if the bit is 1, then the pin is set as output. If a pin is configured as input, then it has some floating voltage unless an external voltage is applied. For an output pin, the voltage is fixed to a particular value. Setting Register Values MSB of DDRA corresponds to the pin A7. If DDRA = 0b10010110, then: PORT register PORT is also an 8 bit register. The bits on the PORT register correspond to the pins of the associated port in the same manner as in the case of the DDR register. PORT is used to set the output value. If the pin is set as output, then a PORT value of 1 will set voltage at that pin to 5V, and PORT value 0 sets the voltage to 0V. If the pin is configured as an input, PORT value serves the purpose of pull up or pull down. PIN register PIN is a register whose value can be read, but cannot be changed inside the program. It gives the value of the actual voltage at a particular pin. 1, if the value at the required pinis 5V and 0 for 0V. Summary Tools Required -> CVAVR Compiler -> CVAVR The code is written in C language so we need to convert it into the format that Atmega understands . Transfer code to Atmega AVR Studio Avr Programmer So we need two softwares overall a) CVAVR –> Editor and Compiler b) Avr Studio –> Transfer Code to Atmega While & For While (conditon) { … ... } for(initialisation; condition; increment) {……} Lets Begin by blinking a simple LED How to program a microcontroller: A microcontroller understands only binary language (0 and 1)…We write the code in C language in CVAVR (Compiler + IDE). We compile the code to generate the .hex file (which the machine understands) We transfer the .hex file to Atmega using a Programmer Hardware: Serial Programmer, STK 500, USB etc… (Contains chips to convert voltage levels and protocols) Software: AVR Studio, AVRDUDE, etc… Programmer Pin connection with Atmega 8 How to Run Motors through UC? The Atmega16 has a current rating of 5-10 mA. The normal DC motor’s current ratings start from 150 mA and above. So the motor cannot be directly attached to the Atmega, hence a motor-driver is used… (eg: L293, L298, etc…) TIMERS: Atmega has: Timer 0, 8 bit (OC0 at PB3) Timer 1, 16 bit (2 parts A and B each of 8 bit, OC1A at PD5, OC1B at PD4) Timer 2, 8 bit (OC2 at PD7) There are 2 clocks: System Clock (fs) Timer Clock (ft = fs or fs/8 or fs/64 or ….) (For generating 38 KHz in TSOP Sensors) (For MOTORS) NOW LET US HAVE A LOOK AT CVAVR AND AVR STUDIO AND HOW TO PRACTICALLY PROGRAM AN ATMEGA 16 THANK YOU