diff --git a/avrIOhelper/io-helper.h b/avrIOhelper/io-helper.h index 8504dbc..194b702 100644 --- a/avrIOhelper/io-helper.h +++ b/avrIOhelper/io-helper.h @@ -81,6 +81,8 @@ void ioHelperEdgeDetector(void); #define LED_PLC_OK BitPL5 #define LED_BUS_OK BitPL3 +#define LED_EXTR_ONOFF BitPL3 + #define LIFT_MOTOR_DIR BitPL6 //Inputs @@ -115,11 +117,15 @@ void ioHelperEdgeDetector(void); #define BTN_LIFT_UP BitPinD7 #define BTN_LIFT_DOWN BitPinG2 +#define BTN_EXTR_ON 8 +#define BTN_EXTR_OFF 9 + #define IN_ANLAGE_EIN_INV BitPinF7 #define IN_NOTAUS_ANLAGE_R BitPinK5 #define IN_NOTAUS_ANLAGE BitPinK4 #define IN_NOTAUS_SCHRANK BitPinK6 #define MOD_OUT_HEIZEN_LED 1 +#define MOD_OUT_EXTR_LED 6 #endif diff --git a/compile_flags.txt b/compile_flags.txt index 4e0c1cc..2561953 100644 --- a/compile_flags.txt +++ b/compile_flags.txt @@ -1,3 +1,4 @@ +--target=avr -D __AVR_ATmega2560__ -D diff --git a/gefran_gtf.c b/gefran_gtf.c new file mode 100644 index 0000000..f1b8a9e --- /dev/null +++ b/gefran_gtf.c @@ -0,0 +1,16 @@ +#include "modbus-master.h" +#include + +#define FIRMWARE_VERSION 120 + +uint16_t gtf_firmware_version(uint8_t address){ + uint16_t val = 0; + readReg(address, FIRMWARE_VERSION, 1); + int8_t res = wait_receive(1, &val, 250); + + if(!res) + return val; + else + return res; +} + diff --git a/gefran_gtf.h b/gefran_gtf.h new file mode 100644 index 0000000..1b1a1ab --- /dev/null +++ b/gefran_gtf.h @@ -0,0 +1,2 @@ + +uint16_t gtf_firmware_version(uint8_t address); diff --git a/kraftsensor.c b/kraftsensor.c index b105b5c..1633ceb 100644 --- a/kraftsensor.c +++ b/kraftsensor.c @@ -18,7 +18,7 @@ void do_kraftsensor(){ /* read 2 16bit values and merge to 32bit signed integer */ readReg(1,0,2); - if(wait_receive(2, m_data, 10)){ + if(wait_receive(2, m_data, 100)){ kraftsensor_valid = 0; printf("modbus error\n\r"); } diff --git a/main.c b/main.c index 6e25824..3394f36 100644 --- a/main.c +++ b/main.c @@ -2,6 +2,7 @@ #include #include // WatchDog #include +#include #include #include "Ethernet/socket.h" @@ -19,6 +20,7 @@ #include "modbus.h" #include "modbus-master.h" #include "modbus_io_slave.h" +#include "gefran_gtf.h" #include "util/delay.h" @@ -194,13 +196,14 @@ int main(){ ioHelperSetBit(outStates, BitPG5, 1); uint32_t timer_blink_outs = millis(); - uint32_t timer_send_uptime = millis(); - uint32_t timer_send_info = millis(); uint32_t timer_read_slave = millis(); +#ifdef PLC_MQTT_ENABLED + uint32_t timer_send_info = millis(); + uint32_t timer_send_uptime = millis(); +#endif //printf("anlage: %x\n\r", read_Input(IN_ANLAGE_EIN_INV, LEVEL)); - uint16_t tgl = 0; while(1) { wdt_reset(); // WDT reset at least every sec @@ -221,16 +224,26 @@ int main(){ #if PLC_MQTT_ENABLED char msg[64]; - sprintf(msg, "%d", kraftsensor_value); + sprintf(msg, "%ld", kraftsensor_value); mqtt_pub(&mqtt_client, "/Filamentanlage/01_Extruder/kraft", msg, strlen(msg)); #endif - modbus_io_set_Output(4, 0, TOGGLE); + //modbus_io_set_Output(4, 0, TOGGLE); + //printf("gefran: 0x%02X\n", gtf_firmware_version(1)); + //printf("gefran: 0x%02X\n", gtf_firmware_version(2)); + //printf("gefran: 0x%02X\n", gtf_firmware_version(3)); + //printf("gefran: 0x%02X\n", gtf_firmware_version(4)); + //printf("gefran: 0x%02X\n", gtf_firmware_version(5)); + //printf("gefran: 0x%02X\n", gtf_firmware_version(6)); + //printf("gefran: 0x%02X\n", gtf_firmware_version(7)); + //printf("gefran: 0x%02X\n", gtf_firmware_version(8)); + //printf("gefran: 0x%02X\n", gtf_firmware_version(9)); + //printf("gefran: 0x%02X\n", gtf_firmware_version(10)); + //printf("\n"); } - if(millis() - timer_read_slave > 100){ + if(millis() - timer_read_slave > 200){ timer_read_slave = millis(); - //readInputState(4, 200, 32); modbus_io_read(); if(modbus_io_read_Input(16, RISING)) @@ -238,8 +251,6 @@ int main(){ if(modbus_io_read_Input(17, RISING)) modbus_io_set_Output(4, 3, OFF); - - //printf("read inputs: 0x%02X 0x%02X 0x%02X 0x%02X\n", inp[3], inp[2], inp[1], inp[0]); } if(read_Input(BTN_HEIZEN_AN, RISING)){ @@ -251,14 +262,23 @@ int main(){ if(read_Input(BTN_LIFT_UP, LEVEL)){ set_Output(LIFT_MOTOR_DIR, 1); - TCCR3B |= _BV(CS31); + TCCR3B |= _BV(CS30); } else if(read_Input(BTN_LIFT_DOWN, LEVEL)){ set_Output(LIFT_MOTOR_DIR, 0); - TCCR3B |= _BV(CS31); + TCCR3B |= _BV(CS30); } else - TCCR3B &= ~_BV(CS31); + TCCR3B &= ~_BV(CS30); + + if(read_Input(BTN_EXTR_ON, RISING)){ + TCCR1B |= _BV(CS11); + modbus_io_set_Output(4, MOD_OUT_EXTR_LED, 1); + } + if(read_Input(BTN_EXTR_OFF, RISING)){ + TCCR1B &= ~_BV(CS11); + modbus_io_set_Output(4, MOD_OUT_EXTR_LED, 0); + } #if PLC_MQTT_ENABLED // send misc info @@ -279,14 +299,6 @@ int main(){ } #endif - //if(read_Input(IN_ANLAGE_EIN_INV, FALLING)){ - // printf("anlage ein\n\r"); - //} - // ioHelperSetBit(outStates, LED_GRN_NOTAUS_SCHRANK, 1); - //} - //else{ - // ioHelperSetBit(outStates, LED_GRN_NOTAUS_SCHRANK, 0); - //} do_notaus(); #if PLC_MQTT_ENABLED @@ -296,8 +308,7 @@ int main(){ ioHelperSetBit(outStates, LED_BUS_OK, 0); #endif ioHelperSetOuts(); -} -return 0; + } } // Timer0 @@ -313,16 +324,13 @@ void timer0_init(void) void timer1_init() { - TCCR3A |= (1<