Browse Source

Cleanups for thesis inclusion

tags/zoom-1.0
Jim Paris 10 years ago
parent
commit
150732ee3c
12 changed files with 34 additions and 33 deletions
  1. +1
    -1
      firmware/adc.c
  2. +3
    -3
      firmware/adcext.c
  3. +3
    -2
      firmware/calibrate.c
  4. +2
    -2
      firmware/config.c
  5. +1
    -1
      firmware/led.c
  6. +3
    -4
      firmware/mode_debug.c
  7. +10
    -7
      firmware/mode_normal.c
  8. +5
    -4
      firmware/packet.c
  9. +2
    -2
      firmware/timer.c
  10. +3
    -3
      firmware/uart.c
  11. +1
    -2
      firmware/zoom.c
  12. +0
    -2
      firmware/zoom.h

+ 1
- 1
firmware/adc.c View File

@@ -38,7 +38,7 @@ int16_t adc_get(void)
LAT_CS = IO_HIGH;

/* Sign-extend the 12-bit value */
if (v & 0x0800)
if (v & 0x0800)
v |= 0xF000;
else
v &= ~0xF000;


+ 3
- 3
firmware/adcext.c View File

@@ -8,7 +8,7 @@
This means we can't have the hardware do SPI for us. */

/* External serial clock, 2-wire I/O -- tie /EXT low,
tie ADC SDI for rate selection, tie /CS low, use BUSY for
tie ADC SDI for rate selection, tie /CS low, use BUSY for
interrupt notification if desired */

#define TRIS_SDO TRISBbits.TRISB5
@@ -34,13 +34,13 @@ void adcext_init(void)
TRIS_SCK = 0;
LAT_SCS = IO_LOW;
TRIS_SCS = 0;
/* Startup delay CS down to SCK high t4 = 5000ns */
for (i = 0; i < 5000 / 25; i++)
wait_25ns();

/* We need to monitor BUSY, I think. With the 2-wire
interface, we never know if we start in the middle of
interface, we never know if we start in the middle of
a data output phase. For now, consider reading broken..
just return early. XXXX */
return;


+ 3
- 2
firmware/calibrate.c View File

@@ -14,7 +14,8 @@ float g_scale; /* delta(DAC) / delta(ADC) */
/* Initialize. Assume some relatively-safe scaling if no calibration is run */
void calibrate_init(void)
{
g_scale = (DAC_RANGE / 65536.0); /* 1 count at 16-bit DAC means 1 counts at ADC */
g_scale = (DAC_RANGE / 65536.0); /* 1 count at 16-bit DAC
* means 1 counts at ADC */
}

/* Given the current DAC and ADC values d1 and a1,
@@ -34,7 +35,7 @@ float calculate_scale(uint16_t d1, float a1, uint16_t d2, float a2)
{
float scale;
float a = a2 - a1;
/* Correct for known errors */
d1 = dac_get_actual_float(d1);
d2 = dac_get_actual_float(d2);


+ 2
- 2
firmware/config.c View File

@@ -11,12 +11,12 @@ void config_init(void)
AD1PCFGL = 0xffff;
AD1PCFGH = 0xffff;
AD2PCFGL = 0xffff;
/* Configure PLL to multiply from 8 -> 40 MHz */
PLLFBD = 38;
CLKDIVbits.PLLPRE = 0;
CLKDIVbits.PLLPOST = 0;
/* Switch to XTPLL clock */
__builtin_write_OSCCONH(0x03);
__builtin_write_OSCCONL(0x01);


+ 1
- 1
firmware/led.c View File

@@ -6,7 +6,7 @@ int16_t __led_pattern;

