void APM2RCInput::init(void* _isrregistry) { ISRRegistry* isrregistry = (ISRRegistry*) _isrregistry; isrregistry->register_signal(ISR_REGISTRY_TIMER5_CAPT, _timer5_capt_cb); /* initialize overrides */ clear_overrides(); /* Arduino pin 48 is ICP5 / PL1, timer 5 input capture */ hal.gpio->pinMode(48, GPIO_INPUT); /** * WGM: 1 1 1 1. Fast WPM, TOP is in OCR5A * COM all disabled * CS51: prescale by 8 => 0.5us tick * ICES5: input capture on rising edge * OCR5A: 40000, 0.5us tick => 2ms period / 50hz freq for outbound * fast PWM. */ TCCR5A = _BV(WGM50) | _BV(WGM51); TCCR5B = _BV(WGM53) | _BV(WGM52) | _BV(CS51) | _BV(ICES5); OCR5A = 40000 - 1; // -1 to correct for wrap /* OCR5B and OCR5C will be used by RCOutput_APM2. init to nil output */ OCR5B = 0xFFFF; OCR5C = 0xFFFF; /* Enable input capture interrupt */ TIMSK5 |= _BV(ICIE5); /* Enable overflow interrupt */ TIMSK5 |= _BV(TOIE5); }
void APM1RCInput::init(void* _isrregistry) { ISRRegistry* isrregistry = (ISRRegistry*) _isrregistry; isrregistry->register_signal(ISR_REGISTRY_TIMER4_CAPT, _timer4_capt_cb); /* initialize overrides */ clear_overrides(); /* Arduino pin 49 is ICP4 / PL0, timer 4 input capture */ hal.gpio->pinMode(49, GPIO_INPUT); /** * WGM: 1 1 1 1. Fast WPM, TOP is in OCR4A * COM all disabled * CS41: prescale by 8 => 0.5us tick * ICES4: input capture on rising edge * OCR4A: 40000, 0.5us tick => 2ms period / 50hz freq for outbound * fast PWM. */ TCCR4A = _BV(WGM40) | _BV(WGM41); TCCR4B = _BV(WGM43) | _BV(WGM42) | _BV(CS41) | _BV(ICES4); OCR4A = 40000; /* OCR4B and OCR4C will be used by RCOutput_APM1. init to nil output */ OCR4B = 0xFFFF; OCR4C = 0xFFFF; /* Enable input capture interrupt */ TIMSK4 |= _BV(ICIE4); }
void MPNGRCInput::init(void* _isrregistry) { /* initialize overrides */ clear_overrides(); DDRK = 0; // Set PORTK as a digital port ([A8-A15] are consired as digital PINs and not analogical) // hal.gpio->pinMode(46, GPIO_OUTPUT); // ICP5 pin (PL1) (PPM input) CRIUS v2 // hal.gpio->write(46,0); //Timer5 already configured in Scheduler //TCCR5A = 0; //standard mode with overflow at A and OC B and C interrupts //TCCR5B = (1<<CS11); //Prescaler set to 8, resolution of 0.5us #if SERIAL_PPM == SERIAL_PPM_DISABLED FireISRRoutine = _pwm_A8_A15_isr; PORTK = (1<<0) | (1<<1) | (1<<2) | (1<<3) | (1<<4) | (1<<5) | (1<<6) | (1<<7); //enable internal pull ups on the PINs of PORTK PCMSK2 = (1<<0) | (1<<1) | (1<<2) | (1<<3) | (1<<4) | (1<<5) | (1<<6) | (1<<7); // enable interrupts on A8-A15 pins; PCICR |= (1 << PCIE2); // PCINT2 Interrupt enable #elif SERIAL_PPM == SERIAL_PPM_ENABLED FireISRRoutine = _ppmsum_A8_isr; PORTK = (1<<PCINT16); //enable internal pull up on the SERIAL SUM pin A8 PCMSK2 |= (1 << PCINT16); // Enable int for pin A8(PCINT16) PCICR |= (1 << PCIE2); // PCINT2 Interrupt enable #elif SERIAL_PPM == SERIAL_PPM_ENABLED_PL1 FireISRRoutine = 0; hal.gpio->pinMode(48, GPIO_INPUT); // ICP5 pin (PL1) (PPM input) CRIUS v2 ISRRegistry* isrregistry = (ISRRegistry*) _isrregistry; isrregistry->register_signal(ISR_REGISTRY_TIMER5_CAPT, _ppmsum_PL1_isr); TCCR5B |= (1<<ICES5); // Enable input capture on rising edge TIMSK5 |= (1<<ICIE5); // Enable input capture interrupt. Timer interrupt mask PCMSK2 = 0; // Disable INT for pin A8-A15 #else #error You must check SERIAL_PPM mode, something wrong #endif }
void AVRScheduler::init(void* _isrregistry) { ISRRegistry* isrregistry = (ISRRegistry*) _isrregistry; /* _timer: sets up timer hardware to Arduino defaults, and * uses TIMER0 to implement millis & micros */ _timer.init(); /* TIMER2: Setup the overflow interrupt to occur at 1khz. */ TIMSK2 = 0; /* Disable timer interrupt */ TCCR2A = 0; /* Normal counting mode */ TCCR2B = _BV(CS21) | _BV(CS22); /* Prescaler to clk/256 */ TCNT2 = 0; /* Set count to 0 */ TIFR2 = _BV(TOV2); /* Clear pending interrupts */ TIMSK2 = _BV(TOIE2); /* Enable overflow interrupt*/ /* Register _timer_isr_event to trigger on overflow */ isrregistry->register_signal(ISR_REGISTRY_TIMER2_OVF, _timer_isr_event); }
void AVRScheduler::init(void* _isrregistry) { ISRRegistry* isrregistry = (ISRRegistry*) _isrregistry; /* _timer: sets up timer hardware to implement millis & micros. */ _timer.init(); /* TIMER2: Setup the overflow interrupt to occur at 1khz. */ TIMSK2 = 0; /* Disable timer interrupt */ TCCR2A = 0; /* Normal counting mode */ TCCR2B = _BV(CS21) | _BV(CS22); /* Prescaler to clk/256 */ TCNT2 = 0; /* Set count to 0 */ TIFR2 = _BV(TOV2); /* Clear pending interrupts */ TIMSK2 = _BV(TOIE2); /* Enable overflow interrupt*/ /* Register _timer_isr_event to trigger on overflow */ isrregistry->register_signal(ISR_REGISTRY_TIMER2_OVF, _timer_isr_event); /* Turn on global interrupt flag, AVR interupt system will start from this point */ sei(); memcheck_init(); }
void APM1RCInput::init(void* _isrregistry) { ISRRegistry* isrregistry = (ISRRegistry*) _isrregistry; isrregistry->register_signal(ISR_REGISTRY_TIMER4_CAPT, _timer4_capt_cb); /* initialize overrides */ clear_overrides(); /* Arduino pin 49 is ICP4 / PL0, timer 4 input capture */ hal.gpio->pinMode(49, HAL_GPIO_INPUT); /** * WGM: 1 1 1 1. Fast WPM, TOP is in OCR4A * COM all disabled * CS41: prescale by 8 => 0.5us tick * ICES4: input capture on rising edge * OCR4A: 40000, 0.5us tick => 2ms period / 50hz freq for outbound * fast PWM. */ uint8_t oldSREG = SREG; cli(); /* Timer cleanup before configuring */ TCNT4 = 0; TIFR4 = 0; /* Set timer 8x prescaler fast PWM mode toggle compare at OCRA with rising edge input capture */ TCCR4A = _BV(WGM40) | _BV(WGM41); TCCR4B |= _BV(WGM43) | _BV(WGM42) | _BV(CS41) | _BV(ICES4); OCR4A = 40000 - 1; // -1 to correct for wrap /* OCR4B and OCR4C will be used by RCOutput_APM1. Init to 0xFFFF to prevent premature PWM output */ OCR4B = 0xFFFF; OCR4C = 0xFFFF; /* Enable input capture interrupt */ TIMSK4 |= _BV(ICIE4); SREG = oldSREG; }