Microprocessor based Design for Biomedical Applications MBE 3 – MDBA IV : The ATmega8 Basic Features (3)

Slides:



Advertisements
Similar presentations
Georgia Tech Digital Back-end µHRG interface Curtis Mayberry School of Electrical and Computer Engineering Georgia Institute of Technology January 13 th,
Advertisements

Mark Neil - Microprocessor Course 1 Device Drivers – Digital Voltmeter.
SHIFT REGISTERS: CONVERTING BETWEEN SERIAL AND PARALLEL DATA Mark Neil - Microprocessor Course 1 Serial versus Parallel Data Transfers.
DATA COLLECTION USING ZIGBEE NETWORK Timothy Melton Moscow, ID.
Analog to Digital Conversion
Kuliah Mikrokontroler AVR Comparator AVR Eru©September 2009 PENS.
Analog/Digital Subsystem
Analog Comparator Positive input chooses bet. PB2 and Bandgap Reference. Negative input chooses bet. PB3 and the 8 inputs of the A/D. ACME= Analog Comparator.
Oscilloscope Watch Teardown. Agenda History and General overview Hardware design: – Block diagram and general overview – Choice of the microcontroller.
Kuliah Mikrokontroler AVR ADC AVR Eru©September 2009 PENS.
COMP3221: Microprocessors and Embedded Systems Lecture 22: Serial Input/Output (II) Lecturer: Hui Wu Session 1, 2005.
USARTS CS423 Dick Steflik. USART ● Universal Synchronous Asynchronous Receiver Transmitter ● used to send and receive small packets over a serial line.
Aztec PC Scope Preliminary Design Review Fall 2006 Michael MasonJed Brown Andrew YoungsJosh Price.
USART and Asynchrono us Communica tion The USART is used for synchronous and asynchronous serial communication. USART = Universal Synchronous/Asynchronous.
7-1 Digital Serial Input/Output Two basic approaches  Synchronous shared common clock signal all devices synchronised with the shared clock signal data.
Aztec PC Oscilloscope Michael Mason Jed Brown Josh Price Andrew Youngs.
Network and Systems Laboratory nslab.ee.ntu.edu.tw.
Arduino Josh Villbrandt February 4, Digital Circuits Analog versus digital – What’s the difference? – How to represent an analog signal in a computer?
Input/Output mechanisms
Renesas Electronics Europe GmbH A © 2010 Renesas Electronics Corporation. All rights reserved. RL78 Clock Generator.
Clock Options and Sleep Modes. Clock Sources Flash Fuse bits can be programmed to choose one of the following Clock sources: 1. External RC Osc. f = 1/(3RC).
Universal Synchronous/Asynchronous Receiver/Transmitter (USART)
AT91 Embedded Peripherals
Embedded System Design Laboratory October 11, 2002Stanford University - EE281 Lecture #4#1 Lecture #4 Outline Announcements Project Proposal AVR Processor.
Digital to Analogue Converter
ELE2MIC Lecture 21 The AVR Sleep Modes ATMEGA128’s Analog to Digital Converter –Features –Block Diagram –Clock Source –Input Sources –Interrupts –BandGap.
Microprocessor based Design for Biomedical Applications MBE 3 – MDBA III : The ATmega8 Basic Features (2)
Universal Asynchronous Receiver/Transmitter (UART)
Embedded System Design Laboratory October 4, 2002Stanford University - EE281 Lecture #3#1 Lecture #3 Outline Announcements AVR Processor Resources –UART.
بسمه تعالي AVR Microcontrollers. The ATmega8 Basic Features -1.
Advanced uC Session Speaker : Chiraag Juvekar Jan 13, 2011 Speaker : Chiraag Juvekar Jan 13, 2011.
Advanced Microprocessor1 I/O Interface Programmable Interval Timer: 8254 Three independent 16-bit programmable counters (timers). Each capable in counting.
 8251A is a USART (Universal Synchronous Asynchronous Receiver Transmitter) for serial data communication.  Programmable peripheral designed for synchronous.
