// Public Methods //////////////////////////////////////////////////////////////
// Public Methods //////////////////////////////////////////////////////////////
voidAPM_RC_Class::Init(void)
voidAPM_RC_Class::Init(void)
{
{
// Init PPM input
pinMode(49,INPUT);// ICP4 pin (PL0) (PPM input)
// Init PWM Timer 1
// Init PWM Timer 1
pinMode(11,OUTPUT);// (PB5/OC1A)
pinMode(11,OUTPUT);// (PB5/OC1A)
pinMode(12,OUTPUT);// OUT3 (PB6/OC1B)
pinMode(12,OUTPUT);//OUT2 (PB6/OC1B)
pinMode(13,OUTPUT);// OUT4 (PB7/OC1C)
pinMode(13,OUTPUT);//OUT3 (PB7/OC1C)
// Init PWM Timer 3
pinMode(2,OUTPUT);// OUT8 (PE4/OC3B)
pinMode(3,OUTPUT);// OUT7 (PE5/OC3C)
pinMode(4,OUTPUT);// (PE3/OC3A)
// Init PWM Timer 4
// not avail // (PH3/OC4A)
pinMode(7,OUTPUT);// OUT6 (PH4/OC4B)
pinMode(8,OUTPUT);// OUT5 (PH5/OC4C)
// Init PWM Timer 5
pinMode(44,OUTPUT);// OUT2 (PL5/OC5C)
pinMode(45,OUTPUT);// OUT1 (PL4/OC5B)
pinMode(46,OUTPUT);// (PL3/OC5A)
//Remember the registers not declared here remains zero by default...
TCCR1A=((1<<WGM11)|(1<<COM1A1)|(1<<COM1B1)|(1<<COM1C1));//Please read page 131 of DataSheet, we are changing the registers settings of WGM11,COM1B1,COM1A1 to 1 thats all...
TCCR1A=((1<<WGM11)|(1<<COM1A1)|(1<<COM1B1)|(1<<COM1C1));//Please read page 131 of DataSheet, we are changing the registers settings of WGM11,COM1B1,COM1A1 to 1 thats all...
TCCR1B=(1<<WGM13)|(1<<WGM12)|(1<<CS11);//Prescaler set to 8, that give us a resolution of 0.5us, read page 134 of data sheet
TCCR1B=(1<<WGM13)|(1<<WGM12)|(1<<CS11);//Prescaler set to 8, that give us a resolution of 0.5us, read page 134 of data sheet
ICR1=40000;// 50hz freq...Datasheet says (system_freq/prescaler)/target frequency. So (16000000hz/8)/50hz=40000,
OCR1A=3000;//PB5, none
OCR1A=3000;//PB5, none
OCR1B=3000;// PB6, OUT3
//OCR1B = 3000; //PB6, OUT2
OCR1C=3000;// PB7, OUT4
//OCR1C = 3000; //PB7 OUT3
ICR1=40000;//50hz freq...Datasheet says (system_freq/prescaler)/target frequency. So (16000000hz/8)/50hz=40000,