Compare commits
7 Commits
b2721c0123
...
1aa6b17065
| Author | SHA1 | Date | |
|---|---|---|---|
| 1aa6b17065 | |||
| 1a8b4418a6 | |||
| f2fd5c52fa | |||
| 32ee1da8e8 | |||
| 5e9d3578a1 | |||
| 93f0ef3759 | |||
| 690f4b308a |
4
Makefile
4
Makefile
@@ -4,9 +4,9 @@ FILES = $(SRCS:%.c=%) #main uart avrIOhelper/io-helper #uart#hier alle c-Datei
|
||||
MCU = atmega2560
|
||||
PROGC = m2560
|
||||
CC = avr-gcc
|
||||
#TOOL = atmelice_isp
|
||||
TOOL = atmelice_isp
|
||||
#TOOL = avrispmkii
|
||||
TOOL = usbasp-clone
|
||||
#TOOL = usbasp-clone
|
||||
|
||||
BUILDDIR = Builds
|
||||
|
||||
|
||||
@@ -25,8 +25,8 @@ typedef struct {
|
||||
} PID_vars;
|
||||
|
||||
|
||||
#define PID_VARS_INIT(x) PID_vars x = {.Kp=1.0,.Ki=0.00,.Kd=0.1,.output_max=15000.0, \
|
||||
.output_min=-15000.0,._integral_sum=0.0,._prev_err=0.0,._dt=1.0}
|
||||
#define PID_VARS_INIT(x) PID_vars x = {.Kp=1.3,.Ki=0.00,.Kd=0.0,.output_max=20000.0, \
|
||||
.output_min=-20000.0,._integral_sum=0.0,._prev_err=0.0,._dt=1.0}
|
||||
|
||||
/* Function Prototypes */
|
||||
double pid(PID_vars *vars, double current_err);
|
||||
|
||||
44
spule.c
44
spule.c
@@ -33,7 +33,6 @@ void timer5_init()
|
||||
OCR5C = 500;
|
||||
|
||||
DDRL |= 1 << 5;
|
||||
|
||||
}
|
||||
|
||||
void do_spule(){
|
||||
@@ -58,6 +57,10 @@ void do_spule(){
|
||||
else{
|
||||
/* speed regulation - keep taenzer at 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;
|
||||
OCR5C = ICR5/2;
|
||||
|
||||
@@ -75,6 +78,8 @@ void do_spule(){
|
||||
|
||||
if (read_Input(BTN_INIT, RISING)) {
|
||||
spule_trans_homed = 0;
|
||||
taenzer_state.homed = 0;
|
||||
taenzer_state.active = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -82,23 +87,52 @@ void do_spule(){
|
||||
ISR(TIMER1_OVF_vect) {
|
||||
if(ioHelperReadBit(outStates, MOTOR_TRANS_DIR)){
|
||||
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){
|
||||
//TCCR1B &= ~(_BV(CS11));
|
||||
//TIMSK5 |= 1<<TOIE5;
|
||||
ICR1 = ICR5/0.7;
|
||||
OCR1A = ICR1/2;
|
||||
printf("front stop\n");
|
||||
set_Output(MOTOR_TRANS_DIR, 0); // direction: back
|
||||
}
|
||||
}
|
||||
else{
|
||||
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){
|
||||
//TCCR1B &= ~(_BV(CS11));
|
||||
//TIMSK5 |= 1<<TOIE5;
|
||||
ICR1 = ICR5/0.7;
|
||||
OCR1A = ICR1/2;
|
||||
printf("end stop\n");
|
||||
set_Output(MOTOR_TRANS_DIR, 1); // direction: front
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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,
|
||||
.pos = 0,
|
||||
.force_setpoint = TAENZER_KRAFT_SETPOINT,
|
||||
.active = 0
|
||||
};
|
||||
|
||||
double pid(PID_vars *vars, double current_err) {
|
||||
@@ -55,6 +56,8 @@ void do_taenzer(){
|
||||
taenzer_state.pos = 0;
|
||||
}
|
||||
if(!taenzer_state.homed && notaus_state == POWER_ON){
|
||||
ICR4 = 30;
|
||||
OCR4A = 15;
|
||||
set_Output(MOTOR_TAENZER_DIR, 1); // direction: up
|
||||
TCCR4B |= _BV(CS41); //TURN ON
|
||||
}
|
||||
@@ -71,9 +74,12 @@ void do_taenzer(){
|
||||
send_info();
|
||||
#endif
|
||||
}
|
||||
if (read_Input(BTN_TAENZER_START, RISING)) {
|
||||
taenzer_state.active = 1;
|
||||
}
|
||||
|
||||
/* 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);
|
||||
|
||||
double pid_out = pid(®ler, err);
|
||||
|
||||
Reference in New Issue
Block a user