EECS 498 Lecture 3 - PowerPoint PPT Presentation

1 / 19
About This Presentation
Title:

EECS 498 Lecture 3

Description:

Prelab due Friday, inlab/postlab on Tuesday. ... he difference is the time elapsed between the two events. Timer 0. 8 Bit Up Counter ... – PowerPoint PPT presentation

Number of Views:27
Avg rating:3.0/5.0
Slides: 20
Provided by: caen2
Category:
Tags: eecs | elapsed | lecture

less

Transcript and Presenter's Notes

Title: EECS 498 Lecture 3


1
EECS 498Lecture 3
  • ATmega8 Hardware features

2
Status?
  • Labs
  • Lab 1 due today.
  • May have been too short
  • Lab 2 posted
  • Prelab due Friday, inlab/postlab on Tuesday.
  • Use a board weve designed and modify part of our
    software.
  • Project
  • Well discuss project ideas, groups etc. on
    Thursday.
  • Draft proposal due the following week.
  • Space
  • Stuff is a mess at the moment. Hope to have
    really ready over weekend (as much as furniture
    status allows).

3
AVR stuff
  • Timers
  • SPI
  • USART
  • Much taken from Pascal Stangs class at Stanford.
  • http//www.stanford.edu/class/ee281/

4
Timers Review
  • Provide accurately timed delays or actions
    independent of code execution time
  • How are Timers used?
  • Accurate delay
  • Read the timer, store value as K. Loop until
    timer reaches K100.
  • Schedule important events
  • Setup an Output Compare to trigger an interrupt
    at a precise time
  • Measure time between events
  • When event1 happens, store timer value as K
  • When event2 happens, read timer value and
    subtract K
  • he difference is the time elapsed between the two
    events

5
Timer 0
  • 8 Bit Up Counter
  • counts from 0 to 255 (0xFF), then loops to 0
  • Internal or External Clock source
  • Prescaler
  • Interrupt on Overflow
  • Transition from 255 to 0 can trigger interrupt if
    desired

6
  • Up counter (only)
  • ClkT0 can be generated from an external or
    internal clock source, selected by the clock
    select bits (CS020).
  • TOVn goes high (and may generate an interrupt)
    when going from 0xFF to 0x00

7
Timer 0
8
Timer 1
  • 16 Bit Counter
  • Counts from 0 to 65535 (0xFFFF), then loops
  • Internal clock source with prescaler or External
    Clock
  • Dual Comparators
  • Interrupts possible on
  • Overflow
  • Compare A/B
  • Input Capture of external event on ICP pin
  • Can also act as an 8, 9 or 10 bit PWM Up-Down
    Counter

9
(No Transcript)
10
Quick note 16 bit operations
  • 16-bit operations are tricky
  • Stores
  • When writing the 16-bit locations, you must
    always write the high byte first.
  • The write goes to a temp register and is ignored
    until the low byte is written
  • You need to disable interrupts so the temp
    register doesnt get trashed
  • Loads
  • When you read the low the high value goes to the
    (same?) temp.
  • When you read the high you get the temp.
  • Notes
  • Our lab2 code doesnt do this! (oops)
  • Some 16-bit accesses dont do this (reading
    OCR1A/B) is the only one I know of

11
Timer 1 continued
  • The timer1 on the ATmega8 has two output compares
    (OCR1A/B)
  • OCR1A/B are 16-bit registers
  • When the value of OCR1x matches that of Timer1
  • A user-defined action can take place on the OC1x
    pin (set/clear/inv)
  • An interrupt can be triggered
  • Timer1 can be cleared to zero
  • Once set up, output compares operate continuously
    without software intervention
  • Can drive pins OC1A and OC1B
  • Great for
  • Precise recurring timing
  • Frequency/Tone generation (maybe sound effects)
  • All kinds of digital signal generation
  • Infrared communications
  • Software-driven serial ports

12
Timer 1 modes
  • Modes of operation (chosen by bits WGM130)
  • Normal mode
  • Just an up-counter, interrupt can be generated on
    overflow.
  • Can be used to time external events
  • Can be used to trigger interrupts
  • Either compare or overflow
  • CTC (Clear Timer on Compare)
  • Has a number of features, but lets you modify the
    period by having the counter reset when it hits a
    certain value.
  • Other modes for PWM exist
  • They are fairly complex and full featured.

13
Timer 2
  • 8-bit
  • Has external pin it controls
  • Can do CTC
  • Has PWM features
  • Can have own external clock (32Khz)

14
SPI (Serial Peripheral Interface)
  • Allows transfer of information, 8 bits at a time,
    between microcontroller and any number of
    peripherals
  • Read and Write operations happen simultaneously
  • Using chip selects allows lots of peripherals to
    be connected to a single SPI bus at the same time
  • Has no start/stop bit overhead
  • High data rates 250Kbit to 2Mbit/sec
  • Common uses
  • Inter-Processor Network
  • Sending MP3 data to MP3 decoders
  • Interfacing to external serial RAM/EEPROM/FLASH
  • Interfacing to serial graphic LCDs
  • Compatible with thousands of chips with SPI,
    Microwire, I2S, and other serial interfaces

15
(No Transcript)
16
SPI pins and registers
  • SPI Pins
  • MOSI (master out, slave in)
  • MISO (master in, slave out)
  • SCK (serial clock)
  • SS (slave select, optional)
  • SPI Registers
  • SPDR (transferred data read/write register)
  • SPCR (control register)
  • SPSR (status register)
  • SPI Transfer Complete interrupt

17
USART
  • The USART, or Universal Synchronous Asynchronous
    Receiver Transmitter, provides hardware support
    for a serial port on AVR processors
  • Signaling is compatible with PC/Mac/Unix serial
    (RS-232C)
  • Provides
  • Parallel-to-Serial and Serial-to-Parallel
    conversion
  • Start and Stop Bit framing
  • Parity Generation
  • Baud-Rate Generation (2400-115.2kbps at 3.686 or
    7.37MHz)
  • Interrupts
  • Transmit Complete
  • Transmit Data Register Empty
  • Receive Complete

18
Projects
  • Some thoughts about projects
  • I want you to use the AVR platform if possible.
  • Overlap with work not allowed unless line is well
    defined.
  • If you are paid, its work.
  • Solving a problem rather than competing in the
    mass-market probably best
  • Next week you will have formal requirements

19
Some ideas
  • Have 3 potential customers
  • Speaker tracking
  • Has
  • Human Powered Submarine. adjust weight to
    stabilize their sub
  • Card-reader
  • Read the order of a deck of cards.
  • No really.
  • Sensor gathering
  • ?
Write a Comment
User Comments (0)
About PowerShow.com