The minimal not workingMy testing code is:
// using a 16-bit timer to generate PWM signals for ESCs
// Phase Correct Mode counts from Bottom to Top and back to Bottom
// settingwith thea rangeprescaler toof 8
// motor signal (BOTTOMOCRnx) 0uses values of 1000 (idle) - 20482000 (TOPvaluemax)
// we need a prescalerwhich ofdirectly 8corresponds to get 488.28microseconds HzHIGH-time
// whichsetting isthe max,range sinceto 2000(BOTTOM) is0 nearly- fullTOPvalue dutycyclesets the frequency
// Motortwo signalimportant formulas are:
// frequency(OCRnxPWM) uses= valuesF_CPU of/ 1000-2000(2*Prescalar*TOPvalue)
//
// whichPulseWidth directly[s] corresponds= toHigh-tick-count microseconds/ HIGH(F_CPU/Prescalar)
// High-timetick-count = 2 * OCR-value
// n = number of timer (1,3)
// x = A,B,C
#include "Arduino.h"
// #include <Arduino.h>
// #define DEBUG
// #include <Moto.h>
#define PRESCALAR 8
#define PWM_FREQUENCY 50
#define TOP_VALUE F_CPU/(2*PRESCALAR*PWM_FREQUENCY)
uint16_t dutytime = 1000; // this gives idle throttle signal
void setup(void) {
Serial.begin(115200);
// moto.setup();
// TIMER 1
// TIMSK1 = 0; // disable Interrupts for timer1
DDRB |= (1<<DDB5); // D9 Output
DDRC |= (1<<DDC6); // D5 Output
// set 1000ms to start motors in idle mode
OCR1A = 1000L;
OCR3A = 1000L;
// bits 7,5,3 PWM Output on pins A,B,C respectively
// bits 1,0 WGM_1,0: phase correction mode
// TCCR1A |= 0x82;B10000010; // in hex: 0xAA for all 3 = 0bB 1010 1010
TCCR1A |= (1<<COM1A1)|(1<<WGM11);
// bit 4,3 WGM_3,2: phase correction mode
// bits 2,1,0 Prescalar: 8
// TCCR1B |= 0x12;B00010010; // 0bin hex: 0x12; B 0001 0010
ICR1TCCR1B =|= 2500;(1<<WGM13)|(1<<CS11);
// TOPvalueICR1 = 2500TOP_VALUE;
// TIMER 3
// TIMSK3 = 0; // disable Interrupts for timer3
// bit 7 PWM Output on pin A
// bits 1,0 WGM_1,0: phase correction mode
TCCR3A |= B10000010; // in hex: 0x82; // 0bB 1000 0010
// bit 4,3 WGM_3,2: phase correction mode
// bits 2,1,0 Prescalar: 8
TCCR3B |= 0x12;B00010010; // 0bin hex: 0x12; B 0001 0010
ICR3 = 2500;TOP_VALUE; // TOPvalue = 2048
OCR1A = dutytime;}//setup
OCR3A
void =loop(void) dutytime;{
// delaySerial.println(1000TOP_VALUE);
} //setup
void loopdelay(void500) {;
while (dutytime < 2000) {
dutytime += 10;150;
OCR1A = dutytime;
OCR3A = dutytime;
Serial.println(dutytime);
delay(10001500);
}
while (dutytime > 1000) {
dutytime -= 10;150;
OCR1A = dutytime;
OCR3A = dutytime;
Serial.println(dutytime);
delay(10001500);
}
}//loop