Compare commits

...

13 Commits

10 changed files with 171 additions and 39 deletions

14
abzug.c
View File

@@ -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
}

View File

@@ -1,6 +1,8 @@
#ifndef _ABZUG_H
#define _ABZUG_H
#include <stdint.h>
extern uint16_t abzug_speed;
void do_abzug(void);

View File

@@ -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
View File

@@ -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

View File

@@ -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);

View File

@@ -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

102
spule.c
View File

@@ -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(BTN_WICKELN_EIN, RISING)) {
TCCR5B |= _BV(CS51); //TURN ON
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 (read_Input(BTN_WICKELN_AUS, RISING)) {
TCCR5B &= ~(_BV(CS51));
if(!spule_trans_homed){
set_Output(MOTOR_TRANS_DIR, 1); // direction: front
TCCR1B |= _BV(CS11); //TURN ON
}
if (read_Input(BTN_TAENZER_START, RISING)) {
ICR5-=15;
OCR5C = ICR5/2;
}
if (read_Input(BTN_SPULENWECHSEL, RISING)) {
ICR5+=15;
OCR5C = ICR5/2;
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) {
}

View File

@@ -1,6 +1,7 @@
#ifndef _SPULE_H_
#define _SPULE_H_
void timer1_init(void);
void timer5_init(void);
void do_spule(void);

View File

@@ -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;

View File

@@ -3,11 +3,11 @@
#include <stdint.h>
typedef struct {
typedef volatile struct {
uint8_t homed;
uint32_t pos;
int16_t force_setpoint;
} taenzer_state_t;
extern taenzer_state_t taenzer_state;
void do_taenzer(void);