tried to translate this soft made for MAPLE in DUINO format but I have still two errors and I don’t know how to solve.
src\DRONE_SetUp_Base.cpp:316:3: error: ‘Timer3’ was not declared in this scope
316 | Timer3.attachCompare1Interrupt(handler_channel_5);
| ^~~~~~
src\DRONE_SetUp_Base.cpp:374:18: error: ‘PWM’ was not declared in this scope; did you mean ‘PWR’?
374 | pinMode(PB6, PWM);
| ^~~
Timerx and PWM are some where in MAPLE core but not in Duino core
/*==================== timer_setup(void) ==============================*/
//
//In this file the timers for reading the receiver pulses and for creating the output ESC pulses are set. To mesure the lengh of the pulse
void timer_setup(void) {
Timer2.attachCompare1Interrupt(handler_channel_1);
Timer2.attachCompare2Interrupt(handler_channel_2);
Timer2.attachCompare3Interrupt(handler_channel_3);
Timer2.attachCompare4Interrupt(handler_channel_4);
TIM2->CR1 = TIM_CR1_CEN;
TIM2->CR2 = 0;
TIM2->SMCR = 0;
TIM2->DIER = TIM_DIER_CC1IE | TIM_DIER_CC2IE | TIM_DIER_CC3IE | TIM_DIER_CC4IE;
TIM2->EGR = 0;
TIM2->CCMR1 = 0b100000001; //Register is set like this due to a bug in the define table (30-09-2017)
TIM2->CCMR2 = 0b100000001; //Register is set like this due to a bug in the define table (30-09-2017)
TIM2->CCER = TIM_CCER_CC1E | TIM_CCER_CC2E | TIM_CCER_CC3E | TIM_CCER_CC4E;
TIM2->PSC = 71;
TIM2->ARR = 0xFFFF;
TIM2->DCR = 0;
Timer3.attachCompare1Interrupt(handler_channel_5);
Timer3.attachCompare2Interrupt(handler_channel_6);
TIM3->CR1 = TIM_CR1_CEN;
TIM3->CR2 = 0;
TIM3->SMCR = 0;
TIM3->DIER = TIM_DIER_CC1IE | TIM_DIER_CC2IE;
TIM3->EGR = 0;
TIM3->CCMR1 = 0b100000001; //Register is set like this due to a bug in the define table (30-09-2017)
TIM3->CCMR2 = 0;
TIM3->CCER = TIM_CCER_CC1E | TIM_CCER_CC2E;
TIM3->PSC = 71;
TIM3->ARR = 0xFFFF;
TIM3->DCR = 0;
//A test is needed to check if the throttle input is active and valid. Otherwise the ESC's might start without any warning.
loop_counter = 0;
while ((channel_3 > 2100 || channel_3 < 900) && warning == 0) {
delay(100);
loop_counter++;
if (loop_counter == 40) {
Serial.println( "Waiting for a valid receiver channel-3 input signal");
Serial.println( "");
Serial.println( "The input pulse should be between 1000 till 2000us");
Serial.print( "Current channel-3 receiver input value = ");
Serial.println(channel_3);
Serial.println( "");
Serial.println( "Is the receiver connected and the transmitter on?");
Serial.println( "For more support and questions: www.brokking.net");
Serial.println( "");
Serial.print( "Waiting for another 5 seconds.");
}
if (loop_counter > 40 && loop_counter % 10 == 0)Serial.print( ".");
if (loop_counter == 90) {
Serial.println( "");
Serial.println( "");
Serial.println( "The ESC outputs are disabled for safety!!!");
warning = 1;
}
}
if (warning == 0) {
TIM4->CR1 = TIM_CR1_CEN | TIM_CR1_ARPE;
TIM4->CR2 = 0;
TIM4->SMCR = 0;
TIM4->DIER = 0;
TIM4->EGR = 0;
TIM4->CCMR1 = (0b110 << 4) | TIM_CCMR1_OC1PE |(0b110 << 12) | TIM_CCMR1_OC2PE;
TIM4->CCMR2 = (0b110 << 4) | TIM_CCMR2_OC3PE |(0b110 << 12) | TIM_CCMR2_OC4PE;
TIM4->CCER = TIM_CCER_CC1E | TIM_CCER_CC2E | TIM_CCER_CC3E | TIM_CCER_CC4E;
TIM4->PSC = 71;
TIM4->ARR = 4000;
TIM4->DCR = 0;
TIM4->CCR1 = 1000;
TIM4->CCR1 = channel_3;
TIM4->CCR2 = channel_3;
TIM4->CCR3 = channel_3;
TIM4->CCR4 = channel_3;
pinMode(PB6, PWM); // to have output signal on pin PB6
pinMode(PB7, PWM);
pinMode(PB8, PWM);
pinMode(PB9, PWM);
}
}
/*========================= handler_channel =================================*/
void handler_channel_1(void) { //This function is called when channel 1 is captured.
if (0b1 & GPIOA->IDR >> 0) { //If the receiver channel 1 input pulse on A0 is high.
channel_1_start = TIM2->CCR1; //Record the start time of the pulse.
TIM2->CCER |= TIM_CCER_CC1P; //Change the input capture mode to the falling edge of the pulse.
}
else { //If the receiver channel 1 input pulse on A0 is low.
channel_1 = TIM2->CCR1 - channel_1_start; //Calculate the total pulse time.
if (channel_1 < 0)channel_1 += 0xFFFF; //If the timer has rolled over a correction is needed.
TIM2->CCER &= ~TIM_CCER_CC1P; //Change the input capture mode to the rising edge of the pulse.
}
}
void handler_channel_2(void) { //This function is called when channel 2 is captured.
if (0b1 & GPIOA->IDR >> 1) { //If the receiver channel 2 input pulse on A1 is high.
channel_2_start = TIM2->CCR2; //Record the start time of the pulse.
TIM2->CCER |= TIM_CCER_CC2P; //Change the input capture mode to the falling edge of the pulse.
}
else { //If the receiver channel 2 input pulse on A1 is low.
channel_2 = TIM2->CCR2 - channel_2_start; //Calculate the total pulse time.
if (channel_2 < 0)channel_2 += 0xFFFF; //If the timer has rolled over a correction is needed.
TIM2->CCER &= ~TIM_CCER_CC2P; //Change the input capture mode to the rising edge of the pulse.
}
}
void handler_channel_3(void) { //This function is called when channel 3 is captured.
if (0b1 & GPIOA->IDR >> 2) { //If the receiver channel 3 input pulse on A2 is high.
channel_3_start = TIM2->CCR3; //Record the start time of the pulse.
TIM2->CCER |= TIM_CCER_CC3P; //Change the input capture mode to the falling edge of the pulse.
}
else { //If the receiver channel 3 input pulse on A2 is low.
channel_3 = TIM2->CCR3 - channel_3_start; //Calculate the total pulse time.
if (channel_3 < 0)channel_3 += 0xFFFF; //If the timer has rolled over a correction is needed.
TIM2->CCER &= ~TIM_CCER_CC3P; //Change the input capture mode to the rising edge of the pulse.
}
}
void handler_channel_4(void) { //This function is called when channel 4 is captured.
if (0b1 & GPIOA->IDR >> 3) { //If the receiver channel 4 input pulse on A3 is high.
channel_4_start = TIM2->CCR4; //Record the start time of the pulse.
TIM2->CCER |= TIM_CCER_CC4P; //Change the input capture mode to the falling edge of the pulse.
}
else { //If the receiver channel 4 input pulse on A3 is low.
channel_4 = TIM2->CCR4 - channel_4_start; //Calculate the total pulse time.
if (channel_4 < 0)channel_4 += 0xFFFF; //If the timer has rolled over a correction is needed.
TIM2->CCER &= ~TIM_CCER_CC4P; //Change the input capture mode to the rising edge of the pulse.
}
}
void handler_channel_5(void) { //This function is called when channel 5 is captured.
if (0b1 & GPIOA->IDR >> 6) { //If the receiver channel 5 input pulse on A6 is high.
channel_5_start = TIM3->CCR1; //Record the start time of the pulse.
TIM3->CCER |= TIM_CCER_CC1P; //Change the input capture mode to the falling edge of the pulse.
}
else { //If the receiver channel 5 input pulse on A6 is low.
channel_5 = TIM3->CCR1 - channel_5_start; //Calculate the total pulse time.
if (channel_5 < 0)channel_5 += 0xFFFF; //If the timer has rolled over a correction is needed.
TIM3->CCER &= ~TIM_CCER_CC1P; //Change the input capture mode to the rising edge of the pulse.
}
}
void handler_channel_6(void) { //This function is called when channel 6 is captured.
if (0b1 & GPIOA->IDR >> 7) { //If the receiver channel 6 input pulse on A7 is high.
channel_6_start = TIM3->CCR2; //Record the start time of the pulse.
TIM3->CCER |= TIM_CCER_CC2P; //Change the input capture mode to the falling edge of the pulse.
}
else { //If the receiver channel 6 input pulse on A7 is low.
channel_6 = TIM3->CCR2 - channel_6_start; //Calculate the total pulse time.
if (channel_6 < 0)channel_6 += 0xFFFF; //If the timer has rolled over a correction is needed.
TIM3->CCER &= ~TIM_CCER_CC2P; //Change the input capture mode to the rising edge of the pulse.
}
}