Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Science Summer term 2012 Final Project Team 2.

Similar presentations


Presentation on theme: "Computer Science Summer term 2012 Final Project Team 2."— Presentation transcript:

1 Computer Science Summer term 2012 Final Project Team 2

2

3 Project Manager (Salvador Reyes) Technical Managed David TecuanhuehueAmri Mohamed Quality Managed Cecilia Cruz Documentation Managed Spandan ShroffAmin Mitul Integration Managed Edgar EscobarRodrigo Gutierrez Team organization

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

5 ATMEL AVR Butterfly ATmega169 Low power design Peripherals: ● 120 segment LCD ● 4 Mbit external DataFlash ● Programming Methods: 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 ● Request

6 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 Software development

7 #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. Software development

8 JOYSTICK PORT/PIN CONFIGURATION UpPB6 DownPB7 RightPE3 LeftPE2 Joystick port/pin configuration

9 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))); Joystick Macros

10 #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 Example:

11 // The volume must be between a value of 0 to 100, this macro must be used to allow the sound be heard #define BEEP_VOLUME(v) {OCR1AH = 0; OCR1AL = v;} OCR1A is a 16 bit register. In order to modify the value of the volume of the speaker the value of this register must be modified. This register controls the PWM pulse width. Thereby it controls the power of the signal (volume). Buzzer Macros

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

13 void InitBuzzer(int f, int d) { int icr1; 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)// Start Timer1, prescaler=1 WAIT_SEC(d)// Waits d seconds CLEAR_BIT(TCCR1B, CS10)// Stop Timer1 } Buzzer Macros

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

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

16 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 ADC Macros The result is of 10 bit resolution and will be stored in the 16 bit variable. This variable has to be previously declared The actual conversion is started

17 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; ADC Macros start a single conversion Wait for completion of ADC Shifting bit to show only 8 bits value The actual conversion is started The 8 most significant bits of the 10 bit result will be stored in the 8 bit variable.

18 ADCONVERT_MV(x) 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 ADC Macros The actual conversion is started Performs a 10 bit AD conversion and store the result in mV in an integer or float variable x.

19 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 ADC Macros

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

21 // 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 #define VOLTAGE(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 for the V_in pin is the PORTF1, the result of the conversion is a float value that can be stored in an integer (or double or float) variable. Voltage Measurement

22 #define TEMPERATURE(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); int adc=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 the temperature sensor is input in the PORTF0, the result of the conversion is a float value that can be stored in an integer (or double or float) variable. Temperature Measurement

23 LCD Macros #define ACTIVATE_LCD LCD_Init (); //Macro to initialize the LCD #define CLEAR_LCD LCD_Clear(); //Macro to clear the LCD #define LCD_CHAR(character) LCD_putc(character); //Macro to write a character on the LCD #define LCD_TEXT(pStr) LCD_puts(pStr); //Macro to write a string on the LCD #define LCD_NUMBER(v) {itoa(v,lcd_str,10); LCD_puts(lcd_str);}; //Macro to write a number on the LCD #define LCD_D_NUMBER(v,w,p) {dtostrf((v),w,p,lcd_str); LCD_puts(lcd_str);}; //Macro to write a float on the LCD

24 LCD Macros Key Variables char gTextBuffer[TEXTBUFFER_SIZE]; // Buffer that contains the text to be displayed char gScroll; // Only six letters can be shown on the LCD. unsigned int LCD_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 #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 Example LCD Macro :

28 UART:

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

30 uart.c File Reference : Uart Macros: UART_TEX T UART_TEXT_CO NST UART_NUMBER UART_CHAR UART_CRL F UART_READ_CHA R UART_READ_LI NE

31 #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" Macros definition:

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 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. Dataflash Memory

34

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

36 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 Dataflash Macro for writing

37 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 Dataflash Macro for reading

38 #include "projectdefinitions.h" #include int main(void) { INIT_DF unsigned char 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 Example Dataflash Macro : unsigned char 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 } }

39 Good Can be improved Team work experience

40


Download ppt "Computer Science Summer term 2012 Final Project Team 2."

Similar presentations


Ads by Google