Compare commits

...

21 Commits

Author SHA1 Message Date
24ef8ce70d add prints 2023-01-12 18:03:57 +01:00
701ae5501a fix spooling bug 2023-01-12 18:03:21 +01:00
4ba5a3c39f modbus/kraftsensor cleanup 2023-01-12 17:51:22 +01:00
2f5f57546a change button fine ajdustments 2023-01-12 17:40:29 +01:00
3f662045e6 less aggressive pid 2022-09-21 14:37:47 +02:00
18d2ae2f3c add start/stop when brake is engaged 2022-09-21 14:36:28 +02:00
c62792a864 zero sensor value when both buttons pressed 2022-09-05 17:10:22 +02:00
0b5dc619a6 changes for 1:5 gear instead of 1:10 2022-09-05 17:09:24 +02:00
21099092c0 increse control var to 32bit, decrease Hysteresis 2022-09-05 15:58:33 +02:00
93debb7dd6 add comments 2022-09-05 15:57:42 +02:00
393da679e0 adjust regulator (more agressive p) 2022-09-05 15:56:18 +02:00
e938862cde fix bug where regulator locks on overflown integer 2022-07-28 18:31:55 +02:00
560b4fbc4d fix limit bug 2022-07-28 18:14:34 +02:00
012f133dbe new spooling speed regulation
still needs some tuning
2022-05-24 19:56:02 +02:00
daadb91055 change function call name 2022-05-24 19:49:43 +02:00
6fbc0d4c08 check init when spooling is stopped 2022-05-24 19:43:11 +02:00
39f9c1691a move initial send_settings out of main loop 2022-05-24 19:35:45 +02:00
b37d685690 disable spike detection
false sensor readings should be fixed by commit 105b208bed in hx711 repo
2022-05-24 19:27:32 +02:00
14850ae8e9 reduce timeout value on modbus 2022-05-24 19:24:35 +02:00
e514d57ddf getter method for abzug_state 2022-05-24 19:03:10 +02:00
dcf1531033 manual spooling when button is held down 2022-05-24 19:01:38 +02:00
10 changed files with 175 additions and 94 deletions

49
abzug.c
View File