/* Debug LED */
void TISR_HANDLER(6)
{
{
timer_clear_txif(6);

if (__led_pattern == -1)


+ 3
- 4
firmware/mode_debug.c View File

@@ -9,14 +9,13 @@
#include "util.h"
#include "led.h"
#include "mode.h"
#include "zoom.h"

static uint16_t dac = DAC_MID;

void sweep(void)
{
int32_t d;
int16_t a;
int16_t a;

#define SWEEP ((DAC_HIGH - DAC_LOW) * (int32_t)2000 / 65535)

@@ -47,7 +46,7 @@ void run_debug(void)
int16_t adc;
int32_t v;
char buf[4];
uart1_init(115200);
uart1_init(115200);

led_pattern(0b10101010);

@@ -122,7 +121,7 @@ void run_debug(void)
dac = seek(dac, 1024);
uart1_get();
break;
// test seeking
case '1':
uart1_put_string("seek 512\r\n");


+ 10
- 7
firmware/mode_normal.c View File

@@ -10,7 +10,6 @@
#include "util.h"
#include "mode.h"
#include "led.h"
#include "zoom.h"
#include "packet.h"

int send_data = 0;
@@ -41,7 +40,7 @@ void TISR_HANDLER(5)
LATAbits.LATA9 = 1;
#endif
timer_clear_txif(5);
/* Get most recent sample from 12-bit ADC. */
v = adc_get();

@@ -51,20 +50,22 @@ void TISR_HANDLER(5)
/* Send data to PC */
if (++count >= (TIMER_RATE / PC_RATE)) {
count = 0;
/* Send most recent sample and old DAC value */
send_adc = v;
send_dac = dac_cmd;
send_data = 1;
}

#define WINDOW
#define WINDOW
#ifdef WINDOW
/* If ADC value is outside the window, step DAC */
if (v < ADC_WINDOW_MIN)
dac_cmd = adc_to_dac(dac_cmd, v, ADC_WINDOW_MIN_STEPTO, g_scale);
dac_cmd = adc_to_dac(dac_cmd, v, ADC_WINDOW_MIN_STEPTO,
g_scale);
else if (v > ADC_WINDOW_MAX)
dac_cmd = adc_to_dac(dac_cmd, v, ADC_WINDOW_MAX_STEPTO, g_scale);
dac_cmd = adc_to_dac(dac_cmd, v, ADC_WINDOW_MAX_STEPTO,
g_scale);
#else
dac_cmd = adc_to_dac(dac_cmd, v, 1024, g_scale);
#endif
@@ -113,7 +114,9 @@ void run_normal(void)
uint16_t a, d, o;
disable_int({
if (possibly_clamped) {
/* Mark a possible overflow in the output */
/* Mark a possible
* overflow in the
* output */
o = 1;
possibly_clamped = 0;
} else o = 0;


+ 5
- 4
firmware/packet.c View File

@@ -7,13 +7,13 @@ void packet_send_adc_dac(int16_t adc, uint16_t dac, int overflow)
{
char b[4];
/* Packet format for DAC/ADC values:
10100000 ffffAaaa aaaaaaaa Dddddddd dddddddd
10100000 ffffAaaa aaaaaaaa Dddddddd dddddddd

ffff = flags, default 0000
...1 = possible overflow
Aaaaaaaaaaaa = 12-bit ADC value (2s compliment signed)
Dddddddddddddddd = 16-bit DAC command (unsigned)
*/
*/

uart1_put(PACKET_ADC_DAC);

@@ -34,10 +34,11 @@ void packet_send_calibration(float scale)
/* Packet format for calibration data:
A1 xx xx xx xx

where xx xx xx xx = 32-bit floating point value, little endian IEEE 754 */
where xx xx xx xx = 32-bit floating point value, little
endian IEEE 754 */

uint8_t *b = (uint8_t *)&scale;
uart1_put(PACKET_CALIBRATION);
uart1_put(b[0]);
uart1_put(b[1]);


+ 2
- 2
firmware/timer.c View File

@@ -10,7 +10,7 @@ int timer_setup_16bit(int timer, uint32_t freq, int ie)
{
uint32_t period;
uint16_t prescale;
if (timer < 1 || timer > 9)
return -1;

@@ -63,7 +63,7 @@ case x: \
__timer_setup_case(9);
#undef __timer_setup_case
}
/* Enable interrupt if requested */
timer_clear_txif(timer);
switch (timer) {


+ 3
- 3
firmware/uart.c View File

@@ -5,7 +5,7 @@
void uart_init(int uart, int32_t rate)
{
int32_t brg;
brg = ((FCY + (8 * rate - 1)) / (16 * rate)) - 1;
if (brg < 1) brg = 1;
if (brg > 65535) brg = 65535;
@@ -54,12 +54,12 @@ uint8_t uart_get(int uart)
if (uart == 1) {
while (!U1STAbits.URXDA) continue;
data = U1RXREG;
if (U1STAbits.OERR)
if (U1STAbits.OERR)
U1STAbits.OERR = 0;
} else if (uart == 2) {
while (!U2STAbits.URXDA) continue;
data = U2RXREG;
if (U2STAbits.OERR)
if (U2STAbits.OERR)
U2STAbits.OERR = 0;
}
return data;


+ 1
- 2
firmware/zoom.c View File

@@ -7,7 +7,6 @@
#include "util.h"
#include "led.h"
#include "mode.h"
#include "zoom.h"
#include "calibrate.h"

int main(void)
@@ -16,7 +15,7 @@ int main(void)

config_init();
led_init();
led_on();
led_on();
calibrate_init();

/* debug output */


+ 0
- 2
firmware/zoom.h View File

@@ -1,6 +1,4 @@
#ifndef ZOOM_H
#define ZOOM_H

void degauss(void);

#endif

Loading…
Cancel
Save