|
|
|
|
@ -2,6 +2,7 @@
|
|
|
|
|
#include <avr/interrupt.h>
|
|
|
|
|
#include <avr/wdt.h> // WatchDog
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
@ -297,7 +309,6 @@ int main(){
|
|
|
|
|
#endif
|
|
|
|
|
ioHelperSetOuts();
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Timer0
|
|
|
|
|
@ -313,16 +324,13 @@ void timer0_init(void)
|
|
|
|
|
|
|
|
|
|
void timer1_init()
|
|
|
|
|
{
|
|
|
|
|
TCCR3A |= (1<<COM3B1);
|
|
|
|
|
TCCR3B |= _BV(WGM33);
|
|
|
|
|
|
|
|
|
|
ICR3 = 100;
|
|
|
|
|
OCR3A = 50;
|
|
|
|
|
TCCR1A |= (1<<COM1A1);
|
|
|
|
|
TCCR1B |= _BV(WGM13);
|
|
|
|
|
|
|
|
|
|
DDRE |= 1 << 4;
|
|
|
|
|
TIMSK3 |= 1<<TOIE3;
|
|
|
|
|
ICR1 = 100;
|
|
|
|
|
OCR1A = 50;
|
|
|
|
|
|
|
|
|
|
TCCR3B |= _BV(CS31);
|
|
|
|
|
DDRB |= 1 << 5;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void timer3_init()
|
|
|
|
|
@ -330,8 +338,8 @@ void timer3_init()
|
|
|
|
|
TCCR3A |= (1<<COM3B1);
|
|
|
|
|
TCCR3B |= _BV(WGM33);
|
|
|
|
|
|
|
|
|
|
ICR3 = 100;
|
|
|
|
|
OCR3B = 50;
|
|
|
|
|
ICR3 = 60;
|
|
|
|
|
OCR3B = 30;
|
|
|
|
|
|
|
|
|
|
DDRE |= 1 << 4;
|
|
|
|
|
}
|
|
|
|
|
@ -352,6 +360,7 @@ static void avr_init(void)
|
|
|
|
|
wdt_reset(); // wdt reset ~ every <2000ms
|
|
|
|
|
|
|
|
|
|
timer0_init();// Timer0 millis engine init
|
|
|
|
|
timer1_init();
|
|
|
|
|
timer3_init();
|
|
|
|
|
DDRL |= 1<<6;
|
|
|
|
|
uart_init();
|
|
|
|
|
|