Compare commits
13 Commits
c9b79e7339
...
eb680bac89
| Author | SHA1 | Date | |
|---|---|---|---|
| eb680bac89 | |||
| 22a8b37713 | |||
| 5a85471ca5 | |||
| 5ff3793991 | |||
| 6601ae39f9 | |||
| aa30d70cd6 | |||
| b2ef7d8240 | |||
| 76bca5f039 | |||
| 678d40709d | |||
| a33902424e | |||
| 93de6e725c | |||
| 1645f2c37c | |||
| 566b96c8b3 |
14
abzug.c
14
abzug.c
@@ -15,14 +15,14 @@ void timer3_init()
|
||||
}
|
||||
|
||||
|
||||
void send_abzug_speed(void);
|
||||
void send_info(void);
|
||||
void do_abzug(){
|
||||
|
||||
if (read_Input(BTN_ABZUG_EIN, RISING)) {
|
||||
TCCR3B |= _BV(CS31);
|
||||
set_Output(LED_ABZUG, ON);
|
||||
#if PLC_MQTT_ENABLED
|
||||
send_abzug_speed();
|
||||
send_info();
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ void do_abzug(){
|
||||
TCCR3B &= ~(_BV(CS31));
|
||||
set_Output(LED_ABZUG, OFF);
|
||||
#if PLC_MQTT_ENABLED
|
||||
send_abzug_speed();
|
||||
send_info();
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ void do_abzug(){
|
||||
else
|
||||
abzug_speed = 1000;
|
||||
#if PLC_MQTT_ENABLED
|
||||
send_abzug_speed();
|
||||
send_info();
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ void do_abzug(){
|
||||
else
|
||||
abzug_speed = 10;
|
||||
#if PLC_MQTT_ENABLED
|
||||
send_abzug_speed();
|
||||
send_info();
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ void do_abzug(){
|
||||
else
|
||||
abzug_speed = 1000;
|
||||
#if PLC_MQTT_ENABLED
|
||||
send_abzug_speed();
|
||||
send_info();
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ void do_abzug(){
|
||||
else
|
||||
abzug_speed = 10;
|
||||
#if PLC_MQTT_ENABLED
|
||||
send_abzug_speed();
|
||||
send_info();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
2
abzug.h
2
abzug.h
@@ -1,6 +1,8 @@
|
||||
#ifndef _ABZUG_H
|
||||
#define _ABZUG_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
extern uint16_t abzug_speed;
|
||||
|
||||
void do_abzug(void);
|
||||
|
||||
@@ -93,6 +93,7 @@ void ioHelperEdgeDetector(void);
|
||||
// Schrittmotoren richtung
|
||||
|
||||
#define MOTOR_TAENZER_DIR BitPH4
|
||||
#define MOTOR_TRANS_DIR BitPB6
|
||||
|
||||
#define LED_INIT BitPE3
|
||||
#define LED_ABZUG BitPL6
|
||||
@@ -147,6 +148,10 @@ void ioHelperEdgeDetector(void);
|
||||
#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_SPULE_HOME BitPinF1
|
||||
|
||||
#endif
|
||||
|
||||
25
main.c
25
main.c
@@ -72,7 +72,7 @@ static void avr_init()
|
||||
}
|
||||
|
||||
void send_info(void){
|
||||
char msg[6];
|
||||
char msg[10];
|
||||
sprintf(msg, "%d", abzug_speed);
|
||||
mqtt_pub(&mqtt_client, "/Filamentanlage/05_Abzug/state/abzug/speed", msg, strlen(msg));
|
||||
|
||||
@@ -86,13 +86,17 @@ void send_info(void){
|
||||
ltoa(kraftsensor_value, msg, 10);
|
||||
else
|
||||
msg[0] = '0';
|
||||
mqtt_pub(&mqtt_client, "/Filamentanlage/05_Abzug/state/kraft", msg, strlen(msg));
|
||||
mqtt_pub(&mqtt_client, "/Filamentanlage/05_Abzug/state/taenzer/pv_kraft", msg, strlen(msg));
|
||||
|
||||
ltoa(taenzer_state.pos, msg, 10);
|
||||
mqtt_pub(&mqtt_client, "/Filamentanlage/05_Abzug/state/speicher/pos", 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(taenzer_state.force_setpoint, msg, 10);
|
||||
mqtt_pub(&mqtt_client, "/Filamentanlage/05_Abzug/state/taenzer/sp_kraft", msg, strlen(msg));
|
||||
|
||||
sprintf(msg, "%ld", millis()/1000);
|
||||
mqtt_pub(&mqtt_client, "/Filamentanlage/04_Abzug/state/uptime", msg, strlen(msg));
|
||||
mqtt_pub(&mqtt_client, "/Filamentanlage/05_Abzug/state/uptime", msg, strlen(msg));
|
||||
}
|
||||
|
||||
|
||||
@@ -106,6 +110,9 @@ int main()
|
||||
|
||||
printf("moin!\n\r");
|
||||
|
||||
set_Output(LED_FEHLER, ON);
|
||||
|
||||
timer1_init(); //translation
|
||||
timer3_init(); //abzug
|
||||
timer4_init(); //taenzer
|
||||
timer5_init(); //spule
|
||||
@@ -134,7 +141,7 @@ int main()
|
||||
MQTTPacket_connectData data = MQTTPacket_connectData_initializer;
|
||||
data.willFlag = 0;
|
||||
data.MQTTVersion = 4;//3;
|
||||
data.clientID.cstring = (char*)"controllino";
|
||||
data.clientID.cstring = (char*)"controllino_aufspuleinheit";
|
||||
data.username.cstring = (char*)"Aufspuleinheit";
|
||||
data.password.cstring = (char*)"\0";
|
||||
data.keepAliveInterval = 10;
|
||||
@@ -162,6 +169,8 @@ int main()
|
||||
uint32_t timer_send_info = millis();
|
||||
uint32_t timer_modbus_poll = millis();
|
||||
|
||||
set_Output(LED_FEHLER, OFF);
|
||||
|
||||
while(1)
|
||||
{
|
||||
wdt_reset(); // WDT reset at least every sec
|
||||
@@ -184,9 +193,9 @@ int main()
|
||||
timer_blink_outs = millis();
|
||||
}
|
||||
|
||||
if(millis() - timer_modbus_poll > 100){
|
||||
if(millis() - timer_modbus_poll > 20){
|
||||
do_kraftsensor();
|
||||
timer_modbus_poll += 100;
|
||||
timer_modbus_poll += 20;
|
||||
}
|
||||
|
||||
#if PLC_MQTT_ENABLED
|
||||
|
||||
12
notaus.c
12
notaus.c
@@ -1,10 +1,16 @@
|
||||
#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(){
|
||||
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_GELB, 0);
|
||||
ioHelperSetBit(outStates, AMPEL_GRUEN, 0);
|
||||
@@ -34,6 +40,8 @@ void do_notaus(){
|
||||
}
|
||||
else if(!read_Input(IN_ANLAGE_EIN, LEVEL)){
|
||||
/* nothing pressed, but power not on */
|
||||
notaus_state = ARMED;
|
||||
|
||||
ioHelperSetBit(outStates, AMPEL_ROT, 0);
|
||||
ioHelperSetBit(outStates, AMPEL_GELB, 1);
|
||||
ioHelperSetBit(outStates, AMPEL_GRUEN, 0);
|
||||
@@ -48,6 +56,8 @@ void do_notaus(){
|
||||
}
|
||||
else{
|
||||
/* powered on */
|
||||
notaus_state = POWER_ON;
|
||||
|
||||
ioHelperSetBit(outStates, AMPEL_ROT, 0);
|
||||
ioHelperSetBit(outStates, AMPEL_GELB, 0);
|
||||
ioHelperSetBit(outStates, AMPEL_GRUEN, 1);
|
||||
|
||||
8
notaus.h
8
notaus.h
@@ -1,6 +1,14 @@
|
||||
#ifndef _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);
|
||||
|
||||
#endif
|
||||
|
||||
80
spule.c
80
spule.c
@@ -1,30 +1,106 @@
|
||||
#include <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include <stdio.h>
|
||||
#include "avrIOhelper/io-helper.h"
|
||||
|
||||
|
||||
int32_t spule_trans_pos = 0;
|
||||
uint8_t spule_trans_homed = 0;
|
||||
|
||||
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 = 500;
|
||||
OCR5C = 250;
|
||||
ICR5 = 1000;
|
||||
OCR5C = 500;
|
||||
|
||||
DDRL |= 1 << 5;
|
||||
|
||||
}
|
||||
|
||||
void do_spule(){
|
||||
|
||||
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/0.7;
|
||||
OCR1A = ICR1/2;
|
||||
}
|
||||
|
||||
if(!spule_trans_homed){
|
||||
set_Output(MOTOR_TRANS_DIR, 1); // direction: front
|
||||
TCCR1B |= _BV(CS11); //TURN ON
|
||||
}
|
||||
else{
|
||||
if (read_Input(BTN_WICKELN_EIN, RISING)) {
|
||||
TCCR5B |= _BV(CS51); //TURN ON
|
||||
TCCR1B |= _BV(CS11); //TURN ON
|
||||
}
|
||||
if (read_Input(BTN_WICKELN_AUS, RISING)) {
|
||||
TCCR5B &= ~(_BV(CS51));
|
||||
TCCR1B &= ~(_BV(CS11));
|
||||
}
|
||||
if (read_Input(BTN_TAENZER_START, RISING)) {
|
||||
ICR5-=15;
|
||||
OCR5C = ICR5/2;
|
||||
|
||||
ICR1 = ICR5/0.7;
|
||||
OCR1A = ICR1/2;
|
||||
}
|
||||
if (read_Input(BTN_SPULENWECHSEL, RISING)) {
|
||||
ICR5+=15;
|
||||
OCR5C = ICR5/2;
|
||||
|
||||
ICR1 = ICR5/0.7;
|
||||
OCR1A = ICR1/2;
|
||||
}
|
||||
|
||||
if (read_Input(BTN_INIT, RISING)) {
|
||||
spule_trans_homed = 0;
|
||||
ICR1 = 100;
|
||||
OCR1A = 50;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ISR(TIMER1_OVF_vect) {
|
||||
if(ioHelperReadBit(outStates, MOTOR_TRANS_DIR)){
|
||||
spule_trans_pos -= 1;
|
||||
if(spule_trans_homed && spule_trans_pos <= 0){
|
||||
//TCCR1B &= ~(_BV(CS11));
|
||||
//TIMSK5 |= 1<<TOIE5;
|
||||
printf("front stop\n");
|
||||
set_Output(MOTOR_TRANS_DIR, 0); // direction: back
|
||||
}
|
||||
}
|
||||
else{
|
||||
spule_trans_pos += 1;
|
||||
if(spule_trans_pos >= 85000){
|
||||
//TCCR1B &= ~(_BV(CS11));
|
||||
//TIMSK5 |= 1<<TOIE5;
|
||||
printf("end stop\n");
|
||||
set_Output(MOTOR_TRANS_DIR, 1); // direction: front
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ISR(TIMER5_OVF_vect) {
|
||||
}
|
||||
|
||||
1
spule.h
1
spule.h
@@ -1,6 +1,7 @@
|
||||
#ifndef _SPULE_H_
|
||||
#define _SPULE_H_
|
||||
|
||||
void timer1_init(void);
|
||||
void timer5_init(void);
|
||||
void do_spule(void);
|
||||
|
||||
|
||||
37
taenzer.c
37
taenzer.c
@@ -6,27 +6,48 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#define TAENZER_KRAFT_SETPOINT 12000
|
||||
#define TAENZER_KRAFT_HYST 1000
|
||||
|
||||
|
||||
taenzer_state_t taenzer_state;
|
||||
|
||||
#define TAENZER_KRAFT_SETPOINT 12000
|
||||
#define TAENZER_KRAFT_HYST 2000
|
||||
taenzer_state_t taenzer_state = {
|
||||
.homed = 0,
|
||||
.pos = 0,
|
||||
.force_setpoint = TAENZER_KRAFT_SETPOINT,
|
||||
};
|
||||
|
||||
void send_info(void);
|
||||
void do_taenzer(){
|
||||
|
||||
/* 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)){
|
||||
TCCR4B &= ~_BV(CS41); //TURN OFF
|
||||
taenzer_state.homed = 1;
|
||||
taenzer_state.pos = 0;
|
||||
}
|
||||
if(!taenzer_state.homed && notaus_state == POWER_ON){
|
||||
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_info();
|
||||
#endif
|
||||
}
|
||||
if (read_Input(BTN_KRAFT_MINUS, RISING)) {
|
||||
taenzer_state.force_setpoint -= 1000;
|
||||
#if PLC_MQTT_ENABLED
|
||||
send_info();
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Force regualtion */
|
||||
if(kraftsensor_valid && taenzer_state.homed){
|
||||
int16_t err = abs(kraftsensor_value - TAENZER_KRAFT_SETPOINT);
|
||||
if(kraftsensor_valid && taenzer_state.homed && taenzer_state.pos >= 0 && taenzer_state.pos < 500000){
|
||||
int16_t err = (kraftsensor_value - taenzer_state.force_setpoint);
|
||||
|
||||
if(err > 8000)
|
||||
err=8000;
|
||||
|
||||
Reference in New Issue
Block a user