Compare commits
82 Commits
fca12c1546
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 24ef8ce70d | |||
| 701ae5501a | |||
| 4ba5a3c39f | |||
| 2f5f57546a | |||
| 3f662045e6 | |||
| 18d2ae2f3c | |||
| c62792a864 | |||
| 0b5dc619a6 | |||
| 21099092c0 | |||
| 93debb7dd6 | |||
| 393da679e0 | |||
| e938862cde | |||
| 560b4fbc4d | |||
| 012f133dbe | |||
| daadb91055 | |||
| 6fbc0d4c08 | |||
| 39f9c1691a | |||
| b37d685690 | |||
| 14850ae8e9 | |||
| e514d57ddf | |||
| dcf1531033 | |||
| 1ad6f56a9d | |||
| cf5cdfc79f | |||
| 59fa66e164 | |||
| 53ceb7a0ba | |||
| c861a8b58a | |||
| 1aa6b17065 | |||
| 1a8b4418a6 | |||
| f2fd5c52fa | |||
| 32ee1da8e8 | |||
| 5e9d3578a1 | |||
| 93f0ef3759 | |||
| 690f4b308a | |||
| b2721c0123 | |||
| 76f3fd1d5a | |||
| 721689c525 | |||
| c4181a27e2 | |||
| b88d9fb85c | |||
| 349962b454 | |||
| 836d2e3e6e | |||
| eb680bac89 | |||
| 22a8b37713 | |||
| 5a85471ca5 | |||
| 5ff3793991 | |||
| 6601ae39f9 | |||
| aa30d70cd6 | |||
| b2ef7d8240 | |||
| 76bca5f039 | |||
| 678d40709d | |||
| a33902424e | |||
| 93de6e725c | |||
| 1645f2c37c | |||
| 566b96c8b3 | |||
| c9b79e7339 | |||
| a103131163 | |||
| db6f03ef97 | |||
| 54572ac7f2 | |||
| f8f515dc59 | |||
| c8b985ccff | |||
| b21076ce2b | |||
| 56ff8260a1 | |||
| b842604f98 | |||
| 55ef5f2031 | |||
| e775792323 | |||
| 62cb87ffa0 | |||
| 08f9838b19 | |||
| 001d8da421 | |||
| e1defa6d00 | |||
| fa0562e4ea | |||
| 71dcd107a2 | |||
| e0baf7e58d | |||
| 2ce4da06e3 | |||
| 0e562b3cee | |||
| 79b6384063 | |||
| 408c586876 | |||
| ecd6f47400 | |||
| 7e97d54d0f | |||
| f590396e0c | |||
| 8a759f7f21 | |||
| 27cffc4971 | |||
| 696c9eac0e | |||
| 64751e00c7 |
@@ -117,7 +117,7 @@ char* MQTTFormat_toClientString(char* strbuf, int32_t strbuflen, uint8_t* buf, i
|
|||||||
int32_t index = 0;
|
int32_t index = 0;
|
||||||
int32_t rem_length = 0;
|
int32_t rem_length = 0;
|
||||||
MQTTHeader header = {0};
|
MQTTHeader header = {0};
|
||||||
int32_t strindex = 0;
|
//int32_t strindex = 0;
|
||||||
|
|
||||||
header.byte = buf[index++];
|
header.byte = buf[index++];
|
||||||
index += MQTTPacket_decodeBuf(&buf[index], &rem_length);
|
index += MQTTPacket_decodeBuf(&buf[index], &rem_length);
|
||||||
@@ -128,7 +128,7 @@ char* MQTTFormat_toClientString(char* strbuf, int32_t strbuflen, uint8_t* buf, i
|
|||||||
{
|
{
|
||||||
uint8_t sessionPresent, connack_rc;
|
uint8_t sessionPresent, connack_rc;
|
||||||
if (MQTTDeserialize_connack(&sessionPresent, &connack_rc, buf, buflen) == 1)
|
if (MQTTDeserialize_connack(&sessionPresent, &connack_rc, buf, buflen) == 1)
|
||||||
strindex = MQTTStringFormat_connack(strbuf, strbuflen, connack_rc, sessionPresent);
|
/*strindex = */MQTTStringFormat_connack(strbuf, strbuflen, connack_rc, sessionPresent);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PUBLISH:
|
case PUBLISH:
|
||||||
@@ -141,7 +141,7 @@ char* MQTTFormat_toClientString(char* strbuf, int32_t strbuflen, uint8_t* buf, i
|
|||||||
|
|
||||||
if (MQTTDeserialize_publish(&dup, &qos, &retained, &packetid, &topicName,
|
if (MQTTDeserialize_publish(&dup, &qos, &retained, &packetid, &topicName,
|
||||||
&payload, &payloadlen, buf, buflen) == 1)
|
&payload, &payloadlen, buf, buflen) == 1)
|
||||||
strindex = MQTTStringFormat_publish(strbuf, strbuflen, dup, qos, retained,
|
/*strindex = */MQTTStringFormat_publish(strbuf, strbuflen, dup, qos, retained,
|
||||||
packetid, topicName, payload, payloadlen);
|
packetid, topicName, payload, payloadlen);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -153,7 +153,7 @@ char* MQTTFormat_toClientString(char* strbuf, int32_t strbuflen, uint8_t* buf, i
|
|||||||
uint8_t packettype, dup;
|
uint8_t packettype, dup;
|
||||||
uint16_t packetid;
|
uint16_t packetid;
|
||||||
if (MQTTDeserialize_ack(&packettype, &dup, &packetid, buf, buflen) == 1)
|
if (MQTTDeserialize_ack(&packettype, &dup, &packetid, buf, buflen) == 1)
|
||||||
strindex = MQTTStringFormat_ack(strbuf, strbuflen, packettype, dup, packetid);
|
/*strindex = */MQTTStringFormat_ack(strbuf, strbuflen, packettype, dup, packetid);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SUBACK:
|
case SUBACK:
|
||||||
@@ -162,20 +162,20 @@ char* MQTTFormat_toClientString(char* strbuf, int32_t strbuflen, uint8_t* buf, i
|
|||||||
int32_t maxcount = 1, count = 0;
|
int32_t maxcount = 1, count = 0;
|
||||||
int32_t grantedQoSs[1];
|
int32_t grantedQoSs[1];
|
||||||
if (MQTTDeserialize_suback(&packetid, maxcount, &count, grantedQoSs, buf, buflen) == 1)
|
if (MQTTDeserialize_suback(&packetid, maxcount, &count, grantedQoSs, buf, buflen) == 1)
|
||||||
strindex = MQTTStringFormat_suback(strbuf, strbuflen, packetid, count, grantedQoSs);
|
/*strindex = */MQTTStringFormat_suback(strbuf, strbuflen, packetid, count, grantedQoSs);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case UNSUBACK:
|
case UNSUBACK:
|
||||||
{
|
{
|
||||||
uint16_t packetid;
|
uint16_t packetid;
|
||||||
if (MQTTDeserialize_unsuback(&packetid, buf, buflen) == 1)
|
if (MQTTDeserialize_unsuback(&packetid, buf, buflen) == 1)
|
||||||
strindex = MQTTStringFormat_ack(strbuf, strbuflen, UNSUBACK, 0, packetid);
|
/*strindex = */MQTTStringFormat_ack(strbuf, strbuflen, UNSUBACK, 0, packetid);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PINGREQ:
|
case PINGREQ:
|
||||||
case PINGRESP:
|
case PINGRESP:
|
||||||
case DISCONNECT:
|
case DISCONNECT:
|
||||||
strindex = snprintf(strbuf, strbuflen, "%s", MQTTPacket_names[header.bits.type]);
|
/*strindex = */snprintf(strbuf, strbuflen, "%s", MQTTPacket_names[header.bits.type]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,7 +188,7 @@ char* MQTTFormat_toServerString(char* strbuf, int32_t strbuflen, uint8_t* buf, i
|
|||||||
int32_t index = 0;
|
int32_t index = 0;
|
||||||
int32_t rem_length = 0;
|
int32_t rem_length = 0;
|
||||||
MQTTHeader header = {0};
|
MQTTHeader header = {0};
|
||||||
int32_t strindex = 0;
|
//int32_t strindex = 0;
|
||||||
|
|
||||||
header.byte = buf[index++];
|
header.byte = buf[index++];
|
||||||
index += MQTTPacket_decodeBuf(&buf[index], &rem_length);
|
index += MQTTPacket_decodeBuf(&buf[index], &rem_length);
|
||||||
@@ -201,7 +201,7 @@ char* MQTTFormat_toServerString(char* strbuf, int32_t strbuflen, uint8_t* buf, i
|
|||||||
int32_t rc;
|
int32_t rc;
|
||||||
|
|
||||||
if ((rc = MQTTDeserialize_connect(&data, buf, buflen)) == 1)
|
if ((rc = MQTTDeserialize_connect(&data, buf, buflen)) == 1)
|
||||||
strindex = MQTTStringFormat_connect(strbuf, strbuflen, &data);
|
/*strindex = */MQTTStringFormat_connect(strbuf, strbuflen, &data);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PUBLISH:
|
case PUBLISH:
|
||||||
@@ -214,7 +214,7 @@ char* MQTTFormat_toServerString(char* strbuf, int32_t strbuflen, uint8_t* buf, i
|
|||||||
|
|
||||||
if (MQTTDeserialize_publish(&dup, &qos, &retained, &packetid, &topicName,
|
if (MQTTDeserialize_publish(&dup, &qos, &retained, &packetid, &topicName,
|
||||||
&payload, &payloadlen, buf, buflen) == 1)
|
&payload, &payloadlen, buf, buflen) == 1)
|
||||||
strindex = MQTTStringFormat_publish(strbuf, strbuflen, dup, qos, retained,
|
/*strindex = */MQTTStringFormat_publish(strbuf, strbuflen, dup, qos, retained,
|
||||||
packetid, topicName, payload, payloadlen);
|
packetid, topicName, payload, payloadlen);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -227,7 +227,7 @@ char* MQTTFormat_toServerString(char* strbuf, int32_t strbuflen, uint8_t* buf, i
|
|||||||
uint16_t packetid;
|
uint16_t packetid;
|
||||||
|
|
||||||
if (MQTTDeserialize_ack(&packettype, &dup, &packetid, buf, buflen) == 1)
|
if (MQTTDeserialize_ack(&packettype, &dup, &packetid, buf, buflen) == 1)
|
||||||
strindex = MQTTStringFormat_ack(strbuf, strbuflen, packettype, dup, packetid);
|
/*strindex = */MQTTStringFormat_ack(strbuf, strbuflen, packettype, dup, packetid);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SUBSCRIBE:
|
case SUBSCRIBE:
|
||||||
@@ -240,7 +240,7 @@ char* MQTTFormat_toServerString(char* strbuf, int32_t strbuflen, uint8_t* buf, i
|
|||||||
|
|
||||||
if (MQTTDeserialize_subscribe(&dup, &packetid, maxcount, &count,
|
if (MQTTDeserialize_subscribe(&dup, &packetid, maxcount, &count,
|
||||||
topicFilters, requestedQoSs, buf, buflen) == 1)
|
topicFilters, requestedQoSs, buf, buflen) == 1)
|
||||||
strindex = MQTTStringFormat_subscribe(strbuf, strbuflen, dup, packetid, count, topicFilters, requestedQoSs);;
|
/*strindex = */MQTTStringFormat_subscribe(strbuf, strbuflen, dup, packetid, count, topicFilters, requestedQoSs);;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case UNSUBSCRIBE:
|
case UNSUBSCRIBE:
|
||||||
@@ -250,13 +250,13 @@ char* MQTTFormat_toServerString(char* strbuf, int32_t strbuflen, uint8_t* buf, i
|
|||||||
int32_t maxcount = 1, count = 0;
|
int32_t maxcount = 1, count = 0;
|
||||||
MQTTString topicFilters[1];
|
MQTTString topicFilters[1];
|
||||||
if (MQTTDeserialize_unsubscribe(&dup, &packetid, maxcount, &count, topicFilters, buf, buflen) == 1)
|
if (MQTTDeserialize_unsubscribe(&dup, &packetid, maxcount, &count, topicFilters, buf, buflen) == 1)
|
||||||
strindex = MQTTStringFormat_unsubscribe(strbuf, strbuflen, dup, packetid, count, topicFilters);
|
/*strindex = */MQTTStringFormat_unsubscribe(strbuf, strbuflen, dup, packetid, count, topicFilters);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PINGREQ:
|
case PINGREQ:
|
||||||
case PINGRESP:
|
case PINGRESP:
|
||||||
case DISCONNECT:
|
case DISCONNECT:
|
||||||
strindex = snprintf(strbuf, strbuflen, "%s", MQTTPacket_names[header.bits.type]);
|
/*strindex = */snprintf(strbuf, strbuflen, "%s", MQTTPacket_names[header.bits.type]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
9
Makefile
9
Makefile
@@ -4,16 +4,16 @@ FILES = $(SRCS:%.c=%) #main uart avrIOhelper/io-helper #uart#hier alle c-Datei
|
|||||||
MCU = atmega2560
|
MCU = atmega2560
|
||||||
PROGC = m2560
|
PROGC = m2560
|
||||||
CC = avr-gcc
|
CC = avr-gcc
|
||||||
#TOOL = atmelice_isp
|
TOOL = atmelice_isp
|
||||||
#TOOL = avrispmkii
|
#TOOL = avrispmkii
|
||||||
TOOL = usbasp-clone
|
#TOOL = usbasp-clone
|
||||||
|
|
||||||
BUILDDIR = Builds
|
BUILDDIR = Builds
|
||||||
|
|
||||||
DEFINES = -I . -IInternet/MQTT -I Internet/MQTT/MQTTPacket/src -I Ethernet/W5500 -I Ethernet -DF_CPU=16000000UL -D_WIZCHIP_=W5100
|
DEFINES = -I . -IInternet/MQTT -I Internet/MQTT/MQTTPacket/src -I Ethernet/W5500 -I Ethernet -DF_CPU=16000000UL -D_WIZCHIP_=W5100
|
||||||
|
|
||||||
CFLAGS =-mmcu=$(MCU) -O2 -Wall -Wpedantic $(DEFINES) -std=c99 -ffunction-sections -fdata-sections
|
CFLAGS =-mmcu=$(MCU) -O2 -Wall -Wpedantic $(DEFINES) -std=c99 -ffunction-sections -fdata-sections
|
||||||
LDFLAGS =-mmcu=$(MCU) -Wl,--gc-sections
|
LDFLAGS =-mmcu=$(MCU) -Wl,-u,vfprintf -lprintf_flt -lm
|
||||||
|
|
||||||
LDFILES = $(foreach FILE,$(FILES),$(BUILDDIR)/$(FILE).o)
|
LDFILES = $(foreach FILE,$(FILES),$(BUILDDIR)/$(FILE).o)
|
||||||
|
|
||||||
@@ -38,6 +38,9 @@ load: $(BUILDDIR)/$(TARGET).hex
|
|||||||
|
|
||||||
program: clean load
|
program: clean load
|
||||||
|
|
||||||
|
reset:
|
||||||
|
avrdude -p $(PROGC) -c $(TOOL)
|
||||||
|
|
||||||
size: $(BUILDDIR)/$(TARGET).elf
|
size: $(BUILDDIR)/$(TARGET).elf
|
||||||
avr-size -C --mcu=$(MCU) $(BUILDDIR)/$(TARGET).elf
|
avr-size -C --mcu=$(MCU) $(BUILDDIR)/$(TARGET).elf
|
||||||
|
|
||||||
|
|||||||
48
README.md
Normal file
48
README.md
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
## Network Config
|
||||||
|
|
||||||
|
|Parameter| Value
|
||||||
|
|---------|-------------
|
||||||
|
| IP Adr. | 192.168.5.1
|
||||||
|
| Subnet | 255.255.0.0
|
||||||
|
| MAC | 00-08-dc-ab-cd-f0
|
||||||
|
|
||||||
|
### MQTT
|
||||||
|
|
||||||
|
#### Connect to MQTT Host 192.168.5.2
|
||||||
|
|
||||||
|
##### Publish
|
||||||
|
|Topic |Values | Unit
|
||||||
|
|--------------------------------------------------------|------------ |-------
|
||||||
|
|/Filamentanlage/05_Abzug/state/abzug/speed | 10 - 1000 | mm/s
|
||||||
|
|/Filamentanlage/05_Abzug/state/abzug/onoff | True/False |
|
||||||
|
|/Filamentanlage/05_Abzug/state/kraft | 24-bit signed | mN
|
||||||
|
|/Filamentanlage/05_Abzug/state/speicher/pos | 32-bit unsigned (valid: 0~1000000) | Steps
|
||||||
|
|/Filamentanlage/04_Abzug/state/uptime | 32-bit unsigned | milliseconds
|
||||||
|
|
||||||
|
##### Subscribe
|
||||||
|
|
||||||
|
|Topic |Values | Unit
|
||||||
|
|--------------------------------------------------------|------------ |-------
|
||||||
|
|/Filamentanlage/05_Abzug/set/# | |
|
||||||
|
|
||||||
|
## Hardware usage
|
||||||
|
|
||||||
|
### Timers
|
||||||
|
|
||||||
|
|Timer| Type | Usage | Mode | used ISRs | Output connected
|
||||||
|
|-----|--------|-------------------------------|------------------------|----------------|------------------
|
||||||
|
| 0 | 8 bit | Millis Tick Timer (1kHz) | 2 (CTC) | COMPA | -
|
||||||
|
| 1 | 16 bit | Step Signal Translation Spule | 8 (PWM, Phase & Freq.) | OVF | OC1A / PB5
|
||||||
|
| 2 | 8 bit | Modbus Tick Timer (10kHz) | 2 (CTC) | COMPA | -
|
||||||
|
| 3 | 16 bit | Step Signal Abzugsrolle | 8 (PWM, Phase & Freq.) | - | OC3B / PE4
|
||||||
|
| 4 | 16 bit | Step Signal Taenzer | 8 (PWM, Phase & Freq.) | OVF, ~~COMPA~~ | OC4A / PH3
|
||||||
|
| 5 | 16 bit | Step Signal Rotation Spule | 8 (PWM, Phase & Freq.) | - | OC5C / PL5
|
||||||
|
|
||||||
|
### UART
|
||||||
|
|
||||||
|
|UART| Usage
|
||||||
|
|----|----------------------------------
|
||||||
|
| 0 | Debug Prints (connected to USB)
|
||||||
|
| 1 |
|
||||||
|
| 2 |
|
||||||
|
| 3 | Modbus (connected to MAX485)
|
||||||
59
abzug.c
59
abzug.c
@@ -1,5 +1,7 @@
|
|||||||
#include <avr/io.h>
|
#include <avr/io.h>
|
||||||
|
#include <stdint.h>
|
||||||
#include "avrIOhelper/io-helper.h"
|
#include "avrIOhelper/io-helper.h"
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
uint16_t abzug_speed = 100;
|
uint16_t abzug_speed = 100;
|
||||||
|
|
||||||
@@ -14,15 +16,18 @@ void timer3_init()
|
|||||||
DDRE |= 1 << 4;
|
DDRE |= 1 << 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t get_abzug_state(){
|
||||||
|
return TCCR3B & _BV(CS31);
|
||||||
|
}
|
||||||
|
|
||||||
void send_abzug_speed(void);
|
extern void send_settings(void);
|
||||||
void do_rolle(){
|
void do_abzug(){
|
||||||
|
|
||||||
if (read_Input(BTN_ABZUG_EIN, RISING)) {
|
if (read_Input(BTN_ABZUG_EIN, RISING)) {
|
||||||
TCCR3B |= _BV(CS31);
|
TCCR3B |= _BV(CS31);
|
||||||
set_Output(LED_ABZUG, ON);
|
set_Output(LED_ABZUG, ON);
|
||||||
#if PLC_MQTT_ENABLED
|
#if PLC_MQTT_ENABLED
|
||||||
send_abzug_speed();
|
send_settings();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,47 +35,47 @@ void do_rolle(){
|
|||||||
TCCR3B &= ~(_BV(CS31));
|
TCCR3B &= ~(_BV(CS31));
|
||||||
set_Output(LED_ABZUG, OFF);
|
set_Output(LED_ABZUG, OFF);
|
||||||
#if PLC_MQTT_ENABLED
|
#if PLC_MQTT_ENABLED
|
||||||
send_abzug_speed();
|
send_settings();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if (read_Input(BTN_ABZUG_PLUS, RISING)) {
|
if (read_Input(BTN_ABZUG_PLUS, RISING)) {
|
||||||
if(abzug_speed <= 900)
|
|
||||||
abzug_speed += 100;
|
|
||||||
else
|
|
||||||
abzug_speed = 1000;
|
|
||||||
#if PLC_MQTT_ENABLED
|
|
||||||
send_abzug_speed();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
if (read_Input(BTN_ABZUG_MINUS, RISING)) {
|
|
||||||
if(abzug_speed >= 110)
|
|
||||||
abzug_speed -= 100;
|
|
||||||
else
|
|
||||||
abzug_speed = 10;
|
|
||||||
#if PLC_MQTT_ENABLED
|
|
||||||
send_abzug_speed();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
if (read_Input(BTN_ABZUG_PLUS_FEIN, RISING)) {
|
|
||||||
if(abzug_speed <= 990)
|
if(abzug_speed <= 990)
|
||||||
abzug_speed += 10;
|
abzug_speed += 10;
|
||||||
else
|
else
|
||||||
abzug_speed = 1000;
|
abzug_speed = 1000;
|
||||||
#if PLC_MQTT_ENABLED
|
#if PLC_MQTT_ENABLED
|
||||||
send_abzug_speed();
|
send_settings();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if (read_Input(BTN_ABZUG_MINUS_FEIN, RISING)) {
|
if (read_Input(BTN_ABZUG_MINUS, RISING)) {
|
||||||
if(abzug_speed >= 20)
|
if(abzug_speed >= 20)
|
||||||
abzug_speed -= 10;
|
abzug_speed -= 10;
|
||||||
else
|
else
|
||||||
abzug_speed = 10;
|
abzug_speed = 10;
|
||||||
#if PLC_MQTT_ENABLED
|
#if PLC_MQTT_ENABLED
|
||||||
send_abzug_speed();
|
send_settings();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
if (read_Input(BTN_ABZUG_PLUS_FEIN, RISING)) {
|
||||||
|
if(abzug_speed <= 999)
|
||||||
|
abzug_speed += 1;
|
||||||
|
else
|
||||||
|
abzug_speed = 1000;
|
||||||
|
#if PLC_MQTT_ENABLED
|
||||||
|
send_settings();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
if (read_Input(BTN_ABZUG_MINUS_FEIN, RISING)) {
|
||||||
|
if(abzug_speed >= 11)
|
||||||
|
abzug_speed -= 1;
|
||||||
|
else
|
||||||
|
abzug_speed = 10;
|
||||||
|
#if PLC_MQTT_ENABLED
|
||||||
|
send_settings();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
6
abzug.h
6
abzug.h
@@ -1,8 +1,12 @@
|
|||||||
#ifndef _ABZUG_H
|
#ifndef _ABZUG_H
|
||||||
#define _ABZUG_H
|
#define _ABZUG_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
extern uint16_t abzug_speed;
|
extern uint16_t abzug_speed;
|
||||||
|
|
||||||
void do_rolle(void);
|
void do_abzug(void);
|
||||||
|
void timer3_init(void);
|
||||||
|
uint8_t get_abzug_state(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ void ioHelperEdgeDetector(void);
|
|||||||
// Status Lampen Schrank
|
// Status Lampen Schrank
|
||||||
#define LED_PLC_OK BitPL4
|
#define LED_PLC_OK BitPL4
|
||||||
#define LED_BUS_OK BitPL2
|
#define LED_BUS_OK BitPL2
|
||||||
#define LED_FEHLER BitPL5
|
#define LED_FEHLER BitPB7
|
||||||
|
|
||||||
// Ampel
|
// Ampel
|
||||||
#define AMPEL_ROT BitPL1
|
#define AMPEL_ROT BitPL1
|
||||||
@@ -93,6 +93,7 @@ void ioHelperEdgeDetector(void);
|
|||||||
// Schrittmotoren richtung
|
// Schrittmotoren richtung
|
||||||
|
|
||||||
#define MOTOR_TAENZER_DIR BitPH4
|
#define MOTOR_TAENZER_DIR BitPH4
|
||||||
|
#define MOTOR_TRANS_DIR BitPB6
|
||||||
|
|
||||||
#define LED_INIT BitPE3
|
#define LED_INIT BitPE3
|
||||||
#define LED_ABZUG BitPL6
|
#define LED_ABZUG BitPL6
|
||||||
@@ -141,8 +142,18 @@ void ioHelperEdgeDetector(void);
|
|||||||
#define BTN_ABZUG_PLUS_FEIN BitPinK6
|
#define BTN_ABZUG_PLUS_FEIN BitPinK6
|
||||||
#define BTN_ABZUG_MINUS_FEIN BitPinK7
|
#define BTN_ABZUG_MINUS_FEIN BitPinK7
|
||||||
|
|
||||||
#define BTN_INIT BitPinF4
|
#define BTN_WICKELN_EIN BitPinF5
|
||||||
|
#define BTN_WICKELN_AUS BitPinF6
|
||||||
#define BTN_TAENZER_START BitPinF7
|
#define BTN_TAENZER_START BitPinF7
|
||||||
|
#define BTN_SPULENWECHSEL BitPinK0
|
||||||
|
|
||||||
|
#define BTN_INIT BitPinF4
|
||||||
|
#define BTN_KRAFT_PLUS BitPinD7
|
||||||
|
#define BTN_KRAFT_MINUS BitPinG2
|
||||||
|
|
||||||
#define IN_TAENZER_HOME BitPinF0
|
#define IN_TAENZER_HOME BitPinF0
|
||||||
|
#define IN_SPULE_HOME BitPinF1
|
||||||
|
|
||||||
|
#define IN_BREMSE_STATE BitPinF2
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
#include <avr/io.h>
|
#include <avr/io.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <util/delay.h>
|
#include <util/delay.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <avr/interrupt.h>
|
#include <avr/interrupt.h>
|
||||||
@@ -10,6 +12,8 @@
|
|||||||
int32_t kraftsensor_value;
|
int32_t kraftsensor_value;
|
||||||
uint8_t kraftsensor_valid;
|
uint8_t kraftsensor_valid;
|
||||||
|
|
||||||
|
int32_t kraftsensor_zero_offset = 0/*197700*/;
|
||||||
|
|
||||||
void timer2_init()
|
void timer2_init()
|
||||||
{
|
{
|
||||||
TCCR2A = (1<<WGM21); //TIMER0 SET-UP: CTC MODE
|
TCCR2A = (1<<WGM21); //TIMER0 SET-UP: CTC MODE
|
||||||
@@ -27,30 +31,35 @@ void kraftsensor_init(){
|
|||||||
void do_kraftsensor(){
|
void do_kraftsensor(){
|
||||||
uint16_t m_data[4];
|
uint16_t m_data[4];
|
||||||
|
|
||||||
|
/* read 2 16bit values and merge to 32bit signed integer */
|
||||||
readReg(1,0,2);
|
readReg(1,0,2);
|
||||||
if(wait_receive(2, m_data, 10))
|
if(wait_receive(2, m_data, 10)){
|
||||||
kraftsensor_valid = 0;
|
kraftsensor_valid = 0;
|
||||||
|
printf("modbus error\n\r");
|
||||||
|
}
|
||||||
else{
|
else{
|
||||||
kraftsensor_valid = 1;
|
kraftsensor_valid = 1;
|
||||||
int32_t tmp = (uint32_t)m_data[0]<<16;
|
int32_t tmp = (uint32_t)m_data[1]<<16;
|
||||||
tmp |= m_data[1];
|
tmp |= m_data[0];
|
||||||
kraftsensor_value = ((tmp + 539363)*9.81)/177.380;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/* conversion magic to milliNewton */
|
||||||
|
kraftsensor_value = (((tmp /* + 539363*/)*9.81)/177.380)+kraftsensor_zero_offset;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t wait_receive(uint8_t len, uint16_t dest[], uint8_t timeout){
|
int8_t wait_receive(uint8_t len, uint16_t dest[], uint8_t timeout){
|
||||||
|
|
||||||
uint8_t breaker = timeout;
|
uint8_t breaker = timeout;
|
||||||
while(!receiveOkay && breaker) { //wait for client response, time out after 1s
|
while(!receiveOkay && breaker) { //wait for client response, time out after 1s
|
||||||
breaker--;
|
breaker--;
|
||||||
_delay_ms(10);
|
_delay_ms(1);
|
||||||
|
if(breaker==0)
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(receiveOkay) { //if this fails, there was either no response or a crc error
|
if(receiveOkay) { //if this fails, there was either no response or a crc error
|
||||||
if(rxbuffer[1]&0x80) { //client responded with an error code
|
if(rxbuffer[1]&0x80) { //client responded with an error code
|
||||||
//handle the error
|
//handle the error
|
||||||
printf("error\n\r");
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -63,6 +72,23 @@ uint8_t wait_receive(uint8_t len, uint16_t dest[], uint8_t timeout){
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int8_t wait_write(uint8_t timeout){
|
||||||
|
uint8_t breaker = timeout;
|
||||||
|
while(!receiveOkay && breaker) { //wait for client response, time out after 1s
|
||||||
|
breaker--;
|
||||||
|
_delay_ms(1);
|
||||||
|
if(breaker==0)
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(receiveOkay) { //if this fails, there was either no response or a crc error
|
||||||
|
if(rxbuffer[1]&0x80) { //client responded with an error code
|
||||||
|
return rxbuffer[1]&0x80;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void readReg(uint8_t slaveid, uint16_t address, uint8_t amount) {
|
void readReg(uint8_t slaveid, uint16_t address, uint8_t amount) {
|
||||||
_delay_ms(2);
|
_delay_ms(2);
|
||||||
rxbuffer[0]=slaveid;
|
rxbuffer[0]=slaveid;
|
||||||
@@ -88,5 +114,7 @@ void writeReg(uint8_t slaveid, uint16_t address, uint16_t value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ISR(TIMER2_COMPA_vect) { //this ISR is called 9765.625 times per second
|
ISR(TIMER2_COMPA_vect) { //this ISR is called 9765.625 times per second
|
||||||
|
//PORTH &= ~(1<<5);
|
||||||
modbusTickTimer();
|
modbusTickTimer();
|
||||||
|
//PORTH |= (1<<5);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,10 +8,12 @@
|
|||||||
extern int32_t kraftsensor_value;
|
extern int32_t kraftsensor_value;
|
||||||
extern uint8_t kraftsensor_valid;
|
extern uint8_t kraftsensor_valid;
|
||||||
|
|
||||||
|
extern int32_t kraftsensor_zero_offset;
|
||||||
|
|
||||||
void timer2_init();
|
void timer2_init();
|
||||||
void kraftsensor_init();
|
void kraftsensor_init();
|
||||||
void do_kraftsensor(void);
|
void do_kraftsensor(void);
|
||||||
uint8_t wait_receive(uint8_t len, uint16_t dest[], uint8_t timeout);
|
int8_t wait_receive(uint8_t len, uint16_t dest[], uint8_t timeout);
|
||||||
void readReg(uint8_t slaveid, uint16_t address, uint8_t amount);
|
void readReg(uint8_t slaveid, uint16_t address, uint8_t amount);
|
||||||
void writeReg(uint8_t slaveid, uint16_t address, uint16_t value);
|
void writeReg(uint8_t slaveid, uint16_t address, uint16_t value);
|
||||||
|
|
||||||
|
|||||||
131
main.c
131
main.c
@@ -1,11 +1,11 @@
|
|||||||
#include <avr/io.h>
|
#include <avr/io.h>
|
||||||
#include <avr/interrupt.h>
|
#include <avr/interrupt.h>
|
||||||
#include <avr/wdt.h> // WatchDog
|
#include <avr/wdt.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "common.h"
|
|
||||||
|
|
||||||
#include "Ethernet/socket.h"
|
#include "Ethernet/socket.h"
|
||||||
#include "Ethernet/wizchip_conf.h"
|
#include "Ethernet/wizchip_conf.h"
|
||||||
|
|
||||||
@@ -17,12 +17,13 @@
|
|||||||
#include "uart.h"
|
#include "uart.h"
|
||||||
#include "spi.h"
|
#include "spi.h"
|
||||||
#include "mqtt.h"
|
#include "mqtt.h"
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
#include "util/delay.h"
|
#include "notaus.h"
|
||||||
|
|
||||||
#include "kraftsensor.h"
|
#include "kraftsensor.h"
|
||||||
#include "taenzer.h"
|
#include "taenzer.h"
|
||||||
#include "abzug.h"
|
#include "abzug.h"
|
||||||
|
#include "spule.h"
|
||||||
|
|
||||||
Client mqtt_client;
|
Client mqtt_client;
|
||||||
|
|
||||||
@@ -43,8 +44,6 @@ void get_mcusr(void)
|
|||||||
|
|
||||||
//FUNC headers
|
//FUNC headers
|
||||||
static void avr_init(void);
|
static void avr_init(void);
|
||||||
void timer0_init(void);
|
|
||||||
void timer3_init(void);
|
|
||||||
void print_network_information(void);
|
void print_network_information(void);
|
||||||
|
|
||||||
void IO_LIBRARY_Init(void) {
|
void IO_LIBRARY_Init(void) {
|
||||||
@@ -67,7 +66,6 @@ static void avr_init()
|
|||||||
wdt_reset(); // wdt reset ~ every <2000ms
|
wdt_reset(); // wdt reset ~ every <2000ms
|
||||||
|
|
||||||
timer0_init();// Timer0 millis engine init
|
timer0_init();// Timer0 millis engine init
|
||||||
//timer3_init();
|
|
||||||
uart_init();
|
uart_init();
|
||||||
|
|
||||||
sei(); //re-enable global interrupts
|
sei(); //re-enable global interrupts
|
||||||
@@ -75,8 +73,37 @@ static void avr_init()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void send_abzug_speed(void){
|
// send processvalues that are constantly changing
|
||||||
char msg[4];
|
void send_values(void){
|
||||||
|
char msg[10];
|
||||||
|
|
||||||
|
/* Taenzer */
|
||||||
|
if(kraftsensor_valid)
|
||||||
|
ltoa(kraftsensor_value, msg, 10);
|
||||||
|
else
|
||||||
|
msg[0] = '0';
|
||||||
|
mqtt_pub(&mqtt_client, "/Filamentanlage/05_Abzug/state/taenzer/pv_kraft", msg, strlen(msg));
|
||||||
|
|
||||||
|
int8_t temp = taenzer_state.pos / 10000;
|
||||||
|
ltoa(temp, msg, 10);
|
||||||
|
mqtt_pub(&mqtt_client, "/Filamentanlage/05_Abzug/state/taenzer/pos", msg, strlen(msg));
|
||||||
|
|
||||||
|
itoa((250*60)/ICR5, msg, 10);
|
||||||
|
mqtt_pub(&mqtt_client, "/Filamentanlage/05_Abzug/state/spule/speed", msg, strlen(msg));
|
||||||
|
|
||||||
|
sprintf(msg, "%d", windings);
|
||||||
|
mqtt_pub(&mqtt_client, "/Filamentanlage/05_Abzug/state/spule/windings", msg, strlen(msg));
|
||||||
|
|
||||||
|
sprintf(msg, "%ld", spule_trans_pos);
|
||||||
|
mqtt_pub(&mqtt_client, "/Filamentanlage/05_Abzug/state/spule/trans_pos", msg, strlen(msg));
|
||||||
|
}
|
||||||
|
|
||||||
|
// send settings wich only change on buttion press
|
||||||
|
void send_settings(void){
|
||||||
|
//TODO only send on change or improve performance otherwise
|
||||||
|
char msg[10];
|
||||||
|
|
||||||
|
/* Abzug */
|
||||||
sprintf(msg, "%d", abzug_speed);
|
sprintf(msg, "%d", abzug_speed);
|
||||||
mqtt_pub(&mqtt_client, "/Filamentanlage/05_Abzug/state/abzug/speed", msg, strlen(msg));
|
mqtt_pub(&mqtt_client, "/Filamentanlage/05_Abzug/state/abzug/speed", msg, strlen(msg));
|
||||||
|
|
||||||
@@ -85,8 +112,25 @@ void send_abzug_speed(void){
|
|||||||
else
|
else
|
||||||
sprintf(msg, "False");
|
sprintf(msg, "False");
|
||||||
mqtt_pub(&mqtt_client, "/Filamentanlage/05_Abzug/state/abzug/onoff", msg, strlen(msg));
|
mqtt_pub(&mqtt_client, "/Filamentanlage/05_Abzug/state/abzug/onoff", msg, strlen(msg));
|
||||||
|
|
||||||
|
/* Taenzer */
|
||||||
|
itoa(taenzer_state.force_setpoint, msg, 10);
|
||||||
|
mqtt_pub(&mqtt_client, "/Filamentanlage/05_Abzug/state/taenzer/sp_kraft", msg, strlen(msg));
|
||||||
|
|
||||||
|
/* Spule */
|
||||||
|
if(TCCR5B & (1<<CS31))
|
||||||
|
sprintf(msg, "True");
|
||||||
|
else
|
||||||
|
sprintf(msg, "False");
|
||||||
|
mqtt_pub(&mqtt_client, "/Filamentanlage/05_Abzug/state/spule/onoff", msg, strlen(msg));
|
||||||
|
|
||||||
|
///* Uptime */
|
||||||
|
//sprintf(msg, "%ld", millis()/1000);
|
||||||
|
//mqtt_pub(&mqtt_client, "/Filamentanlage/05_Abzug/state/uptime", msg, strlen(msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// INIT MCU
|
// INIT MCU
|
||||||
@@ -95,13 +139,17 @@ int main()
|
|||||||
kraftsensor_init();
|
kraftsensor_init();
|
||||||
|
|
||||||
printf("moin!\n\r");
|
printf("moin!\n\r");
|
||||||
timer3_init();
|
|
||||||
timer4_init();
|
set_Output(LED_FEHLER, ON);
|
||||||
|
|
||||||
|
timer1_init(); //translation
|
||||||
|
timer3_init(); //abzug
|
||||||
|
timer4_init(); //taenzer
|
||||||
|
timer5_init(); //spule
|
||||||
|
|
||||||
ioHelperInitBuffer();
|
ioHelperInitBuffer();
|
||||||
ioHelperIoConf();
|
ioHelperIoConf();
|
||||||
|
|
||||||
|
|
||||||
//Wizchip WIZ5500 Ethernet initialize
|
//Wizchip WIZ5500 Ethernet initialize
|
||||||
IO_LIBRARY_Init(); //After that ping must working
|
IO_LIBRARY_Init(); //After that ping must working
|
||||||
print_network_information();
|
print_network_information();
|
||||||
@@ -123,8 +171,8 @@ int main()
|
|||||||
MQTTPacket_connectData data = MQTTPacket_connectData_initializer;
|
MQTTPacket_connectData data = MQTTPacket_connectData_initializer;
|
||||||
data.willFlag = 0;
|
data.willFlag = 0;
|
||||||
data.MQTTVersion = 4;//3;
|
data.MQTTVersion = 4;//3;
|
||||||
data.clientID.cstring = (char*)"controllino";
|
data.clientID.cstring = (char*)"controllino_aufspuleinheit";
|
||||||
data.username.cstring = (char*)"Messmodul";
|
data.username.cstring = (char*)"Aufspuleinheit";
|
||||||
data.password.cstring = (char*)"\0";
|
data.password.cstring = (char*)"\0";
|
||||||
data.keepAliveInterval = 10;
|
data.keepAliveInterval = 10;
|
||||||
data.cleansession = 1;
|
data.cleansession = 1;
|
||||||
@@ -139,28 +187,29 @@ int main()
|
|||||||
while(1); //Reboot the board
|
while(1); //Reboot the board
|
||||||
}
|
}
|
||||||
|
|
||||||
char SubString[] = "/Filamentanlage/04_Messmodul/set/#";
|
char SubString[] = "/Filamentanlage/05_Abzug/set/#";
|
||||||
mqtt_rc = MQTTSubscribe(&mqtt_client, SubString, QOS0, messageArrived);
|
mqtt_rc = MQTTSubscribe(&mqtt_client, SubString, QOS0, messageArrived);
|
||||||
printf("Subscribed (%s) %ld\r\n", SubString, mqtt_rc);
|
printf("Subscribed (%s) %ld\r\n", SubString, mqtt_rc);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ioHelperSetBit(outStates, RELAY_INTERLOCK, 1);
|
ioHelperSetBit(outStates, RELAY_INTERLOCK, 1);
|
||||||
|
|
||||||
ioHelperSetBit(outStatesBlinking, LED_PLC_OK, 1);
|
ioHelperSetBit(outStatesBlinking, LED_PLC_OK, 1);
|
||||||
|
|
||||||
uint32_t timer_blink_outs = millis();
|
uint32_t timer_blink_outs = millis();
|
||||||
uint32_t timer_send_uptime = millis();
|
uint32_t timer_send_info = millis();
|
||||||
uint32_t timer_modbus_poll = millis();
|
uint32_t timer_modbus_poll = millis();
|
||||||
|
|
||||||
while(1)
|
set_Output(LED_FEHLER, OFF);
|
||||||
{
|
|
||||||
wdt_reset(); // WDT reset at least every sec
|
set_Output(BitPH5, ON); //DEBUG
|
||||||
|
|
||||||
#if PLC_MQTT_ENABLED
|
#if PLC_MQTT_ENABLED
|
||||||
if(millis() < 10)
|
send_settings();
|
||||||
send_abzug_speed();
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
while(1){
|
||||||
|
wdt_reset(); // WDT reset at least every sec
|
||||||
|
|
||||||
ioHelperReadPins();
|
ioHelperReadPins();
|
||||||
ioHelperDebounce();
|
ioHelperDebounce();
|
||||||
ioHelperEdgeDetector();
|
ioHelperEdgeDetector();
|
||||||
@@ -172,41 +221,35 @@ int main()
|
|||||||
outStates[2] ^= outStatesBlinking[2];
|
outStates[2] ^= outStatesBlinking[2];
|
||||||
outStates[3] ^= outStatesBlinking[3];
|
outStates[3] ^= outStatesBlinking[3];
|
||||||
timer_blink_outs = millis();
|
timer_blink_outs = millis();
|
||||||
|
//printf("icr5: %u\n", ICR5);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(millis() - timer_modbus_poll > 20){
|
||||||
|
do_kraftsensor(); // 8ms !!!
|
||||||
|
timer_modbus_poll += 20;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if PLC_MQTT_ENABLED
|
#if PLC_MQTT_ENABLED
|
||||||
// send misc info
|
// send misc info
|
||||||
//if(millis() - timer_send_uptime > 5000){
|
if(millis() - timer_send_info > 200){
|
||||||
// timer_send_uptime += 5000;
|
timer_send_info += 200;
|
||||||
// char msg[64];
|
send_values(); // 10ms
|
||||||
// sprintf(msg, "%ld", millis()/1000);
|
//send_info(); // 27ms every 200ms
|
||||||
// mqtt_pub(&mqtt_client, "/Filamentanlage/04_Messmodul/state/uptime", msg, strlen(msg));
|
|
||||||
//}
|
|
||||||
#endif
|
|
||||||
if(millis() - timer_modbus_poll > 200){
|
|
||||||
timer_modbus_poll += 200;
|
|
||||||
do_kraftsensor();
|
|
||||||
#if PLC_MQTT_ENABLED
|
|
||||||
send_abzug_speed();
|
|
||||||
char msg[10];
|
|
||||||
ltoa(kraftsensor_value, msg, 10);
|
|
||||||
mqtt_pub(&mqtt_client, "/Filamentanlage/05_Abzug/state/kraft", msg, strlen(msg));
|
|
||||||
ltoa(taenzer_state.pos, msg, 10);
|
|
||||||
mqtt_pub(&mqtt_client, "/Filamentanlage/05_Abzug/state/speicher/pos", msg, strlen(msg));
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
do_notaus();
|
do_notaus();
|
||||||
do_rolle();
|
do_abzug();
|
||||||
do_taenzer();
|
do_taenzer();
|
||||||
|
do_spule();
|
||||||
|
|
||||||
#if PLC_MQTT_ENABLED
|
#if PLC_MQTT_ENABLED
|
||||||
ioHelperSetBit(outStates, LED_BUS_OK, 1);
|
ioHelperSetBit(outStates, LED_BUS_OK, 1);
|
||||||
ioHelperSetOuts();
|
ioHelperSetOuts();
|
||||||
MQTTYield(&mqtt_client, 10); //blocking call
|
MQTTYield(&mqtt_client, 1); //blocking call
|
||||||
ioHelperSetBit(outStates, LED_BUS_OK, 0);
|
ioHelperSetBit(outStates, LED_BUS_OK, 0);
|
||||||
#endif
|
#endif
|
||||||
ioHelperSetOuts();
|
ioHelperSetOuts(); //40us
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
2
modbus.h
2
modbus.h
@@ -52,7 +52,7 @@ THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
|
|
||||||
/* define baudrate of modbus */
|
/* define baudrate of modbus */
|
||||||
#ifndef BAUD
|
#ifndef BAUD
|
||||||
#define BAUD 38400L
|
#define BAUD 115200L
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
56
mqtt.c
56
mqtt.c
@@ -22,7 +22,7 @@ void messageArrived(MessageData* md)
|
|||||||
MQTTString* topic = md->topicName;
|
MQTTString* topic = md->topicName;
|
||||||
strncpy(_topic_name, topic->lenstring.data, topic->lenstring.len);
|
strncpy(_topic_name, topic->lenstring.data, topic->lenstring.len);
|
||||||
strncpy(_message, message->payload, message->payloadlen);
|
strncpy(_message, message->payload, message->payloadlen);
|
||||||
printf("<<MQTT Sub: [%s] %s", _topic_name , _message);
|
//printf("<<MQTT Sub: [%s] %s", _topic_name , _message);
|
||||||
|
|
||||||
//md->topicName->
|
//md->topicName->
|
||||||
/*
|
/*
|
||||||
@@ -35,32 +35,32 @@ void messageArrived(MessageData* md)
|
|||||||
|
|
||||||
void mqtt_pub(Client* mqtt_client, char * mqtt_topic, char * mqtt_msg, int mqtt_msg_len)
|
void mqtt_pub(Client* mqtt_client, char * mqtt_topic, char * mqtt_msg, int mqtt_msg_len)
|
||||||
{
|
{
|
||||||
static uint32_t mqtt_pub_count = 0;
|
//static uint32_t mqtt_pub_count = 0;
|
||||||
static uint8_t mqtt_err_cnt = 0;
|
static uint8_t mqtt_err_cnt = 0;
|
||||||
int32_t mqtt_rc;
|
int32_t mqtt_rc;
|
||||||
|
|
||||||
printf(">>MQTT pub msg nr%lu ", ++mqtt_pub_count);
|
//printf(">>MQTT pub msg nr%lu ", ++mqtt_pub_count);
|
||||||
MQTTMessage pubMessage;
|
MQTTMessage pubMessage;
|
||||||
pubMessage.qos = QOS0;
|
pubMessage.qos = QOS0;
|
||||||
pubMessage.id = mes_id++;
|
pubMessage.id = mes_id++;
|
||||||
pubMessage.payloadlen = (size_t)mqtt_msg_len;
|
pubMessage.payloadlen = (size_t)mqtt_msg_len;
|
||||||
pubMessage.payload = mqtt_msg;
|
pubMessage.payload = mqtt_msg;
|
||||||
mqtt_rc = MQTTPublish(mqtt_client, mqtt_topic , &pubMessage);
|
mqtt_rc = MQTTPublish(mqtt_client, mqtt_topic , &pubMessage);
|
||||||
//Analize MQTT publish result (for MQTT failover mode)
|
//Analize MQTT publish result (for MQTT failover mode)
|
||||||
if (mqtt_rc == SUCCESSS)
|
if (mqtt_rc == SUCCESSS)
|
||||||
{
|
{
|
||||||
mqtt_err_cnt = 0;
|
mqtt_err_cnt = 0;
|
||||||
printf(" - OK\r\n");
|
//printf(" - OK\r\n");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf(" - ERROR\r\n");
|
//while(1);
|
||||||
//Reboot device after 20 continuous errors (~ 20sec)
|
//Reboot device after 20 continuous errors (~ 20sec)
|
||||||
while(1);
|
if(mqtt_err_cnt++ > 10)
|
||||||
//if(mqtt_err_cnt++ > 20)
|
{
|
||||||
//{
|
printf("mqtt pub - ERROR\r\n");
|
||||||
// printf("Connection with MQTT Broker was lost!!\r\nReboot the board..\r\n");
|
printf("Connection with MQTT Broker was lost!!\r\nReboot the board..\r\n");
|
||||||
// while(1);
|
while(1);
|
||||||
//}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
24
notaus.c
24
notaus.c
@@ -1,8 +1,16 @@
|
|||||||
#include <avrIOhelper/io-helper.h>
|
#include "kraftsensor.h"
|
||||||
|
#include "avrIOhelper/io-helper.h"
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "notaus.h"
|
||||||
|
|
||||||
|
uint8_t notaus_state = POWER_OFF;
|
||||||
|
|
||||||
void do_notaus(){
|
void do_notaus(){
|
||||||
if(!read_Input(IN_NOTAUS_ANLAGE, LEVEL) || read_Input(IN_NOTAUS_SCHRANK, LEVEL) || read_Input(IN_NOTAUS_DISPLAY, LEVEL)){
|
if(!read_Input(IN_NOTAUS_ANLAGE, LEVEL) || read_Input(IN_NOTAUS_SCHRANK, LEVEL) || read_Input(IN_NOTAUS_DISPLAY, LEVEL)){
|
||||||
/* at least on pressed */
|
/* at least one pressed */
|
||||||
|
notaus_state = POWER_OFF;
|
||||||
|
|
||||||
ioHelperSetBit(outStates, AMPEL_ROT, 1);
|
ioHelperSetBit(outStates, AMPEL_ROT, 1);
|
||||||
ioHelperSetBit(outStates, AMPEL_GELB, 0);
|
ioHelperSetBit(outStates, AMPEL_GELB, 0);
|
||||||
ioHelperSetBit(outStates, AMPEL_GRUEN, 0);
|
ioHelperSetBit(outStates, AMPEL_GRUEN, 0);
|
||||||
@@ -32,6 +40,8 @@ void do_notaus(){
|
|||||||
}
|
}
|
||||||
else if(!read_Input(IN_ANLAGE_EIN, LEVEL)){
|
else if(!read_Input(IN_ANLAGE_EIN, LEVEL)){
|
||||||
/* nothing pressed, but power not on */
|
/* nothing pressed, but power not on */
|
||||||
|
notaus_state = ARMED;
|
||||||
|
|
||||||
ioHelperSetBit(outStates, AMPEL_ROT, 0);
|
ioHelperSetBit(outStates, AMPEL_ROT, 0);
|
||||||
ioHelperSetBit(outStates, AMPEL_GELB, 1);
|
ioHelperSetBit(outStates, AMPEL_GELB, 1);
|
||||||
ioHelperSetBit(outStates, AMPEL_GRUEN, 0);
|
ioHelperSetBit(outStates, AMPEL_GRUEN, 0);
|
||||||
@@ -46,6 +56,8 @@ void do_notaus(){
|
|||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
/* powered on */
|
/* powered on */
|
||||||
|
notaus_state = POWER_ON;
|
||||||
|
|
||||||
ioHelperSetBit(outStates, AMPEL_ROT, 0);
|
ioHelperSetBit(outStates, AMPEL_ROT, 0);
|
||||||
ioHelperSetBit(outStates, AMPEL_GELB, 0);
|
ioHelperSetBit(outStates, AMPEL_GELB, 0);
|
||||||
ioHelperSetBit(outStates, AMPEL_GRUEN, 1);
|
ioHelperSetBit(outStates, AMPEL_GRUEN, 1);
|
||||||
@@ -58,6 +70,14 @@ void do_notaus(){
|
|||||||
set_Output(LED_ROT_NOTAUS_SCHRANK, OFF);
|
set_Output(LED_ROT_NOTAUS_SCHRANK, OFF);
|
||||||
set_Output(LED_ROT_NOTAUS_DISPLAY, OFF);
|
set_Output(LED_ROT_NOTAUS_DISPLAY, OFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!kraftsensor_valid)
|
||||||
|
{
|
||||||
|
set_Output(LED_FEHLER, ON);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
set_Output(LED_FEHLER, OFF);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
8
notaus.h
8
notaus.h
@@ -1,6 +1,14 @@
|
|||||||
#ifndef _NOTAUS_H_
|
#ifndef _NOTAUS_H_
|
||||||
#define _NOTAUS_H_
|
#define _NOTAUS_H_
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#define POWER_ON 2
|
||||||
|
#define ARMED 1
|
||||||
|
#define POWER_OFF 0
|
||||||
|
|
||||||
|
extern uint8_t notaus_state;
|
||||||
|
|
||||||
void do_notaus(void);
|
void do_notaus(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
34
pid_controller.h
Normal file
34
pid_controller.h
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* pid_controller.h
|
||||||
|
*
|
||||||
|
* Created on: Apr 24, 2016
|
||||||
|
* Author: subham roy
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __PID_CONTROLLER_H
|
||||||
|
#define __PID_CONTROLLER_H
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
/* PID controller parameters */
|
||||||
|
double Kp;
|
||||||
|
double Ki;
|
||||||
|
double Kd;
|
||||||
|
|
||||||
|
/* max output limits for the PID controller */
|
||||||
|
double output_max;
|
||||||
|
double output_min;
|
||||||
|
|
||||||
|
/* below are session variables for the PID controller */
|
||||||
|
double _integral_sum;
|
||||||
|
double _prev_err;
|
||||||
|
double _dt;
|
||||||
|
} PID_vars;
|
||||||
|
|
||||||
|
|
||||||
|
#define PID_VARS_INIT(x) PID_vars x = {.Kp=1.3,.Ki=0.00,.Kd=0.00,.output_max=25000.0, \
|
||||||
|
.output_min=-25000.0,._integral_sum=0.0,._prev_err=0.0,._dt=1.0}
|
||||||
|
|
||||||
|
/* Function Prototypes */
|
||||||
|
double pid(PID_vars *vars, double current_err);
|
||||||
|
|
||||||
|
#endif
|
||||||
215
spule.c
Normal file
215
spule.c
Normal file
@@ -0,0 +1,215 @@
|
|||||||
|
#include <avr/io.h>
|
||||||
|
#include <avr/interrupt.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "avrIOhelper/io-helper.h"
|
||||||
|
|
||||||
|
#include "taenzer.h"
|
||||||
|
#include "abzug.h"
|
||||||
|
|
||||||
|
volatile uint16_t windings = 0;
|
||||||
|
volatile uint16_t windings_wakeup = 0;
|
||||||
|
|
||||||
|
volatile uint8_t trans_state = 0;
|
||||||
|
|
||||||
|
int32_t spule_trans_pos = 0;
|
||||||
|
uint8_t spule_trans_homed = 0;
|
||||||
|
|
||||||
|
#define TRANS_ROT_FACTOR 0.14
|
||||||
|
|
||||||
|
void timer1_init()
|
||||||
|
{
|
||||||
|
TCCR1A |= (1<<COM1A1);
|
||||||
|
TCCR1B |= _BV(WGM13);
|
||||||
|
|
||||||
|
ICR1 = 100;
|
||||||
|
OCR1A = 50;
|
||||||
|
|
||||||
|
DDRB |= 1 << 5;
|
||||||
|
TIMSK1 |= 1<<TOIE1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void timer5_init()
|
||||||
|
{
|
||||||
|
TCCR5A |= (1<<COM5C1);
|
||||||
|
TCCR5B |= _BV(WGM53);
|
||||||
|
|
||||||
|
ICR5 = 1000;
|
||||||
|
OCR5C = 500;
|
||||||
|
|
||||||
|
DDRL |= 1 << 5;
|
||||||
|
TIMSK5 |= 1<<TOIE5;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void spule_onoff(uint8_t state){
|
||||||
|
if(state){
|
||||||
|
TCCR5B |= _BV(CS51); // ROTATION
|
||||||
|
TCCR1B |= _BV(CS11); // TRANSLATION
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
TCCR5B &= ~(_BV(CS51));
|
||||||
|
TCCR1B &= ~(_BV(CS11));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_spooling_speed(uint16_t speed){
|
||||||
|
ICR5=speed;
|
||||||
|
OCR5C = ICR5/2;
|
||||||
|
|
||||||
|
ICR1 = ICR5/TRANS_ROT_FACTOR;
|
||||||
|
OCR1A = ICR1/2;
|
||||||
|
}
|
||||||
|
|
||||||
|
void do_spule(){
|
||||||
|
// Translatoric axis homeing code
|
||||||
|
if(read_Input(IN_SPULE_HOME, LEVEL) && spule_trans_homed == 0){
|
||||||
|
spule_trans_homed = 1;
|
||||||
|
spule_trans_pos = 0;
|
||||||
|
|
||||||
|
TCCR1B &= ~(_BV(CS11));
|
||||||
|
set_Output(MOTOR_TRANS_DIR, 0); // direction: back
|
||||||
|
|
||||||
|
ICR1 = ICR5/TRANS_ROT_FACTOR;
|
||||||
|
OCR1A = ICR1/2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if not homed goto home
|
||||||
|
if(!spule_trans_homed){
|
||||||
|
ICR1 = 100;
|
||||||
|
OCR1A = 50;
|
||||||
|
set_Output(MOTOR_TRANS_DIR, 1); // direction: front
|
||||||
|
TCCR1B |= _BV(CS11); //TURN ON
|
||||||
|
}
|
||||||
|
|
||||||
|
// manual forwarding if button is held
|
||||||
|
else if(!get_abzug_state() || (get_abzug_state() && read_Input(IN_BREMSE_STATE, LEVEL)) ){
|
||||||
|
if(read_Input(BTN_WICKELN_EIN, LEVEL)){
|
||||||
|
set_spooling_speed(300);
|
||||||
|
spule_onoff(1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
spule_onoff(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// normal operation
|
||||||
|
else{
|
||||||
|
/* speed regulation - keep taenzer at 10% */
|
||||||
|
float p = 100.0/(int32_t)(taenzer_state.pos/1000);
|
||||||
|
p-=1;
|
||||||
|
p/=2;
|
||||||
|
p+=1;
|
||||||
|
//tmp = (int32_t)(taenzer_state.pos/10000);
|
||||||
|
//printf("%ld\n", tmp);
|
||||||
|
|
||||||
|
//printf("temp1: %d\n", tmp);
|
||||||
|
//TODO fix bounds
|
||||||
|
//if(tmp < -7500/abzug_speed/2)
|
||||||
|
// tmp = -7500/abzug_speed/2;
|
||||||
|
//printf("temp2: %d\n", tmp);
|
||||||
|
if(p < 0.5)
|
||||||
|
p = 0.5;
|
||||||
|
if(p > 2)
|
||||||
|
p = 2;
|
||||||
|
|
||||||
|
uint16_t base_speed = (14000/abzug_speed);
|
||||||
|
uint16_t ctrl_speed = base_speed * p;
|
||||||
|
|
||||||
|
if(ctrl_speed <= 70)
|
||||||
|
ctrl_speed = 70;
|
||||||
|
|
||||||
|
ICR5 = ctrl_speed;
|
||||||
|
OCR5C = ICR5/2;
|
||||||
|
|
||||||
|
if(trans_state != 4)
|
||||||
|
ICR1 = ICR5/TRANS_ROT_FACTOR;
|
||||||
|
else
|
||||||
|
ICR1 = 0.5*(ICR5/TRANS_ROT_FACTOR);
|
||||||
|
OCR1A = ICR1/2;
|
||||||
|
|
||||||
|
if (read_Input(BTN_WICKELN_EIN, RISING) && !read_Input(IN_BREMSE_STATE, LEVEL)) {
|
||||||
|
spule_onoff(1);
|
||||||
|
}
|
||||||
|
if (read_Input(BTN_WICKELN_AUS, RISING)) {
|
||||||
|
spule_onoff(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (read_Input(BTN_INIT, RISING)) {
|
||||||
|
spule_trans_homed = 0;
|
||||||
|
taenzer_state.homed = 0;
|
||||||
|
taenzer_state.active = 0;
|
||||||
|
windings = 0;
|
||||||
|
windings_wakeup = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (read_Input(IN_BREMSE_STATE, FALLING)) {
|
||||||
|
printf("draußen\n");
|
||||||
|
spule_onoff(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (read_Input(IN_BREMSE_STATE, RISING)) {
|
||||||
|
printf("drinne\n");
|
||||||
|
spule_onoff(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
//PORTH |= (1<<5);
|
||||||
|
}
|
||||||
|
|
||||||
|
ISR(TIMER1_OVF_vect) {
|
||||||
|
//PORTH &= ~(1<<5);
|
||||||
|
//if(ioHelperReadBit(outStates, MOTOR_TRANS_DIR)){
|
||||||
|
if(PORTB & (1<<6)){
|
||||||
|
spule_trans_pos -= 1;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
spule_trans_pos += 1;
|
||||||
|
}
|
||||||
|
//TODO keep track if position stays in bounds
|
||||||
|
//PORTH |= (1<<5);
|
||||||
|
}
|
||||||
|
|
||||||
|
ISR(TIMER5_OVF_vect) {
|
||||||
|
//PORTH &= ~(1<<5);
|
||||||
|
static uint16_t steps = 0;
|
||||||
|
steps++;
|
||||||
|
if(steps == 25000){
|
||||||
|
windings++;
|
||||||
|
steps=0;
|
||||||
|
printf("windungen: %d\t", windings);
|
||||||
|
printf("trans pos: %ld\n", spule_trans_pos);
|
||||||
|
printf("speed %d\n", ICR1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(windings == windings_wakeup){
|
||||||
|
TIMSK1 |= 1<<TOIE1;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t windings_on_layer = windings % 25;
|
||||||
|
|
||||||
|
if(windings_on_layer == 0 && steps == 0){
|
||||||
|
trans_state = 1;
|
||||||
|
ICR1 = ICR5/TRANS_ROT_FACTOR;
|
||||||
|
OCR1A = ICR1/2;
|
||||||
|
set_Output(MOTOR_TRANS_DIR, TOGGLE);
|
||||||
|
printf("toggle at pos: %ld\n", spule_trans_pos);
|
||||||
|
printf("speed %d\n", ICR1);
|
||||||
|
}
|
||||||
|
if(windings_on_layer == 1 && steps == 0){
|
||||||
|
trans_state = 2;
|
||||||
|
printf("nachlauf aufbauen\n");
|
||||||
|
TCCR1B &= ~(_BV(CS11));
|
||||||
|
}
|
||||||
|
if(windings_on_layer == 3 && steps == 0){
|
||||||
|
trans_state = 3;
|
||||||
|
TCCR1B |= _BV(CS11);
|
||||||
|
printf("done\n");
|
||||||
|
printf("speed %d\n", ICR1);
|
||||||
|
}
|
||||||
|
if(windings_on_layer == 21 && steps == 0){
|
||||||
|
trans_state = 4;
|
||||||
|
ICR1 = 0.5*(ICR5/TRANS_ROT_FACTOR);
|
||||||
|
OCR1A = ICR1/2;
|
||||||
|
printf("nachlauf abbauen\n");
|
||||||
|
printf("speed %d\n", ICR1);
|
||||||
|
}
|
||||||
|
//;PORTH |= (1<<5);
|
||||||
|
}
|
||||||
13
spule.h
Normal file
13
spule.h
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#ifndef _SPULE_H_
|
||||||
|
#define _SPULE_H_
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
void timer1_init(void);
|
||||||
|
void timer5_init(void);
|
||||||
|
void do_spule(void);
|
||||||
|
|
||||||
|
extern volatile uint16_t windings;
|
||||||
|
extern int32_t spule_trans_pos;
|
||||||
|
|
||||||
|
#endif
|
||||||
111
taenzer.c
111
taenzer.c
@@ -3,35 +3,118 @@
|
|||||||
#include "taenzer.h"
|
#include "taenzer.h"
|
||||||
#include "avrIOhelper/io-helper.h"
|
#include "avrIOhelper/io-helper.h"
|
||||||
#include "kraftsensor.h"
|
#include "kraftsensor.h"
|
||||||
|
#include "notaus.h"
|
||||||
|
#include "pid_controller.h"
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#define TAENZER_KRAFT_SETPOINT 12000
|
||||||
|
#define TAENZER_KRAFT_HYST 500
|
||||||
|
|
||||||
|
|
||||||
taenzer_state_t taenzer_state;
|
taenzer_state_t taenzer_state;
|
||||||
|
PID_VARS_INIT(regler);
|
||||||
|
|
||||||
|
taenzer_state_t taenzer_state = {
|
||||||
|
.homed = 0,
|
||||||
|
.pos = 0,
|
||||||
|
.force_setpoint = TAENZER_KRAFT_SETPOINT,
|
||||||
|
.active = 0
|
||||||
|
};
|
||||||
|
|
||||||
|
double pid(PID_vars *vars, double current_err) {
|
||||||
|
|
||||||
|
/* current_error = setpoint - current_process_variable */
|
||||||
|
|
||||||
|
vars->_integral_sum += current_err*(vars->_dt);
|
||||||
|
|
||||||
|
double output = (vars->Kp)*current_err \
|
||||||
|
+ (vars->Ki)*(vars->_integral_sum) \
|
||||||
|
+ (vars->Kd)*((current_err-(vars->_prev_err)) \
|
||||||
|
/(vars->_dt));
|
||||||
|
|
||||||
|
vars->_prev_err = current_err;
|
||||||
|
|
||||||
|
/* limit output within output_min and output_max */
|
||||||
|
if (output>(vars->output_max))
|
||||||
|
output = vars->output_max;
|
||||||
|
else if (output<(vars->output_min))
|
||||||
|
output = vars->output_min;
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern void send_settings(void);
|
||||||
void do_taenzer(){
|
void do_taenzer(){
|
||||||
|
|
||||||
/* Homing */
|
/* Homing */
|
||||||
if(!taenzer_state.homed){
|
|
||||||
set_Output(MOTOR_TAENZER_DIR, 1); // direction: up
|
|
||||||
TCCR4B |= _BV(CS41); //TURN ON
|
|
||||||
}
|
|
||||||
if(read_Input(IN_TAENZER_HOME, LEVEL)){
|
if(read_Input(IN_TAENZER_HOME, LEVEL)){
|
||||||
TCCR4B &= ~_BV(CS41); //TURN OFF
|
TCCR4B &= ~_BV(CS41); //TURN OFF
|
||||||
taenzer_state.homed = 1;
|
taenzer_state.homed = 1;
|
||||||
taenzer_state.pos = 0;
|
taenzer_state.pos = 0;
|
||||||
}
|
}
|
||||||
|
if(!taenzer_state.homed && notaus_state == POWER_ON){
|
||||||
|
ICR4 = 30;
|
||||||
|
OCR4A = 15;
|
||||||
|
set_Output(MOTOR_TAENZER_DIR, 1); // direction: up
|
||||||
|
TCCR4B |= _BV(CS41); //TURN ON
|
||||||
|
}
|
||||||
|
|
||||||
|
if (read_Input(BTN_KRAFT_PLUS, RISING)) {
|
||||||
|
taenzer_state.force_setpoint += 1000;
|
||||||
|
#if PLC_MQTT_ENABLED
|
||||||
|
send_settings();
|
||||||
|
#endif
|
||||||
|
if(taenzer_state.homed == 1 && read_Input(BTN_KRAFT_MINUS, LEVEL))
|
||||||
|
{
|
||||||
|
kraftsensor_zero_offset = -(kraftsensor_value-kraftsensor_zero_offset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (read_Input(BTN_KRAFT_MINUS, RISING)) {
|
||||||
|
taenzer_state.force_setpoint -= 1000;
|
||||||
|
#if PLC_MQTT_ENABLED
|
||||||
|
send_settings();
|
||||||
|
#endif
|
||||||
|
if(taenzer_state.homed == 1 && read_Input(BTN_KRAFT_PLUS, LEVEL))
|
||||||
|
{
|
||||||
|
kraftsensor_zero_offset = -(kraftsensor_value-kraftsensor_zero_offset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (read_Input(BTN_TAENZER_START, RISING)) {
|
||||||
|
taenzer_state.active = 1;
|
||||||
|
}
|
||||||
|
|
||||||
/* Force regualtion */
|
/* Force regualtion */
|
||||||
if(kraftsensor_valid && taenzer_state.homed){
|
if(kraftsensor_valid && taenzer_state.active && taenzer_state.homed && taenzer_state.pos >= 0){
|
||||||
if(kraftsensor_value < 9000){
|
int32_t err = (kraftsensor_value - taenzer_state.force_setpoint);
|
||||||
set_Output(MOTOR_TAENZER_DIR, 0); // direction: down
|
|
||||||
TCCR4B |= _BV(CS41); //TURN ON
|
double pid_out = pid(®ler, err);
|
||||||
}
|
int32_t out = (int32_t)pid_out;
|
||||||
else if(kraftsensor_value > 10000){
|
|
||||||
set_Output(MOTOR_TAENZER_DIR, 1); // direction: up
|
ICR4 = 400000/abs(out);
|
||||||
TCCR4B |= _BV(CS41); //TURN ON
|
OCR4A = ICR4/2;
|
||||||
|
|
||||||
|
if(kraftsensor_valid && notaus_state == POWER_ON){
|
||||||
|
if(out < -TAENZER_KRAFT_HYST/2 && taenzer_state.pos < 970000UL){
|
||||||
|
set_Output(MOTOR_TAENZER_DIR, 0); // direction: down
|
||||||
|
TCCR4B |= _BV(CS41); //TURN ON
|
||||||
|
}
|
||||||
|
else if(out > TAENZER_KRAFT_HYST/2 && taenzer_state.pos > 0){
|
||||||
|
set_Output(MOTOR_TAENZER_DIR, 1); // direction: up
|
||||||
|
TCCR4B |= _BV(CS41); //TURN ON
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
TCCR4B &= ~_BV(CS41); //TURN OFF
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
TCCR4B &= ~_BV(CS41); //TURN OFF
|
TCCR4B &= ~_BV(CS41); //TURN OFF
|
||||||
}
|
}
|
||||||
|
//else
|
||||||
|
// TCCR4B &= ~_BV(CS41); //TURN OFF
|
||||||
}
|
}
|
||||||
|
|
||||||
void timer4_init()
|
void timer4_init()
|
||||||
@@ -42,8 +125,8 @@ void timer4_init()
|
|||||||
TIMSK4 |= 1<<TOIE4;
|
TIMSK4 |= 1<<TOIE4;
|
||||||
// TIMSK4 |= 1<<OCIE4A;
|
// TIMSK4 |= 1<<OCIE4A;
|
||||||
|
|
||||||
ICR4 = 100;
|
ICR4 = 30;
|
||||||
OCR4A = 50;
|
OCR4A = 15;
|
||||||
|
|
||||||
DDRH |= 1 << 3;
|
DDRH |= 1 << 3;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
#ifndef _TAENZER_H_
|
#ifndef _TAENZER_H_
|
||||||
#define _TAENZER_H
|
#define _TAENZER_H
|
||||||
|
|
||||||
typedef struct {
|
#include <stdint.h>
|
||||||
|
|
||||||
|
typedef volatile struct {
|
||||||
uint8_t homed;
|
uint8_t homed;
|
||||||
uint32_t pos;
|
uint32_t pos;
|
||||||
|
int16_t force_setpoint;
|
||||||
|
uint8_t active;
|
||||||
} taenzer_state_t;
|
} taenzer_state_t;
|
||||||
|
|
||||||
extern taenzer_state_t taenzer_state;
|
extern taenzer_state_t taenzer_state;
|
||||||
|
|
||||||
void do_taenzer(void);
|
void do_taenzer(void);
|
||||||
|
|||||||
Reference in New Issue
Block a user