Thank you very much!
I corrected my code thanks to your help. It looks like this, now, and seems to work properly (I haven't tested very extensively yet)
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
const int ModeSwitchHigh = 2;
const int ModeSwitchLow = 3;
const int HighSideMos = 9;
const int LowSideMos = 10;
volatile boolean IsCharging = true; //True -> Buck converter mode, using only High-side Mosfet. False -> Boost converter mode, using only Low-Side Mosfet
volatile boolean TimerSet = false;
volatile int CompareValueHigh = 40;
volatile int CompareValueLow = 40;
void setup() {
pinMode(ModeSwitchHigh,INPUT_PULLUP);
pinMode(ModeSwitchLow,INPUT_PULLUP);
pinMode(HighSideMos, OUTPUT);
pinMode(LowSideMos, OUTPUT);
attachInterrupt(digitalPinToInterrupt(ModeSwitchHigh), Buckmode, FALLING); //Buckconverter mode, Battery loading, High-Side Mosfet
attachInterrupt(digitalPinToInterrupt(ModeSwitchLow), Boostmode, FALLING); //Boostconverter mode, Battery unloading, Low-Side Mosfet
//InitTimer1
TCNT1 = 0;
TCCR1A = 0;
TCCR1B = 0;
// set to mode 14 fast pwm.
// TCCR1B
// Bit 7 6 5 4 3 2 1 0
// Bit Name COM1A1 COM1A0 COM1B1 COM1B0 ----- ----- WGM11 WGM10
// Initial Value 0 0 0 0 0 0 0 0
// changed to 1 0 1 0 0 0 1 0
TCCR1A = B10100010;
// TCCR1B
// Bit 7 6 5 4 3 2 1 0
// Bit Name ICNC1 ICES1 ---- WGM13 WGM12 CS12 CS11 CS10
// Initial Value 0 0 0 0 0 0 0 0
// changed to 0 0 0 1 1 0 0 1
TCCR1B = B00011001;
ICR1 = 159; //Set Top Value, -> frequenz 100 kHz 16 MHz/100kHz-1, 16 MHz internal clock
OCR1A = 50; // init Wert 5 mikro sek
OCR1B = 50;
}
void loop() {
//Buckmode
if ((IsCharging == true)&&(TimerSet==false)) {
// Here Pin 10 stoppen, Pin 9 enable
TCCR1A &= ~(1 << COM1B1);
TCCR1A |= (1 << COM1A1);
OCR1A = 20;
TimerSet=true;
}
//Boostmode
else if ((IsCharging == false)&&(TimerSet==false)){
TCCR1A &= ~(1 << COM1A1);
TCCR1A |= (1 << COM1B1);
OCR1B = 20;
TimerSet = true;
}
}
void Buckmode(){
IsCharging = true;
TimerSet = false;
// PINB = (1 << PINB1); //toggle pin9
}
void Boostmode(){
IsCharging = false;
TimerSet = false;
}