Skip to content
Snippets Groups Projects
Commit fe853aa5 authored by Anders Blomdell's avatar Anders Blomdell
Browse files

Correct type error, update calibrator

parent 8c49bb10
Branches
No related tags found
No related merge requests found
......@@ -192,7 +192,7 @@ SIGNAL(TIMER1_COMPA_vect)
PORT_SPI |= (1<<DD_SS); // Chip deselect
union {
int32_t i;
uint32_t i;
unsigned char b[4];
} v;
uint8_t chan;
......@@ -204,10 +204,10 @@ SIGNAL(TIMER1_COMPA_vect)
adc.value[chan] = (v.i>>6);
}
static uint32_t conf_millivolt(uint32_t value)
static uint32_t conf_millivolt(int32_t value)
{
if (value < 0) {
return CONF_NEGATIVE_MILLIVOLT(value);
return CONF_NEGATIVE_MILLIVOLT(-value);
} else {
return CONF_POSITIVE_MILLIVOLT(value);
}
......@@ -271,30 +271,31 @@ int main()
cli(); // Global interrupt disable
if (readchannels == 0) {
// Process all old readchannels before updating
readchannels = serial_readchannels;
serial_readchannels = 0;
}
local_adc = adc;
config = serial_readconfig;
serial_readconfig = 0;
local_adc = adc;
sei(); // Global interrupt enable
if (readchannels & 0x01) {
serialio_putchannel(0, local_adc.value[0]);
serialio_putchannel(0, local_adc.value[0] & 0x3ffff);
readchannels &= ~0x01;
} else if (readchannels & 0x02) {
serialio_putchannel(1, local_adc.value[1]);
serialio_putchannel(1, local_adc.value[1] & 0x3ffff);
readchannels &= ~0x02;
} else if (readchannels & 0x04) {
serialio_putchannel(2, local_adc.value[2]);
serialio_putchannel(2, local_adc.value[2] & 0x3ffff);
readchannels &= ~0x04;
} else if (readchannels & 0x08) {
serialio_putchannel(3, local_adc.value[3]);
serialio_putchannel(3, local_adc.value[3] & 0x3ffff);
readchannels &= ~0x08;
}
if (i2c_idle()) {
cli();
dac8574_set_chan(&dac8574.a, calibration.channel[0].offset);
dac8574_set_chan(&dac8574.b, calibration.channel[0].offset);
dac8574_set_chan(&dac8574.b, calibration.channel[1].offset);
dac8574_set_chan(&dac8574.c, dac.value[0]);
dac8574_set_chan(&dac8574.d, dac.value[1]);
sei();
......@@ -316,8 +317,6 @@ int main()
CONF_ANALOG_IN(3, CONF_MAX(CONF_POSITIVE_MILLIVOLT(10000)));
CONF_ANALOG_OUT(0, CONF_RESOLUTION(16)); // Analog Out 0
//CONF_ANALOG_OUT(0, CONF_MIN(CONF_NEGATIVE_MILLIVOLT(10000)));
//CONF_ANALOG_OUT(0, CONF_MAX(CONF_POSITIVE_MILLIVOLT(10000)));
CONF_ANALOG_OUT(0, CONF_MIN(conf_millivolt(calibration.channel[0].min)));
CONF_ANALOG_OUT(0, CONF_MAX(conf_millivolt(calibration.channel[0].max)));
CONF_ANALOG_OUT(1, CONF_RESOLUTION(16)); // Analog Out 1
......
......@@ -119,6 +119,10 @@ class ChinaIO:
if c.bits != 18:
raise Exception('analogIn[%d] is not 18 bit (%d)' % (i, c.bits))
pass
for i,c in analogOut.items():
if c.bits != 16:
raise Exception('analogOut[%d] is not 16 bit (%d)' % (i, c.bits))
pass
# Set offset calibration to default value
# self.io.setchannel(31, (0x8000 << 8) | 0x00)
......@@ -133,7 +137,6 @@ class ChinaIO:
(-0.1, 0.1), (-0.1, 0.1) ],
N=500,
message='Ground all input pins'):
break
pass
# Connect AOut0 -> AIn0,AIn2 (+9V)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment