|
@@ -48,7 +48,7 @@ void Board_Init(void)
|
|
|
ADC_Init();
|
|
|
|
|
|
TIM1_Init();
|
|
|
- TIM3_Init();
|
|
|
+ //TIM3_Init();
|
|
|
|
|
|
//IWDG_Init();
|
|
|
}
|
|
@@ -87,30 +87,24 @@ void SystemClock_Config(void)
|
|
|
static void GPIO_Init(void)
|
|
|
{
|
|
|
/* Servo_1_Pin, Servo_2_Pin - Servos control, Alt PP out, middle speed */
|
|
|
- GPIO_SetAFPin_8_15(Servo_1_Port, (Servo_1_Pin|Servo_2_Pin), GPIO_AF_2);
|
|
|
- GPIO_SetPinOutputType(Servo_1_Port, (Servo_1_Pin|Servo_2_Pin), GPIO_OTYPE_PP);
|
|
|
- GPIO_SetPinPull(Servo_1_Port, (Servo_1_Pin|Servo_2_Pin), GPIO_PUPDR_NO);
|
|
|
- GPIO_SetPinSpeed(Servo_1_Port, (Servo_1_Pin|Servo_2_Pin), GPIO_OSPEED_LW);
|
|
|
- GPIO_SetPinMode(Servo_1_Port, (Servo_1_Pin|Servo_2_Pin), GPIO_MODE_AFF);
|
|
|
-
|
|
|
- GPIO_SetAFPin_0_7(GPIOB, GPIO_PIN_3, GPIO_AF_1);
|
|
|
- GPIO_SetPinOutputType(GPIOB, GPIO_PIN_3, GPIO_OTYPE_PP);
|
|
|
- GPIO_SetPinPull(GPIOB, GPIO_PIN_3, GPIO_PUPDR_NO);
|
|
|
- GPIO_SetPinSpeed(GPIOB, GPIO_PIN_3, GPIO_OSPEED_LW);
|
|
|
- GPIO_SetPinMode(GPIOB, GPIO_PIN_3, GPIO_MODE_AFF);
|
|
|
+ GPIO_SetAFPin_8_15(Servo_1_Port, Servo_1_Pin, GPIO_AF_2);
|
|
|
+ GPIO_SetPinOutputType(Servo_1_Port, Servo_1_Pin, GPIO_OTYPE_PP);
|
|
|
+ GPIO_SetPinPull(Servo_1_Port, Servo_1_Pin, GPIO_PUPDR_NO);
|
|
|
+ GPIO_SetPinSpeed(Servo_1_Port, Servo_1_Pin, GPIO_OSPEED_LW);
|
|
|
+ GPIO_SetPinMode(Servo_1_Port, Servo_1_Pin, GPIO_MODE_AFF);
|
|
|
+
|
|
|
+ GPIO_SetAFPin_0_7(Servo_2_Port, Servo_2_Pin, GPIO_AF_1);
|
|
|
+ GPIO_SetPinOutputType(Servo_2_Port, Servo_2_Pin, GPIO_OTYPE_PP);
|
|
|
+ GPIO_SetPinPull(Servo_2_Port, Servo_2_Pin, GPIO_PUPDR_NO);
|
|
|
+ GPIO_SetPinSpeed(Servo_2_Port, Servo_2_Pin, GPIO_OSPEED_LW);
|
|
|
+ GPIO_SetPinMode(Servo_2_Port, Servo_2_Pin, GPIO_MODE_AFF);
|
|
|
|
|
|
/* Photo_Pin: analog in, pull none */
|
|
|
GPIO_SetPinPull(Photo_Port, Photo_Pin, GPIO_PUPDR_NO);
|
|
|
GPIO_SetPinMode(Photo_Port, Photo_Pin, GPIO_MODE_ANL);
|
|
|
|
|
|
- /* Test out Pin A4 */
|
|
|
- GPIO_SetPinMode(GPIOA, GPIO_PIN_4, GPIO_MODE_OUT);
|
|
|
- //GPIO_SetPinOutputType(GPIOA, GPIO_PIN_4, GPIO_OTYPE_PP);
|
|
|
- //GPIO_SetPinSpeed(GPIOA, GPIO_PIN_4, GPIO_OSPEED_LW);
|
|
|
- //GPIO_SetPinPull(GPIOA, GPIO_PIN_4, GPIO_PUPDR_NO);
|
|
|
-
|
|
|
- /* Test in Pin A5 */
|
|
|
- GPIO_SetPinPull(GPIOA, GPIO_PIN_5, GPIO_PUPDR_UP);
|
|
|
+ /* Num of chnls select pin */
|
|
|
+ GPIO_SetPinPull(Select_Port, Select_Pin, GPIO_PUPDR_UP);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -130,8 +124,6 @@ static void ADC_Init(void)
|
|
|
//ADC synchronous clock derived from AHB clock divided by 2
|
|
|
ADC1->CFGR2 |= ADC_CFGR2_CKMODE_0;
|
|
|
|
|
|
- /* Poll for ADC channel configuration ready */
|
|
|
- //while ((ADC1->ISR & ADC_ISR_CCRDY) == 0) {};
|
|
|
/* Clear flag ADC channel configuration ready */
|
|
|
ADC1->ISR |= ADC_ISR_CCRDY;
|
|
|
|
|
@@ -172,9 +164,6 @@ static void ADC_Init(void)
|
|
|
*/
|
|
|
static void TIM1_Init(void)
|
|
|
{
|
|
|
- /* TIM1 interrupt Init */
|
|
|
- //NVIC_SetPriority(TIM1_BRK_UP_TRG_COM_IRQn, 0);
|
|
|
- //NVIC_EnableIRQ(TIM1_BRK_UP_TRG_COM_IRQn);
|
|
|
/* target clock */
|
|
|
TIM1->PSC = TIM1_PSC; // prescaler
|
|
|
TIM1->ARR = TIM1_ARR; // auto reload value
|
|
@@ -186,17 +175,13 @@ static void TIM1_Init(void)
|
|
|
// pwm mode 1 for chanels
|
|
|
TIM1->CCMR1 = (TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC1PE);
|
|
|
TIM1->CCMR1 |= (TIM_CCMR1_OC2M_1 | TIM_CCMR1_OC2M_2 | TIM_CCMR1_OC2PE);
|
|
|
- TIM1->CCMR2 = (TIM_CCMR2_OC4M_1 | TIM_CCMR2_OC4M_2 | TIM_CCMR2_OC4PE);
|
|
|
//TIM1->SR |= TIM_SR_UIF;
|
|
|
TIM1->BDTR = TIM_BDTR_MOE; // enable main output
|
|
|
TIM1->EGR = TIM_EGR_UG; // force timer update
|
|
|
/* TIM1 CC_EnableChannel */
|
|
|
- TIM1->CCER = (TIM_CCER_CC1E | TIM_CCER_CC1P | TIM_CCER_CC4E | TIM_CCER_CC4P);
|
|
|
- TIM1->CCER |= (TIM_CCER_CC2E | TIM_CCER_CC2P);
|
|
|
+ TIM1->CCER = (TIM_CCER_CC1E | TIM_CCER_CC1P | TIM_CCER_CC2E | TIM_CCER_CC2P);
|
|
|
/* Set the trigger output 2 (TRGO2) used for ADC synchronization */
|
|
|
TIM1->CR2 |= TIM_CR2_MMS2_1; // update event
|
|
|
- /* Enable interrupts */
|
|
|
- //TIM1->DIER = TIM_DIER_UIE;
|
|
|
/* TIM_EnableCounter */
|
|
|
TIM1->CR1 |= TIM_CR1_CEN;
|
|
|
}
|