Portable Low Cost Spectrometer

Download Report

Transcript Portable Low Cost Spectrometer

Portable Low Cost
Spectrometer
Design Review
March 22, 2007
Brett Hamilton
Kodin Taylor
Mateusz Wyganowski
Outline







Background
High Level Design Overview
Texas Instruments TSL1401-LR Sensor Array
Atmel Atmega8 Microcontroller
Master Graphical User Interface
Electrical Schematic
Demo
Background



The purpose of this project is to create a portable
optical spectrometer with inexpensive components
for use in environmental monitoring
Current optical spectrometers are often expensive
and generally provide more power and functionality
than is necessary for our desired use
Inexpensive light sensors have become available
that when coupled with a prism will be able to detect
levels of light at various wavelength ranges in the
visible spectrum.
Cost Estimation






Microcontroller:
$3-4
PCB Manufacture:
$100
Sensor/Prism and Assembly: $20-30
RS-232 Interface chip:
$10
Power Regulator
$10
Total:
< $170
High Level Design Overview
Software UI
Serial Data
PC
RS232 Connection
Microprocessor Control
Board
Analog Data
CLK
Database
Sensor / Prism Assembly
Texas Instruments TSL1401R
Sensor Array



128 x 1 Sensor-Element Organization
3-5 Vcc
2 Digital Signal Inputs



SI
CLK
Analog Output

AO
Sensor Array Cont.
Sensor Array Cont.
Sensor Array Cont.
Atmel Atmega8 Microcontroller

Features







2.7 – 5.5V, ~7-15 mA
0-16 Mhz CPU Clock
8K Bytes of Flash
512 Bytes of EEPROM
1K Byte of SRAM
One 16-bit Timer/Counter with Separate Prescaler
Sensor Interface



Master Interface




Digital I/O (output)
10-bit Accuracy ADC Input (input)
Programmable Serial USART with Separate Prescaler
External Clock source
Power-down modes
C Programming Language Environment
Microcontroller Software
Internals




Interface with Sensor
Reduced Power Mode
Raw Sensor Value Adjustment
Communication Protocol
Sensor-Microcontroller
Interface (Control Output)

Control Signals


Pins 0 and 1 of PortB
16-bit timer with Periodic ISR
 One large c switch statement
 Cases

LO_HI, HI_LO, AD_SAMPLE
Example ISR Case Statement
case SA_LO_HI:
PORTB |= _BV(SSIG_CLK);
sensor_state.tick++;
if( sensor_state.reading == TRUE )
{
sensor_state.next_action = SA_AD_START;
next_time = T_S;
}
else
{
sensor_state.next_action = SA_HI_LO;
next_time = T_PER/2;
}
break;
Sensor-Microcontroller
Interface (Analog Input)

Reading Analog Values


10-bit Analog-to-Digital Converter
AD Conversion Done Interrupt
 Fires automatically when ATC is done after every
AD_SAMPLE case in the timer ISR
Sensor-Microcontroller
Interface
Reduced Power Mode



The ADC is turned on just before starting the
read cycle and back off when finished.
Idle Mode is used when waiting for
instructions.
ADC Noise Reduction Mode is used each
time starting an ADC sampling. The ADC
module generates an interrupt when value is
ready.
Value Normalization



Sensor Elements are not equally sensitive to entire supported
wavelength range.
Normalization value for each element (128 total)
 Possible values 1-65535 (1024 => 1)
Algorithm
 output_val : uint16_t
 temp32_val : uint32_t
 raw_val : uint16_t
 norm_val : uint16_t

// Final normalized value
// 32 bit value for calculations
// raw value from the sensor
// normalization “multiplier”
for each raw_val, norm_val value pair in memory




temp32_val = raw_val * norm_val
temp32_val = temp_val >> 10
temp32_val = MIN( temp_val, ADC_MAX_VAL )
output_val = (uint16_t) ((0x00FF) | temp_val)
// 32 bit result
// Normalize
// Bound value
// Lower 16-bits
Master-Microcontroller
Interface (Comm. Protocol)

