+/*
+#####################################################
+# ### ### #
+# ### CODE for MDC DCDC Converter Board ### #
+# ### for remote configuration ### #
+# ### via Universal Ethernet Board ### #
+# ### with LANTelnetToSerial Code ### #
+# ### ### #
+# ### useing EEPROM to save settings ### #
+# ### ### #
+# ### author: O.Artz ### #
+# ### ### #
+# ### UPDATE 2022-07-19 ### #
+# ### ### #
+#####################################################
+*/
+
// #define F_CPU 8000000UL
+/*
+ * #################################### load libraries
+ */
#include <avr/eeprom.h>
#include <avr/interrupt.h>
#include <avr/io.h>
#include <usb_serial.h>
#include <util/delay.h>
-#define FIRMWARE_VERSION 0x001
-
/*
//ADC
// 0 Sense1 Vin
// PD6 LED1 (yellow)
// PD4 LED2 (red)
-//PB7 Output enable
+// PB7 Output enable
//shift register outputs (times 4) Output 0 on MSB, Output 3 on LSB side
// CTRL10 (MSB)
// CTRL01
// CTRL02
+
+// **Data format:** *XuuGcRvvvv*
+// X - command (write: W, read: R, answer: A etc.)
+// uu - Controllernumber (Hex value)
+// G - Groupnumber (to talk to all channels, that belong together, in one command.)
+// c - channelnumber in the group (Hex value)
+// R - register (Hex value)
+// vvvv - 16 Bit value
+//
+// All in all 10 characters
+//
+// close with a "\n"
+// e.g. "RF2012FE51\n"
+
// | Registers | description |
// |-----------|--------------------------------------------------------------|
// | 0 | DCDC ON/OFF |
// | 7 | Voltage V_out (RO) |
// | 8 | Current C_out (NA) |
// | 9 | Sense GND (NA) |
-
-// **Data format:** *XuuGcRvvvv*
-// **Data format:** *X000cRvvvv*
*/
+/*
+ * #################################### define parameters to fixed values
+ */
+#define FIRMWARE_VERSION 0x001
+
#define ISMYADDR() (rxbuf[1] == '0' && rxbuf[2] == '0')
#define LED1_ON() PORTD |= (1 << PD6)
#define SHIFT_EN_OUTPUT() PORTB &= ~(1 << PB7)
#define SHIFT_DIS_OUTPUT() PORTB |= (1 << PB7)
-// declaration of needed variables
+/*
+ * #################################### declaration of needed variables
+ */
uint16_t time;
uint16_t C_out;
uint16_t GND;
+/*
+ * #################################### converter
+ */
uint8_t nib_to_hex(uint16_t in, uint8_t nib) {
// convert integer or nibbles into hex value
uint8_t t = (in >> (nib * 4)) & 0xF;
return h - 0x61 + 10;
}
+/*
+ * #################################### communication functions
+ */
void send_answer_buf(uint8_t *b) { UCSR1B |= (1 << UDRIE1); }
// activate transmit interupt "ISR(USART1_UDRE_vect)"
send_answer_buf(txbuf);
}
+/*
+ * #################################### chaining functions
+ */
void sub1(uint8_t *c1, uint8_t *c2) {
// need for chain boards to count down the board number
uint8_t b = hex_to_int(*c1) * 16 + hex_to_int(*c2);
}
}
+/*
+ * #################################### setting functions
+ */
void setVoltages(void) {
// need to change the voltage by dis/enable resistor with the shiftregister "NPIC6C596A"
cli();
information |= (FIRMWARE_VERSION << 4);
}
-/*
-// Data: XuuGcRvvvv
-// Switch deactivated
-// X - command (write: W, read: R, answer: A etc.)
-// uu - Controllernumber (Hex value)
-// G - Groupnumber (to talk to all channels, that belong together,
-in one command.)
-// c - channelnumber in the group (Hex value)
-// R - register (Hex value)
-// vvvv - 16 Bit value
-//
-// All in all 10 characters
-// RF2012FE51
-//
-// close with a "\n"
-// e.g. "RF2012FE51\n"
-//
-//
-//
-// | Registers | description |
-// |-----------|--------------------------------------------------------------|
-// | 0 | DCDC ON/OFF |
-// | 1 | DCDC set voltage adjustment resistors |
-// | 2 | Voltage V_in (RO) |
-// | 3 | Current C_in (RO) |
-// | 4 | Temperature (RO) |
-// | 5 | [15:4] Firmware; [3:2] reserved; [1] Switch ; [0] LED (RO) |
-// | 6 | Current Offset |
-// | 7 | Voltage V_out (RO) |
-// | 8 | Current C_out (NA) |
-// | 9 | Sense GND (RO) |
-*/
+/*
+ * #################################### interupts
+ */
+ISR(ADC_vect) {
+ // interupt for reading adc and save the values
+ static uint8_t channel = 0;
+ adc[channel] = ADC;
+
+ if (channel == 1) channel = 4;
+ else if (channel == 7) channel = 13;
+ else if (channel == 13) channel = 0;
+ else channel++;
+
+ ADMUX &= 0xe0;
+ ADMUX |= (channel & 0xf);
+ if (channel == 13)
+ ADCSRB |= (1 << MUX5);
+ else
+ ADCSRB &= ~(1 << MUX5);
+
+ ADCSRA |= (1 << ADSC);
+}
+
+ISR(USART1_RX_vect) {
+ // interupt for incoming command
+ uint8_t buf = UDR1;
+ if (isMaster == 0) {
+ getdata(buf);
+ } else {
+ // usb_serial_putchar(buf);
+ }
+}
+
+ISR(USART1_UDRE_vect) {
+ // interupt for transmitting answer message
+ if (txbuf[txpoint] != 0)
+ UDR1 = txbuf[txpoint++];
+ if (txpoint > 11 || txbuf[txpoint] == 0) {
+ txpoint = 0;
+ UCSR1B &= ~(1 << UDRIE1); // deactivate Transmit
+ }
+}
+ISR(TIMER0_OVF_vect) {
+ // interupt for time, actual only need for watchdoc if programm crashed as reset function
+ time++;
+ asm volatile("wdr");
+}
+
+/*
+ * #################################### head functions
+ */
void getdata(uint8_t buf) {
// handle the incoming command and call the correct function
if (rxcnt != 0 || (buf == 'A' || buf == 'S' || buf == 'W' || buf == 'R')) {
}
-
-ISR(ADC_vect) {
- // interupt for reading adc and save the values
- static uint8_t channel = 0;
- adc[channel] = ADC;
-
- if (channel == 1) channel = 4;
- else if (channel == 7) channel = 13;
- else if (channel == 13) channel = 0;
- else channel++;
-
- ADMUX &= 0xe0;
- ADMUX |= (channel & 0xf);
- if (channel == 13)
- ADCSRB |= (1 << MUX5);
- else
- ADCSRB &= ~(1 << MUX5);
-
- ADCSRA |= (1 << ADSC);
-}
-
-ISR(USART1_RX_vect) {
- // interupt for incoming command
- uint8_t buf = UDR1;
- if (isMaster == 0) {
- getdata(buf);
- } else {
- // usb_serial_putchar(buf);
- }
-}
-
-ISR(USART1_UDRE_vect) {
- // interupt for transmitting answer message
- if (txbuf[txpoint] != 0)
- UDR1 = txbuf[txpoint++];
- if (txpoint > 11 || txbuf[txpoint] == 0) {
- txpoint = 0;
- UCSR1B &= ~(1 << UDRIE1); // deactivate Transmit
- }
-}
-
-ISR(TIMER0_OVF_vect) {
- // interupt for time, actual only need for watchdoc if programm crashed as reset function
- time++;
- asm volatile("wdr");
-}
-
__attribute__((naked)) void main(void) {
// initialize the board