|
- #include "config.h"
- #include "adc.h"
- #include "dac.h"
- #include "uart.h"
- #include "timer.h"
- #include <stdio.h>
- #include <math.h>
- #include "calibrate.h"
- #include "util.h"
- #include "led.h"
- #include "mode.h"
- #include "zoom.h"
-
- static uint16_t dac = 32768;
-
- void sweep(void)
- {
- int32_t d;
- int16_t a;
-
- /* sweep range */
- for (d = (int32_t)dac - 2000; d < (int32_t)dac + 2000; d++) {
- if (d < 0x0000) {
- uart1_put_string("0 0\r\n");
- continue;
- }
- if (d > 0xffff) {
- uart1_put_string("65535 0\r\n");
- continue;
- }
- dac_write(d);
- msleep(1);
- a = adc_get();
- uart1_put_dec(d);
- uart1_put(' ');
- uart1_put_dec(a);
- uart1_crlf();
- }
- }
-
- void run_debug(void)
- {
- int16_t adc;
- int32_t v;
- char buf[4];
- uart1_init(115200);
-
- led_pattern(0b10101010);
-
- uart1_put_string("Zoom NILM Debug\r\n");
-
- while (1) {
- dac_write(dac);
- uart1_put_hex16(dac);
- uart1_put(' ');
- uart1_put_dec(dac);
- uart1_put(' ');
- uart1_put(' ');
- adc = adc_get();
- uart1_put_hex16(adc);
- uart1_put(' ');
- uart1_put_dec(adc);
- uart1_crlf();
- switch (uart1_get()) {
-
- // small step
- case '[':
- dac--;
- break;
- case ']':
- dac++;
- break;
-
- // medium step
- case '-':
- dac -= 16;
- break;
- case '+':
- case '=':
- dac += 16;
- break;
-
- // big step
- case ',':
- case '<':
- dac -= 1024;
- break;
- case '.':
- case '>':
- dac += 1024;
- break;
-
- // set DAC to midpoint
- case '0':
- dac = 32768;
- break;
-
- // set DAC to specified hex value
- case 'v':
- case 'V':
- buf[0] = uart1_get();
- buf[1] = uart1_get();
- buf[2] = uart1_get();
- buf[3] = uart1_get();
- v = hex_to_u16(buf);
- if (v < 0)
- uart1_put_string("bad value\r\n");
- else
- dac = v;
- break;
-
- // maintain ADC input at zero
- case 'z':
- case 'Z':
- uart1_put_string("zeroing input...\r\n");
- while (!uart1_can_get())
- dac = seek(dac, 1024);
- uart1_get();
- break;
-
- // test seeking
- case '1':
- uart1_put_string("seek 512\r\n");
- dac = seek(dac, 512);
- break;
-
- case '2':
- uart1_put_string("seek 1536\r\n");
- dac = seek(dac, 1536);
- break;
-
- // run calibration
- case 'c':
- case 'C':
- uart1_put_string("calibrating...\r\n");
- dac = do_calibrate();
- uart1_put_string("new g_scale ");
- uart1_put_float(g_scale);
- uart1_crlf();
- break;
-
- // sweep DAC
- case 's':
- case 'S':
- uart1_put_string("sweep around ");
- uart1_put_dec(dac);
- uart1_crlf();
- sweep();
- break;
- }
- }
- }
-
|