CDEBUG = -g$(DEBUG)
CWARN = -Wall -Wstrict-prototypes
-CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wl,--relax -Wl,-u,vfprintf -lprintf_flt -lm
+CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wl,--relax -Wl,-u,vfscanf -lscanf_flt -Wl,-u,vfprintf -lprintf_flt -lm
#CEXTRA = -Wa,-adhlns=$(<:.c=.lst)
CFLAGS = $(CDEBUG) $(CDEFS) $(CINCS) -O$(OPT) $(CWARN) $(CSTANDARD) $(CEXTRA) $(CTUNING)
--- /dev/null
+
+## ADCuC
+
+### Protocol
+
+ # sending
+ > V1?\n
+ # returns
+ < A1 0.624\n
+ # The 1 denotes the ADC channel (1 .. 8)
+ # After the channel in the answer follows the voltage (float value).
+
+To calibrate a channel, type:
+
+ C 1 1.05
+ # to scale the channel #1 up by 5%
+
+On a brand new board, the channels need to be be initialized with
+
+ C 1 1.0
+ C 2 1.0
+ ...
+
+### Building and Flashing
+
+ make
+ # enter RESET mode of the chip (short RESET with GND)
+ sudo make program_bootloader
+
+### AVR Source Code Conventions
+
+* Indentation:
+ * No TABs, 2 spaces instead.
+ * Closing curly brackets should be indented too.
+
uint8_t rxbuf[7];
uint8_t txbuf[32];
+float calibration[8] = {1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0};
+
uint8_t conversion_active = 0;
uint8_t channel = 0;
rxbuf[rxcnt++] = buf;
}
if (buf == '\n' || buf == '\r') {
- if(rxcnt == 4) { //3 letter commands
- if (rxbuf[0] == 'V' && rxbuf[2] == '?') {
- channel = rxbuf[1]-49;
+ if(rxcnt == 4 && rxbuf[0] == 'V' && rxbuf[2] == '?') {
+ uint8_t chan = rxbuf[1]-48;
+ if (chan >= 1 && chan <= 8) {
+ channel = chan-1;
conversion_active = 1;
}
}
+ if (rxbuf[0] == 'C') {
+ float calib_value;
+ uint8_t chan;
+ sscanf(rxbuf, "C %d %f\n", &chan, &calib_value);
+ if (chan >= 1 && chan <= 8) {
+ calibration[chan-1] = calib_value;
+ eeprom_update_float((float*)(0x100+(chan-1)), calib_value);
+ int nbytes = sprintf(txbuf, "OK %1d %.3f\n", chan, calib_value);
+ usb_serial_write(txbuf, nbytes);
+ usb_serial_flush_output();
+ }
+ }
}
if (rxcnt >= 7 || buf == '\n' || buf == '\r') { rxcnt = 0; }
}
uint16_t val = (get_value_1 << 8) | get_value_2;
float result = val;
result = result / 8.0 / 1000.;
+ result *= calibration[channel];
send_answer(channel+1, result);
}
DDRE = 0b00000000;
//limit[3] |= eeprom_read_byte((uint8_t*)0x26);
+ for (int i = 0; i < 8; i++)
+ calibration[i] = eeprom_read_float((float*)(0x100+i));
//Timer0 at ~488 Hz overflow for ADC control and buttons
TCCR0B = 4 << CS00; //(1 << CS01) | (1 << CS00);