1 / 40

Computer Science

Computer Science. Summer term 2012 . Final Project Team 2. Content 1.- Organization 2.- Request 2.- Software Development 3.- Team work experience 4.- Final Product. Team organization. Request.

eudora
Download Presentation

Computer Science

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ComputerScience Summerterm2012 Final Project Team 2

  2. Content • 1.- Organization • 2.- Request • 2.- Software Development • 3.- Team work experience • 4.- Final Product

  3. Teamorganization

  4. Request Write an ACUAS μCEasy package for the AVR Butterfly board. The following macros must be available • ACTIVATE_ADC • BRIGHTNESS • TEMPERATURE • VOLTAGE • BEEP • ACTIVATE_LCD • INIT_UART • DATAFLASH • PROGRAM_INIT • PROGRAM_START • PROGRAM_END • VARIABLE • STRING • WAIT_SEC

  5. Request ATMEL AVR Butterfly ATmega169 Lowpowerdesign Peripherals: ● 120 segment LCD ● 4 MbitexternalDataFlash ● ProgrammingMethods: Bootloader, SPI, Parallel, JTAG ● Joystick, 4 directions ● Piezo speaker ● 32768 Hz oscillator for real time clock ● RS232 level converter for PC ● Temperature sensor ● Light sensor ● 3V, 600 mA button cell battery ●

  6. Software development Macro… A macro is a fragment of code which has been given a name. Whenever the name is used, it is replaced by the contents of the macro. There are two kinds of macros. Object-like It looks like a data object in code that uses it function-like Resemble function calls

  7. Software development Macro- Function-like… • #define • #define PROGRAM_INIT() • ( )parentheses immediately after the macro name Macro Arguments  To define a macro that uses arguments, to insert parameters between the pair of parentheses in the macro definition is necessary. The parameters must be valid C identifiers, separated by commas and optionally whitespace.

  8. Joystick port/pin configuration JOYSTICK PORT/PIN CONFIGURATION Up PB6 Down PB7 Right PE3 Left PE2

  9. Joystick Macros • Pin configuration from the pin diagram were observed. ///Execute the following instruction if the joystick up button is pressed #define ON_JOYSTICK_UP if(!(PINB & (1 << 6))) ///Execute the following instruction if the joystick up button is not pressed #define OFF_JOYSTICK_UP if(PINB & (1 << 6)) ///Wait until the joystick up button is pressed #define WAIT_FOR_JOYSTICK_UP while(PINB & (1 << 6)); ///Wait until the joystick up button is released #define WAIT_FOR_RELEASE_JOYSTICK_UP while(!(PINB & (1 << 6)));

  10. Example: #include "projectdefinitions.h" PROGRAM_INIT PROGRAM_START ON_JOYSTICK_UP PORTA = PORTA | 0b00000001; OFF_JOYSTICK_UP PORTA = PORTA & 0b11111110; ON_JOYSTICK_DOWN PORTA = PORTA | 0b00000010; OFF_JOYSTICK_DOWN PORTA = PORTA & 0b11111101; ON_JOYSTICK_RIGHT PORTA = PORTA | 0b00000100; OFF_JOYSTICK_RIGHT PORTA = PORTA & 0b11111011; ON_JOYSTICK_LEFT PORTA = PORTA | 0b00001000; OFF_JOYSTICK_LEFT PORTA = PORTA & 0b11110111; ON_JOYSTICK_CENTER PORTA = PORTA | 0b00010000; OFF_JOYSTICK_CENTER PORTA = PORTA & 0b11101111; PROGRAM_END

  11. // The volume must be between a value of 0 to 100, this macro must be used to allow the sound be heard #defineBEEP_VOLUME(v) {OCR1AH = 0; OCR1AL = v;} OCR1A is a 16 bit register. In ordertomodifythevalue of thevolume of the speaker thevalue of thisregistermustbemodified. Thisregistercontrolsthe PWM pulse width. Therebyitcontrolsthepower of thesignal (volume). Buzzer Macros

  12. Buzzer Macros // The tone is a vale between 20 and 20000 in Hz (the “audible” frequencies), duration in seconds in values between 0.1 and 25 #defineBEEP(tone,duration) {InitBuzzer(tone,duration);} BEEP macro callsInitBuzzerfunction.

  13. Buzzer Macros voidInitBuzzer(int f, intd) { inticr1; icr1 = 1000000/(2*f); ICR1 = icr1; // Top value of the Timer1 TCCR1A = (1<<COM1A1); // Set OC1A when upcounting, clear when downcounting TCCR1B = (1<<WGM13); // Phase/Freq-correct PWM, top value = ICR1 SET_BIT(TCCR1B, CS10) // StartTimer1, prescaler=1 WAIT_SEC(d) // Waits d seconds CLEAR_BIT(TCCR1B, CS10) // Stop Timer1 }

  14. ADC Macros • To switch on the AD converter ACTIVATE_ADC ADCSRA = (1<<ADEN); ADMUX |= (0<<REFS1) | (1<<REFS0); autoADCps(); Set ADEN bit to activate AD Converter. Reference voltage AVCC = 5V Functionthat sets the ADC prescalervaluedependingfromclockfrequency. • This instruction has to be executed only one time (in the PROGRAM_INIT part).

  15. ADC Macros • To chose for analogue input (from 1 to 8) ADC_CHANNEL(ch) ADMUX &= 0b11110000; ADMUX |= (ch-1); PORTF &= ~(1 << (ch-1)); initialize channel bits (0-3) set channel “ch”. Clear PORTF selectedchannel bit -->switch off pull up resistor “ch-1” • ADC_CHANNEL(1) // pin 0 of port A is chosen for analogue input

  16. ADC Macros • The actual conversion is started ADCONVERT(x) ADCSRA |= (1<<ADSC); loop_until_bit_is_clear(ADCSRA,ADSC); ADCSRA |= (1<<ADSC); loop_until_bit_is_clear(ADCSRA,ADSC); x=ADCW; start a single conversion Wait for completion of ADC x acquires the value of the AD conversion • The result is of 10 bit resolution and will be stored in the 16 bit variable <x>. This variable has to be previously declared

  17. ADC Macros • The actual conversion is started ADCONVERTlow(x) ADCSRA |= (1<<ADSC); loop_until_bit_is_clear(ADCSRA,ADSC); ADCSRA |= (1<<ADSC); loop_until_bit_is_clear(ADCSRA,ADSC); x=ADCW >> 2; start a single conversion Wait for completion of ADC Shifting bit to show only 8 bits value • The 8 most significant bits of the 10 bit result will be stored in the 8 bit variable <x>.

  18. ADC Macros • The actual conversion is started ADCONVERT_MV(x) ADCSRA |= (1<<ADSC); loop_until_bit_is_clear(ADCSRA,ADSC); ADCSRA |= (1<<ADSC); loop_until_bit_is_clear(ADCSRA,ADSC); x=ADCW*5./1.024; start a single conversion Wait for completion of ADC Shifting bit to show only 8 bits value • Performs a 10 bit AD conversion and store the result in mV in an integer or float variable x.

  19. ADC Macros Example: #include “easybutterfly.h“ // library for Buterfly PROGRAM_INIT VAR16(mvolt) // Declares a 16 bit unsigned variable ACTIVATE_ADC // To switch on the AD converter ADC_CHANNEL(1) // Select pin 0 of the ADC multiplexer PROGRAM_START ADCONVERT_MV(mvolt) //The AD conversion is executed and store in // the variable “mvolt” PROGRAM_END

  20. Brightness // Perform a 10 bit AD conversion from the value of the brightness sensor and store the value in a 8 bit variable #defineBRIGHTNESS(x) {ACTIVATE_ADC ADC_CHANNEL(3) ADCONVERTlow(x)} The BRIGHTNESS macro uses the macros of the ADC previously defined, the output of thebrightness sensor is input in the PORTF2, theresult of theconversionis a 8 bits value.

  21. VoltageMeasurement // Perform a 10 bit AD conversion from the value of the V_in pin and store the result in volts in an integer (or double or float) variable #defineVOLTAGE(x) {ACTIVATE_ADC ADC_CHANNEL(2) ADCSRA |= (1<<ADSC); loop_until_bit_is_clear(ADCSRA,ADSC); ADCSRA |= (1<<ADSC); loop_until_bit_is_clear(ADCSRA,ADSC); x=ADCW*5.0/1023.0;} The VOLTAGE macro uses some macros of the ADC previously defined, the input fortheV_in pin isthe PORTF1, theresult of theconversionis a floatvaluethat can bestored in an integer(or double or float) variable.

  22. TemperatureMeasurement #defineTEMPERATURE(x) {ACTIVATE_ADC ADC_CHANNEL(1) ADCSRA |= (1<<ADSC); loop_until_bit_is_clear(ADCSRA,ADSC); ADCSRA |= (1<<ADSC); loop_until_bit_is_clear(ADCSRA,ADSC); intadc=ADCW; float t=adc/(1024-adc);float r=log(t); x=4250/(r+14.2617)-273;} The TEMPERATURE macro uses some macros of the ADC previously defined, the output of thetemperature sensor is input in the PORTF0, theresult of theconversionis a floatvaluethat can bestored in an integer(or double or float) variable.

  23. LCD Macros #defineACTIVATE_LCDLCD_Init (); //Macro toinitializethe LCD #define CLEAR_LCDLCD_Clear(); //Macro toclearthe LCD #define LCD_CHAR(character)LCD_putc(character); //Macro towrite a characteronthe LCD #define LCD_TEXT(pStr) LCD_puts(pStr); //Macro towrite a stringonthe LCD #define LCD_NUMBER(v) {itoa(v,lcd_str,10); LCD_puts(lcd_str);}; //Macro towrite a numberonthe LCD #defineLCD_D_NUMBER(v,w,p) {dtostrf((v),w,p,lcd_str); LCD_puts(lcd_str);}; //Macro towrite a floatonthe LCD

  24. LCD Macros Key Variables chargTextBuffer[TEXTBUFFER_SIZE]; // Buffer that contains the text to be displayed chargScroll; // Only six letters can be shown on the LCD. unsigned intLCD_character_table[] PROGMEM = { 0x0A51, // '*' (?) 0x2A80, // '+' 0x0000, // ',' (Not defined) 0x0A00, // '-' 0x4000, // '.' Degree sign

  25. LCD Macros LCD Segments Connections on the STK502 • The LCD glass has in total 120 segments

  26. LCD Macros LCD digit segment mapping into the LCD Data Registers

  27. Example LCD Macro : #include "projectdefinitions.h" PROGRAM_INIT ACTIVATE_LCD // initialize the LCD. The output begins at the first position of the display. CLEAR_LCD // Clears the LCD screen. PROGRAM_START LCD_TEXT("HALLO WIE GEHTS") WAIT_SEC(25) CLEAR_LCD // Clears the LCD screen. LCD_CHAR (‘G') WAIT_SEC(10) CLEAR_LCD // Clears the LCD screen. LCD_D_NUMBER(11.31,1,2) WAIT_SEC(5) CLEAR_LCD // Clears the LCD screen. PROGRAM_END

  28. UART:

  29. UART is Available on pin header J406With level converters Connections : Just connect TxD , RxD and GND with Vcc min 2.0V

  30. uart.c File Reference : Uart Macros: UART_TEXT UART_TEXT_CONST UART_NUMBER UART_CHAR UART_CRLF UART_READ_CHAR UART_READ_LINE

  31. Macros definition: #define INIT_UART {uart_init( UART_BAUD_SELECT(UART_BAUD_RATE,F_CPU) ); sei();} Initialises the UART. Must be invoked in the PROGRAM_INIT part. Sets frame format: asynchronous, 8 data bits, no parity, 1 stop bit #define UART_TEXT(string) uart_puts((char*) string); Sends a string which is located in SRAM over UART #define UART_TEXT_CONST(string) uart_puts_p(string); Sends a string which is located in flash ROM over UART. The string must be declared as: static const char PText[] PROGMEM = "text"

  32. #define UART_NUMBER (x) {itoa( x, (char*)uart_str, 10); uart_puts((char*)uart_str);} Used to ”Sends a number over UART“ #define UART_CHAR(c) uart_putc(c); Used to ”Sends one character over UART“ #define UART_CRLF uart_putc(13) ; uart_putc(10) ; Used to”Sends a linefeed over UART“ #define UART_READ_CHAR(c) c = uart_getc(); Used to ”Reads one character from UART“ #define UART_READ_LINE(c_array,max_char) uart_read_line((c_array), (max_char), 3) Used to ”Reads a Line from UART“

  33. DataflashMemory • DataFlash is a low pin-count serial interface for flash memory compatible with the SPI standard. • The DataFlash only supports the most commonly used SPI modes, 0 and 3.

  34. DATAFLASH Architecture

  35. Dataflash Macros • INIT_DF • Initialize the communication with the dataflash via SPI • END_DF • Disable the communication with the dataflash

  36. Dataflash Macro for writing • WRITE_BYTE_BUFFER(IntPageAdr, Data) • Writes a byte in the buffer • WRITE_STR_BUFFER(IntPageAdr, NB, string) • Writes a string in the buffer • BUFFER_TO_DF(PageAdr) • Sends the buffer information in to a page address of the dataflash

  37. Dataflash Macro for reading • DF_TO_BUFFER(PageAdr) • Reads the data in a page address of the buffer and sends the information to the buffer. • READ_STR_BUFFER(IntPageAdr, NB, string) • Reads a string in the internal address of the buffer to save it into an array • READ_BYTE_BUFFER(IntPageAdr) • Reads a byte from the buffer

  38. Example Dataflash Macro : unsignedchar FRIEND[8] = {0};while(1) {    ACTIVATE_LCD    CLEAR_LCD    INIT_DF        DF_TO_BUFFER(2)    READ_STR_BUFFER(1, 8, FRIEND)    LCD_TEXT(FRIEND)    _delay_ms(2000);        END_DF  }} #include "projectdefinitions.h"#include <avr/delay.h>intmain(void) {INIT_DFunsignedchar Word[4];    Word[0]= ‘T';    Word[1]= 'e';    Word[2]= ‘a';    Word[3]= ‘m';    WRITE_STR_BUFFER(1,8,Word)    _delay_ms(100);    BUFFER_TO_DF(1)END_DF

  39. Team work experience • Good • Can be improved

More Related