/* * * Created: 26.08.2021 12:01:13 * Author : Joachim J. * MC: ATmega 328p mit 16MHz / Arduino Nano */ #include #include #include #include #include #include /*-------- Define --------*/ #define FOSC 16000000 //Clock Speed #define BAUD 19200 //Debug #define MYUBRR FOSC/16/BAUD-1 #define LED_PIN PC0 #define LED_ON PORTC |= (1 << LED_PIN) #define LED_OFF PORTC &= ~(1 << LED_PIN) #define set_cap_low_high TCCR1B |= (1 << ICES1); //Bit setzen: Capture von low zu high / rising #define set_cap_high_low TCCR1B &= ~(1 << ICES1); //Bit löschen: Capture von high zu low / falling #define RC_RECEIVER_PORT PD2 #define RISING_EDGE PIND & (1 << RC_RECEIVER_PORT) #define PPM_min 1145 #define PPM_max 1932 /*Variablen*/ volatile uint16_t Throttle; volatile uint8_t ppm_ready=0; volatile uint8_t cap_low_high; void USART_Init( unsigned int ubrr) { /*Set baud rate */ UBRR0H = (unsigned char)(ubrr>>8); UBRR0L = (unsigned char)ubrr; /*Enable receiver and transmitter */ UCSR0B = (1<high TIMSK1 = (1< 10 kHz für Motoren OCR0A=0; //Motor1 aus OCR0B=0; //Motor2 aus } void PWM_Timer2_init (void) { TCCR2A = (1< ca. 10 kHz für Motoren OCR2A=0; //Motor1 aus OCR2B=0; //Motor2 aus } void PWM_init (void) { TCCR0A = TCCR2A = 0xF3; TCCR0B = TCCR2B = 0x02; OCR0A = OCR0B = OCR2A = OCR2B = 0; } ISR (TIMER1_CAPT_vect) { if (cap_low_high==1) //steigende Flanke { TCNT1=0; set_cap_high_low; LED_ON; cap_low_high=0; } else //fallende Flanke { Throttle=ICR1; set_cap_low_high; LED_OFF; cap_low_high=1; ppm_ready=1; } } int main() { char Buffer[12]; uint16_t Throttle_l; uint8_t M1=0; DDRD = (1<PPM_max) { Throttle_l=PPM_max; } if (Throttle_l