Compare commits
7 Commits
fca12c1546
...
ecd6f47400
| Author | SHA1 | Date | |
|---|---|---|---|
| ecd6f47400 | |||
| 7e97d54d0f | |||
| f590396e0c | |||
| 8a759f7f21 | |||
| 27cffc4971 | |||
| 696c9eac0e | |||
| 64751e00c7 |
2
abzug.c
2
abzug.c
@@ -16,7 +16,7 @@ void timer3_init()
|
|||||||
|
|
||||||
|
|
||||||
void send_abzug_speed(void);
|
void send_abzug_speed(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);
|
||||||
|
|||||||
3
abzug.h
3
abzug.h
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
extern uint16_t abzug_speed;
|
extern uint16_t abzug_speed;
|
||||||
|
|
||||||
void do_rolle(void);
|
void do_abzug(void);
|
||||||
|
void timer3_init(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -141,8 +141,12 @@ 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 IN_TAENZER_HOME BitPinF0
|
#define IN_TAENZER_HOME BitPinF0
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
58
main.c
58
main.c
@@ -1,11 +1,9 @@
|
|||||||
#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 <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 +15,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 +42,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) {
|
||||||
@@ -75,7 +72,7 @@ static void avr_init()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void send_abzug_speed(void){
|
void send_info(void){
|
||||||
char msg[4];
|
char msg[4];
|
||||||
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 +82,19 @@ 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));
|
||||||
|
|
||||||
|
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));
|
||||||
|
|
||||||
|
sprintf(msg, "%ld", millis()/1000);
|
||||||
|
mqtt_pub(&mqtt_client, "/Filamentanlage/04_Messmodul/state/uptime", msg, strlen(msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// INIT MCU
|
// INIT MCU
|
||||||
@@ -95,8 +103,10 @@ int main()
|
|||||||
kraftsensor_init();
|
kraftsensor_init();
|
||||||
|
|
||||||
printf("moin!\n\r");
|
printf("moin!\n\r");
|
||||||
|
//timer0_init();
|
||||||
timer3_init();
|
timer3_init();
|
||||||
timer4_init();
|
timer4_init();
|
||||||
|
timer5_init();
|
||||||
|
|
||||||
ioHelperInitBuffer();
|
ioHelperInitBuffer();
|
||||||
ioHelperIoConf();
|
ioHelperIoConf();
|
||||||
@@ -149,7 +159,7 @@ int main()
|
|||||||
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)
|
while(1)
|
||||||
@@ -158,7 +168,7 @@ int main()
|
|||||||
|
|
||||||
#if PLC_MQTT_ENABLED
|
#if PLC_MQTT_ENABLED
|
||||||
if(millis() < 10)
|
if(millis() < 10)
|
||||||
send_abzug_speed();
|
send_info();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ioHelperReadPins();
|
ioHelperReadPins();
|
||||||
@@ -174,31 +184,23 @@ int main()
|
|||||||
timer_blink_outs = millis();
|
timer_blink_outs = millis();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if PLC_MQTT_ENABLED
|
|
||||||
// send misc info
|
|
||||||
//if(millis() - timer_send_uptime > 5000){
|
|
||||||
// timer_send_uptime += 5000;
|
|
||||||
// char msg[64];
|
|
||||||
// sprintf(msg, "%ld", millis()/1000);
|
|
||||||
// mqtt_pub(&mqtt_client, "/Filamentanlage/04_Messmodul/state/uptime", msg, strlen(msg));
|
|
||||||
//}
|
|
||||||
#endif
|
|
||||||
if(millis() - timer_modbus_poll > 200){
|
if(millis() - timer_modbus_poll > 200){
|
||||||
timer_modbus_poll += 200;
|
timer_modbus_poll += 200;
|
||||||
do_kraftsensor();
|
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if PLC_MQTT_ENABLED
|
||||||
|
// send misc info
|
||||||
|
if(millis() - timer_send_info > 200){
|
||||||
|
timer_send_info += 200;
|
||||||
|
send_info();
|
||||||
|
}
|
||||||
|
#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);
|
||||||
|
|||||||
30
spule.c
Normal file
30
spule.c
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
#include <avr/io.h>
|
||||||
|
#include "avrIOhelper/io-helper.h"
|
||||||
|
|
||||||
|
void timer5_init()
|
||||||
|
{
|
||||||
|
TCCR5A |= (1<<COM5C1);
|
||||||
|
TCCR5B |= _BV(WGM53);
|
||||||
|
|
||||||
|
ICR5 = 500;
|
||||||
|
OCR5C = 250;
|
||||||
|
|
||||||
|
DDRL |= 1 << 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
void do_spule(){
|
||||||
|
if (read_Input(BTN_WICKELN_EIN, RISING)) {
|
||||||
|
TCCR5B |= _BV(CS51); //TURN ON
|
||||||
|
}
|
||||||
|
if (read_Input(BTN_WICKELN_AUS, RISING)) {
|
||||||
|
TCCR5B &= ~(_BV(CS51));
|
||||||
|
}
|
||||||
|
if (read_Input(BTN_TAENZER_START, RISING)) {
|
||||||
|
ICR5-=15;
|
||||||
|
OCR5C = ICR5/2;
|
||||||
|
}
|
||||||
|
if (read_Input(BTN_SPULENWECHSEL, RISING)) {
|
||||||
|
ICR5+=15;
|
||||||
|
OCR5C = ICR5/2;
|
||||||
|
}
|
||||||
|
}
|
||||||
7
spule.h
Normal file
7
spule.h
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#ifndef _SPULE_H_
|
||||||
|
#define _SPULE_H_
|
||||||
|
|
||||||
|
void timer5_init(void);
|
||||||
|
void do_spule(void);
|
||||||
|
|
||||||
|
#endif
|
||||||
18
taenzer.c
18
taenzer.c
@@ -4,6 +4,8 @@
|
|||||||
#include "avrIOhelper/io-helper.h"
|
#include "avrIOhelper/io-helper.h"
|
||||||
#include "kraftsensor.h"
|
#include "kraftsensor.h"
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
taenzer_state_t taenzer_state;
|
taenzer_state_t taenzer_state;
|
||||||
|
|
||||||
void do_taenzer(){
|
void do_taenzer(){
|
||||||
@@ -21,11 +23,19 @@ void do_taenzer(){
|
|||||||
|
|
||||||
/* Force regualtion */
|
/* Force regualtion */
|
||||||
if(kraftsensor_valid && taenzer_state.homed){
|
if(kraftsensor_valid && taenzer_state.homed){
|
||||||
if(kraftsensor_value < 9000){
|
int16_t err = abs(kraftsensor_value - 10000);
|
||||||
|
|
||||||
|
if(err > 8000)
|
||||||
|
err=8000;
|
||||||
|
|
||||||
|
ICR4 = 400000/err;
|
||||||
|
OCR4A = ICR4/2;
|
||||||
|
|
||||||
|
if(kraftsensor_value < 19000){
|
||||||
set_Output(MOTOR_TAENZER_DIR, 0); // direction: down
|
set_Output(MOTOR_TAENZER_DIR, 0); // direction: down
|
||||||
TCCR4B |= _BV(CS41); //TURN ON
|
TCCR4B |= _BV(CS41); //TURN ON
|
||||||
}
|
}
|
||||||
else if(kraftsensor_value > 10000){
|
else if(kraftsensor_value > 20000){
|
||||||
set_Output(MOTOR_TAENZER_DIR, 1); // direction: up
|
set_Output(MOTOR_TAENZER_DIR, 1); // direction: up
|
||||||
TCCR4B |= _BV(CS41); //TURN ON
|
TCCR4B |= _BV(CS41); //TURN ON
|
||||||
}
|
}
|
||||||
@@ -42,8 +52,8 @@ void timer4_init()
|
|||||||
TIMSK4 |= 1<<TOIE4;
|
TIMSK4 |= 1<<TOIE4;
|
||||||
// TIMSK4 |= 1<<OCIE4A;
|
// TIMSK4 |= 1<<OCIE4A;
|
||||||
|
|
||||||
ICR4 = 100;
|
ICR4 = 50;
|
||||||
OCR4A = 50;
|
OCR4A = 25;
|
||||||
|
|
||||||
DDRH |= 1 << 3;
|
DDRH |= 1 << 3;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user