@@ -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,8 +16,11 @@ void timer3_init()
DDRE |= 1 << 4; DDRE |= 1 << 4;
} }
uint8_t get_abzug_state(){
return TCCR3B & _BV(CS31);
}
void send_settings(void); extern void send_settings(void);
void do_abzug(){ void do_abzug(){
if (read_Input(BTN_ABZUG_EIN, RISING)) { if (read_Input(BTN_ABZUG_EIN, RISING)) {
@@ -35,26 +40,6 @@ void do_abzug(){
} }
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_settings();
#endif
}
if (read_Input(BTN_ABZUG_MINUS, RISING)) {
if(abzug_speed >= 110)
abzug_speed -= 100;
else
abzug_speed = 10;
#if PLC_MQTT_ENABLED
send_settings();
#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
@@ -64,7 +49,7 @@ void do_abzug(){
#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
@@ -74,6 +59,26 @@ void do_abzug(){
#endif #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
}
// 16000000/8 // 16000000/8
ICR3 = ((1.0/abzug_speed)*3.14*42.0*(1.0/5.0))*2.0*500.0*(1/1.03); ICR3 = ((1.0/abzug_speed)*3.14*42.0*(1.0/5.0))*2.0*500.0*(1/1.03);

View File

@@ -7,5 +7,6 @@ extern uint16_t abzug_speed;
void do_abzug(void); void do_abzug(void);
void timer3_init(void); void timer3_init(void);
uint8_t get_abzug_state(void);
#endif #endif

View File

@@ -152,6 +152,8 @@ void ioHelperEdgeDetector(void);
#define BTN_KRAFT_MINUS BitPinG2 #define BTN_KRAFT_MINUS BitPinG2
#define IN_TAENZER_HOME BitPinF0 #define IN_TAENZER_HOME BitPinF0
#define IN_SPULE_HOME BitPinF1 #define IN_SPULE_HOME BitPinF1
#define IN_BREMSE_STATE BitPinF2
#endif #endif

View File

@@ -12,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,47 +29,25 @@ void kraftsensor_init(){
} }
void do_kraftsensor(){ void do_kraftsensor(){
static int32_t last_read;
static int32_t old_value;
uint16_t m_data[4]; uint16_t m_data[4];
int32_t kraftsensor_read;
/* read 2 16bit values and merge to 32bit signed integer */ /* read 2 16bit values and merge to 32bit signed integer */
readReg(1,0,2); readReg(1,0,2);
if(wait_receive(2, m_data, 100)){ if(wait_receive(2, m_data, 10)){
kraftsensor_valid = 0; kraftsensor_valid = 0;
//printf("modbus error\n\r"); printf("modbus error\n\r");
} }
else{ else{
kraftsensor_valid = 1; kraftsensor_valid = 1;
int32_t tmp = (uint32_t)m_data[1]<<16; int32_t tmp = (uint32_t)m_data[1]<<16;
tmp |= m_data[0]; tmp |= m_data[0];
//kraftsensor_value = tmp;
/* conversion magic to milliNewton */ /* conversion magic to milliNewton */
kraftsensor_read = ((tmp + 197700 /*539363*/)*9.81)/177.380; kraftsensor_value = (((tmp /* + 539363*/)*9.81)/177.380)+kraftsensor_zero_offset;
if(abs(kraftsensor_read - old_value) > 10000){
if(abs(last_read - kraftsensor_read) > 10000){
kraftsensor_value = old_value;
//printf("delta: %ld\tvalue:%ld\n", kraftsensor_read - old_value, kraftsensor_read);
//printf("spike\n");
}
else{
kraftsensor_value = kraftsensor_read;
//printf("jump\n");
}
}
else{
kraftsensor_value = kraftsensor_read;
}
last_read = kraftsensor_read;
old_value = kraftsensor_value;
} }
} }
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
@@ -92,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;

View File

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

26
main.c
View File

@@ -2,6 +2,7 @@
#include <avr/interrupt.h> #include <avr/interrupt.h>
#include <avr/wdt.h> #include <avr/wdt.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
@@ -89,6 +90,12 @@ void send_values(void){
itoa((250*60)/ICR5, msg, 10); itoa((250*60)/ICR5, msg, 10);
mqtt_pub(&mqtt_client, "/Filamentanlage/05_Abzug/state/spule/speed", msg, strlen(msg)); 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 // send settings wich only change on buttion press
@@ -96,8 +103,6 @@ void send_settings(void){
//TODO only send on change or improve performance otherwise //TODO only send on change or improve performance otherwise
char msg[10]; char msg[10];
//PORTH &= ~(1<<5);
//PORTH |= (1<<5);
/* Abzug */ /* 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));
@@ -196,18 +201,15 @@ int main()
set_Output(LED_FEHLER, OFF); set_Output(LED_FEHLER, OFF);
set_Output(BitPH5, ON); set_Output(BitPH5, ON); //DEBUG
while(1)
{
wdt_reset(); // WDT reset at least every sec
#if PLC_MQTT_ENABLED #if PLC_MQTT_ENABLED
if(millis() < 10) send_settings();
send_settings();
#endif #endif
while(1){
wdt_reset(); // WDT reset at least every sec
ioHelperReadPins(); ioHelperReadPins();
ioHelperDebounce(); ioHelperDebounce();
ioHelperEdgeDetector(); ioHelperEdgeDetector();
@@ -223,7 +225,7 @@ int main()
} }
if(millis() - timer_modbus_poll > 20){ if(millis() - timer_modbus_poll > 20){
do_kraftsensor(); do_kraftsensor(); // 8ms !!!
timer_modbus_poll += 20; timer_modbus_poll += 20;
} }
@@ -231,7 +233,7 @@ int main()
// send misc info // send misc info
if(millis() - timer_send_info > 200){ if(millis() - timer_send_info > 200){
timer_send_info += 200; timer_send_info += 200;
send_values(); send_values(); // 10ms
//send_info(); // 27ms every 200ms //send_info(); // 27ms every 200ms
} }
#endif #endif

View File

@@ -25,8 +25,8 @@ typedef struct {
} PID_vars; } PID_vars;
#define PID_VARS_INIT(x) PID_vars x = {.Kp=1.5,.Ki=0.00,.Kd=0.0,.output_max=20000.0, \ #define PID_VARS_INIT(x) PID_vars x = {.Kp=1.3,.Ki=0.00,.Kd=0.00,.output_max=25000.0, \
.output_min=-20000.0,._integral_sum=0.0,._prev_err=0.0,._dt=1.0} .output_min=-25000.0,._integral_sum=0.0,._prev_err=0.0,._dt=1.0}
/* Function Prototypes */ /* Function Prototypes */
double pid(PID_vars *vars, double current_err); double pid(PID_vars *vars, double current_err);

97
spule.c
View File

@@ -10,10 +10,12 @@
volatile uint16_t windings = 0; volatile uint16_t windings = 0;
volatile uint16_t windings_wakeup = 0; volatile uint16_t windings_wakeup = 0;
volatile uint8_t trans_state = 0;
int32_t spule_trans_pos = 0; int32_t spule_trans_pos = 0;
uint8_t spule_trans_homed = 0; uint8_t spule_trans_homed = 0;
#define TRANS_ROT_FACTOR 0.07 #define TRANS_ROT_FACTOR 0.14
void timer1_init() void timer1_init()
{ {
@@ -50,8 +52,16 @@ static void spule_onoff(uint8_t state){
} }
} }
void set_spooling_speed(uint16_t speed){
ICR5=speed;
OCR5C = ICR5/2;
ICR1 = ICR5/TRANS_ROT_FACTOR;
OCR1A = ICR1/2;
}
void do_spule(){ void do_spule(){
//PORTH &= ~(1<<5); // Translatoric axis homeing code
if(read_Input(IN_SPULE_HOME, LEVEL) && spule_trans_homed == 0){ if(read_Input(IN_SPULE_HOME, LEVEL) && spule_trans_homed == 0){
spule_trans_homed = 1; spule_trans_homed = 1;
spule_trans_pos = 0; spule_trans_pos = 0;
@@ -63,48 +73,84 @@ void do_spule(){
OCR1A = ICR1/2; OCR1A = ICR1/2;
} }
// if not homed goto home
if(!spule_trans_homed){ if(!spule_trans_homed){
ICR1 = 100; ICR1 = 100;
OCR1A = 50; OCR1A = 50;
set_Output(MOTOR_TRANS_DIR, 1); // direction: front set_Output(MOTOR_TRANS_DIR, 1); // direction: front
TCCR1B |= _BV(CS11); //TURN ON TCCR1B |= _BV(CS11); //TURN ON
} }
else if(taenzer_state.pos <= 10){
spule_onoff(0); // 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{ else{
/* speed regulation - keep taenzer at 10% */ /* speed regulation - keep taenzer at 10% */
int32_t tmp = 0;//(100 - (int32_t)taenzer_state.pos/1000); 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); //printf("temp1: %d\n", tmp);
//TODO fix bounds //TODO fix bounds
//if(tmp < -7500/abzug_speed/2) //if(tmp < -7500/abzug_speed/2)
// tmp = -7500/abzug_speed/2; // tmp = -7500/abzug_speed/2;
//printf("temp2: %d\n", tmp); //printf("temp2: %d\n", tmp);
if(tmp < -35) if(p < 0.5)
tmp = -35; p = 0.5;
if(p > 2)
p = 2;
ICR5=7500/abzug_speed + tmp; 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; OCR5C = ICR5/2;
ICR1 = ICR5/TRANS_ROT_FACTOR; if(trans_state != 4)
ICR1 = ICR5/TRANS_ROT_FACTOR;
else
ICR1 = 0.5*(ICR5/TRANS_ROT_FACTOR);
OCR1A = ICR1/2; OCR1A = ICR1/2;
if (read_Input(BTN_WICKELN_EIN, RISING)) { if (read_Input(BTN_WICKELN_EIN, RISING) && !read_Input(IN_BREMSE_STATE, LEVEL)) {
spule_onoff(1); spule_onoff(1);
} }
if (read_Input(BTN_WICKELN_AUS, RISING)) { if (read_Input(BTN_WICKELN_AUS, RISING)) {
spule_onoff(0); 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(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); //PORTH |= (1<<5);
} }
@@ -125,10 +171,12 @@ ISR(TIMER5_OVF_vect) {
//PORTH &= ~(1<<5); //PORTH &= ~(1<<5);
static uint16_t steps = 0; static uint16_t steps = 0;
steps++; steps++;
if(steps == 50000){ if(steps == 25000){
windings++; windings++;
steps=0; steps=0;
printf("windungen: %d\n", windings); printf("windungen: %d\t", windings);
printf("trans pos: %ld\n", spule_trans_pos);
printf("speed %d\n", ICR1);
} }
if(windings == windings_wakeup){ if(windings == windings_wakeup){
@@ -138,23 +186,30 @@ ISR(TIMER5_OVF_vect) {
uint8_t windings_on_layer = windings % 25; uint8_t windings_on_layer = windings % 25;
if(windings_on_layer == 0 && steps == 0){ if(windings_on_layer == 0 && steps == 0){
trans_state = 1;
ICR1 = ICR5/TRANS_ROT_FACTOR; ICR1 = ICR5/TRANS_ROT_FACTOR;
OCR1A = ICR1/2; OCR1A = ICR1/2;
set_Output(MOTOR_TRANS_DIR, TOGGLE); set_Output(MOTOR_TRANS_DIR, TOGGLE);
printf("toggle at pos: %ld\n", spule_trans_pos); printf("toggle at pos: %ld\n", spule_trans_pos);
printf("speed %d\n", ICR1);
} }
if(windings_on_layer == 1 && steps == 0){ if(windings_on_layer == 1 && steps == 0){
trans_state = 2;
printf("nachlauf aufbauen\n"); printf("nachlauf aufbauen\n");
TCCR1B &= ~(_BV(CS11)); TCCR1B &= ~(_BV(CS11));
} }
if(windings_on_layer == 3 && steps == 0){ if(windings_on_layer == 3 && steps == 0){
trans_state = 3;
TCCR1B |= _BV(CS11); TCCR1B |= _BV(CS11);
printf("done\n"); printf("done\n");
printf("speed %d\n", ICR1);
} }
if(windings_on_layer == 21 && steps == 0){ if(windings_on_layer == 21 && steps == 0){
trans_state = 4;
ICR1 = 0.5*(ICR5/TRANS_ROT_FACTOR); ICR1 = 0.5*(ICR5/TRANS_ROT_FACTOR);
OCR1A = ICR1/2; OCR1A = ICR1/2;
printf("nachlauf abbauen\n"); printf("nachlauf abbauen\n");
printf("speed %d\n", ICR1);
} }
//PORTH |= (1<<5); //;PORTH |= (1<<5);
} }

View File

@@ -1,8 +1,13 @@
#ifndef _SPULE_H_ #ifndef _SPULE_H_
#define _SPULE_H_ #define _SPULE_H_
#include <stdint.h>
void timer1_init(void); void timer1_init(void);
void timer5_init(void); void timer5_init(void);
void do_spule(void); void do_spule(void);
extern volatile uint16_t windings;
extern int32_t spule_trans_pos;
#endif #endif

View File

@@ -5,13 +5,14 @@
#include "kraftsensor.h" #include "kraftsensor.h"
#include "notaus.h" #include "notaus.h"
#include "pid_controller.h" #include "pid_controller.h"
#include "common.h"
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#define TAENZER_KRAFT_SETPOINT 12000 #define TAENZER_KRAFT_SETPOINT 12000
#define TAENZER_KRAFT_HYST 1000 #define TAENZER_KRAFT_HYST 500
taenzer_state_t taenzer_state; taenzer_state_t taenzer_state;
@@ -46,7 +47,7 @@ double pid(PID_vars *vars, double current_err) {
return output; return output;
} }
void send_info(void); extern void send_settings(void);
void do_taenzer(){ void do_taenzer(){
/* Homing */ /* Homing */
@@ -65,31 +66,39 @@ void do_taenzer(){
if (read_Input(BTN_KRAFT_PLUS, RISING)) { if (read_Input(BTN_KRAFT_PLUS, RISING)) {
taenzer_state.force_setpoint += 1000; taenzer_state.force_setpoint += 1000;
#if PLC_MQTT_ENABLED #if PLC_MQTT_ENABLED
send_info(); send_settings();
#endif #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)) { if (read_Input(BTN_KRAFT_MINUS, RISING)) {
taenzer_state.force_setpoint -= 1000; taenzer_state.force_setpoint -= 1000;
#if PLC_MQTT_ENABLED #if PLC_MQTT_ENABLED
send_info(); send_settings();
#endif #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)) { if (read_Input(BTN_TAENZER_START, RISING)) {
taenzer_state.active = 1; taenzer_state.active = 1;
} }
/* Force regualtion */ /* Force regualtion */
if(kraftsensor_valid && taenzer_state.active && taenzer_state.homed && taenzer_state.pos >= 0 && taenzer_state.pos < 500000){ if(kraftsensor_valid && taenzer_state.active && taenzer_state.homed && taenzer_state.pos >= 0){
int16_t err = (kraftsensor_value - taenzer_state.force_setpoint); int32_t err = (kraftsensor_value - taenzer_state.force_setpoint);
double pid_out = pid(&regler, err); double pid_out = pid(&regler, err);
int16_t out = (int16_t)pid_out; int32_t out = (int32_t)pid_out;
ICR4 = 400000/abs(out); ICR4 = 400000/abs(out);
OCR4A = ICR4/2; OCR4A = ICR4/2;
if(kraftsensor_valid && notaus_state == POWER_ON){ if(kraftsensor_valid && notaus_state == POWER_ON){
if(out < -TAENZER_KRAFT_HYST/2 /* && taenzer_state.pos < 300000UL*/){ if(out < -TAENZER_KRAFT_HYST/2 && taenzer_state.pos < 970000UL){
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
} }
@@ -97,12 +106,15 @@ void do_taenzer(){
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
} }
else else{
TCCR4B &= ~_BV(CS41); //TURN OFF 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()