You Are Here: Home » AVR ATmega Projects » Sensor - Transducer - Detector Projects » 3D ultrasonic mouse Using Atmega644

3D ultrasonic mouse Using Atmega644




Introduction

Ultramouse 3D times the delay of high-frequency sound waves from the unit held by the user to each of three receivers and passes this information along a serial cable to the computer. The accompanying open-source API provides easy functions that let any Win32/C++ application start reading 3d data in less than 5 minutes.

This is our unique final project for ECE 4760 at Cornell University.

Karl Gluck
MCU software implementation, C++ API and 3d demo code
David DeTomaso
Hardware design, refinement and analysis

High-Level Design

Sound travels through air at approximately 345 m/s. From this, the time it takes for sound to travel between a transmitter and receiver can be described as:

From this, a reasonably fast counter could keep track of a time delay between transmission and reception and back calculate a distance.

If the time of transmission and the time of reception on each of three receivers is known, R1, R2, and R3 can be calculated. Then, with known values of w and h, the 3d coordinates of the transmitter can be calculated by solving a system of equations of the form:

Pulses from the transmitter are initiated by the MCU. The MCU then checks input pins from each of three receivers every 6.25 s while keeping track of a counter variable. When an input is detected, the current counter value is saved. After all three inputs have been detected, the three saved counter times are sent to the PC for processing and update of the mouse position.

The only patent we could find is US Patent # 4862152 which details a similar system of ultrasonic 3d positioning and was filed in 1985. However, beause the patent does not seem to be extended and because our design differs in the specific way pulses are detected and position data is filtered, we do not think that our project is in violation of this patent.

Design Considerations

Placement of the ultrasonic sound receivers will affect the accuracy of the measurements. In order for sufficient resolution, the distances between receives should be on the same scale as the distance between the transmitter and the receivers. Receivers very far apart are not practical for the user and receivers close together will have very small time offsets. For the application space we intended, it made sense to mount the three receivers on three corners of a computer monitor.

3D ultrasonic mouse Using Atmega644

In order for the MCU to accurately resolve the three distances, a fast counter is needed. However, because the MCUs onboard Timers cannot be interrupted with three separate external inputs we must emulate a timer by calling an interrupt at a fixed rate. Increasing the rate of this interrupt will allow the system to resolve distances more accurately but also limit the amount of code that can be executed within the interrupt. We chose to run this interrupt at a rate of 160 kHz so that accuracies as fine as 2mm could be resolved and the interrupt could use up to 100 processor cycles to handle the receiver signals.

Analog Design

Receiver Circuit

The main purpose of the receiver circuit is to amplify the small 40 kHz signal coming from the ultrasonic receiver so that a digital input port on the MCU will read a logic high when a signal is being transmitted and a logic low at all other times. Additionally, the delay through the circuit should be minimal to allow for accurate positioned based on the sounds propagation delay in air. To accomplish this, we have cascaded three operational amplifiers configured for an overall gain of around 80 dB. For each amplifier, we required the following specifications:

  • An input range that includes ground
  • Low input offset voltage
  • 30-40 dB of gain at 40 kHz
  • High slew rate (at least 1 V/S)

We found the following specifications well satisfied by the Japan Radio Co. NJU7031D operational amplifier. The resulting circuit worked well within the required specifications and was able to amplify input signals to small to be discerned on the oscilloscope to levels detectable by the digital input pin.

Transmitter Circuit

Our transmitter circuit is modeled after the fan driver circuit found in lab 5. To drive the ultrasonic transmitter an alternating voltage at 40 kHz must supplied across the transmitters two leads. To accomplish this, we used a digital output pin the MCU to drive the gate of a power transistor. By placing the transmitter, in parallel with a resistor, between the transistors drain and the supply voltage, a 40 kHz signal supplied by the MCU can drive a 40 kHz signal across the transmitter ranging from supply to ground. To transmit as strong a signal as possible, we use the voltage coming directly out of the AC/DC transformer which tends to range from 9  13 volts.

