firmware
v0.1.2
Chromation Spectrometer Dev-Kit
|
#include <stdint.h>
#include <stdbool.h>
#include "SpiSlave.h"
#include "StatusCode.h"
#include "Queue.h"
#include "BiColorLed.h"
#include "UartSpi.h"
#include "AutoExpose.h"
#include <util/delay_basic.h>
Go to the source code of this file.
Functions | |
bool | LedNumIsValid (bicolorled_num led_num) |
uint8_t | ReadLedState (bicolorled_num led_num) |
bool | AutoExposeConfigIsValid (uint8_t new_max_tries, uint16_t new_start_pixel, uint16_t new_stop_pixel, uint16_t new_target) |
uint16_t | GetPeak (uint16_t const, uint16_t const) |
uint16_t | AutoExpose (void) |
void | NullCommand (void) |
void | GetSensorLED (void) |
void | SetSensorLED (void) |
void | GetExposure (void) |
void | SetExposure (void) |
static void | CaptureFrame (void) |
void | AutoExposure (void) |
void | GetAutoExposeConfig (void) |
void | SetAutoExposeConfig (void) |
void | GetSensorHash (void) |
Variables | |
volatile Queue_s * | SpiFifo |
Allocate static memory for the SPI Rx Queue. | |
uint8_t | frame [] |
One frame of pixel data is, at most, 1568 bytes. | |
Definition in file VisCmd.h.
uint16_t AutoExpose | ( | void | ) |
AutoExpose behavior:
Find an exposure time that gets a peak within +/-5% of the target peak value. On each iteration, multiply exposure time, either by:
10
, if peak is below the dark background1/2
, if peak is above the target rangegain
, if peak is visible but below the target rangegain
= target
÷ peak
gain
is always > 1:target
is the center of the target rangepeak
is below the target
range, so peak
< target
target
÷ peak
must be > 1target
BEFORE dividing by peak
:exposure_ticks
x target
) ÷ peak
The algorithm gives up if:
The large tolerance, ±5%, makes the algorithm fast. It usually settles within a few iterations.
The range of target values is configured by setting target
and target_tolerance
. The recommended values are:
target
: 46420 countstarget_tolerance
: 3277 countsAutoExpose tries to get the peak counts between min_peak
and max_peak
.
target - target_tolerance
is the min_peak
target + target_tolerance
is the max_peak
Using the recommended values, this results in:
min_peak
: 43143 countsmax_peak
: 49697 counts49697 counts is the top of the guaranteed linear range of output values for the LIS-770i
This target range, [ 43143 : 49697 ], represents 10% of the full-scale reading, 65535.
Signal below max_dark
is considered no signal because it is indistinguishable from the dark background.
max_dark
max_dark
to 4500 ensures the algorithm calculates a gain only when necessarymax_dark
depends on:AutoExpose is not done
Exposure time is stored in 16-bit global exposure_ticks
.
Clamp adjustments to exposure_ticks
between 1 and 65535.
When multiplying exposure_ticks
by:
10
or gain
:exposure_ticks
at 655351/2
:exposure_ticks
at 1while AutoExpose is not done:
frame
bufferpeak
from global frame
buffer// peak <= max_dark
peak
is ABOVE target range: // peak is > max_peak
// exposure time = 1/2 exposure time
peak
is BELOW target range: // peak is < min_peak
target
÷ peak
// exposure time = ( target x exposure time ) ÷ peak
// signal in target range: min_peak <= peak <= max_peak
|
inlinestatic |
|
inline |
uint16_t GetPeak | ( | uint16_t const | _start_pixel, |
uint16_t const | _stop_pixel | ||
) |
GetPeak behavior:
peak
starts at 0frame
buffer_start_pixel
_stop_pixel
pixval
> peakpeak
= pixval
peak
byte_index example: v----— if _start_pixel is 7 pixel: 1 2 3 4 5 6 7 8 byte: 01 23 45 67 89 AB CD EF ^----— then byte_index is 12
|
inline |
|
inline |
|
inline |
ReadLedState behavior:
|
inline |
|
inline |