107 lines
4.9 KiB
C
107 lines
4.9 KiB
C
// intellectual property is bullshit bgdc
|
|
|
|
// ============================================================================
|
|
// TIMDAC REFERENCE DESIGN CONFIGURATION - REFERENCE DESIGN 1.0
|
|
//
|
|
// This file is designed to be #included from your main timdac_config.h, and
|
|
// provides all the configuration specified for the timdac hardware reference
|
|
// design. These parameters should not be changed without good reason, as they
|
|
// can affect the DAC performance in surprising ways. If you do need to change
|
|
// them, you should #undef and re-#define them after including this file.
|
|
//
|
|
// The macros in this file depend on a definition in timdac_config.h:
|
|
//
|
|
// #define TIMDAC_TIMERFREQ_HZ 72000000
|
|
// This definition should be set to the base operating frequency of your
|
|
// system's timer in Hz. It is strongly recommended not to deviate far
|
|
// from the design frequency of 72 MHz.
|
|
//
|
|
// For the curious, there is a good amount of documentation in this file
|
|
// explaining how the parameters affect the output, but for a basic
|
|
// implementation you are not required to understand this.
|
|
// ============================================================================
|
|
|
|
#ifndef TIMDAC_CONFIG_REF1P0_H
|
|
#define TIMDAC_CONFIG_REF1P0_H
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// Helper macros
|
|
|
|
// Convert n*R*C into a number of timer counts
|
|
#ifdef __GNUC__
|
|
#define TIMDAC_NRC(n, r, c) ({ \
|
|
_Static_assert((n) * (r) * (c) * TIMDAC_TIMERFREQ_HZ <= 65535, \
|
|
"Time constant too high for 16-bit timer"); \
|
|
(unsigned)(((n) * (r) * (c) * TIMDAC_TIMERFREQ_HZ)) })
|
|
#else
|
|
#define TIMDAC_NRC(n, r, c) ((unsigned)((n) * (r) * (c) * TIMDAC_TIMERFREQ_HZ))
|
|
#endif
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// Circuit properties
|
|
|
|
#define TIMDAC_INT_CAP 10e-9
|
|
#define TIMDAC_OUT_CAP 100e-9
|
|
#define TIMDAC_DISCH_RES 1e+3
|
|
#define TIMDAC_OUT_RES 1e+3
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// TIMDAC control parameters
|
|
|
|
// Numerator of the tuning weight. This weight determines how quickly the DAC
|
|
// tuning is pulled towards the result of each tuning operation; adjustments
|
|
// are made by a factor of (TIMDAC_TUNE_WEIGHT / 65536). This parameter will
|
|
// determine how much tuning noise bleeds through into the output; the RMS
|
|
// noise can be measured using the TIMDAC_DIAGNOSTIC option, but should also
|
|
// be validated using a precise multimeter.
|
|
#define TIMDAC_TUNE_WEIGHT 64
|
|
|
|
// Tuning noise threshold. Above this amount of error in timer counts, the
|
|
// tuning is assumed to have drifted suddenly, and is immediately clobbered.
|
|
// Because the tuning algorithm can be noisy, this must be high enough to avoid
|
|
// spurious clobbers which can result in sudden shifts in output value. The
|
|
// clobber count can be measured using the TIMDAC_DIAGNOSTIC option.
|
|
#define TIMDAC_TUNE_NTHRESH 2048
|
|
|
|
// How many channels may be scanned before tuning. Beware that changing this
|
|
// will have ramifications for TIMDAC_TUNE_WEIGHT and TIMDAC_TUNE_NTHRESH.
|
|
#define TIMDAC_TUNE_INTERVAL 64
|
|
|
|
// Integrator discharge time. It is essential that all charge on the integrator
|
|
// be fully discharged before the next channel is emitted. This parameter can
|
|
// be validated by setting all channels to zero and measuring the output, then
|
|
// setting all channels except one to full-scale and ensuring that the channel
|
|
// that remains set to zero has not shifted.
|
|
//
|
|
// REV 1.1 TODO: Rev 1.1 is changing the recommended integrating cap type;
|
|
// recheck this afterward. It can probably go down.
|
|
#define TIMDAC_DISCHARGE_TIME TIMDAC_NRC(12, TIMDAC_DISCH_RES, TIMDAC_INT_CAP)
|
|
|
|
// Stabilization time. This is the time after the pulse finishes before we
|
|
// transfer the final ramp value to the holding capacitor. This time allows the
|
|
// integrator to settle. If too short, transient edge behavior could create
|
|
// offsets or ripple in the output. If too long, the integrator will integrate
|
|
// leakage current and create an offset error.
|
|
#define TIMDAC_STABILIZATION_TIME TIMDAC_NRC(50e-6, 1, 1)
|
|
|
|
// Fast transfer time in timer counts. This is the time for which the
|
|
// integrated ramp is sent to the output when doing fast scanning (no output
|
|
// has been changed significantly). It only needs to be fast enough to "top up"
|
|
// the output capacitor to account for any leakage that may have occurred
|
|
// during a cycle.
|
|
#define TIMDAC_FAST_TRANSFER_TIME TIMDAC_NRC(2, TIMDAC_OUT_RES, TIMDAC_OUT_CAP)
|
|
|
|
// Slow transfer time in timer counts. This is the time for which the
|
|
// integrated ramp is sent to the output when performing an output value
|
|
// change.
|
|
//
|
|
// REV 1.1 TODO: This is currently set to the maximum because dielectric
|
|
// absorption in the rev 1.0 design is extending the time necessary to set the
|
|
// output voltage. After changing to lower absorption capacitors, recheck.
|
|
#define TIMDAC_SLOW_TRANSFER_TIME 65535
|
|
|
|
// How much can an output change without triggering a slow transfer cycle.
|
|
#define TIMDAC_SLOW_DELTA 128
|
|
|
|
#endif // !defined(TIMDAC_CONFIG_REF1P0_H)
|