Browse Source

calibration test

git-svn-id: https://bucket.mit.edu/svn/nilm/zoom@5806 ddd99763-3ecb-0310-9145-efcb8ce7c51f
tags/zoom-1.0
jim 16 years ago
parent
commit
d341d1ef6b
7 changed files with 62 additions and 61 deletions
  1. +2
    -1
      firmware/adc.c
  2. +1
    -1
      firmware/adc.h
  3. +2
    -0
      firmware/config.h
  4. +1
    -1
      firmware/dac.c
  5. +1
    -1
      firmware/uart.c
  6. +45
    -51
      firmware/zoom.c
  7. +10
    -6
      firmware/zoom.mcp

+ 2
- 1
firmware/adc.c View File

@@ -89,7 +89,8 @@ uint32_t adc_read(void)
/* Convert a raw 32-bit value into a signed 32-bit result.
The return value is full int32 range but only the high
24 should be significant (low 3 will always be 0) */
24 should be significant: low 3 will always be 0,
and the next 5 will be sub-resolution (see datasheet). */
int32_t adc_convert(uint32_t raw)
{
int sigmsb = (raw >> 28) & 3;


+ 1
- 1
firmware/adc.h View File

@@ -10,7 +10,7 @@ void adc_init(void);
uint32_t adc_read(void);
/* Convert a raw 32-bit value into a signed result.
The return value range is -(2^23) to (2^23)-1 */
The return value range is -(2^31) to (2^31)-1 */
int32_t adc_convert(uint32_t raw);
/* Start a new conversion. If a conversion was already started


+ 2
- 0
firmware/config.h View File

@@ -9,6 +9,8 @@ typedef signed int int16_t;
typedef unsigned int uint16_t;
typedef signed long int int32_t;
typedef unsigned long int uint32_t;
typedef signed long long int64_t;
typedef unsigned long long uint64_t;

#define FCY 40000000



+ 1
- 1
firmware/dac.c View File

@@ -1,7 +1,7 @@
#include "config.h"
#include "dac.h"
/* Initialize DAC */
/* Initialize DAC (AD5542) */
void dac_init(void)
{
/* SPI2 */


+ 1
- 1
firmware/uart.c View File

@@ -105,7 +105,7 @@ void uart_put_dec(int uart, int32_t x)
uint32_t val;
uint32_t place = 1;

if (x > 0) {
if (x >= 0) {
val = x;
} else {
uart_put(uart, '-');


+ 45
- 51
firmware/zoom.c View File

@@ -2,68 +2,62 @@
#include "adc.h"
#include "dac.h"
#include "uart.h"
#include "timer.h"
#include <stdio.h>
#include <math.h>

#define TEST_LEN 128

uint32_t samples[TEST_LEN];
uint32_t mean;
uint32_t stdev;

/* Read TEST_LEN samples and compute mean & stdev. */
void test_adc(void)
{
uint32_t tmp = 0;
int i;

for (i = 0; i < TEST_LEN; i++) {
samples[i] = adc_read();
tmp += samples[i];
}

mean = tmp / TEST_LEN;

tmp = 0;
for (i = 0; i < TEST_LEN; i++)
tmp += (samples[i] - mean) * (samples[i] - mean);
stdev = sqrt(tmp);
}

int main(void)
{
uint32_t v;
char ch;
int32_t i;
int32_t j;
config_init();
uart1_init(115200);
tmr1_init();
tmr1_wait_ms(100);

adc_init();
dac_init();
uart1_put_string("ADC/DAC test\r\n");

for (;;) {
switch((ch = uart1_get())) {
case 'r':
uart1_put_string("read");
v = adc_read();
uart1_put_string(" 0x");
uart1_put_hex32(v);
v = adc_convert(v);
uart1_put_string(" 0x");
uart1_put_hex32(v);
uart1_put_string(" ");
uart1_put_dec(v);
uart1_put_string("\r\n");
break;
case 'c':
uart1_put_string("convert");
adc_start_conversion();
while (!adc_is_conversion_ready())
uart1_put('.');
uart1_put_string("done\r\n");
break;
case '1'...'9':
v = (ch - '1') * 0x2000L;
if (v > 65535) v = 65535;
uart1_put_string("write 0x");
uart1_put_hex16(v);
uart1_put_string("\r\n");
dac_write(v);
break;
case 't':
uart1_put_string("toggling, keypress to end\r\n");
while (!uart1_can_get()) {
dac_write(0x0000);
dac_write(0xFFFF);
}
uart1_get();
break;
case 's':
uart1_put_string("sweeps, keypress to end\r\n");
while (!uart1_can_get())
for (v = 0; v < 65536; v++)
dac_write(v);
uart1_get();
break;
default:
uart1_put_string("ADC: Read Convert\r\n");
uart1_put_string("DAC: 123456789 Toggle Sweep\r\n");
break;
top:
for (i = 0; i < 32768; i ++) {
dac_write(i);
tmr1_wait_ms(1);
for (j = 0; j < TEST_LEN; j++) {
uart1_put_dec(i);
uart1_put(' ');
uart1_put_dec(adc_convert(adc_read()));
uart1_put_string("\r\n");
}
}

uart1_put_string("-----\r\n");
goto top;
return 0;
}

+ 10
- 6
firmware/zoom.mcp View File

@@ -29,6 +29,8 @@ file_008=no
file_009=no
file_010=no
file_011=no
file_012=no
file_013=no
[FILE_INFO]
file_000=zoom.c
file_001=config.c
@@ -36,12 +38,14 @@ file_002=uart.c
file_003=util.c
file_004=dac.c
file_005=adc.c
file_006=config.h
file_007=uart.h
file_008=util.h
file_009=dac.h
file_010=adc.h
file_011=p33fj256gp710.gld
file_006=timer.c
file_007=config.h
file_008=uart.h
file_009=util.h
file_010=dac.h
file_011=adc.h
file_012=timer.h
file_013=p33fj256gp710.gld
[SUITE_INFO]
suite_guid={479DDE59-4D56-455E-855E-FFF59A3DB57E}
suite_state=


Loading…
Cancel
Save