| 6 | Current Offset |
| 7 | Voltage V_out (RO) |
| 8 | Current C_out (NA) |
-| 9 | Sense GND (NA) |
+| 9 | Sense GND (RO) |
NA := not available
RO := read only
The DCDC MDC Converter Board get his operating voltage via MicroUSB and receives messages via the LANTelnetServerBoard with UART Baud rate 57600.
------------------------------------------------------------------------------------------------------------------------
-### Version 1.2, 2022-07-19
+### Version 1.2, 2022-08-23
--- /dev/null
+__author__ = "Artz, Ole"
+__email__ = "ole.artz@stud.uni-frankfurt.de"
+
+#strucutre: 192.168.8.63 2323 -X W -u 0 -G 0 -c 0 -R 0 -v 5
+#sys.arg number 1 2 3 4 5 6 7 8 9 10 11 12 13 14
+
+
+import socket
+import sys
+import argparse
+from time import sleep
+
+
+def parsing_func():
+ 'Recieve arguments as the command and create defaults for missing arguments'
+
+ parser = argparse.ArgumentParser(add_help=True)
+ parser.add_argument('-ip', type=str, metavar ='',default='192.168.8.68', help='IP address. (default: %(default)s)')
+ parser.add_argument('-port', type=str, metavar ='',default='2323', help='Port. (default: %(default)s)')
+ parser.add_argument('-x', '--command', type=str, metavar ='',default='R', help='command: W := write, R := read, S := scan. (default: %(default)s)')
+ parser.add_argument('-u', '--controllernumber', type=str, metavar ='', default='00', help='controllernumber: 00 up to 99. (default: %(default)s)')
+ parser.add_argument('-g', '--groupnumber', type=str, metavar ='',default='0', help='groupnumber: 0 up to 3, A := all. (default: %(default)s)')
+ parser.add_argument('-c', '--channelnumber', type=str, metavar ='',default='0', help='channelnumber: 0 or 1, A := all. (default: %(default)s)')
+ parser.add_argument('-r', '--register', type=str, metavar ='', default='0', help='register: 0 := DCDC on/off, 1 := Channel. (default: %(default)s)')
+ parser.add_argument('-v', '--value', type=str, metavar ='', default='0000', help='value: 0000 up to 9999. (default: %(default)s)')
+
+ args = parser.parse_args()
+
+ return args
+
+
+def connection(args, s):
+ 'Create the connection to the Server (Board)'
+
+ TCP_IP = str(args.ip) #192.168.8.63
+ TCP_PORT = int(args.port) #2323
+
+ print("Command to:", args.ip, args.port)
+ s.connect((TCP_IP, TCP_PORT))
+
+
+def message(args):
+ 'Create the correct data format XuuGcRvvvv from the recieve arguments'
+
+ sleeper = 0.01 #need between comands
+
+ controllernumber = str()
+ if len(controllernumber) == 1:
+ controllernumber = str(0 + args.controllernumber)
+ else:
+ controllernumber = args.controllernumber
+
+ value = str()
+ if len(args.value) == 1:
+ value = str('000' + args.value)
+ elif len(args.value) == 2:
+ value = str('00' + args.value)
+ elif len(args.value) == 3:
+ value = str('0' + args.value)
+ elif len(args.value) == 4:
+ value = args.value
+
+ s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ connection(args, s)
+
+ # for Write Powerboard general dcdc on/off
+
+
+ # for Write Controller general dcdc on/off
+ if (args.command == 'w' or args.command == 'W') and (args.groupnumber == 'a' or args.groupnumber == 'A') and args.register == '0':
+ commando = str('W' + controllernumber + '0' + args.channelnumber + args.register + value + "\n")
+ s.send(commando.encode())
+ sleep(sleeper)
+ print(commando)
+ commando = str('W' + controllernumber + '1' + args.channelnumber + args.register + value + "\n")
+ s.send(commando.encode())
+ sleep(sleeper)
+ print(commando)
+ commando = str('W' + controllernumber + '2' + args.channelnumber + args.register + value + "\n")
+ s.send(commando.encode())
+ sleep(sleeper)
+ print(commando)
+ commando = str('W' + controllernumber + '3' + args.channelnumber + args.register + value + "\n")
+ s.send(commando.encode())
+ sleep(sleeper)
+ print(commando)
+
+ # for Write group voltage adjustment registor
+ elif (args.command == 'w' or args.command == 'W') and (args.channelnumber == 'a' or args.channelnumber == 'A') and args.register == '1':
+ commando = str(args.command + controllernumber + args.groupnumber+ '0' + '1' + value + "\n")
+ s.send(commando.encode())
+ sleep(sleeper)
+ print(commando)
+ commando = str(args.command + controllernumber + args.groupnumber + '1' + '1' + value + "\n")
+ s.send(commando.encode())
+ sleep(sleeper)
+ print(commando)
+
+ else:
+ commando = str(args.command + controllernumber + args.groupnumber + args.channelnumber + args.register + value + "\n")
+# print("\nCommand:", args.command, "\nControllernumber:", controllernumber, "\nGroupnumber:", args.groupnumber, "\nChannelnumber:", args.channelnumber, "\nRegister:", args.register, "\nValue:", value)
+# print(args)
+# print("\n X", "uu", "G", "c", "R", "vvvv \n", args.command, controllernumber, args.groupnumber, args.channelnumber, args.register, value)
+ print(commando)
+
+ s.send(commando.encode())
+
+ BUFFER_SIZE = 1024
+ data = s.recv(BUFFER_SIZE)
+ s.close()
+ print(data.decode("ascii"))
+
+
+def main():
+ args = parsing_func()
+ message(args)
+
+
+if __name__ == '__main__':
+ main()
-# MDC DCDC Dummy Converter Board
+# MDC DCDC Converter Board
-This is the firmware for the dcdc_mdc_dummy Converter Board. It's a test board for the upcomming MDC DCDC Converter Board which serves as the power supply for the mdc layers/chambers.
+This is the firmware for the DCDC MDC Converter Board which serves as the power supply for the MDC layers/chambers.
------------------------------------------------------------------------------------------------------------------------
## Usage
-The dcdc_mdc_dummy Converter Board get his operating voltage via MicroUSB and receives messages via the LANTelnetServerBoard with UART Baud rate 57600.
+The DCDC MDC Converter Board get his operating voltage via MicroUSB and receives messages via the LANTelnetServerBoard with UART Baud rate 57600.
------------------------------------------------------------------------------------------------------------------------
-### Version 1.0, 2021-08-19
+### Version 1.1, 2022-05-30
#define SHIFT_EN_OUTPUT() PORTB &= ~(1 << PB7)
#define SHIFT_DIS_OUTPUT() PORTB |= (1 << PB7)
+// declaration of needed variables
+
uint16_t time;
uint8_t rxcnt = 0, txpoint = 0;
uint16_t GND;
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;
if (t <= 9) {
return t + 0x30;
return t - 10 + 0x61;
}
-uint8_t hex_to_int(uint8_t h) { // assumes valid number
+uint8_t hex_to_int(uint8_t h) {//assumes valid number
+ // convert hex value to integer
if (h < 0x40) return h - 0x30;
if (h < 0x50) return h - 0x41 + 10;
return h - 0x61 + 10;
}
-void sub1(uint8_t *c1, uint8_t *c2) {
- uint8_t b = hex_to_int(*c1) * 16 + hex_to_int(*c2);
- b -= 1;
- *c1 = nib_to_hex(b, 1);
- *c2 = nib_to_hex(b, 0);
-}
-
void send_answer_buf(uint8_t *b) { UCSR1B |= (1 << UDRIE1); }
+ // activate transmit interupt "ISR(USART1_UDRE_vect)"
void send_answer_hex(uint8_t *rxbuf, uint16_t v) {
+ // modeling the answer message in hex value
txbuf[0] = 'A';
txbuf[1] = rxbuf[1];
txbuf[2] = rxbuf[2];
send_answer_buf(txbuf);
}
+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);
+ b -= 1;
+ *c1 = nib_to_hex(b, 1);
+ *c2 = nib_to_hex(b, 0);
+}
+
void forward_msg(uint8_t i) {
+ // need for chain boards to send the command to next board
sub1(&rxbuf[1], &rxbuf[2]);
memcpy((uint8_t *)txbuf, (uint8_t *)rxbuf, i);
txbuf[i] = 0;
}
uint8_t is_my_address(uint8_t s) {
+ // need for chain boards and handle to communicate to the right board
if (ISMYADDR()) {
// rxbuf[2] -= '0'; // write number to buffer, instead of ascii.
return 1;
}
}
-// NPIC6C596A
void setVoltages(void) {
+ // need to change the voltage by dis/enable resistor with the shiftregister "NPIC6C596A"
cli();
STCP_LOW();
uint32_t mask = (uint32_t)0x80000000;
}
SHCP_LOW();
SHIFT_DATA_LOW();
- // Load to Ouput Register:
+ // Load to Output Register:
STCP_HIGH();
STCP_HIGH();
STCP_LOW();
}
void switchDCDC(uint8_t group, uint8_t val) {
+ // de/activate the dcdc itself
if (val == 0) {
shift_register &= ~((uint32_t)1 << (4 + group * 8)); // DCDC off
if (group == 0) {
}
void setDCDC(uint8_t group, uint8_t chan, uint8_t val) {
+ // enable resistor of the voltage devider to change the feedback line to control the dcdc voltage output
// DCDC CH0
if (chan == 0 && val <= 7) {
val = 7 - val;
*/
void getdata(uint8_t buf) {
- if (rxcnt != 0 || (buf == 'A' || buf == 'W' || buf == 'R')) {
+ // handle the incoming command and call the correct function
+ if (rxcnt != 0 || (buf == 'A' || buf = 'S' || buf == 'W' || buf == 'R')) {
rxbuf[rxcnt++] = buf;
}
if (buf == '\n' || buf == '\r') { // End of Command
- if (rxbuf[0] == 'A') {
- // answer
+
+ if (rxbuf[0] == 'A' && rxcnt == 11) {
+ // get answer from another MC and transmit it to the next
memcpy((uint8_t *)txbuf, (uint8_t *)rxbuf, 10);
txbuf[11] = 0;
send_answer_buf(txbuf);
- } else if (rxbuf[0] == 'S') { // Scann of chain, returns number of boards
+
+ } else if (rxbuf[0] == 'S') {
+ // Scan of chain, returns number of boards
txbuf[0] = 'S';
uint8_t length = rxcnt - 2; // Length of Counter
// read current counter value
txbuf[length + 2] = 0;
send_answer_buf(txbuf);
rxcnt = 0;
- } else if (rxcnt == 11 && is_my_address(10)) { // message is for this uC
+ } else if (rxcnt == 11 && is_my_address(10)) {
+ // message is for this uC
// } else if (is_my_address(10)) { //answer 0x00d1 works with this line
+
if (rxbuf[0] == 'W') {
// write
switch (hex_to_int(rxbuf[5])) {
if (hex_to_int(rxbuf[3]) == 0) {
V_out = (5 * adc[10]) / 2; // 2.5 (5/2) stepsize of adc
send_answer_hex(&rxbuf[0], V_out);
- }
+ }CSR1B |= (1 << UDRIE1); }
// DCDC 1
if (hex_to_int(rxbuf[3]) == 1) {
V_out = (5 * adc[7]) / 2;
ISR(ADC_vect) {
+ // interupt for reading adc and save the values
static uint8_t channel = 0;
adc[channel] = ADC;
}
ISR(USART1_RX_vect) {
+ // interupt for incoming command
uint8_t buf = UDR1;
if (isMaster == 0) {
getdata(buf);
}
ISR(USART1_UDRE_vect) {
+ // interupt for transmitting answer message
if (txbuf[txpoint] != 0)
UDR1 = txbuf[txpoint++];
if (txpoint > 11 || txbuf[txpoint] == 0) {
}
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
CLKPR = (1 << CLKPCE); // prescaler 2 = 8 MHz
CLKPR = (1 << CLKPS0); // prescaler 2
/*
* #################################### define parameters to fixed values
*/
-/*
+/* EEPROM Useage
* Address Value
- * 0x11 ADC measurment range
+ * 0x11 ADC measurement range
* 0x12 Unit
* 0x13, 0x14 Device Transformationfactor
* 0x21, 0x22 Voltage divider