MICROCONTROLLER SYSTEMS Part 1. Figure 1.1Elements of a digital controller CPU Central Processing Unit Input Peripherals Output Peripherals ROM Read Only.
Atmel Atmega128 Overview ALU Particulars RISC Architecture 133, Mostly single cycle instructions 2 Address instructions (opcode, Rs, Rd, offset) 32x8 Register.
Universal Asynchronous Receiver/Transmitter (UART)
CE-2810 Dr. Mark L. Hornick 1 Using the USART Configuration and Programming.
Features of the new Alibava firmware: 1. Universal for laboratory use (readout of stand-alone detector via USB interface) and for the telescope readout.
ATtiny23131 A SEMINAR ON AVR MICROCONTROLLER ATtiny2313.
The Silicon Laboratories C8051F020
INTERFACING THE ADS1210 CONVERTER WITH AN ATmega8535 MICROCONTROLLER Author: Eng. Magnelli Luca.
© 2009, Renesas Technology America, Inc., All Rights Reserved 1 Course Introduction  Purpose:  This course provides an overview of the serial communication.
Analog to Digital Converter (ADC)
Analog to Digital Conversion - ADC Mark Neil - Microprocessor Course 1 Device Drivers – Measuring Voltages.
SHIFT REGISTERS: CONVERTING BETWEEN SERIAL AND PARALLEL DATA Mark Neil - Microprocessor Course 1 Serial versus Parallel Data Transfers.
Chapter Microcontroller
Communicating. The ATmega16 communicates through one of the following ways: Serial Peripheral Interface (SPI) Universal Synchronous and Asynchronous serial.
NAM S.B MDLAB. Electronic Engineering, Kangwon National University 1.
8251 USART.
Sensing Algorithm using IR Sensor and ADC Soong-sil University. Robotics 기 정 두 원.
1 Lab 4: D/A Converter Lab 4: D/A Converter This is a simple resistive network for a D/A converter Port 1, Port 0 are digital inputs ==> 00 (minimum),
By: Shivanshi pandya(30) Ayushi chourasia (3) Pranavi chhikniwala(6)
1. PIC ADC  PIC18F877 has 8 analog input channels i.e. port A pins(RA0 to RA5) and port E pins(RE1 and RE2). These pins are used as Analog input pins.
USING TV REMOTE AS A CORDLESS MOUSE FOR THE COMPUTER
CORDLESS MOUSE FEATURES BY TV REMOTE USING PIC MICROCONTROLLER
Application Case Study Christmas Lights Controller
Chip Config & Drivers – Required Drivers:
C. K. Pithawalla College of Engineering and Technology, Surat
Analog Comparator An analog comparator is available on pins PE2(AIN0), PE3(AIN1) The comparator operates like any other comparator. -when (+) exceeds (-)
Atmega32 Serial Programming Basics
UART Protocol Chapter 11 Sepehr Naimi
COMP3221: Microprocessors and Embedded Systems
Lecturer: Reza Arjmandi Autumn 2015
Configuration and Programming
ADC and DAC Programming in AVR
MSP432™ MCUs Training Part 6: Analog Peripherals
AVR – ATmega103(ATMEL) Architecture & Summary
Device Drivers – Digital Voltmeter
Serial Communication 19th Han Seung Uk.
AVR UART The UART, or Universal Asynchronous Receiver Transmitter, provides hardware support for a serial port on AVR processors Signaling is compatible.
Presentation transcript:

Microprocessor based Design for Biomedical Applications MBE 3 – MDBA IV : The ATmega8 Basic Features (3)

Last lecture: AVR Simulator avr-gcc, avr-objdump, make ISR – Interrupt Service Routines Timer Interrupt Example Uart – Configuration and Modes Uart Example

Today: Interrupt driven Uart Communication Setup stdio- functions, printf RS232 and alternatives to RS232 Atmega8 Analog Digital Conveter Analog Comparator Review Uart project, Interrupt Driven Uart example

The USART Data Register ● Transmit- and Receive Buffer (TXB and RXB) share the same address ● Reading from UDR returns current contents of the RXB Writing to UDR stores value to TXB and initiates transmission ● ISR must read/write data from/to UDR or disable the UDR-Interrupt

