add gefran and stuff
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
--target=avr
|
||||
-D
|
||||
__AVR_ATmega2560__
|
||||
-D
|
||||
|
||||
16
gefran_gtf.c
Normal file
16
gefran_gtf.c
Normal file
@@ -0,0 +1,16 @@
|
||||
#include "modbus-master.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
|
||||
2
gefran_gtf.h
Normal file
2
gefran_gtf.h
Normal file
@@ -0,0 +1,2 @@
|
||||
|
||||
uint16_t gtf_firmware_version(uint8_t address);
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
73
main.c
73
main.c
@@ -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
|
||||
@@ -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<<COM3B1);
|
||||
TCCR3B |= _BV(WGM33);
|
||||
TCCR1A |= (1<<COM1A1);
|
||||
TCCR1B |= _BV(WGM13);
|
||||
|
||||
ICR3 = 100;
|
||||
OCR3A = 50;
|
||||
ICR1 = 100;
|
||||
OCR1A = 50;
|
||||
|
||||
DDRE |= 1 << 4;
|
||||
TIMSK3 |= 1<<TOIE3;
|
||||
|
||||
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();
|
||||
|
||||
2
modbus.h
2
modbus.h
@@ -52,7 +52,7 @@ THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
/* define baudrate of modbus */
|
||||
#ifndef BAUD
|
||||
#define BAUD 38400L
|
||||
#define BAUD 19200L
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user