|
|
@@ -22,19 +22,21 @@ uint16_t send_adc, send_dac; |
|
|
|
|
|
|
|
uint16_t dac_cmd = ((uint32_t)DAC_MAX + DAC_MIN) / 2; |
|
|
|
|
|
|
|
/* 64 KHz */ |
|
|
|
void timer(void) |
|
|
|
#define TIMER_RATE 8000L |
|
|
|
void TISR_HANDLER(5) |
|
|
|
{ |
|
|
|
static int count = 0; |
|
|
|
uint16_t v; |
|
|
|
int32_t adjustment; |
|
|
|
int32_t newdac; |
|
|
|
|
|
|
|
timer_clear_txif(5); |
|
|
|
|
|
|
|
/* Get most recent sample from 12-bit ADC. */ |
|
|
|
v = adc_get(); |
|
|
|
|
|
|
|
/* Send data to PC at 8 KHz */ |
|
|
|
if (count++ >= 8) { |
|
|
|
if (count++ >= (TIMER_RATE / 8000)) { |
|
|
|
count = 0; |
|
|
|
|
|
|
|
/* Send most recent sample and old DAC value */ |
|
|
@@ -77,6 +79,8 @@ void run_debug(void) |
|
|
|
uint16_t dac = 32768; |
|
|
|
uart1_init(115200); |
|
|
|
|
|
|
|
uart1_put_string("Zoom NILM Debug\r\n"); |
|
|
|
|
|
|
|
while (1) { |
|
|
|
dac_write(dac); |
|
|
|
uart1_put_dec(dac); |
|
|
@@ -115,6 +119,10 @@ void run_debug(void) |
|
|
|
void run_normal(void) |
|
|
|
{ |
|
|
|
uart1_init(500000); |
|
|
|
// uart1_init(115200); |
|
|
|
// uart1_put_string("Zoom NILM Normal\r\n"); |
|
|
|
timer_setup_16bit(5, TIMER_RATE, 1); |
|
|
|
// uart1_put_string("Timer OK\r\n"); |
|
|
|
|
|
|
|
while(1) { |
|
|
|
if (send_data) { |
|
|
@@ -127,14 +135,17 @@ void run_normal(void) |
|
|
|
int main(void) |
|
|
|
{ |
|
|
|
config_init(); |
|
|
|
|
|
|
|
/* Pull PGD high internally. */ |
|
|
|
TRISCbits.TRISC13 = 1; |
|
|
|
CNPU1bits.CN1PUE = 1; |
|
|
|
|
|
|
|
adcext_init(); |
|
|
|
dac_init(); |
|
|
|
adc_init(); |
|
|
|
|
|
|
|
/* Pull PGD high internally. If it is externally tied |
|
|
|
to ground, run in special debug mode. */ |
|
|
|
TRISCbits.TRISC13 = 1; |
|
|
|
CNPU1bits.CN1PUE = 1; |
|
|
|
/* If PGD is externally tied to ground, run in debug mode. |
|
|
|
(Short ICD pins 3 and 4) */ |
|
|
|
if (PORTCbits.RC13 == 0) |
|
|
|
run_debug(); |
|
|
|
else |
|
|
|