Example: Interrupt driven UART communication Initialisation: void init_uart (unsigned long baudrate) { unsigned int ubrr = (F_CPU/16/baudrate)-1; // Set baud rate UBRRH = (unsigned char)(ubrr>>8); UBRRL = (unsigned char)(ubrr&0xff); // Enable receiver and transmitter UCSRB = ( 1<<TXEN | 1<<RXEN ); // select character size, stop and parity bits: 8N1 UCSRC = ( 1<<URSEL | 1<<UCSZ1 | 1<<UCSZ0 ); // enable receive complete interrupt UCSRB |= (1<<RXCIE); }

Example: Interrupt driven UART communication Data Reception: ● Set Receive Complete Interrupt Enable bit RXCIE in UCSRB and enable global interrupts: sei() ● USART_RXC_vect Interrupt will be called as long as new bytes are ready in the UDR ● ISR must read data from UDR or disable the RXCIE-Interrupt

Example: Interrupt driven UART communication Data Reception using RXC-Interrupt : ISR (USART_RXC_vect) // interrupt service routine USART character received { static int rxindex=0; // receive buffer index // read UDR and store received character RXBuf[rxindex++] = UDR; }

Example: Interrupt driven UART communication Data Transmission: ● Set Data Register empty Interrupt Enable – Bit UDRIE in UCSRB and enable global interrupts: sei() ● USART_UDRE_vect - Interrupt will be called as long as UDR is empty ● ISR must write new data to UDR or disable the UDRE-Interrupt

Example: Interrupt driven UART communication Data Transmission using UDRE Interrupt: (…) UCSRB |= ~(1<<UDRIE); (…) // enable UDRE-interrupts ISR (USART_UDRE_vect) // interrupt service routine UART Data Register empty { static int txindex=0; // transmit buffer index if (TXBuf[txindex]) // characters left ? UDR=TXBuf[txindex++]; // send current character from the buffer else { txindex=0; UCSRB &= ~(1<<UDRIE); } // Disable USART_UDRE interrupts, // reset character index }

Setup of the stdio-functions: ● AVR Libc supports stdin, stdout and stderr devices needed for printf, scanf and stream I/O ● no standard in/output device is defined for the microcontroller ● the I/O-subsystem has to be initialised -> setup functions for character based IO: FILE * fdevopen ( int (*) (char, FILE*) put , int (*) (FILE*) get ); ● fdevopen() replaces fopen() the first write device is used for stdout, stderr; the first read-device is used for stdin ● these functions can use any physical medium / bus ● beware: printf is useful but need lots of memory (floating point conversion routines etc.)

Setup of the stdio-functions: int uart_putchar_file(char c, FILE * fp) // helper function to put out a character on the UART { if (c == '\n') uart_putchar_file('\r',0); // add a carrige return to a line feed character loop_until_bit_is_set(UCSRA, UDRE); // wait until the Data Register Empty bit is set UDR = c; // send out the character return(0); } ( …) fdevopen(uart_putchar_file, NULL); printf (" The value is %.2f \n", (float) val ); ( …)

USART – RS232 Level Converter ● RS232 – Levels (10/-10 V) extend transmission distance ● Max 232: 2 TTL inputs -> RS232 outputs 2 RS232 inputs -> TTL outputs

RS232 Alternatives

UART – USB Converter Solutions Example: FTDI 232 / FTDI245 converter chips ● connect directly to UART ● provide USB enumeration Device IDs (Eeprom) ● royality free Driver for Win / Linux generates virtual Com Port (VCP) ● data rates up to 1 MBit/s ● 5V and 3.3V designs supported ● Bus-powered and self-powered configurations

UART – USB Converter Solutions ● UM232 Dip – Module with Crystal and USB- Plug ● FT245 based parallel FIFO Module up to 3MBit/s ● Vinculum VDrive USB Host controller USB Flash Drive <-> UART Interface http://www.ftdichip.com

Wireless communication: UART <-> Bluetooth Example: Bluegiga WT11 – module http://www.bluegiga.com ● Class 1 BT Device (<300m) ● on-chip or external antenna ● UART, SPI, USB busses ● iWrap firmware ( AT - like commandset ) ● RFCOMM, HCI, HID stacks and Serial Port Profile

The Analog Digital Converter ● 10-bit Resolution (8-bit Accuracy on ADC4 and ADC5) ● Up to 15 kSPS at Maximum Resolution ● 6 Multiplexed Single Ended Input Channels ● 8 Multiplexed Single Ended Input Channels in TQFP / MLF Package ● 0 - VCC ADC Input Voltage Range ● Selectable internal 2.56V Reference Voltage ● Free Running or Single Conversion Mode ● Interrupt on ADC Conversion Complete ● Sleep Mode Noise Canceler http://www.reedag.ch

The Analog Digital Converter ● A/D conversion by successive approximation: DAC and comparator Min: 0x0000 = GND Max: 0x03FF = AREF-1LSB ● Internal 2,56V reference: do not connect external voltages to AREF if internal reference is used ● Channel multiplexer select input channel before conversion starts

The Analog Digital Converter Successive approximation: ● Starting with the MSB, test values are generated converted to analog (DAC) ● Result of comparation influences current bit in approximation register ● After n bits, the result is latched out

The Analog Digital Converter Types of Conversion Errors: Offset error Gain error Non-linearity ● 0.5 LSB Integral Non-linearity ● ± 2 LSB Absolute Accuracy ATmega8 – ADC:

The Analog Digital Converter ● ADC Clock should run at 50kHz – 200kHz to give full resolution ● Prescaler generates ADC clock from CPU clocks >= 100 kHz ● ADPS2:0 bits of ADCSRA Register select clock prescaler value

The Analog Digital Converter Single / First conversion takes 25 ADC clock cycles Free running conversions take 13 ADC clock cycles After the conversion is complete (ADIF is high), the conversion result can be found in the ADC Result Registers (ADCL, ADCH)

The Analog Digital Converter ADEN: ADC Enable ADSC: ADC Start Conversion start a single conversion or free running mode ADFR: ADC Free Running Select 1: continuous sampling and update of data registers ADIF: ADC Interrupt Flag ADIE: ADC Interrupt Enable Reset pending interrupts by writing 1 to the ADIF-Bit !

The Analog Digital Converter REFS1:0 Reference Selection Bits 00: external AREF, 01: AVCC, 11: internal 2,56V reference ADLAR: ADC Left Adjust Result 1: result is left adjusted, 0: result is right adjusted MUX3:0: select the A/D input channel: 0000: ADC0 – 0111: ADC7, 1110: 1,23V, 1111: GND

The Analog Digital Converter Handling of the ADC Data Registers (ADCL, ADCH): ADLAR=0 ADLAR=1 ● read Low Byte (ADCL) first, then high byte (ADCH) ● If only 8 bits resolution are needed, use left adjustment and read only high byte

The Analog Digital Converter ADC Noise canceler: ● conversion during sleep mode to reduce noise induced from the CPU core and other I/O peripherals ● select single conversion mode and enable ADC interrupts Enter ADC Noise Reduction mode (select sleep mode „Idle“) ● ADC conversion be will start automatically after CPU is put to sleep using the sleep () command ● ADC interrupt (or other interrupt) will wake up the CPU ● next conversion will be issued after next sleep - command

The Analog Digital Converter General issues for using the A/D converter ● connect low impedance sources ( < 10kOhm) to achieve fast sampling rates ● do not connect signals with frequencies higher than the Nyqist frequency (half the sampling frequency) ● Use a low-pass filter to remove higher frequency components to prevent aliasing ● Keep analog signal paths as short as possible

The Analog Digital Converter General issues for using the A/D converter ● Make sure analog tracks run over the analog ground plane, keep them well away from high-speed switching digital tracks ● Use an LC network to connect AVCC (low pass filter the supply voltage)

The Analog Digital Converter Example: Initialisation for Interrupt driven AD Conversion ADCSRA = (1<<ADPS2) | (1<<ADPS1); // Prescaler = 64, free running mode = off, interrupts off // prescaler = 64 (ADPS2 = 1, ADPS1 = 1, ADPS0 = 0) // ADCYCLE = 7,3728Mhz / prescaler = 115200Hz or 8.68 us/cycle // 14 (single conversion) cycles = 121.5 us (8230 samples/sec) // 26 (1st conversion) cycles = 225.69 us ADCSRA |= (1<<ADIF); // Reset any pending ADC interrupts ADCSRA |= (1<<ADEN); // Enable the ADC ADCSRA |= (1<<ADIE); // Enable ADC interrupts ADMUX=0; // Select ADC channel 0 ADCSRA |= (1<<ADSC); // single conversion: Start the ADC

The Analog Digital Converter Example: ADC Interrupt Service Routine ISR(ADC_vect) // AD-conversion-complete interrupt service routine { unsigned char low,high; unsigned int value; low = ADCL; // read ADC value (low byte first !) high = ADCH; // read ADC value high byte value = (high<<8) + low; // calculate integer value }

The Analog Comparator

The Analog Comparator ACD: Analog Comparator Disable: 1 turns AC off ACBG: Analog Comparator Bandgap Select ‚1‘ selects internal reference voltage ACO: Analog Comparator Output ACI: Analog Comparator Interrupt Flag ACIE: Analog Comparator Interrupt Enable ACIC: Analog Comparator Input Capture Enable ‚1‘ triggers Timer1-capture-interrupts (if enabled) ACIS1,0: Analog Comparator Interrupt Mode Select 00: toggle, 10: falling edge, 11: rising edge

The Analog Comparator ACME (Bit 3 of SFIOR): Analog Comparator Multiplexer Enable if ACME set 1, the ADC – Channel selected by ADMUX is used as negative comparator input instead of AIN1