AVR-M103 Application Board User Manual
Transcription
AVR-M103 Application Board User Manual
AVR-M103 Application Board AVR-M103 Application Board User Manual -1- AVR-M103 Application Board CONTENTS PART 1 : AVR SERIES 1. What is AVR? 2. AVR Series 3. Features of ATmega103 PART 2 : AVR-M103 Application Board 1. Introduction 2. Features 3. Specifications 4. Schematic 5. Parts List 6. Connections PART 3 : Software Tools 1. AVR Development Program Installation 2. How to use Microrobot AVR GCC 3. How to use AVR ISP(In-System Programming) 4. How to use Imagecraft ICC AVR 5. How to use AVR ISP(In-System Programming) Part 4 : Sample Sources 1. LED On/Off Using the Push Switch. 2. Display Hexadecimal with 8-segment LED Display. 3. Display Time to the LCD. 4. Counter using External Interrupt. 5. DC Motor Control using PWM 6. Play a song with the Buzzer 7. Detect an Obstacle Using Infrared ray. 8. Stepper Motor Control 9. EEPROM 10. Serial Communication 11. Wireless Communication Using RF Module Silkscreen Schematic1(ATmega103 CPU Board) Schematic2(AVR-M103 Application Board) -2- AVR-M103 Application Board PART 1 : AVR SERIES 1. What is AVR? AVR is one of Atmel’s 8-bit microcontroller series names, which has high-performance and lowpower RISC(Reduced Instruction Set Computer) architecture. Alf Bogen and Vergard Wollan designed AVR microcontrollers. AVR stands for Alf Vergard RISC microcontroller. Atmel's AVR microcontrollers have RISC core running single cycle instructions and a well-defined I/O structure which limits the need for external components. Internal oscillators, timers, UART, SPI, pull-up resistors, pulse width modulation, ADC, analog comparator and watch dog timers are some of the features you will find in AVR devices. In addition, the AVR has on-chip in-system programmable Flash and EEPROM that provides a highly flexible and cost-effective solution to many embedded control applications. The on-chip ISP Flash allows the program memory to be reprogrammed in-system through a serial interface or by a conventional nonvolatile memory programmer. AVR instructions are designed to decrease the size of the program whether the code is written in C or Assembly. 2. AVR Series l ATmega Series AVR → ATmegaxxx (16KB~128KB Flash Memory) l AT90 Series AVR → AT90Sxxxx (1KB~8KB Flash Memory) l ATtiny Series AVR → ATtinyxx (1KB~2KB Flash Memory) Refer to the ‘Atmel Product Guide.pdf’ for more detail. 3. Features of ATmega103 • Utilizes the AVR ® RISC Architecture • AVR – High-performance and Low-power RISC Architecture – 121 Powerful Instructions – Most Single Clock Cycle Execution – 32 x 8 General Purpose Working Registers + Peripheral Control Registers – Up to 6 MIPS Throughput at 6 MHz • Data and Nonvolatile Program Memory – 128K Bytes of In-System Programmable Flash Endurance: 1,000 Write/Erase Cycles – 4K Bytes Internal SRAM – 4K Bytes of In-System Programmable EEPROM Endurance: 100,000 Write/Erase Cycles – Programming Lock for Flash Program and EEPROM Data Security -3- AVR-M103 Application Board – SPI Interface for In-System Programming • Peripheral Features – On-chip Analog Comparator – Programmable Watchdog Timer with On-chip Oscillator – Programmable Serial UART – Master/Slave SPI Serial Interface – Real Time Counter (RTC) with Separate Oscillator – Two 8-bit Timer/Counters with Separate Prescaler and PWM – Expanded 16-bit Timer/Counter System, with Separate Prescaler, Compare, Capture Modes and Dual 8-, 9-, or 10-bit PWM – Programmable Watchdog Timer with On-chip Oscillator – 8-channel, 10-bit ADC • Special Microcontroller Features – Low-power Idle, Power Save and Power-down Modes – Software Selectable Clock Frequency – External and Internal Interrupt Sources • Specifications – Low-power, High-speed CMOS Process Technology – Fully Static Operation • Power Consumption at 4 MHz, 3V, 25°C – Active: 5.5 mA – Idle Mode: 1.6 mA – Power-down Mode: < 1 µA • I/O and Packages – 32 Programmable I/O Lines, 8 Output Lines, 8 Input Lines – 64-lead TQFP • Operating Voltages – 2.7 - 3.6V (ATmega103L) – 4.0 - 5.5V (ATmega103) • Speed Grades – 0 - 4 MHz (ATmega103L) – 0 - 6 MHz (ATmega103) -4- AVR-M103 Application Board PART 2 : AVR-M103 Application Board 1. Introduction AVR-M103 Application Board is designed to study the ATmega103 8-bit microcontroller. The best way to master one CPU is studying with a well-designed educational board. Thus, AVR-M103 Application board is useful for anyone who is studying AVR CPU family or designing with them. This board has many different kinds of testing hardware such as LED, LED Network, 8-Segment Display, LCD, Buzzer, Infrared Sensor, PC Interface, Stepping Motor Interface, RF Module Interface and others. After gaining the basic knowledge to control this hardware, you may be successful in making a complicated robot like a micromouse. 2. Features • Uses an ATmega103 CPU Board(refer to ATmega103 CPU BOARD). • On board stepper motor driver(SLA7024). • On board small DC motor driver TR. • Serial cable, ISP download cable and power cable included. • User manual, a program CD included. • Stepper motor and RF module(BiM 418 or BiM 433) are optional. 3. Specifications Item SIZE CPU BOARD DISPLAY SENSOR KEY PORT BUZZER OTHERS POWER OPTION Description 85 x 146 mm ATmega103 CPU BOARD 16 x 2 Line LCD 8-Segment Display, LED Network Infrared LED and Sensor Reset Key, User Key x 6 Stepper Motor Port DC Motor Port RF Module Port Piezo Buzzer(BTG-47) frequency controlled MAX232 DC 8-12V, DC 15V(for stepper motor) Stepper Motor, RF module(BiM 418 or BiM 433) 4. Schematic Refer to the end of this file. -5- AVR-M103 Application Board 5. Parts List NO. Reference Parts 1 BZ1 Buzzer 2 C1 Capacitor 3 C2, C10, C11, C20 " 4 C3, C4 " 5 C5, C7 " 6 C6 " 7 C8, C9 " 8 C12~C14, C17, C18 " 9 C15, C19 " 10 C16 " Infrared Emitting 11 D1 Diodes 12 D2 Array LED 13 D3 Diode 14 D4 " 15 D5 LED 16 J1~J4 Connector 17 J5 " 18 J6, J7 " 19 J8 " 20 J9 " 21 J10, J14 " 22 J11 " 23 J12 " 24 J13 " 25 Q1 Phototransistors 26 Q2, Q3 Transistor 27 RA1 Array Resistor 28 RA2 " 29 R1, R12, R14 Resistor 30 R2, R24 " 31 R3, R15, R16 " 32 R4~R11 " 33 R13 " 34 R17 " Value BTG-47 103 104 470pF 20pF 10uF 2200pF 1uF 100uF/25V 220uF/25V Q’ty 1 1 3 2 2 1 2 5 2 1 CL-1L5 1 SR B-10 1N4004 1N4148 RED 3φ CON16A CON6 CON9 CON2 CON6AP CON3 CON16 CON10AP CON3 ST-1KLA C1815 330Ω / 9pin 10KΩ / 9pin 1KΩ 470Ω 47KΩ 330Ω 10Ω 510Ω 1 1 1 1 4 1 2 1 1 2 1 1 1 1 2 1 1 3 2 3 8 1 1 -6- Remark monolithic Condenser “ “ Ceramic Condenser Electrolytic Condenser Monolithic Condenser Electrolytic Condenser “ “ Infrared Emitter Two lines Header(F) 5268 Header(F) 5268 2 × 3 Header(M) 5046 Header(F) HIF3F/10 Right angle 5268 Infrared Sensor NPN AVR-M103 Application Board Remark NO. Reference Parts Value Q’ty 35 R18, R20 " 2 2.4KΩ 36 R19 " 1 Variable Resistor 500Ω 37 R21, R22 " 2 DIP 1Ω/0.5W 38 R23 " 1 10KΩ 39 S1 Switch Tack(medium) 1 40 S2~S7 " Tack(small) 6 41 S8, S9 " Toggle-3P 2 42 U1 FND SND417A 1 43 U2 Motor Driver SLA7024M 1 44 U3 C-MOS 74HC14A 1 45 U4 Regulator 7805 / TO220 1 46 U5 I.C MAX232A 1 47 XTAL1 X-tal 6MHz 1 48 P.C.B AVR-M103 1 85mm × 146mm 49 LCD 2×16 Character 1 50 Jumper 1 51 screw 9 3 × 8(Pan head) 52 Nut 5 53 Insulating Washer 10 54 Supporter(Male) 4 10 mm, Plastic 55 Supporter(Female) 4 10 mm, Plastic 56 Ribbon Cable 1 1 meter 57 Downloading a Adapter 1 Connect to printer port 58 Serial port cable 1 59 Power 2 -7- AVR-M103 Application Board 6. Connections Figure 2.1 Downloading Ribbon cable Figure 2.4 Power Cables Figure 2.2 Downloading Adapter Figure 2.3 Serial Communication Cable 1) AVR(ATmega103) CPU BOARD Connect the AVR(ATmega103) CPU board to the AVR-M103 Application Board. Match the connectors’ names(J1, J2, J3, J4) of the CPU board to the App(Application) board. Warning : A wrong connection will cause serious damage to the boards. 2) Power Cables There are two power cables. One is for the board and the other one is for the stepping motor. Connect one of the cables to the App board’s J10 port and provide DC 6.5~9V. When driving the stepping motor, connect the cable to the App board’s J10 port and provide DC 12~20V. There are individual power switches for the board power and the stepping motor power: S8, S9 respectively. 3) Downloading Adapter and Ribbon Cable -8- AVR-M103 Application Board Plug the downloading adapter to the PC printer port and connect the adapter to the App board’s J12 using the ribbon cable. 4) Serial Communication Cable When you want to use the serial communication function, connect the 9-pin PC serial port to the App board’s J13 port(3-pin). 5) Stepper Motor Port(J5) Use a 6-line stepper motor. A SLA7024 unipolar stepper motor driver is used to drive the stepper motor. The following table shows the stepper motor port(J5)’s pin numbers and their control signals. Table 2.1 J5 Stepper Motor Port Pin number Signal 1 A 2 Center Tab of A 3 /A 4 B 5 Center Tab of B 6 /B 6) RF module Port(J6) Put together a RF module(BiM-418 or BiM433, optional) to the App board’s J6. Make sure to match the RF module’s pins to the J6 box-header’s pins properly. Number 1 pin is in the top left corner of the JP box-header. -9- AVR-M103 Application Board PART 3 : Software Tools 1. AVR Development Program Installation AVR Development Tools There are many different kinds of development tools for AVR microcontrollers. Atmel, the AVR CPU manufacturer, provides some AVR development tools free. Microrobot Co. Ltd. also provides a free Windows C-compiler. Wavrasm: AVR assembler, Atmel. AVR Studio: AVR Emulator/Simulator, Atmel. AVR ISP: ISP downloading program, Atmel. Microrobot AVR GCC: C-compiler, Microrobot. ICC AVR : C-compiler, Imagecraft.(30-day trial version included in the CD) System requirements for AVR development tools l Windows 9x/ME or NT/2000 l Pentium-133 or higher l At least 4 Mbytes of RAM l CD-ROM Drive -10- AVR-M103 Application Board AVR ISP installation: Run setup.exe in the CD’s avr_isp folder. Microrobot AVR GCC installation Refer to the ‘Microrobot AVR GCC User Guide.pdf’ file in the CD’s MaroGcc0.9C folder. Imagecraft ICC AVR (30-day trial version) installation Run iccavrdem.exe in the CD. Attention : Do not attempt to extend the limited 30-day. Any attempts such as changing date, cracking, reinstalling might cause that the program does not work anymore. 2. How to use Microrobot AVR GCC Refer to the ‘Microrobot AVR GCC User Guide.pdf’ file in the CD’s MaroGcc0.9C folder. 3. How to use AVR ISP(In-System Programming) Refer to the ‘AVR ISP Manual for Microrobot AVR Products.pdf’ file. 4. How to use Imagecraft ICC AVR Copy the (Imagecraft) Source folder on the CD to the C drive root directory. Remove (uncheck) read-only file attributes for the all copied files. Run the ICC AVR. -11- AVR-M103 Application Board Figure 3.16 ICCAVR Window Select ‘File → Open’ or click on . icon and load c:\source\sw.c file. -12- AVR-M103 Application Board Figure 3.17 Source file loading. Select ‘Project → Options → Target’ and configure as shown below. Figure 3.18 Target setting There are two items(COFF, Intel HEX) to choose from the ‘Output Format’ box. COFF is used to debug the source program using the AVR Studio. Intel HEX is an executable file. -13- AVR-M103 Application Board Select ‘Compiler’ tab and set up as shown below. Figure 3.19 Compiler setting Select ‘Paths’ tab and set up the paths. Figure 3.19 Paths setting Include Path(s) : The path where iom103.inc (or *.inc files) exists. Library Path : Library Path. Output Directory : Current working source folder. Click on ‘Set As Default’ button and OK button. Select ‘File → Compile File → To output’ or press ‘Ctrl + F9’ to show the output message window. -14- AVR-M103 Application Board Figure 3.21 Output message window ‘Done’ is displayed in the Output message window if there is no compiling error. The following files are generated in the output folder as a result of the compiling. *.hex : Hex file. Executable file. *.mp : Address mapping information for the functions and variables used. *.s : C source code + Asm source code. *.lst : Asm List file. -15- AVR-M103 Application Board 5. How to use AVR ISP(In-System Programming) Refer to the ‘AVR ISP Manual for Microrobot AVR Products.pdf’ file in the CD. -16- AVR-M103 Application Board Part 4 : Sample Sources For simplicity, all source lists are not included in this chapter. Refer to the sources in the CD. Reference the pdf data for the ATmega103 CPU. All source files have the following source line in common. #include<init.inc> The init.inc file has a system_init() function that initializes I/O ports and their direction. 1. LED On/Off Using the Push Switch. (1) LED(Light Emitting Diode) LED is a semiconductor device that emits light when a voltage is applied to it. A LED has two lead wires which have different polarities. (+) polarity is called anode and (-) polarity is called cathode. LED (2) SW.C -17- AVR-M103 Application Board void main() { system_init(); // init.inc while (1){ if(!S2) LED2_ON; else LED2_OFF; if(!S3) LED3_ON; else LED3_OFF; if(!S4) LED4_ON; else LED4_OFF; if(!S5) LED5_ON; else LED5_OFF; if(!S6) LED6_ON; else LED6_OFF; if(!S7) LED7_ON; else LED7_OFF; } } (3) Explanation • Push Button Switches S2~S7 are connected to the Bit2~Bit7 of the PORTF. (Open = 1(5V), Close(Pressed) = 0(0V)). • The LED0~LED7 are connected to the Bit0~Bit7 of the PORTD. The LEDs are turned on when the corresponding bits are low. The LED0~LED7 are allocated in the LED network. • LEDx(x=2~7) light up when the Push Button switch Sx(x=2~7) is pressed. -18- AVR-M103 Application Board 2. Display Hexadecimal with 8-segment LED Display. (1) 8-segment LED Display An 8-segment LED Display has 8 LEDs which have been combined into one case to make a convenient device for displaying numbers and some letters. There are two different types 8segment LED Displays. They are referred to as the Common Anode(CA) and Common Cathode(CA). Each one of the LED legs is connected to one output pin. When the anode legs are common, it is called CA type and when cathode legs are common, it is called CC type. A CA type 8segment LED Display is used on this board. To turn on the LED segment, output 0 to the corresponding bit. a f e g b c d h 8-segment display (Each segment’s name) A b c d E F Hexadecimal numbers (2) FND.C -19- AVR-M103 Application Board byte fnd_data[16]={ 0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8, 0x80, 0x90, 0x88, 0x83, 0xA7, 0xA1, 0x86, 0x8E}; void main(void) { byte fndP=0; system_init(); while (1){ delay_1ms(500); PORTC = fnd_data[fndP++]; fndP &= 0x0F; } } (3) Explanation • The LED segments ‘a’ to ‘h’ are connected to Bit0 to Bit7 of the PORTC respectively. • To display number 1, turn on the ‘b’ and ‘c’ LED segments. Output 0XF9(11111001B) to the PORTC to do that. • Counts from 0 to F(15) every 0.5 sec. -20- AVR-M103 Application Board 3. Display Time to the LCD. (1) LCD (Liquid Crystal Display) LCD is a kind of display that consists of segments of liquid crystal whose reflectivity varies according to the voltage applied to them. An LCD module is a special LCD that is combined with LCD controller(s) and driver(s) for easy interface to the other controller such as CPU. Pin # 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Symbol Vss VDD VL RS R//W E1 D0 D1 D2 D3 D4 D5 D6 D7 A K Function 0V Power 5V H : Data Input, L : Instruction Code H : Data Read, L : Data Write H : Enable Signal Data Bus LCD Back-Light Power Table 4.1 LCD Module Pin Assignment PE4 E1 H H H H PE6 R//W 0 0 1 1 PE5 RS 0 1 0 1 Function Instruction Register Write Data RAM Write Status Register Read Data RAM Read Table 4.2 LCD Module Control Port Pins Note : LCD is a slow device compared to a CPU. Delay time is required to control the LCD. Refer to the ‘S6A0069.PDF’ file for the LCD instructions. -21- AVR-M103 Application Board (2) LCD.C The LCD.C refer to the lcd.inc file. #include<lcd.inc> The lcd.inc file has some LCD functions. -22- AVR-M103 Application Board #pragma interrupt_handler compare1a:13 byte hour = 19, minute = 27, second = 48; void compare1a(void) { gotoxy(7,1); putchar('0'+hour/10); putchar('0'+hour%10); putchar(':'); putchar('0'+minute/10); putchar('0'+minute%10); putchar(':'); putchar('0'+second/10); putchar('0'+second%10); // then increment counter second++; if(second == 60){ second = 0; minute++; if(minute == 60){ minute = 0; hour++; if(hour == 24){ hour = 0; } } } } void main(void) { system_init(); TIMSK = (1<<4); // set OCIE1A TCCR1A = 0; TCCR1B = 0x0C; // CTC1, CK/256 OCR1A = 0x5B8D; // 6000000/256=23437.5 -> 1SEC=23437=0x5B8D TCNT1 = 0; init_lcd(); gotoxy(0,0); outtext(" Made by MICRO- "); gotoxy(0,1); outtext(" ROBOT "); compare1a(); SREG = 0x80; // SEI while(1); } (3) Explanation • The PORTA is connected to the LCD as a data bus. • Sets the Timer1’s prescaler as a CK/256 divider. -23- AVR-M103 Application Board • Sets 0x5B8D(=23437) to the ‘Timer1 Output Compare Register’ to make the ‘compare interrupt’ at one second intervals.(6000000/256 = 23437 =0x5B8D). • Updates and displays the current time in the interrupt routine. -24- AVR-M103 Application Board 4. Counter using External Interrupt. (1) COUNT.C #pragma interrupt_handler int7: word Pulse=0; void int7(void) { Pulse++; gotoxy(12,1); putchar( '0'+Pulse/1000 ); putchar( '0'+(Pulse%1000)/100 ); putchar( '0'+((Pulse%1000)%100)/10 ); putchar( '0'+((Pulse%1000)%100)%10 ); } void main(void) { system_init(); EIMSK = (1<<7); EICR = 0x80; // set INT7 // The falling edge of INT7 init_lcd(); // lcd.h gotoxy(0,0); outtext("Made by H.S Yoon"); gotoxy(0,1); outtext("PULSE COUNT:0000"); SREG = 0x80; // SEI while(1); } (2) Explanation • Push button switch S7 is connected to the Bit7(INT7) of the PORTE. • The INT4~NT7 are external interrupt input pins which can be set with one of the following triggers : low level, falling edge and rising edge. • Sets the INT7 to the falling edge trigger. • The external interrupt is activated by pressing the S7 key. -25- AVR-M103 Application Board 5. DC Motor Control using PWM (1) Driving DC motor A motor transforms electrical energy into mechanical energy. A motor which is driven by DC(Direct Current) is called a DC motor. DC motors are commonly used to control small system such as toy, robots and small machines. Generally, the turning speed of the DC motor is determined by the amount of power supplied. To control the amount of power, the voltage must be varied. To vary the voltage without loss requires a complex circuit. Thus, PWM(Pulse Width Modulation) method is used to control a DC motor instead of using a hardware solution. PWM is a software control method, which turns the motor on and off quickly with a fixed amount of voltage supplied. (2) MOTOR.C void main(void) { system_init(); OCR2 = Speed; TCNT2 = 0; TCCR2 = 0x63; while(1) { if(SW_UP==SW_ON){ Speed++; while(SW_UP==SW_ON); }else if(SW_DN==SW_ON){ Speed--; while(SW_DN==SW_ON); } OCR2 = Speed; gotoxy(13,1); putchar( '0'+Speed/100 ); putchar( '0'+(Speed%100)/10 ); putchar( '0'+(Speed%100)%10 ); } // SET PWM MODE, Frequency = CK/64 //Wait until release SW // Wait until release SW } (3) Explanation • Connect a DC motor to the J8. • PB7(PWM2) is the PWM output pin. • PWM value can be from 0 to 255. • SW_UP(S6) : Increase speed. • SW_DN(S7) : Decrease speed. • The ‘Speed’ is stored to OCR2 which determines PWM duty cycle. -26- AVR-M103 Application Board 6. Play a song with the Buzzer (1) Buzzer A buzzer(BTG-47) is installed on the board to make a sound. Usually a buzzer is used to make a fixed buzzing noise. This kind of buzzer has internal electric vibrator. On the other hand, some buzzers make sound according to the input signal like a speaker. The BTG-47 has no internal vibrator, thus, it can output any sound such as buzzing noise, voice or scale. Oct 0 1 2 3 A 27.5000 55.0000 110.0000 220.0000 Bb 29.1352 58.2705 116.5409 233.0819 B 30.8677 61.7354 123.4708 246.9417 C 32.7032 65.4064 130.8128 261.6256 Db 34.6478 69.2957 138.5913 277.1826 D 36.7081 73.4162 146.8324 293.6648 Eb 38.8909 77.7817 155.5635 311.1270 E 41.2034 82.4069 164.8138 329.6276 F 43.6535 87.3071 174.6141 349.2282 Gb 46.2493 92.4986 184.9972 369.9944 G 48.9994 97.9989 195.9977 391.9954 Ab 51.9130 103.8262 207.6523 415.3047 Scale Table : 261.6256Hz is standard ‘C’. 4 5 6 7 440.0000 466.1638 493.8833 523.2511 554.3653 587.3295 622.2540 659.2551 698.4565 739.9888 783.9909 830.6094 880.0000 932.3275 987.7666 1046.502 1108.731 1174.659 1244.508 1318.510 1396.913 1479.978 1567.982 1661.219 1760.000 1864.655 1975.533 2093.005 2217.461 2349.318 2489.016 2637.020 2793.826 2959.955 3135.963 3322.438 3520.000 3729.310 3951.066 4186.009 4434.922 4698.032 4978.030 5274.041 5587.652 5919.911 6271.927 6644.875 (2) MUSSIC.C Void melody(word scale, word length) { OCR1A = scale; delay_1ms(length*Speed); } void main(void) { system_init(); TCCR1A = 0x10; TCCR1B = 0x09; TCNT1 = 0; // Toggle the OC1B output line // CTC1, CK/1 while(1) rhapsody_of_sadness(); } (3) Explanation • (-) Leg of the Buzzer is connected to the PB6(OC1B). • It is toggled when timer1 compare interrupt is occurred. • Put a half of the time constant of the frequency you want to the OCR1A register. • The melody() function play scale can be varied by changing the scale and length parameters. -27- AVR-M103 Application Board 7. Detect an Obstacle Using Infrared ray. (1) Infrared LED and Sensor An infrared LED emits infrared rays. The infrared rays are invisible. Use a CCD(Charge-Coupled Device) camera such as a digital camera or camcorder to see infrared rays. An Infrared sensor converts received infrared rays to an electronic signal. Usually, infrared LEDs and sensors are used as a pair to detect an obstacle. On the board, CL-1L5 is an infrared LED and ST-1KLA is an infrared sensor. (2) Pulse infrared LED driving A ‘pulse infrared LED driving’ method is an easy way to detect an object from a long distance. With this method, the infrared LED is driven by a high current pulse to avoid environmental infrared interference such as fluorescent light. Usually, the infrared sensor, which is paired with the infrared LED, is adjusted to be dull for the same reason. (3) SENSOR.C #pragma interrupt_handler compare0:16 #pragma interrupt_handler adc_complete:22 void compare0(void) { PORTE |= (1<<3); // LED ON delay(14); ADCSR |= (1<<6); // AD start } void adc_complete(void) { PORTE &= 0xf7; } void main(void) { word AD_DATA; system_init(); TIMSK = (1<<1); // set OCIE0 TCCR0 = 0x0B; // CTC0=Compare Mode, PCK0/32 OCR0 = 0x4B; // 32usec=6 => 2.5KHz = 400usec = 75 = 0x4B TCNT0 = 0; ADMUX = 0; ADCSR = 0x89; // SET ADEN, ADIE, CK/2 = 3MHz DDRE |= (1<<3); SREG = 0x80; // SEI while(1) { AD_DATA = ADC; gotoxy(13,1); putchar( '0'+AD_DATA/100 ); putchar( '0'+(AD_DATA%100)/10 ); putchar( '0'+(AD_DATA%100)%10 ); } } (4) Explanation • The infrared LED is connected to the PE3. • The infrared sensor is connected to the PF0(ADC0). -28- AVR-M103 Application Board • Reads and displays the A/D(Analog-to-Digital) converted value to the LCD. -29- AVR-M103 Application Board 8. Stepper Motor Control (1) Stepper Motor. A stepper motor is a motor whose driveshaft rotates in small steps rather than continuously. It is also called a stepping motor. Figure 4.8.1 Unipolar coil driving (2) Driving coils From a circuit designer's point of view stepper motors can be divided into two basic types: unipolar and bipolar. In the unipolar driving, the winding current flows in one direction. Refer to the above Figure. In the bipolar driving, the winding current flows two directions. To cause the stepper motor to rotate, a pulse has to be sent to each coil in turn and the pulse must have enough power to rotate the driveshaft. Therefore, Power TR, Power FET or a special driver is used to drive a stepper motor. SLA7024M unipolar driver is used on this board. Refer to the SLA7024M.pdf for more details. (3) State sequence A stepper motor steps by switching the windings in sequence. There are three different driving sequences for a motor. 1 : energize. 0 : de-energize. 1 2 3 4 A 1 0 0 0 B 0 1 0 0 /A 0 0 1 0 /B 0 0 0 1 One-phase-on full step mode 1 2 3 4 A 1 0 0 1 B 1 1 0 0 /A 0 1 1 0 /B 0 0 1 1 Two-phase-on full step mode -30- AVR-M103 Application Board 1 2 A 1 0 B 1 1 A 0 0 /B 0 0 Half step mode 3 0 1 1 0 4 0 0 1 0 5 0 0 1 1 6 0 0 0 1 7 1 0 0 1 8 1 0 0 0 (4) Preparation First, turn the variable resistor R19 to the end counterclockwise. Then, turn it clockwise slowly until the motor turns well. If the motor does not work check the motor’s wire connections. (5) STEP.C -31- AVR-M103 Application Board byte pulse_data[8]={ 0x04, 0x14, 0x10, 0x18, 0x08, 0x28, 0x20, 0x24}; word Speed; word Period=3200; byte pulseP=0; void compare1a(void) { OCR1A = Period; pulseP ++; pulseP &= 0x07; PORTB = (PORTB&0xC3) | pulse_data[pulseP]; } void main(void) { system_init(); TIMSK = (1<<4); // set OCIE1A TCCR1A = 0; TCCR1B = 0x09; // CTC1, CK/1 OCR1A = Period; TCNT1H = TCNT1L = 0; SREG = 0x80; // SEI while(1){ if(SW_UP==SW_ON){ Period -= 20; while(SW_UP==SW_ON); }else if(SW_DN==SW_ON){ Period += 20; while(SW_DN==SW_ON); } Speed = 32767/(Period/10); gotoxy(12,1); putchar( '0'+Speed/100 ); putchar( '0'+(Speed%100)/10 ); putchar( '0'+(Speed%100)%10 ); } } (6) Explanation • • • • • The four input pins of the SLA7024M are connected to the PB2~PB5. Generates half step sequence by the software. Changes the bit state(output) using the output compare interrupt. SW_UP(S6) : Increase speed(= reduce the period). SW_DN(S7) : Decrease speed(= increase the period). -32- AVR-M103 Application Board 9. EEPROM (1)EEPROM(Electrically Erasable Programmable Read Only Memory) EEPROM is a memory chip that holds its content without power. It functions like a non-volatile RAM, but writing to EEPROM is slower than writing to RAM. EEPROMs have a lifespan of between 10K and 100K write cycles. There is a 4Kbye EEPROM in the Atmega103 CPU. (2) EEPROM.C #define S7 (PINF&0x80) void main(void) { byte imsi; system_init(); init_lcd(); while(1){ imsi = _256EEPROMread(0); gotoxy(0,0); putchar( '0'+imsi/100 ); putchar( '0'+(imsi%100)/10 ); putchar( '0'+(imsi%100)%10 ); _256EEPROMwrite(0,++imsi); gotoxy(0,1); putchar( '0'+imsi/100 ); putchar( '0'+(imsi%100)/10 ); putchar( '0'+(imsi%100)%10 ); while(S7); while(!S7); } } (3) Explanation • Uses ICC(Imagecraft C Compiler) library functions. • The declaration of _256EEPROMread(), _256EEPROMwrite() are in the eeprom.h. • Reads a value from the EEPROM address 0 and displays it to the LCD’s first line. • Finally, adds one to the value, writes the value to the same address and displays it to the LCD’s second line. -33- AVR-M103 Application Board 10. Serial Communication (1) UART(Universal Asynchronous Receiver Transmitter) UART is an electronic circuit that makes up the serial port. It converts parallel bytes from the CPU into serial bits for transmission and vice versa. It generates and strips the start and stop bits appended to each character. Atmega103 has a full duplex UART. Data transmission is initiated by writing the data to be transmitted to the UART I/O Data Register, UDR. The received byte(data) also appears in the UDR. But UDR is in fact two physically separate registers; one for transmitted data and one for received data. (2) SERIAL.C #pragma interrupt_handler rx_complete:19 byte R_buffer; void putChar( unsigned char data ) { while( !(USR&0x20) ); UDR = data; } void puttext( char *data ) { int i=0; while( data[i] != 0 ) putChar(data[i++]); } void rx_complete( void ) { R_buffer = UDR; if( (USR&0x10) != 0 ) return; putChar( R_buffer ); } void main(void) { unsigned char data=0x30; system_init(); UBRR = 77; // 4800bps UCR = 0x18; UCR |= 0x80; SREG = 0x80; // SEI while (1); } (3) Explanation • Insert a jumper to ‘A’ of the J9 header. • After downloading the program, move the jumper from ‘A’ to ‘B’ of the J9 header. • Run a serial communication program such as hyper-terminal, and set it up with 4800bps. • UBRR = X-tal frequency(6MHz) /(16 × BAUD)-1 = 77.125. • Returns the data from the Rx pin to the Tx pin using rx-complete interrupt. -34- AVR-M103 Application Board 11. Wireless Communication Using RF Module (1) RF Module(BiM-418-F, BiM-433-F) An RF (Radio Frequency) module is a compact component used for wireless radio communication. The BiM-418-F and BiM-433-F are miniature UHF radio modules capable of half duplex data transmissions at speeds up to 40 Kbit/s over distances of 30 meters in-building and 120 meters over open ground. Single 4.5V to 5.5V power supply is required. Refer to the ‘Bim.pdf’ file for more details. (2) RF.C #pragma interrupt_handler rx_complete:19 #define RXE (1 << 2) byte R_buffer; void putChar( unsigned char data ) { while( !(USR&0x20) ); UDR = data; } void puttext( char *data ) { int i=0; while( data[i] != 0 ) putChar(data[i++]); } -35- AVR-M103 Application Board void rx_complete( void ) { R_buffer = UDR; if( (USR&0x10) != 0 ) return; putChar( 0x01 ); putChar( R_buffer|0x80 ); } void main(void) { system_init(); PORTE &= ~RXE; UBRR = 77; UCR = 0x18; UCR |= 0x80; SREG = 0x80; // Set the RF Module with Tx mode. // 4800bps // SEI init_lcd(); gotoxy(1,0); outtext("RF Module TEST"); gotoxy(1,1); outtext("Push keyboard"); while (1); } (2) Explanation • Insert a jumper to ‘A’ of the J9 header. • After downloading the program, move the jumper from ‘A’ to ‘B’ of the J9 header to use the RF module as a transmitter. (If you need to use the RF module as a receiver, move the jumper to ‘C’ of JP9 header.) • Clear the PE2 to set up the module with a transmitter. (If you want to set up the module as a receiver, set the PE2 bit.) • Run a serial communication program such as hyper-terminal, and set it up with 4800bps. • The sample source code is a simple test program, which forwards serial Rx data to the RF module after some processing: or-operation(R_buffer|0x80) and attaching a byte(0x01) in front of the data. • To receive the data, a different RF module control board is required such as a Charisma RF board or an AVR-M103 application board. • Refer to the Charisma RF board manual for the detail RF module controls. Microrobot(www.microrobot.com) -36- U1 PF0 PF1 PF2 PF3 PF4 PF5 PF6 PF7 61 60 59 58 57 56 55 54 J1 /PEN PE1 PE3 PE5 PE7 PB1 PB3 PB5 C 1 3 5 7 9 11 13 15 + + + + + + + + + + + + + + + + 2 4 6 8 10 12 14 16 PE0 PE2 PE4 PE6 PB0 PB2 PB4 PB6 AREF 62 AVCC 64 AGND 63 PE0 PE1 PE2 PE3 PE4 PE5 PE6 PE7 CON16AP 2 3 4 5 6 7 8 9 J2 PB7 TOSC1 VCC XTAL2 PD0 PD2 PD4 PD6 B 1 3 5 7 9 11 13 15 + + + + + + + + + + + + + + + + 2 TOSC2 4 /RESET 6 GND 8 XTAL1 10 PD1 12 PD3 14 PD5 16 PD7 CON16AP /PEN 1 PD0 PD1 PD2 PD3 PD4 PD5 PD6 PD7 25 26 27 28 29 30 31 32 /RESET 20 PF0(ADC0) PF1(ADC1) PF2(ADC2) PF3(ADC3) PF4(ADC4) PF5(ADC5) PF6(ADC6) PF7(ADC7) GND2 D AVCC AGND PE0(PDI/RXD) PE1(PDO/TXD) PE2(AC+) PE3(AC-) PE4(INT4) PE5(INT5) PE6(INT6) PE7(INT7) PA0(AD0) PA1(AD1) PA2(AD2) PA3(AD3) PA4(AD4) PA5(AD5) PA6(AD6) PA7(AD7) ALE RD WR PB0(SS) PB1(SCK) PB2(MOSI) PB3(MISO) PB4(OCO/PWM0) PB5(OC1A/PWM1A) PB6(OC1B/PWM1B) PB7(OC2/PWM2) PEN TOSC1 ATmega103 TOSC2 22 GND GND 21 VCC VCC XTAL1 RESET 1 D PC0(A8) PC1(A9) PC2(A10) PC3(A11) PC4(A12) PC5(A13) PC6(A14) PC7(A15) AREF PD0(INT0) PD1(INT1) PD2(INT2) PD3(INT3) PD4(IC) PD5 PD6(T1) PD7(T2) 2 53 GND2 3 52 VCC2 4 VCC2 5 XTAL2 51 50 49 48 47 46 45 44 PA0 PA1 PA2 PA3 PA4 PA5 PA6 PA7 35 36 37 38 39 40 41 42 PC0 PC1 PC2 PC3 PC4 PC5 PC6 PC7 43 ALE 34 33 /RD /WR 10 11 12 13 14 15 16 17 PB0 PB1 PB2 PB3 PB4 PB5 PB6 PB7 J3 19 TOSC1 18 TOSC2 24 XTAL1 23 XTAL2 /WR PC0 PC2 PC4 PC6 ALE PA6 PA4 1 3 5 7 9 11 13 15 + + + + + + + + + + + + + + + + 2 4 6 8 10 12 14 16 /RD PC1 PC3 PC5 PC7 PA7 PA5 PA3 C CON16AP J4 PA2 1 PA0 3 GND2 5 PF6 7 PF4 9 PF2 11 PF0 13 AGND 15 + + + + + + + + + + + + + + + + 2 PA1 4 VCC2 6 PF7 8 PF5 10 PF3 12 PF1 14 AREF 16 AVCC B CON16AP A A Title AVR Aplication Board Size A Date: 5 4 3 Document Number CPU Tuesday, July 11, 2000 2 Rev 1.0 Sheet 1 of 1 5 5 4 3 2 1 D5V D5V RA1 1 D5V 1 Q1 2ST-1KLA C1 D1 CL-1L5 20 17 18 PD0 15 16 PD1 13 14 PD2 /PEN TXD SEN RS SW6 SCK PB3 PB5 1K 2 3 4 5 6 7 8 9 D2 19 J1 R1 1 330/9pin A5V D 2 ADC0 1 3 5 7 9 11 13 15 103 12 PD3 10 PD4 7 8 PD5 5 6 PD6 3 4 PD7 1 D R4 330 R6 330 R3 470 9 D5V D5V PB2 PB4 BUZZER CON16A R2 11 RXD RXE LCD EN R//W 2 4 6 8 10 12 14 16 G F 47K C2 104 DCSERVO R13 10 XTAL2 PD0 PD2 PD4 PD6 2 LN10204 Q3 1 2 3 4 5 D5V E D J2 Test1 Test2 1 3 5 7 9 11 13 15 2 4 6 8 10 12 14 16 R5 330 R7 330 U1 R8 330 R10 330 G A F B M2 M1 E C D DP J8 D3 A B 10 9 8 7 6 1 2 1N4004 CON2 C DP R12 R9 330 R11 330 SR410 Q2 C1815 DCSERVO 1K /RESET XTAL1 PD1 PD3 PD5 PD7 D5V R14 1K R15 47K C3 470pF CON16A SEN 20V C1815 J3 C5 XTAL2 D5V C 20pF XTAL1 6MHZ C7 + J6A 1 2 3 4 5 6 7 8 9 C6 10uF R16 47K PB2 PB3 PB4 PB5 D5V 2 4 6 8 10 12 14 16 B D F DP AD7 AD5 AD3 B9 B8 B7 B6 B5 B4 B3 B2 B1 18 17 16 15 14 13 12 11 10 2 510 R18 2.4K 74HC14A R19 D5V RXE U3C cn9 4 D5V 5 74HC14A INA INB INC IND OUTA TDA TDB OUTB 8 2 13 3 REFAOUTC 18 9 RSA OUTD 11 C8 AD2 AD0 1 3 5 7 9 11 13 15 74HC14A D4 R23 D1N4148 D5V SW5 SW3 SW1 ADC0 10K S1 /RESET 10 2200pF R21 1/0.5W AD1 2 4 6 8 10 12 14 16 7 12 VSA VSB J5 + 4 15 GA GB RSB C 1 2 3 4 5 6 1 REFB C9 CON6 C19 100uF/25V SLA7024M R22 1/0.5W SW6 SW4 SW2 AREF AVCC D5V 104 BZ1 C11 1 BUZZER J9 CON16A + C12 14 500/VAR /RESET C20 104 2200pF J4 RXD3 6 R20 2.4K A5V C10 104 TXD 3 6 5 17 16 CON16A 1 U3B U2 C4 470pF R17 20pF A1 A2 A3 A4 A5 A6 A7 A8 A9 cn9 AD6 AD4 XTAL1 U3A J6B 1 3 5 7 9 11 13 15 A C E G 1uF RXD1 RXD2 RXD3 2 BTG-47 1 3 5 B + + + + + + 2 4 6 RXD B CON6AP VCC VCC S8 C15 + 1 D5V RA2 J10 2 1 1 2 3 Toggle C16 + 10K/9pin CON3 2 100uF J11 1 VIN 2 3 4 5 6 7 8 9 VOUT GND 3 RS R//W LCD EN AD0 AD1 AD2 AD3 AD4 AD5 AD6 AD7 S2 220uF SW1 S3 SW2 S4 SW3 S5 S9 20V SW4 S6 3 1 Toggle A SW5 J14 2 S7 1 2 3 SW6 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 1uF + C17 1 L7805/TO3 3 JP JUMPER D5 R24 470 J12 RXD1 10 8 /RESET 6 SCK 4 TXD 2 + + + + + + + + + + 9 7 5 3 1 C13 16 1uF 2 1 3 D5V LED 2 U4 D5V + C14 1uF 4 5 6 T1I R1O 11 12 T2I R2O MAX232 GND 10 9 15 TXD RXD2 14 13 T1O R1I 7 8 T2O R2I J13 3 2 1 U5 Vcc V+ C2+ C2C1+ C1V- + D5V + A5V C18 1uF CON3 CON10AP CON16 A CON3 Title AVR Aplication Board Size A3 Date: 5 4 3 2 Document Number Main Rev 1.0 Wednesday, September 27, 2000 Sheet 1 1 of 5