Compare commits

..

7 Commits

@ -4,9 +4,9 @@ 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

@ -25,8 +25,8 @@ typedef struct {
} PID_vars; } PID_vars;
#define PID_VARS_INIT(x) PID_vars x = {.Kp=1.0,.Ki=0.00,.Kd=0.1,.output_max=15000.0, \ #define PID_VARS_INIT(x) PID_vars x = {.Kp=1.3,.Ki=0.00,.Kd=0.0,.output_max=20000.0, \
.output_min=-15000.0,._integral_sum=0.0,._prev_err=0.0,._dt=1.0} .output_min=-20000.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);

@ -33,7 +33,6 @@ void timer5_init()
OCR5C = 500; OCR5C = 500;
DDRL |= 1 << 5; DDRL |= 1 << 5;
} }
void do_spule(){ void do_spule(){
@ -58,6 +57,10 @@ void do_spule(){
else{ else{
/* speed regulation - keep taenzer at 10% */ /* speed regulation - keep taenzer at 10% */
int32_t tmp = (100 - (int32_t)taenzer_state.pos/1000)*10; int32_t tmp = (100 - (int32_t)taenzer_state.pos/1000)*10;
if(tmp < -75000/abzug_speed/2)
tmp = -75000/abzug_speed/2;
ICR5=75000/abzug_speed + tmp; ICR5=75000/abzug_speed + tmp;
OCR5C = ICR5/2; OCR5C = ICR5/2;
@ -75,6 +78,8 @@ void do_spule(){
if (read_Input(BTN_INIT, RISING)) { if (read_Input(BTN_INIT, RISING)) {
spule_trans_homed = 0; spule_trans_homed = 0;
taenzer_state.homed = 0;
taenzer_state.active = 0;
} }
} }
} }
@ -82,23 +87,52 @@ void do_spule(){
ISR(TIMER1_OVF_vect) { ISR(TIMER1_OVF_vect) {
if(ioHelperReadBit(outStates, MOTOR_TRANS_DIR)){ if(ioHelperReadBit(outStates, MOTOR_TRANS_DIR)){
spule_trans_pos -= 1; spule_trans_pos -= 1;
if(spule_trans_homed && spule_trans_pos == 84999){
TCCR1B &= ~(_BV(CS11));
TIMSK5 |= 1<<TOIE5;
printf("nachlauf aufbauen");
}
if(spule_trans_homed && spule_trans_pos == 4*3540){
ICR1 = 0.5*(ICR5/0.7);
OCR1A = ICR1/2;
printf("nachlauf abbauen");
}
if(spule_trans_homed && spule_trans_pos <= 0){ if(spule_trans_homed && spule_trans_pos <= 0){
//TCCR1B &= ~(_BV(CS11)); ICR1 = ICR5/0.7;
//TIMSK5 |= 1<<TOIE5; OCR1A = ICR1/2;
printf("front stop\n"); printf("front stop\n");
set_Output(MOTOR_TRANS_DIR, 0); // direction: back set_Output(MOTOR_TRANS_DIR, 0); // direction: back
} }
} }
else{ else{
spule_trans_pos += 1; spule_trans_pos += 1;
if(spule_trans_homed && spule_trans_pos == 3540){
TCCR1B &= ~(_BV(CS11));
TIMSK5 |= 1<<TOIE5;
printf("nachlauf aufbauen");
}
if(spule_trans_homed && spule_trans_pos == (85000 - (4*3540)) ){
ICR1 = 0.5*(ICR5/0.7);
OCR1A = ICR1/2;
printf("nachlauf abbauen");
}
if(spule_trans_pos >= 85000){ if(spule_trans_pos >= 85000){
//TCCR1B &= ~(_BV(CS11)); ICR1 = ICR5/0.7;
//TIMSK5 |= 1<<TOIE5; OCR1A = ICR1/2;
printf("end stop\n"); printf("end stop\n");
set_Output(MOTOR_TRANS_DIR, 1); // direction: front set_Output(MOTOR_TRANS_DIR, 1); // direction: front
} }
} }
} }
ISR(TIMER5_OVF_vect) { ISR(TIMER5_OVF_vect) {
static int16_t cnt = 0;
cnt++;
if(cnt >= 2*4000){
cnt = 0;
TCCR1B |= _BV(CS11); //TURN ON
TIMSK5 &= ~(1<<TOIE5);
}
} }

@ -21,6 +21,7 @@ taenzer_state_t taenzer_state = {
.homed = 0, .homed = 0,
.pos = 0, .pos = 0,
.force_setpoint = TAENZER_KRAFT_SETPOINT, .force_setpoint = TAENZER_KRAFT_SETPOINT,
.active = 0
}; };
double pid(PID_vars *vars, double current_err) { double pid(PID_vars *vars, double current_err) {
@ -55,6 +56,8 @@ void do_taenzer(){
taenzer_state.pos = 0; taenzer_state.pos = 0;
} }
if(!taenzer_state.homed && notaus_state == POWER_ON){ if(!taenzer_state.homed && notaus_state == POWER_ON){
ICR4 = 30;
OCR4A = 15;
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
} }
@ -71,9 +74,12 @@ void do_taenzer(){
send_info(); send_info();
#endif #endif
} }
if (read_Input(BTN_TAENZER_START, RISING)) {
taenzer_state.active = 1;
}
/* Force regualtion */ /* Force regualtion */
if(kraftsensor_valid && taenzer_state.homed && taenzer_state.pos >= 0 && taenzer_state.pos < 500000){ if(kraftsensor_valid && taenzer_state.active && taenzer_state.homed && taenzer_state.pos >= 0 && taenzer_state.pos < 500000){
int16_t err = (kraftsensor_value - taenzer_state.force_setpoint); int16_t err = (kraftsensor_value - taenzer_state.force_setpoint);
double pid_out = pid(&regler, err); double pid_out = pid(&regler, err);

@ -7,6 +7,7 @@ typedef volatile struct {
uint8_t homed; uint8_t homed;
uint32_t pos; uint32_t pos;
int16_t force_setpoint; 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;