MCU Software Design (AVRStudio / GCC)

The most critical section of software design is the TIMER0_COMPA ISR. When enabled this interrupt runs at 160 kHz by setting Timer 0 at the full 16 MHz speed, activating interrupt-on-overflow, and setting the overflow value at 99. Each pass, the interrupt updates timebase_160kHz, a counter variable, generates the 40 kHz transmit signal if transmission is active, and polls each of 3 receiver inputs, copying over the timebase_160kHz value if a trigger is detected. Because of its high frequency of occurrence, the interrupt must run in under 100 cycles. To achieve this specification, various optimizations have been made. Several cycles were saved by outputting timebase_160kHz on port B and using B.1 as the 40 kHz transmit signal. Redundant polling of receiver pins is avoided by checking first to see if the pin had already been triggered and recorded.

The main method of the MCU program is used to initialize required values and to take over once all three receivers are triggered. After variables are initialized, an infinite while loop continuously checks to see whether three receiver triggers have been detected or if the timeout value has been reached. If either of these is the case, TCCR0B is set to 0 to disable the 160 kHz interrupt so that transmission can be handled efficiently. If three triggers have been detected, the loop waits as ISR USART0_UDRE is called to send time delays to the PC. In either case, delay and counter variables are re-initialized and the 160 kHz interrupt is enabled and set to transmit for its first millisecond.

PC Software Design (Visual C++)

The API for UltraMouse 3D exposes three main functions:

  • UM3DAPI_Create

Initializes the serial port and Ultramouse3D structure

  • UM3DAPI_Update

Called every loop of the main program to read data from the device and calculate its coordinates

  • UM3DAPI_Destroy

Cleans up the structure when the program exits

The functionality of these methods is clearly explained in the source file, but a few design points are worth mentioning.

First, the incoming data from the receiver is very noisy–for every hundred good samples, there are a few huge spikes in the delays. Standard linear filters we attempted (low-pass, mean, moving average, exponential weighting) were unable to remove these effectively without creating such large delays in the data that the interface felt sluggish. Instead, the implementation uses a median filter on the incoming data points. This effectively eliminates all large jumps in the data; however, it leaves smaller ones. In the figure below, data was taken for the user drawing a square (more data here). The blue stars are the source data, and the red line is the median-filtered data.

Parts List:

PartQuantityUnit CostTotalSource
$42.07
Ultrasonic TX/RX Pair
2
$7.95
$15.90
Jameco P/N 139492
Solderless Whiteboard
1
Previously Owned
Custom PC Board
1
$4.00
$4.00
ECE 4760 Lab
BUZ73 N-Channel Power MOSFET
1
ECE 4760 Lab
Push-Button Switch (unused)
1
Scrap Pile
Through-Hole Resistors & Capacitors
many!
ECE 4760 Lab
Wire
lots!
ECE 4760 Lab
High Performance Op-Amps
9
$0.75
$6.75
Digikey NJR P/N NJU7031D
RS-232 Serial Port
1
$1.00
$1.00
ECE 4760 Lab
MAX233CPP
1
Sampled
16 MHz Crystal Oscillator
1
ECE 4760 Lab
LM340T5 Voltage Regulator
1
$0.42
$0.42
ECE 4760 Lab
Atmel ATMega644
1
$8.00
$8.00
ECE 4760 Lab
8 pin DIP Socket
1
$0.50
$0.50
ECE 4760 Lab
40 pin DIP Socket
1
$0.50
$0.50
ECE 4760 Lab
9V Power supply
1
$5.00
$5.00
ECE 4760 Lab
Copper Wire Board
1
Scrap Pile

For more detail:  3D ultrasonic mouse Using Atmega32

Leave a Comment

You must be logged in to post a comment.

Read previous post:
New site, app, links celebrities, charities and donors (Update)

Chatting on the red carpet with Bradley Cooper and Jennifer Lawrence; recording a country song with Clint Black; working a...

Close
Scroll to top