diff --git a/firmware/led.c b/firmware/led.c index 5468538..4ea1e0d 100644 --- a/firmware/led.c +++ b/firmware/led.c @@ -5,4 +5,4 @@ void led_init(void) { TRISBbits.TRISB13 = 0; PORTBbits.RB13 = 1; -} \ No newline at end of file +} diff --git a/firmware/scaling.c b/firmware/scaling.c index c397657..7510ae9 100644 --- a/firmware/scaling.c +++ b/firmware/scaling.c @@ -7,7 +7,7 @@ uint16_t current_to_dac(float amps) float tmp; uint16_t dacc; - tmp = 32768 * (1 + amps / 20); + tmp = 536.0 / 1.0 * amps + 32524; if (tmp < 0) tmp = 0; if (tmp > 65535) @@ -17,10 +17,11 @@ uint16_t current_to_dac(float amps) return dacc; } +/* Convert the DAC output value to an effective current in the measuring loop */ float dac_to_current(uint16_t dacv) { float amps; - amps = dacv * (20.0 / 32768.0) - 20.0; + amps = ((float)dacv - 32524.0) * 1.0 / 536.0; return amps; } @@ -33,6 +34,6 @@ float adc12_to_current(int16_t picv) if (picv > 2047) picv = 2047; - amps = (1024.0 - picv) / 3522.6; + amps = (picv - 1024.0) / 404.0; return amps; } diff --git a/firmware/zoom.c b/firmware/zoom.c index add3eb2..37b5672 100644 --- a/firmware/zoom.c +++ b/firmware/zoom.c @@ -55,8 +55,14 @@ void TISR_HANDLER(5) /* Convert ADC value to current */ i = adc12_to_current(v); +#if 0 /* Adjust DAC to null this current to 0 */ dac_current -= i; +#else + /* If this current exceeds +-1A, cancel it out at the DAC */ + if (i < -1.0 || i > 1.0) + dac_current -= i; +#endif if (dac_current < dac_current_min) dac_current = dac_current_min; @@ -85,12 +91,15 @@ void send_to_pc(uint16_t adc, uint16_t dac) void degauss(void) { + return; +#if 0 dac_write(65535); /* max */ msleep(25); dac_write(0); /* min */ msleep(25); dac_write(32768); /* middle */ msleep(25); +#endif } void run_debug(void) @@ -214,6 +223,8 @@ int main(void) led_init(); led_on(); + /* debug */ + TRISAbits.TRISA9 = 0; /* Detect jumper on B10/B11 */ //TRISCbits.TRISC13 = 1; //CNPU1bits.CN1PUE = 1; @@ -232,9 +243,9 @@ int main(void) /* If PGD is externally tied to ground, use MODE_1 (Short ICD pins 3 and 4) */ // if (PORTCbits.RC13 == 0) - MODE_1(); +// MODE_1(); // else -// MODE_2(); + MODE_2(); for (;;) continue; diff --git a/firmware/zoom.mcw b/firmware/zoom.mcw index fe7ca1c..09254d6 100644 Binary files a/firmware/zoom.mcw and b/firmware/zoom.mcw differ