uint8_t OneTinyPpmGen::begin(uint8_t PpmModu, uint8_t ChNb, uint16_t PpmPeriod_us /*= DEFAULT_PPM_PERIOD*/) { boolean Ok = false; uint8_t Ch; _ChMaxNb = (ChNb > CHANNEL_MAX_NB)?CHANNEL_MAX_NB:ChNb; /* Max is 12 Channels */ _Next = (OneChSt_t *)malloc(sizeof(OneChSt_t) * (_ChMaxNb + 1)); /* + 1 for Synchro Channel */ Ok = (_Next != NULL); if (Ok) { _Idx = _ChMaxNb; /* To reload values at startup */ _PpmPeriod_us = PpmPeriod_us; if(_PpmPeriod_us < PPM_FRAME_MIN_PERIOD_US) _PpmPeriod_us = PPM_FRAME_MIN_PERIOD_US; if(_PpmPeriod_us < ((_ChMaxNb * (uint16_t)CHANNEL_MAX_US) + SYNCHRO_MIN_US)) _PpmPeriod_us = (_ChMaxNb * (uint16_t)CHANNEL_MAX_US) + SYNCHRO_MIN_US; if(_PpmPeriod_us > PPM_FRAME_MAX_PERIOD_US) _PpmPeriod_us = PPM_FRAME_MAX_PERIOD_US; for(Ch = 1; Ch <= _ChMaxNb; Ch++) /* Init all the channels to Neutral */ { setChWidth_us(Ch, PPM_NEUTRAL_US); } #if 1 #warning TO DO: fix issue with positive modulation ! (bad signal randomly generated) /* Set Pin as Output according to the PPM modulation level */ PPM_OC_DDR |= PPM_OC_PIN_MSK; /* Set pin as output */ if(PpmModu == TINY_PPM_GEN_NEG_MOD) { PPM_OC_PIN |= PPM_OC_PIN_MSK; /* Set pin to high */ } else { PPM_OC_PIN &= ~PPM_OC_PIN_MSK; /* Set pin to low */ } TIM_MODE_NORMAL(); if(PpmModu == TINY_PPM_GEN_POS_MOD) { PPM_OC_FORCE(); /* Force Output Compare to initialize properly the output */ } else delay(1); #else //test PPM_OC_DDR |= PPM_OC_PIN_MSK; /* Set pin as output */ TIM_MODE_NORMAL(); INIT_PPM_PIN(PpmModu); #endif TOGGLE_PPM_PIN_ENABLE(); PPM_OC_INT_ENABLE(); } return(Ok); }
uint8_t OneTinyPpmGen::begin(uint8_t PpmModu, uint8_t ChNb, uint16_t PpmPeriod_us /*= DEFAULT_PPM_PERIOD*/) { boolean Ok = false; uint8_t Ch; _ChMaxNb = (ChNb > 8)?8:ChNb; /* Max is 8 Channels */ _Ch = (ChSt_t *)malloc(sizeof(ChSt_t) * (_ChMaxNb + 1)); /* + 1 for Synchro Channel */ Ok = (_Ch != NULL); if (Ok) { _Idx = _ChMaxNb; /* To reload values at startup */ _PpmPeriod_us = PpmPeriod_us; if(_PpmPeriod_us < PPM_FRAME_MIN_PERIOD_US) _PpmPeriod_us = PPM_FRAME_MIN_PERIOD_US; if(_PpmPeriod_us > PPM_FRAME_MAX_PERIOD_US) _PpmPeriod_us = PPM_FRAME_MAX_PERIOD_US; for(Ch = 1; Ch <= _ChMaxNb; Ch++) { setChWidth_us(Ch, PPM_NEUTRAL_US); } /* Set Pin as Output according to the PPM modulation level */ PPM_OC_DDR |= PPM_OC_PIN_MSK; /* Set pin as output */ if(PpmModu == TINY_PPM_GEN_NEG_MOD) { PPM_OC_PIN |= PPM_OC_PIN_MSK; /* Set pin to high */ } else { PPM_OC_PIN &= ~PPM_OC_PIN_MSK; /* Set pin to low */ } TIM_MODE_NORMAL(); if(PpmModu == TINY_PPM_GEN_POS_MOD) { PPM_OC_FORCE(); /* Force Output Compare to initialize properly the output */ } else delay(1); TOGGLE_PPM_PIN_ENABLE(); PPM_OC_INT_ENABLE(); } return(Ok); }