Browse Source

Tweak some build options, add -O1

Make PC output send 0x8000 if there was ever an ADC overflow or underflow.
(The ADC underflow check might be more strict than necessary).


git-svn-id: https://bucket.mit.edu/svn/nilm/zoom@7068 ddd99763-3ecb-0310-9145-efcb8ce7c51f
tags/zoom-1.0
jim 15 years ago
parent
commit
b4375aeab2
4 changed files with 39 additions and 10 deletions
  1. +1
    -0
      firmware/util.c
  2. +10
    -1
      firmware/util.h
  3. +27
    -8
      firmware/zoom.c
  4. +1
    -1
      firmware/zoom.mcp

+ 1
- 0
firmware/util.c View File

@@ -24,3 +24,4 @@ uint8_t from_hex(uint8_t ch)

const uint8_t hex[16]={'0','1','2','3','4','5','6','7',
'8','9','a','b','c','d','e','f'};


+ 10
- 1
firmware/util.h View File

@@ -10,5 +10,14 @@ extern const uint8_t hex[16];
/* Array length */
#define array_len(x) (sizeof(x)/sizeof(x[0]))

#endif
/* ISR disable/enable with saving of previous state */
#define __int_top() int __sr_save
#define __int_disable() __sr_save=SR; SRbits.IPL=7
#define __int_enable() SR=__sr_save
#define disable_int(x) do { \
__int_top(); \
__int_disable(); \
x; \
__int_enable(); } while(0)

#endif

+ 27
- 8
firmware/zoom.c View File

@@ -7,10 +7,12 @@
#include <stdio.h>
#include <math.h>
#include "scaling.h"
#include "util.h"

int send_data = 0;
uint16_t send_adc;
uint16_t send_dac;
int possible_overflow = 0;

#define DAC_MIN 0x0000
#define DAC_MAX 0xFFFF
@@ -19,7 +21,7 @@ float dac_current;
float dac_current_min;
float dac_current_max;

#define TIMER_RATE 10 /* how often to read the ADC and update DAC */
#define TIMER_RATE 8000 /* how often to read the ADC and update DAC */
#define PC_RATE 10 /* how often to send data to the PC */

void TISR_HANDLER(5)
@@ -36,6 +38,9 @@ void TISR_HANDLER(5)
/* Get most recent sample from 12-bit ADC. */
v = adc_get();

if (v < 0 || v >= 2047)
possible_overflow = 1;

/* Send data to PC at 1 Hz */
if (++count >= (TIMER_RATE / PC_RATE)) {
count = 0;
@@ -62,17 +67,17 @@ void TISR_HANDLER(5)
dac_write(dac_cmd);
}

void send_to_pc(void)
void send_to_pc(uint16_t adc, uint16_t dac)
{
/* Sent data format:
1Aaa aaaa 0aaa aaDd 0ddd dddd 0ddd dddd
Aaaaaaaaaaaa = 12-bit ADC value (2s compliment signed)
Dddddddddddddddd = 16-bit DAC command (unsigned)
*/
uart1_put(0x80 | ((send_adc & 0x0FE0) >> 5));
uart1_put(((send_adc & 0x001F) << 2) | ((send_dac & 0xC000) >> 14));
uart1_put((send_dac & 0x3F80) >> 7);
uart1_put((send_dac & 0x007F));
uart1_put(0x80 | ((adc & 0x0FE0) >> 5));
uart1_put(((adc & 0x001F) << 2) | ((dac & 0xC000) >> 14));
uart1_put((dac & 0x3F80) >> 7);
uart1_put((dac & 0x007F));
}

void degauss(void)
@@ -155,8 +160,22 @@ void run_normal(void)

while(1) {
if (send_data) {
send_to_pc();
send_data = 0;
/* There's data to send. Disable the ISR briefly
while we grab it */
uint16_t a, d;
disable_int({
if (possible_overflow) {
/* Mark a possible overflow in the output
by setting ADC to an unlikely value */
possible_overflow = 0;
a = 0x0800;
} else {
a = send_adc;
}
d = send_dac;
send_data = 0;
});
send_to_pc(a, d);
}
}
}


+ 1
- 1
firmware/zoom.mcp View File

@@ -59,7 +59,7 @@ suite_guid={479DDE59-4D56-455E-855E-FFF59A3DB57E}
suite_state=
[TOOL_SETTINGS]
TS{7D9C6ECE-785D-44CB-BA22-17BF2E119622}=-g -ahl="$(BINDIR_)$(INFILEBASE).lst"
TS{25AC22BD-2378-4FDB-BFB6-7345A15512D3}=-g -Wall -Wa,-ahl="$(BINDIR_)$(INFILEBASE).lst"
TS{25AC22BD-2378-4FDB-BFB6-7345A15512D3}=-g -Wall -O1 -Wa,-ahl="$(BINDIR_)$(INFILEBASE).lst"
TS{25AC22BD-2378-4FDB-BFB6-7345A15512D3}_alt=yes
TS{7DAC9A1D-4C45-45D6-B25A-D117C74E8F5A}=--heap=1024 -Map="$(BINDIR_)$(TARGETBASE).map" --report-mem -o"$(BINDIR_)$(TARGETBASE).$(TARGETSUFFIX)"
TS{509E5861-1E2A-483B-8B6B-CA8DB7F2DD78}=


Loading…
Cancel
Save