Browse Source

Bugfixes & updates.

I think the 12-bit ADC can't drive the optoisolator, crap.


git-svn-id: https://bucket.mit.edu/svn/nilm/zoom@6914 ddd99763-3ecb-0310-9145-efcb8ce7c51f
tags/zoom-1.0
jim 15 years ago
parent
commit
7df0122961
3 changed files with 25 additions and 14 deletions
  1. +7
    -7
      firmware/adc.c
  2. +18
    -7
      firmware/zoom.c
  3. BIN
      firmware/zoom.mcw

+ 7
- 7
firmware/adc.c View File

@@ -26,15 +26,15 @@ uint16_t adc_get(void)
uint16_t v = 0;
int i;
LAT_CS = 0;
LAT_CS = IO_LOW;
for (i = 0; i < 16; i++) {
if (R_SDATA)
v |= 1;
v <<= 1;
LAT_SCLK = 0;
nop();
LAT_SCLK = 1;
if (R_SDATA == IO_HIGH)
v |= 1;
LAT_SCLK = IO_LOW;
nop(); nop(); nop();
LAT_SCLK = IO_HIGH;
}
LAT_CS = 1;
LAT_CS = IO_HIGH;
return v;
}

+ 18
- 7
firmware/zoom.c View File

@@ -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


BIN
firmware/zoom.mcw View File


Loading…
Cancel
Save