61,18 → 61,17 |
#define CR1_OLVL1_MASK 0x0100 |
#define CR1_OLVL2_MASK 0x0200 |
|
ServoParams_t ServoParams; |
|
#define TIM2_FREQ 625000 // 625kHz, the same clock like at the FC |
// frame len 22.5 ms = 14063 * 1.6 us |
// stop pulse: 0.3 ms = 188 * 1.6 us |
// min servo pulse: 0.6 ms = 375 * 1.6 us |
// max servo pulse: 2.4 ms = 1500 * 1.6 us |
// resolution: 1500 - 375 = 1125 steps |
|
|
ServoParams_t ServoParams; |
|
#define PPM_STOPPULSE 188 |
#define PPM_FRAMELEN 14063 |
//#define PPM_FRAMELEN (1757 * ParamSet.ServoRefresh) // 22.5 ms / 8 Channels = 2.8125ms per Servo Channel |
//#define PPM_FRAMELEN (1757 * ServoParams.Refresh) // 22.5 ms / 8 Channels = 2.8125ms per Servo Channel |
#define MINSERVOPULSE 375 |
#define MAXSERVOPULSE 1500 |
#define SERVORANGE (MAXSERVOPULSE - MINSERVOPULSE) |
92,6 → 91,7 |
if (TIM2->CR1 & CR1_OLVL1_MASK) // start of high pulse |
{ |
pulselen = MINSERVOPULSE + SERVORANGE/2; |
// input code for nick servo here |
LowPulseTime1 = PPM_FRAMELEN - pulselen; |
TIM2->CR1 &= ~CR1_OLVL1_MASK; // make next a low pulse |
} |
109,13 → 109,14 |
if (TIM2->CR1 & CR1_OLVL2_MASK) // was high pulse |
{ |
pulselen = MINSERVOPULSE + SERVORANGE/2; |
// input code for roll servo here |
LowPulseTime2 = PPM_FRAMELEN - pulselen; |
TIM2->CR1 &= ~CR1_OLVL2_MASK; // make low pulse |
TIM2->CR1 &= ~CR1_OLVL2_MASK; // make next a low pulse |
} |
else |
{ |
pulselen = LowPulseTime2; |
TIM2->CR1 |= CR1_OLVL2_MASK; |
TIM2->CR1 |= CR1_OLVL2_MASK; // make next a high pulse |
} |
TIM2->OC2R += pulselen; |
TIM_ClearFlag(TIM2, TIM_FLAG_OC2); // clear irq pending bit |
133,11 → 134,8 |
GPIO_InitTypeDef GPIO_InitStructure; |
TIM_InitTypeDef TIM_InitStructure; |
|
UART1_PutString("Timer2 init..."); |
UART1_PutString("\r\n Timer2 init..."); |
|
#define TIM2_FREQ 625000 // 625kHz |
|
|
SCU_APBPeriphClockConfig(__GPIO6, ENABLE); // Enable the GPIO6 Clock |
|
// configure the servo pins |
159,18 → 157,20 |
|
SCU_APBPeriphClockConfig(__TIM23, ENABLE); |
|
TIM_DeInit(TIM2); |
TIM_StructInit(&TIM_InitStructure); |
TIM_InitStructure.TIM_Mode = TIM_OCM_CHANNEL_12; |
TIM_InitStructure.TIM_OC1_Modes = TIM_TIMING; |
TIM_InitStructure.TIM_OC2_Modes = TIM_TIMING; |
TIM_InitStructure.TIM_Clock_Source = TIM_CLK_APB; |
TIM_InitStructure.TIM_Pulse_Level_1 = TIM_LOW; |
TIM_InitStructure.TIM_Pulse_Level_2 = TIM_LOW; |
TIM_InitStructure.TIM_Mode = TIM_OCM_CHANNEL_12; // Output Compare Channels 1 & 2 Mode |
TIM_InitStructure.TIM_OC1_Modes = TIM_WAVE; // OCMP1 pin is dedicated to the OC1 capability of the TIM |
TIM_InitStructure.TIM_OC2_Modes = TIM_WAVE; // OCMP2 pin is dedicated to the OC2 capability of the TIM |
TIM_InitStructure.TIM_Clock_Source = TIM_CLK_APB; // APB clock source is used |
TIM_InitStructure.TIM_Pulse_Level_1 = TIM_LOW; // output low at OCMP1 pin on compare match |
TIM_InitStructure.TIM_Pulse_Level_2 = TIM_LOW; // output low at OCMP2 pin on compare match |
TIM_InitStructure.TIM_Prescaler = (SCU_GetPCLKFreqValue() * 1000) / TIM2_FREQ; |
|
TIM_Init(TIM2, &TIM_InitStructure); |
|
TIM_ITConfig(TIM2, TIM_IT_OC1|TIM_IT_OC2, ENABLE); |
TIM_CounterCmd(TIM2, TIM_START); |
TIM_ITConfig(TIM2, TIM_IT_OC1|TIM_IT_OC2, ENABLE); // enable interrupts for the OC 1 & 2 |
TIM_CounterCmd(TIM2, TIM_START); // start the timer |
|
VIC_Config(TIM2_ITLine, VIC_IRQ, 3); |
VIC_ITCmd(TIM2_ITLine, ENABLE); |
186,6 → 186,6 |
ServoParams.RollMin = 50; |
ServoParams.RollMax = 205; |
|
UART1_PutString("ok\n\r"); |
UART1_PutString("ok"); |
} |
|