|
|
@@ -24,7 +24,35 @@ float dac_current_max; |
|
|
|
|
|
|
|
#define TIMER_RATE 8000 /* how often to read the ADC and update DAC */ |
|
|
|
#define PC_RATE 8000 /* how often to send data to the PC */ |
|
|
|
#define DEBUG_BLINK_RATE 4 |
|
|
|
|
|
|
|
/* Debug LED */ |
|
|
|
void TISR_HANDLER(6) |
|
|
|
{ |
|
|
|
static int toggle = 0; |
|
|
|
timer_clear_txif(6); |
|
|
|
|
|
|
|
toggle = !toggle; |
|
|
|
if (toggle) |
|
|
|
led_on(); |
|
|
|
else |
|
|
|
led_off(); |
|
|
|
} |
|
|
|
|
|
|
|
/* Debug mode */ |
|
|
|
int debug_zero_adc = 0; |
|
|
|
void TISR_HANDLER(7) |
|
|
|
{ |
|
|
|
timer_clear_txif(7); |
|
|
|
|
|
|
|
if (debug_zero_adc) |
|
|
|
{ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/* Run mode */ |
|
|
|
void TISR_HANDLER(5) |
|
|
|
{ |
|
|
|
static int count = 0; |
|
|
@@ -110,6 +138,8 @@ void run_debug(void) |
|
|
|
char buf[4]; |
|
|
|
uart1_init(115200); |
|
|
|
|
|
|
|
timer_setup_16bit(6, DEBUG_BLINK_RATE, 1); |
|
|
|
|
|
|
|
uart1_put_string("Zoom NILM Debug\r\n"); |
|
|
|
|
|
|
|
while (1) { |
|
|
@@ -237,43 +267,34 @@ void run_normal(void) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/* This mode is used when the programmer is connected, |
|
|
|
or PGD is tied to ground (jumper between ICD pins 3 and 4) */ |
|
|
|
#define MODE_1 run_debug |
|
|
|
|
|
|
|
/* This mode is used when the programmer is not connected |
|
|
|
and PGD is left floating */ |
|
|
|
#define MODE_2 run_normal |
|
|
|
|
|
|
|
int main(void) |
|
|
|
{ |
|
|
|
int jumper; |
|
|
|
|
|
|
|
config_init(); |
|
|
|
led_init(); |
|
|
|
led_on(); |
|
|
|
|
|
|
|
led_on(); |
|
|
|
/* debug */ |
|
|
|
/* debug output */ |
|
|
|
TRISAbits.TRISA9 = 0; |
|
|
|
/* Detect jumper on B10/B11 */ |
|
|
|
//TRISCbits.TRISC13 = 1; |
|
|
|
//CNPU1bits.CN1PUE = 1; |
|
|
|
|
|
|
|
adcext_init(); |
|
|
|
dac_init(); |
|
|
|
dac_write(32768); |
|
|
|
adc_init(); |
|
|
|
|
|
|
|
led_off(); |
|
|
|
msleep(100); |
|
|
|
led_on(); |
|
|
|
|
|
|
|
degauss(); |
|
|
|
|
|
|
|
/* If PGD is externally tied to ground, use MODE_1 |
|
|
|
(Short ICD pins 3 and 4) */ |
|
|
|
// if (PORTCbits.RC13 == 0) |
|
|
|
// MODE_1(); |
|
|
|
// else |
|
|
|
MODE_2(); |
|
|
|
/* Detect jumper from B8 to GND */ |
|
|
|
TRISBbits.TRISB8 = 0; |
|
|
|
LATBbits.LATB8 = 1; |
|
|
|
nop(); nop(); nop(); |
|
|
|
jumper = (PORTBbits.RB8 == 0); |
|
|
|
TRISBbits.TRISB8 = 1; |
|
|
|
|
|
|
|
/* If jumper present, use MODE_1 */ |
|
|
|
if (jumper) |
|
|
|
run_debug(); |
|
|
|
else |
|
|
|
run_normal(); |
|
|
|
|
|
|
|
for (;;) |
|
|
|
continue; |
|
|
|