Note: This is an exam. Do not discuss this or compare notes. This should be your own work, not a group project.
We will be happy to answer questions relating to clarity of this document via the class mailing list. We will not answer questions about your design.
Congratulations! You’ve just been hired by the Seattle Happy Teddy Bear Company to design and develop a prototype of next year’s Talking Bear toy.
The bear is based on an Atmel AVR ATmega16 microprocessor, with several external peripherals. The bear will listen and respond to certain sounds and movements.
Inputs:
10 bit A to D converter with microphone for listening (AD0 of ATmega16)
Switch input, left ear squeeze, 0=SQUEEZE (Needs to be debounced)
Switch input, right ear squeeze, 0=SQUEEZE (Needs to be debounced)
Switch input, body position detector, 0= HORIZONTAL, 1=VERTICAL (Needs to be debounced)
Switch input, leg position detector 0= HORIZONTAL, 1=VERTICAL (Needs to be debounced)
Single Bit Digital input, greater than 2 G motion detector, 1=GREATER THAN 2 G
Photocell light level detector (AD1 OF ATmega16)
4Mbit Flash Memory, SPI interface, for audio message storage (Part # AT26F004)
Outputs:
12 bit D to A converter—TWI interface, with amp and speaker, for talking (Part #AD5321)
Two blue LEDs, for eyes, COMMON ANODE, 0=ON, 1=OFF
Schematic of the bear’s action module.
Operation:
The bear should have a reasonable user interface and should not make noises unless the user intention is clear. You need to add lots of debouncing to your design so that the system does not flicker between states and annoy parents with lots of repeated phrases.
The AD converter produces a stream of audio samples. These samples need to be analyzed for ambient sounds that will trigger bear responses. See audio analysis section for details.
The LEDs in the bear’s eyes should light up either when the bear is talking or when the ambient room sound is above minimum sound threshold. The brightness of the LEDs should correspond with the loudness of the sound. See audio analysis section for details.
The photocell should be sampled periodically for changes in ambient light. When the lights go down, the bear will say “Good night.” The bear should respond to light levels appropriately and have a reasonable user interface.
The bear has many different responses to motion. To detect these motions the inputs should be debounced and sampled periodically. The switched inputs on the ears are noisy buttons and will settle in 25ms. The body and leg position switches are made of a liquid and can take a minimum of 3 seconds to settle. The single-bit 2G Motion detector input only needs to be sampled periodically. The list of bear responses are:
When no activity occurs on any of the inputs for more than 2 minutes, the bear should say “Let’s play.”. The bear should repeat this every 15 seconds for 1 minute, then enter power-down-mode1 until the next activity is detected. After 5 minutes the bear should enter power-down mode2.
Power-down Mode1
In this mode the real-time clock should be used to wake up the bear from sleep once each second, so that the bear can listen for 200 ms. If no sound activity or movement is detected, the bear should re-start the timer and sleep for a second. After 5 minutes without activity the bear should enter Power-down mode 2.
Power-down Mode2
In this mode the bear sleeps and can be awakened only by an edge on the body position detector. See the AVRmega16 datasheet section on "Power Management and Sleep Modes" for the lowest-power mode possible.
Audio analysis:
The AD converter is sampling ambient sound from the microphone, which can look like this:
The 10-bit audio samples can range from 0x0000 (bottom) to 0x03FF (top), centered around 0x01FF, or half full-scale. Silence would be a line at 0x1FF. Your job is to produce a stream of numbers represented by the black line, call the envelope of the signal. The higher the line, the louder the sound. You should create a moving average of the magnitude from the center, or half-full scale. This average should be long enough to smooth out sounds shorter than 200 msec, like the sound marked in red. You will need to select a sample rate greater than 8k samples per second. See audio lecture slides.
You should select a minimum sound threshold above which you will use the detected sound envelope to control the brightness of the bear’s blue LED eyes via PWM. The bears eyes should get brighter when the room volume goes above the minimum sound threshold. The brightness is determined by how loud the room volume is, or by the loudness of the playback audio when the bear is talking. The bear doesn’t listen while he talks.
Audio Phrases
Audio phrases are stored in the AT26F004 serial interface Flash memory device accessed by SPI interface. Eight phrases are stored in the external memory, each starting on a 64kb memory boundary. See figure 4-1 in the datasheet for address boundaries. The first 16 bit word of the block is the sample count in the phrase; the rest of the data is the audio in 16 bit values, from 0x0000 to 0x0FFF, corresponding to the 12 bit resolution of the AD5321 D to A converter. The recorded sample rate of the phrases is 16000 samples per second. Your DA sample rate should be as close to that rate as possible. The samples are padded with silence to the next 16-sample length, so that their length is a multiple of the buffer size (see below).
The phrases are:
Block 0: “Good night.” Lowest address
Block 1: “I’m sleepy.”
Block 2: “Is it time to eat?”
Block 3: “Let’s play.”
Block 4: “You’re cool.”
Block 5: “Bears rule.”
Block 6: “Ouch, that hurt!”
Block 7: “Wheeeeeeeeeeeeeeee!” Highest address
Audio buffers
Audio input from the on-board ADC and audio output to the DA converter need to be buffered in 16-sample buffers in SRAM, with two buffers in each direction, called INA, INB, OUTA, and OUTB.
Input processing:
The on-board ADC interrupt routine fills INA while INB is available for envelope processing by the foreground routine. When the ADC interrupt routine reaches the end of INA, it signals the foreground routine to process INA data and it switches to filling INB. This buffer-swapping continues with the rate controlled by the ADC interrupt rate. The main routine has 16 sample times to process the buffer.
Output processing:
The TWI interrupt routine will move data from OUTA to the DA converter while the foreground routine fills OUTB with phrase data from the external flash memory. When the TWI interrupt routine empties the OUTA buffer it signals the foreground routine to refill OUTA and it switches to moving data from OUTB. This buffer-swapping continues with the rate controlled by the TWI interrupt rate. The foreground routine must implement a routine to fill the correct buffer from the SPI interface to the external flash memory.
I. Design and write the following code snippets:
Deliverables
Your file should contain comments that include: your full name and email address. Email to: Bruce-- bruceh@cs.washington.edu AND Waylon-- wrb@cs.washington.edu by 11:59 p.m. PST Thursday, December 15, 2005.