ebook img

DT-AVR ATMEGA168 BMS Application Note PDF

12 Pages·2011·0.47 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview DT-AVR ATMEGA168 BMS Application Note

Application Note DT-AVR ATMEGA168 BMS How2Use DT-AVR ATMEGA168 BMS By: IE Team T his Application Note (AN) serves as a tutorial of how to use the DT-AVR ATMEGA168 Bootloader Micro System along with its supplementary software. T he layout of DT-AVR ATMEGA168 BMS is as follows: Picture 1 The layout of DT-AVR ATMEGA168 BMS H ardware preparation for DT-AVR ATMEGA168 BMS is as follows: 1. Arrange jumper J14 and J15 on position 1-2 so that PE.0 and PE.1 function as a serial communication line. 2. Arrange jumper J6, J7, J8, and J9 so that it uses the USB line for bootloader or RS-232 line for bootloader. 3. Connect the USB cable to the module and PC if using USB as bootloader, or connect the serial cable to the PC COM port and the RJ45 connector to the module if using RS232 line for bootloader. 4. If there is another module that will be connected to the DT-AVR ATMEGA168 BMS, it is advised to connect the module to the DT-AVR ATMEGA168 BMS first. Pay attention to the connection, especially for the VCC and GND line, do not put it in reverse. 5. Arrange jumper J4 on position 1-2 (power source from VEXT) and release jumper J5 (5V). 6. Connect a 6 - 12 VDC Power Supply to the “VEXT” connector to give power to the module. Page 1 of 12 How2Use DT-AVR ATMEGA168 BMS T he setup process for CodeVisionAVR evaluation version is as follows: 1. CodeVisionAVR evaluation version is included inside the CD/DVD that comes along with the module. The setup.exe file is located in the CVAVR Evaluation folder. Run the setup.exe to start the installation process. 2. Select the setup language and click OK. Picture 2 Select Setup Language 3. The initial display of CodeVisionAVR. Click Next > to continue the installation process. Picture 3 CodeVisionAVR initial installation screen Page 2 of 12 How2Use DT-AVR ATMEGA168 BMS 4. Proceed to the License Agreement. Click “I accept the agreement” and then click Next > to agree with the terms and continue with the installation process. Picture 4 CodeVisionAVR License Agreement 5. Choose the Install Location of CodeVisionAVR, and click Next >. Picture 5 Choose Install Location screen Page 3 of 12 How2Use DT-AVR ATMEGA168 BMS 6. Pick a Start menu folder, and click Next >. Picture 6 Select Start Menu Folder Screen 7. CodeVisionAVR install preparation screen. Click Install to start the installation. Picture 7 Install Preparation Screen Page 4 of 12 How2Use DT-AVR ATMEGA168 BMS 8. CodeVisionAVR Evaluation installation process. Picture 8 CodeVisionAVR Evaluation Installation Process Screen 9. At the information screen, click Next > to proceed with the installation. Picture 9 Information Screen Page 5 of 12 How2Use DT-AVR ATMEGA168 BMS 10. Installation process is completed, check “Launch CodeVisionAVR C Compiler Evaluation” if you want to launch CodeVisionAVR immediately, or uncheck if you don't. Click Finish to complete the installation process. Picture 10 Completing the CodeVisionAVR Setup Wizard Screen T he steps to make a simple application using CodeVisionAVR Evaluation is as follows: 1. Basic interface of CodeVisionAVR Evaluation and the available menu. Main Menu Quick Navigator menu Error Log Picture 11 Basic interface of CodeVisionAVR Evaluation Page 6 of 12 How2Use DT-AVR ATMEGA168 BMS 2. Create a new file through the main menu, select File, and then New. It can also be done using the quick menu Create new file or project. Picture 12 Creating A New File 3. We will try the Create New File. In this interface we can create a file along with project or just create a source file with a *.c extension. Click OK to proceed. Creates *.c file Creates file along with Project Picture 13 Create New File Interface 4. To make the file creation process easier it is suggested to check the Project option. Because CodeVisionAVR Evaluation will help through CodeWizardAVR. CodeWizardAVR can select and activate the features of the Chip. When the confirmation screen pops up, click Yes, and CodeWizardAVR will appear. Device Feature Chip Type (ATmega128) XTAL Clock Crystal Oscillation Divider Program Type Picture 14 Confirmation Screen and CodeWizardAVR Page 7 of 12 How2Use DT-AVR ATMEGA168 BMS 5. As an example of an application program, we will discuss about testing168.c a program which is also included inside the CD/DVD. The device features that will be used in this program are ADC and USART serial communication, ADC is used to read the analog data input on Pin ADC6, while USART is used to perform a serial communication with the computer. The following is an explanation of the testing168.c program. #include <mega168.h> #include <delay.h> // Standard Input/Output functions #include <stdio.h> The program above shows the library that will be used. The first line shows the type of Chip that will be used. The second line shows the library delay which will be used to create delay timing. The blue colored text shows the statement of the program. Every line that starts with “//” will not be executed when the program start. The fourth line shows the library Standard Input/Output, which will be used for serial communication. 6. The next program discussion is about ADC at DT-AVR ATMEGA168 BMS. #define ADC_VREF_TYPE 0x60 // Read the 8 most significant bits // of the AD conversion result unsigned char read_adc(unsigned char adc_input) { ADMUX=adc_input | (ADC_VREF_TYPE & 0xff); // Start the AD conversion ADCSRA|=0x40; // Wait for the AD conversion to complete while ((ADCSRA & 0x10)==0); ADCSRA|=0x10; return ADCH; } The program above shows the function to read analog data through ADC pins. The ADC uses AVCC as its voltage reference. The function read_adc() above needs to know which ADC canal parameters that will be read. That function returns 8 bit MSB from the result from reading 10 bit ADC. 8. The following is an explanation of the main() function of the testing 168.c Program: void main(void) { // Declare your local variables here unsigned char counter=0; // Crystal Oscillator division factor: 1 #pragma optsize- CLKPR=0x80; CLKPR=0x00; #ifdef _OPTIMIZE_SIZE_ #pragma optsize+ #endif // Input/Output Ports initialization // Port B initialization PORTB=0x00; DDRB=0xFF; // Port C initialization PORTC=0x00; DDRC=0xFF; // Port D initialization PORTD=0x00; DDRD=0xFF; // USART initialization Page 8 of 12 How2Use DT-AVR ATMEGA168 BMS // Communication Parameters: 8 Data, 1 Stop, No Parity // USART Receiver: On // USART Transmitter: On // USART0 Mode: Asynchronous // USART Baud rate: 115200 UCSR0A=0x00; UCSR0B=0x18; UCSR0C=0x06; UBRR0H=0x00; UBRR0L=0x03; // ADC initialization // ADC Clock frequency: 57.600 kHz // ADC Voltage Reference: AVCC pin // ADC Auto Trigger Source: None // Only the 8 most significant bits of // the AD conversion result are used // Digital input buffers on ADC0: On, ADC1: On, ADC2: On, ADC3: On // ADC4: On, ADC5: On DIDR0=0x00; ADMUX=ADC_VREF_TYPE & 0xff; ADCSRA=0x87; while (1) { // Place your code here if(UCSR0A>>7 & 1) { if (getchar()=='A') { printf("DT-AVR Boot, Innovative Electronics\r"); printf("Data ADC Ch. 6 = %d\r",read_adc(6)); printf("Data ADC Ch. 7 = %d\r",read_adc(7)); } } PORTB = ~(0x01 << counter); PORTC = ~(0x01 << counter); PORTD = ~(0x01 << counter); counter++; if (counter>7) counter = 0; delay_ms(200); }; } On the main() Function above, the first thing to do is counter variable declaration. Followed by I/O initialization, UART initialization, and ADC initialization. The program will then start to loop continuously. In that loop, the first thing to do is to check the contents of UCSR0A registry to find out if there's a serial data input or not. If there is an input, then that serial data will be retrieved using the getchar() fuction. If the received serial data is character 'A', the the module will generate the text: “DT-AVR Boot, Innovative Electronics” and the conversion results from ADC channel 6 and 7 acquired by calling the read_adc() function. At Port B, Port C, and Port D will always generate low logic at 1 pin on every port consecutively, except for pin PD.0 and PD.1 which is functioned as serial communication. Page 9 of 12 How2Use DT-AVR ATMEGA168 BMS 9. The next step is to compile the program that we have just created. This process is done to see if there is an error in the program. This process is located in the Project – Compile tab and can also be accessed by pressing F9 on the keyboard. Picture 15 Compile Menu 10. If the created listing program does not contain any kind of mistakes (including syntax or writing) and doesn't encounter any errors during the compiling process, then the form below will appear. Picture 16 Compile Process Result Page 10 of 12 How2Use DT-AVR ATMEGA168 BMS

Description:
CodeVisionAVR evaluation version is included inside the CD/DVD that comes along with the module. The setup.exe file is located in the CVAVR
See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.