ASCII Protocol Messages Consist of
 One Start Delimiter








$:Command, Always Master  Microcontroller
@: Notification of success, Microcontroller  Master
!: Notification of error, Microcontroller  Master
%: Reserved for sensor values
*: Miscellaneous Information shown when debugging and log
files.
Two character command identifier
Optional colon and comma separated parameters
Two End delimiters (CR, LF)
Command Handlers



Each command is paired with a handler
function.
On incoming message, correct handler
function is found based on 2 character
command “key”.
Handler function is responsible for parsing
parameters, performing the requested
operation, and returning a success or failure
message.
Master Graphical Interface
Program Operation



Static “comm controller” class maintains
serial connection
Read thread continuously listening to serial
port for incoming data
All incoming comm traffic is sent to static
main class for processing
Sending Commands
Command
ASCII
Description
REQUEST_CON
rf
Request information and inform the microcontroller of a
connection
ENTER_PC_MODE
pc
Enter the Programming/Calibration mode
READ_ONE
r1
Read current value
READ_CONT_ON
rc
Start continuous reading
READ_CONT_OFF
sc
Stop continuous reading

All commands sent with $ as prefix

$sc<CR><LF>
Programming Mode
Command
ASCII
Description
SET_VAR
sv
Write a value to a particular variable
GET_VAR
gv
Read a value from a variable
DUMP_VAR
dv
Dump name-value pairs for all supported variables
READ_ONE
r1
Read the current value from the sensor
SET_CAL
cl
Modify a multiplier for a single photodiode
REBOOT
rb
Reboot the microcontroller application

Sample Programming Command String

$sv:VAR_BAUD_RATE,115200<CR><LF>
Get / Set Variables

Variables that are accessible using SET_VAR and
GET_VAR are as follows:





VAR_SREAD_INT: The rate at which to send continuous sensor
updates to the master in milliseconds. The minimum value
allowable is 100 ms.
VAR_RD12_INT: The time between the flush read and actual
read (described later).
VAR_BAUD_RATE: serial baud rate. Valid values are all
possible baud rates between 1200 and 115200. The value will
take effect on reset.
VAR_WV_LOW: The wavelength value detected by the
photodiode at the low extreme.
VAR_WV_HIGH: The wavelength value detected by the
photodiode at the high extreme.
Command Confirmations



Command confirmations prefixed with @
Data requests returned with values appended
to the confirmation string
Example:

Sent:


“$rf<CR><LF>”
Received:

“@rf:450,800<CR><LF>”
Error Messages

Errors prefixed with !


Returns the command that caused the error as
well as possible parameters or descriptions
Example

Sent:


“$rf<CR><LF>”
Received:

“!rf:WV_LOW and WV_HIGH not set.<CR><LF>”
Receiving Data

Incoming data prefixed with %



String is tokenized and parsed into integers
Parsed data is used to update GUI’s graph and
tables
Example:

“%10,25,0,13,26,0,0,1,115…<CR><LF>”
Data Handling

GUI



Data is plotted on a large graph
Actual data values displayed in a table with
associated wavelength
Log File

Appended data is saved in a CSV file for archival
purposes as well as possibly generating reports
Other Messages

Other Messages prefixed with *

Anything else the microcontroller wishes to
convey is ignored and sent to a debug file
Electrical Schematic
Power Supply Design
Linear Regulator
vs.
+ Simple
+ Cheap
- Potentially Inefficient
(heat)
Switching Regulator
- Complex
- Noisier output voltage
+ Efficient
Power Supply Design
Power Supply Design
Power Supply Design
TSL1401-LR Sensor Array
TSL1401-LR Sensor Array
MAX232 Level Shifter
Noise Reduction

Power Supply


ADC


Placement of decoupling capacitors at each chip’s
Vcc (as close as possible) to provide sudden
spikes in current.
Separate ADC reference point filtered with an
inductor and decoupling capacitor.
Crystal Oscillator


Placement as close to microcontroller as possible.
Surround with ground plane.
Demo

Master and Microcontroller Communication
Feedback?