|
|
@@ -10,19 +10,15 @@ |
|
|
|
int send_data = 0; |
|
|
|
uint16_t send_adc, send_dac; |
|
|
|
|
|
|
|
/* Outside these thresholds, we step the DAC value */ |
|
|
|
#define ADC_MIN 0x0700 |
|
|
|
#define ADC_MAX 0x0900 |
|
|
|
#define ADC_BIGMIN 0x0500 |
|
|
|
#define ADC_BIGMAX 0x0b00 |
|
|
|
|
|
|
|
/* Max/min DAC output value */ |
|
|
|
/* DAC limits */ |
|
|
|
#define DAC_MIN 0x0000 |
|
|
|
#define DAC_MAX 0xffff |
|
|
|
|
|
|
|
/* A DAC step is this many counts */ |
|
|
|
#define DAC_STEP 0x0180 |
|
|
|
#define DAC_BIGSTEP 0x0400 |
|
|
|
/* A "step" in the DAC output at the resolution we want. */ |
|
|
|
#define DAC_STEP 0x0004 |
|
|
|
|
|
|
|
/* One DAC "step" is this many counts on ADC input */ |
|
|
|
#define ADC_DAC_SCALING (1.0 / 84.935) |
|
|
|
|
|
|
|
uint16_t dac_cmd = ((uint32_t)DAC_MAX + DAC_MIN) / 2; |
|
|
|
|
|
|
@@ -43,12 +39,12 @@ void slow_callback(void) |
|
|
|
send_dac = dac_cmd; |
|
|
|
send_data = 1; |
|
|
|
|
|
|
|
#undef EXPERIMENTAL |
|
|
|
#ifdef EXPERIMENTAL |
|
|
|
#define RECENTER |
|
|
|
#ifdef RECENTER |
|
|
|
/* Update DAC. Add whatever is necessary to cause the ADC |
|
|
|
to recenter at 0x0800 */ |
|
|
|
{ |
|
|
|
int32_t adjustment = (0x0800 - (int32_t)v) * (10 / 10.8); |
|
|
|
int32_t adjustment = ((int32_t) v - 0x0800) * ADC_DAC_SCALING; |
|
|
|
int32_t newdac = dac_cmd + adjustment; |
|
|
|
if (adjustment) { |
|
|
|
if (newdac < DAC_MIN) |
|
|
@@ -91,7 +87,7 @@ void send_to_pc(void) |
|
|
|
|
|
|
|
int main(void) |
|
|
|
{ |
|
|
|
int debug = 1; |
|
|
|
int debug = 0; |
|
|
|
|
|
|
|
config_init(); |
|
|
|
adcext_init(); |
|
|
|