Browse Source

Timer improvements, degauss

git-svn-id: https://bucket.mit.edu/svn/nilm/zoom@7065 ddd99763-3ecb-0310-9145-efcb8ce7c51f
tags/zoom-1.0
jim 15 years ago
parent
commit
7e3e0f9ff1
3 changed files with 25 additions and 17 deletions
  1. +18
    -0
      firmware/timer.c
  2. +2
    -1
      firmware/timer.h
  3. +5
    -16
      firmware/zoom.c

+ 18
- 0
firmware/timer.c View File

@@ -80,3 +80,21 @@ case x: \
return 0;
}
/* sleep for between "ms" and "ms+1" milliseconds */
void msleep(int ms)
{
static int initialized = 0;
if (!initialized) {
timer_setup_16bit(1, 1000, 0);
initialized = 1;
}
/* Very basic, assumes timer1 is set up at 1 khz */
while (ms-- >= 0) {
IFS0bits.T1IF = 0;
while(IFS0bits.T1IF == 0)
continue;
}
}

+ 2
- 1
firmware/timer.h View File

@@ -26,6 +26,7 @@ int timer_setup_16bit(int timer, uint32_t freq, int ie);
if ((timer) == 9) IFS3bits.T9IF = 0; \
} while(0)
/* sleep for between "ms" and "ms+1" milliseconds */
void msleep(int ms);
#endif

+ 5
- 16
firmware/zoom.c View File

@@ -71,16 +71,6 @@ void TISR_HANDLER(6)
send_data = 1;
}

/* Very basic, assumes timer1 is set up at 1 khz */
void wait_msec(int ms)
{
while (ms-- >= 0) {
IFS0bits.T1IF = 0;
while(IFS0bits.T1IF == 0)
continue;
}
}

void send_to_pc(void)
{
/* Sent data format:
@@ -97,11 +87,11 @@ void send_to_pc(void)
void degauss(void)
{
dac_write(65535); /* max */
wait_msec(25);
msleep(25);
dac_write(0); /* min */
wait_msec(25);
msleep(25);
dac_write(32768); /* middle */
wait_msec(25);
msleep(25);
}

void run_debug(void)
@@ -194,14 +184,13 @@ int main(void)
TRISCbits.TRISC13 = 1;
CNPU1bits.CN1PUE = 1;

/* millisecond timer */
timer_setup_16bit(1, 1000, 0);

adcext_init();
dac_init();
dac_write(32768);
adc_init();

msleep(100);

degauss();

/* If PGD is externally tied to ground, run in debug mode.


Loading…
Cancel
Save