Browse Source

Calibration seems to work now with FAKE_BITS set.

git-svn-id: https://bucket.mit.edu/svn/nilm/zoom@8029 ddd99763-3ecb-0310-9145-efcb8ce7c51f
tags/zoom-1.0
jim 12 years ago
parent
commit
06e38991b1
4 changed files with 14 additions and 11 deletions
  1. +10
    -7
      firmware/calibrate.c
  2. +1
    -1
      firmware/calibrate.h
  3. +2
    -2
      firmware/dac.h
  4. +1
    -1
      firmware/mode_debug.c

+ 10
- 7
firmware/calibrate.c View File

@@ -7,12 +7,14 @@
#include "timer.h"
#include "uart.h"
#define DEBUG_CALIBRATION
float g_scale; /* delta(DAC) / delta(ADC) */
/* Initialize. Assume some relatively-safe scaling if no calibration is run */
void calibrate_init(void)
{
g_scale = 0.5 * (DAC_RANGE / 65536); /* 1 count at 16-bit DAC means 2 counts at ADC */
g_scale = (DAC_RANGE / 65536.0); /* 1 count at 16-bit DAC means 1 counts at ADC */
}
/* Given the current DAC and ADC values d1 and a1,
@@ -34,15 +36,15 @@ float calculate_scale(uint16_t d1, float a1, uint16_t d2, float a2)
float a = a2 - a1;
/* Correct for known errors */
d1 = dac_get_actual(d1);
d2 = dac_get_actual(d2);
// d1 = dac_get_actual(d1);
// d2 = dac_get_actual(d2);
if (a < 0.1 && a > -0.1)
scale = 1.0;
else {
scale = ((float)d2 - d1) / a;
if (scale < 0.05)
scale = 0.05;
if (scale < 0.01)
scale = 0.01;
if (scale > 20)
scale = 20;
}
@@ -69,6 +71,7 @@ uint16_t seek(uint16_t starting_dac, int16_t desired_adc)
{
/* give up if we're not making progress */
if (steps++ > SEEK_MAX_STEPS) {
// 2 flashes, delay, repeat
led_pattern(0b00101000);
break;
}
@@ -84,7 +87,7 @@ uint16_t seek(uint16_t starting_dac, int16_t desired_adc)
msleep(1);
adc = adc_get();
#if 0
#ifdef DEBUG_CALIBRATION
uart1_put_hex16(dac);
uart1_put(' ');
uart1_put_hex16(adc);
@@ -141,7 +144,7 @@ uint16_t do_calibrate(void)
/* Calculate scale */
g_scale = calculate_scale(x1, y1, x2, y2);
#if 0
#ifdef DEBUG_CALIBRATION
uart1_put_string("calibrate x1=");
uart1_put_dec(x1);
uart1_put_string(" y1=");


+ 1
- 1
firmware/calibrate.h View File

@@ -11,7 +11,7 @@
#define SEEK_MAX_STEPS 1000
#define SEEK_FUZZ_ADC 100
#define SEEK_FUZZ_DAC ((DAC_RANGE * 5) / 65536)
#define SEEK_FUZZ_DAC (1+((DAC_RANGE * 5) / 65536))
#define CALIBRATE_ADC_ZERO 1024
#define CALIBRATE_ADC_LOW 512


+ 2
- 2
firmware/dac.h View File

@@ -3,9 +3,9 @@
#include "config.h"
//#define FAKE_10_BIT
#define FAKE_BITS
#ifdef FAKE_10_BIT
#ifdef FAKE_BITS
/* fake compressed range with random lookup bits */
#define DAC_BITS 10
#define __dac_actual(x) (dac_lookup[(x)&1023])


+ 1
- 1
firmware/mode_debug.c View File

@@ -58,7 +58,7 @@ void run_debug(void)
dac_write(dac);
uart1_put_hex16(dac);
uart1_put(' ');
uart1_put_dec(dac);
uart1_put_dec(dac_get_actual(dac));
uart1_put(' ');
uart1_put(' ');
adc = adc_get();


Loading…
Cancel
Save