40
Computer Science Summer term 2012 Final Project Team 2

Computer Science

  • Upload
    eudora

  • View
    47

  • Download
    0

Embed Size (px)

DESCRIPTION

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. - PowerPoint PPT Presentation

Citation preview

Page 1: Computer Science

Computer Science Summer term 2012

Final Project

Team 2

Page 2: Computer Science

Content

1.- Organization 2.- Request2.- Software Development3.- Team work experience4.- Final Product

Page 3: Computer Science

Project Manager (Salvador Reyes)Technical Managed David Tecuanhuehue

Amri Mohamed

Quality ManagedCecilia Cruz

Documentation ManagedSpandan Shroff

Amin Mitul

Integration ManagedEdgar Escobar

Rodrigo Gutierrez

Team organization

Page 4: Computer Science

Write an ACUAS μCEasy package for the AVR Butterfly board. The following macros must be available

PROGRAM_INITPROGRAM_STARTPROGRAM_ENDVARIABLESTRINGWAIT_SEC

ACTIVATE_ADCBRIGHTNESSTEMPERATUREVOLTAGEBEEPACTIVATE_LCDINIT_UARTDATAFLASH

Request

Page 5: Computer Science

ATMEL AVR Butterfly

ATmega169Low power designPeripherals:● 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

Page 6: Computer Science

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.

Macro…

Object-like  It looks like a data object in code that uses it

function-like Resemble function calls

Software development

Page 7: Computer Science

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.

Software development

Page 8: Computer Science

JOYSTICK PORT/PIN CONFIGURATION

Up PB6

Down PB7

Right PE3

Left PE2

Joystick port/pin configuration

Page 9: Computer Science

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

Page 10: Computer Science

#include "projectdefinitions.h"

PROGRAM_INITPROGRAM_STARTON_JOYSTICK_UPPORTA = PORTA | 0b00000001;OFF_JOYSTICK_UPPORTA = PORTA & 0b11111110;ON_JOYSTICK_DOWNPORTA = PORTA | 0b00000010;OFF_JOYSTICK_DOWNPORTA = PORTA & 0b11111101;ON_JOYSTICK_RIGHTPORTA = PORTA | 0b00000100;OFF_JOYSTICK_RIGHT PORTA = PORTA & 0b11111011;ON_JOYSTICK_LEFTPORTA = PORTA | 0b00001000;OFF_JOYSTICK_LEFTPORTA = PORTA & 0b11110111;ON_JOYSTICK_CENTERPORTA = PORTA | 0b00010000;OFF_JOYSTICK_CENTERPORTA = PORTA & 0b11101111;PROGRAM_END

Example:

Page 11: Computer Science

// 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

Page 12: Computer Science

// 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

Page 13: Computer Science

void InitBuzzer(int f, int d){

int icr1;icr1 = 1000000/(2*f);ICR1 = icr1; // Top value of the Timer1TCCR1A = (1<<COM1A1); // Set OC1A when upcounting, clear when downcountingTCCR1B = (1<<WGM13); // Phase/Freq-correct PWM, top value = ICR1SET_BIT(TCCR1B, CS10) // Start Timer1, prescaler=1 WAIT_SEC(d) // Waits d secondsCLEAR_BIT(TCCR1B, CS10) // Stop Timer1

}

Buzzer Macros

Page 14: Computer Science

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 MacrosTo switch on the AD converter

This instruction has to be executed only one time (in the PROGRAM_INIT part).

Page 15: Computer Science

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 MacrosTo chose for analogue input (from 1 to 8)

ADC_CHANNEL(1) // pin 0 of port A is chosen for analogue input

Page 16: Computer Science

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 <x>. This variable has to be previously declared

The actual conversion is started

Page 17: Computer Science

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 <x>.

Page 18: Computer Science

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

ADC MacrosThe actual conversion is started

Performs a 10 bit AD conversion and store the result in mV in an integer or float variable x.

Page 19: Computer Science

Example:

#include “easybutterfly.h“ // library for ButerflyPROGRAM_INITVAR16(mvolt) // Declares a 16 bit unsigned variableACTIVATE_ADC // To switch on the AD converterADC_CHANNEL(1) // Select pin 0 of the ADC

multiplexerPROGRAM_STARTADCONVERT_MV(mvolt) //The AD conversion is executed

and store in // the variable “mvolt”PROGRAM_END

ADC Macros

Page 20: Computer Science

// 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 thePORTF2, the result of the conversion is a 8 bits value.

Brightness

Page 21: Computer Science

// 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 previouslydefined, the input for the V_in pin is the PORTF1,the result of the conversion is a float value that can be stored in aninteger (or double or float) variable.

Voltage Measurement

Page 22: Computer Science

#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 previouslydefined, 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 aninteger (or double or float) variable.

Temperature Measurement

Page 23: Computer Science

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

Page 24: Computer Science

LCD MacrosKey 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

Page 25: Computer Science

LCD Macros

LCD Segments Connections on the STK502

• The LCD glass has in total 120 segments

Page 26: Computer Science

LCD MacrosLCD digit segment mapping into the LCD Data Registers

Page 27: Computer Science

#include "projectdefinitions.h"PROGRAM_INITACTIVATE_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 :

Page 28: Computer Science

UART:

Page 29: Computer Science

UART is Available on pin header J406With level converters

Connections : Just connect TxD , RxD and GND

with Vcc min 2.0V

Page 30: Computer Science

uart.c File Reference :

Uart Macros:UART_TEXTUART_TEXT_CONSTUART_NUMBERUART_CHARUART_CRLF

UART_READ_CHARUART_READ_LINE

Page 31: Computer Science

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

Page 32: Computer Science

#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“

Page 33: Computer Science

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

Page 34: Computer Science

DATAFLASH Architecture

Page 35: Computer Science

INIT_DFInitialize the communication with the dataflash

via SPIEND_DF

Disable the communication with the dataflash

Dataflash Macros

Page 36: Computer Science

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

Page 37: Computer Science

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

Page 38: Computer Science

#include "projectdefinitions.h"#include <avr/delay.h>

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 }}

Page 39: Computer Science

GoodCan be improved

Team work experience

Page 40: Computer Science