You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

59 lines
1.3 KiB
C

#include <avr/io.h>
#include <avr/interrupt.h>
#include "taenzer.h"
#include "avrIOhelper/io-helper.h"
#include "kraftsensor.h"
taenzer_state_t taenzer_state;
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;
//}
/* Force regualtion */
if(kraftsensor_valid /* && taenzer_state.homed */){
if(kraftsensor_value < 0){
set_Output(MOTOR_TAENZER_DIR, 0); // direction: down
TCCR4B |= _BV(CS41); //TURN ON
}
else if(kraftsensor_value > 10000){
set_Output(MOTOR_TAENZER_DIR, 1); // direction: up
TCCR4B |= _BV(CS41); //TURN ON
}
else
TCCR4B &= ~_BV(CS41); //TURN OFF
}
}
void timer4_init()
{
TCCR4A |= (1<<COM4A1);
TCCR4B |= _BV(WGM43);
// TIMSK4 |= 1<<TOIE4;
// TIMSK4 |= 1<<OCIE4A;
ICR4 = 100;
OCR4A = 50;
DDRH |= 1 << 3;
}
ISR(TIMER4_OVF_vect) {
if(ioHelperReadBit(outStates, MOTOR_TAENZER_DIR))
taenzer_state.pos -= 1;
else
taenzer_state.pos += 1;
}
//ISR(TIMER4_OVF_vect) {
//}