Browse Source

rip stuff out of mode_debug, replace it with stuff in calibrate

git-svn-id: https://bucket.mit.edu/svn/nilm/zoom@7692 ddd99763-3ecb-0310-9145-efcb8ce7c51f
tags/zoom-1.0
jim 15 years ago
parent
commit
4c6ed3cd06
3 changed files with 10 additions and 57 deletions
  1. +7
    -10
      firmware/calibrate.c
  2. +1
    -0
      firmware/calibrate.h
  3. +2
    -47
      firmware/mode_debug.c

+ 7
- 10
firmware/calibrate.c View File

@@ -41,7 +41,7 @@ uint16_t seek(uint16_t starting_dac, int16_t desired_adc)
uint16_t old_dac, dac;
int16_t old_adc, adc;
float scale = g_scale;
int bad = 0;
int steps = 0;
dac = starting_dac;
@@ -52,21 +52,18 @@ uint16_t seek(uint16_t starting_dac, int16_t desired_adc)
while (1)
{
/* give up if we're not making progress */
if (steps++ > SEEK_MAX_STEPS) {
led_pattern(0b00000001);
break;
}
old_dac = dac;
old_adc = adc;
/* jump to the desired value */
dac = adc_to_dac(old_dac, old_adc, desired_adc, scale);
/* if we're not making progress, give up */
if (dac == old_dac) {
bad++;
if (bad > 5) {
led_pattern(0b00000001);
break;
}
}
/* write it out */
dac_write(dac);
msleep(1);


+ 1
- 0
firmware/calibrate.h View File

@@ -9,6 +9,7 @@
#define OVERSAMPLE_COUNT 128
#define SEEK_MAX_STEPS 1000
#define SEEK_FUZZ_ADC 20
#define SEEK_FUZZ_DAC 5


+ 2
- 47
firmware/mode_debug.c View File

@@ -13,40 +13,6 @@
static uint16_t dac = 32768;
#define TIMER_RATE 8000
static int zero_adc = 0;
void TISR_HANDLER(7)
{
int16_t v;
timer_clear_txif(7);
if (zero_adc) {
v = adc_get();
(1024 - v)
dacval = dac;
dac_current = dac_to_current(dac);
v = adc_get();
i = adc12_to_current(v);
/* adjust by 50% of the estimated value, in case our calibration is wrong */
dac_current -= (i * 0.5);
if (dac_current < dac_current_min)
dac_current = dac_current_min;
if (dac_current > dac_current_max)
dac_current = dac_current_max;
dac = current_to_dac(dac_current);
dac_write(dac);
}
#endif
}
void sweep(void)
{
int32_t d;
@@ -79,9 +45,6 @@ void run_debug(void)
char buf[4];
uart1_init(115200);
timer_setup_16bit(7, TIMER_RATE, 1);
timer_set_priority(7, 6);
led_pattern(0b10101010);
uart1_put_string("Zoom NILM Debug\r\n");
@@ -132,14 +95,6 @@ void run_debug(void)
dac = 32768;
break;
// run degauss (currently a noop)
case 'd':
uart1_put_string("degauss...");
degauss();
uart1_crlf();
dac = 32768;
break;
// set DAC to specified hex value
case 'v':
case 'V':
@@ -158,9 +113,9 @@ void run_debug(void)
case 'z':
case 'Z':
uart1_put_string("zeroing input...\r\n");
zero_adc = 1;
while (!uart1_can_get())
dac = seek(dac, 1024);
uart1_get();
zero_adc = 0;
break;
// sweep DAC


Loading…
Cancel
Save