Browse Source

window tracks properly now

git-svn-id: https://bucket.mit.edu/svn/nilm/zoom@6671 ddd99763-3ecb-0310-9145-efcb8ce7c51f
tags/zoom-1.0
jim 16 years ago
parent
commit
71b0e4f619
1 changed files with 27 additions and 19 deletions
  1. +27
    -19
      firmware/zoom.c

+ 27
- 19
firmware/zoom.c View File

@@ -17,35 +17,30 @@ uint16_t send_adc, send_dac;
/* A "step" in the DAC output at the resolution we want. */
#define DAC_STEP 0x0004

/* 1-bit change at DAC changes the ADC count by this much */
#define ADC_DAC_SCALING (21.234)
/* 1 bit at the ADC is this much change at the DAC */
#define ADC_DAC_SCALING (1.0/21.234)

uint16_t dac_cmd = ((uint32_t)DAC_MAX + DAC_MIN) / 2;

/* 128 KHz, after each ADC sample */
void fast_callback(void)
{
}
/* Run at 64 KHz */
static int count = 0;
if (count++ < 1) return;
count = 0;

/* 8 KHz, after DMA buffer filled */
void slow_callback(void)
{
/* Get most recent sample. */
uint16_t v = adc_dmabuf[adc_offset];

/* Send most recent sample to PC */
send_adc = v;
send_dac = dac_cmd;
send_data = 1;

#define RECENTER
#ifdef RECENTER
#if 1
/* Update DAC. Add whatever is necessary to cause the ADC
to recenter at 0x0800 */
to change by 150% towards the center of 0x0800
(intentional overshoot to increase slew rate capability) */
{
int32_t adjustment = ((int32_t) v - 0x0800) / ADC_DAC_SCALING;
int32_t adjustment = ((int32_t) v - 0x0800) * 1.50 * ADC_DAC_SCALING;
int32_t newdac = dac_cmd + adjustment;
if (adjustment) {
//if (adjustment) {
if (newdac < DAC_MIN)
dac_cmd = DAC_MIN;
else if (newdac > DAC_MAX)
@@ -53,9 +48,10 @@ void slow_callback(void)
else
dac_cmd = newdac;
dac_write(dac_cmd);
}
//}
}
#else
#endif
#if 0
/* Update DAC if necessary */
if (v < ADC_BIGMIN && dac_cmd < (DAC_MAX - DAC_BIGSTEP))
dac_cmd += DAC_BIGSTEP;
@@ -71,6 +67,18 @@ void slow_callback(void)
#endif
}

/* 8 KHz, after DMA buffer filled */
void slow_callback(void)
{
/* Get most recent sample. */
uint16_t v = adc_dmabuf[adc_offset];

/* Send most recent sample to PC */
send_adc = v;
send_dac = dac_cmd;
send_data = 1;
}

void debug_callback(void)
{
send_adc = adc_dmabuf[adc_offset];
@@ -140,7 +148,7 @@ int main(void)
} else {
uart1_init(500000);

//adc_adc_callback = fast_callback;
adc_adc_callback = fast_callback;
adc_dma_callback = slow_callback;

while(1) {


Loading…
Cancel
Save