Subversion Repositories NaviCtrl

Compare Revisions

Ignore whitespace Rev 119 → Rev 120

/trunk/Navi-Ctrl.Uv2
71,6 → 71,7
File 2,5,<.\mkprotocol.h><mkprotocol.h>
File 2,5,<.\timer1.h><timer1.h>
File 2,5,<.\timer2.h><timer2.h>
File 2,5,<.\91x_conf.h><91x_conf.h>
File 3,2,<.\startup912.s><startup912.s>
File 4,1,<.\libstr91x\src\91x_scu.c><91x_scu.c>
File 4,1,<.\libstr91x\src\91x_gpio.c><91x_gpio.c>
/trunk/main.c
198,13 → 198,13
Interrupt_Init();
// initialize timer 1 for System Clock and delay rountines
TIMER1_Init();
// initialize timer 2 for servo outputs
TIMER2_Init();
// initialize the LEDs (needs Timer 1)
Led_Init();
// initialize the debug UART1
UART1_Init();
UART1_PutString("\r\n---------------------------------------------");
// initialize timer 2 for servo outputs
TIMER2_Init();
// initialize UART2 to FLIGHTCTRL
UART2_Init();
// initialize UART0 (to MKGPS or MK3MAG)
263,7 → 263,6
USB_TransmitTxData(); // send answer
 
SPI0_UpdateBuffer();
 
// ------------------------- I2C Timing --------------------------------
if(I2C_State != I2C_OFF)
{
/trunk/timer1.c
82,7 → 82,7
{
TIM_InitTypeDef TIM_InitStructure;
 
UART1_PutString("Timer1 init...");
UART1_PutString("\r\n Timer1 init...");
 
#define TIM1_FREQ 200000 // 200kHz
// TimerOCR set in IntHandler
89,6 → 89,7
 
SCU_APBPeriphClockConfig(__TIM01, ENABLE);
 
TIM_DeInit(TIM1);
TIM_StructInit(&TIM_InitStructure);
TIM_InitStructure.TIM_Mode = TIM_OCM_CHANNEL_1;
TIM_InitStructure.TIM_OC1_Modes = TIM_TIMING;
113,7 → 114,7
 
CountMilliseconds = 0;
 
UART1_PutString("ok\n\r");
UART1_PutString("ok");
 
}
 
/trunk/timer2.c
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");
}