Browse Source

Single channel branch.

Vladimir N. Shilov 3 months ago
parent
commit
6b2da89b5a
3 changed files with 31 additions and 13 deletions
  1. 16 8
      inc/board.h
  2. 6 0
      src/board.c
  3. 9 5
      src/main.c

+ 16 - 8
inc/board.h

@@ -6,11 +6,13 @@
 /* Includes */
 #include "main.h"
 #include "gpio.h"
-//#include "xprintf.h"
 
 /* Type Defs */
 /* Exported macros */
 /* Constants */
+#define USE_SERVO_1         true
+//#define USE_SERVO_2         true
+
 /* PWM Timers for 50 Hz */
 #define TIM1_PSC            (24 - 1)
 #define TIM1_ARR            (20000 - 1)
@@ -25,17 +27,23 @@
 #define Select_Port   GPIOA
 #define Photo_Pin     GPIO_PIN_7
 #define Photo_Port    GPIOB
-#define Servo_1_Pin   GPIO_PIN_3
-#define Servo_1_Port  GPIOB
-#define Servo_1_CHNL  TIM1->CCR2
-#define Servo_1_ON    GPIO_SetPinMode(Servo_1_Port, Servo_1_Pin, GPIO_MODE_AFF)
-#define Servo_1_OFF   GPIO_SetPinMode(Servo_1_Port, Servo_1_Pin, GPIO_MODE_IN)
+#ifdef USE_SERVO_1
+  #define Servo_1_Pin   GPIO_PIN_3
+  #define Servo_1_Port  GPIOB
+  #define Servo_1_CHNL  TIM1->CCR2
+  #define Servo_1_ON    {}
+  //GPIO_SetPinMode(Servo_1_Port, Servo_1_Pin, GPIO_MODE_AFF)
+  #define Servo_1_OFF   {}
+  //GPIO_SetPinMode(Servo_1_Port, Servo_1_Pin, GPIO_MODE_IN)
+#endif
 #ifdef USE_SERVO_2
   #define Servo_2_Pin   GPIO_PIN_8
   #define Servo_2_Port  GPIOA
   #define Servo_2_CHNL  TIM1->CCR1
-  #define Servo_2_ON    GPIO_SetPinMode(Servo_2_Port, Servo_2_Pin, GPIO_MODE_AFF)
-  #define Servo_2_OFF   GPIO_SetPinMode(Servo_2_Port, Servo_2_Pin, GPIO_MODE_IN)
+  #define Servo_2_ON    {}
+  //GPIO_SetPinMode(Servo_2_Port, Servo_2_Pin, GPIO_MODE_AFF)
+  #define Servo_2_OFF   {}
+  //GPIO_SetPinMode(Servo_2_Port, Servo_2_Pin, GPIO_MODE_IN)
 #endif
 
 /* Variables */

+ 6 - 0
src/board.c

@@ -87,11 +87,13 @@ void SystemClock_Config(void)
 static void GPIO_Init(void)
 {
   /* Servo_1_Pin, Servo_2_Pin - Servos control, Alt PP out, middle speed */
+#ifdef USE_SERVO_1
   GPIO_SetAFPin_0_7(Servo_1_Port, Servo_1_Pin, GPIO_AF_1);
   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);
+#endif
 #ifdef USE_SERVO_2
   GPIO_SetAFPin_8_15(Servo_2_Port, Servo_2_Pin, GPIO_AF_2);
   GPIO_SetPinOutputType(Servo_2_Port, Servo_2_Pin, GPIO_OTYPE_PP);
@@ -174,7 +176,9 @@ static void TIM1_Init(void)
   TIM1->CCR2 = SERVO_INIT_VAL;
   TIM1->CCR4 = SERVO_INIT_VAL;
   // pwm mode 1 for chanels
+#ifdef USE_SERVO_1
   TIM1->CCMR1 = (TIM_CCMR1_OC2M_1 | TIM_CCMR1_OC2M_2 | TIM_CCMR1_OC2PE);
+#endif
 #ifdef USE_SERVO_2
   TIM1->CCMR1 |= (TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC1PE);
 #endif
@@ -182,7 +186,9 @@ static void TIM1_Init(void)
   TIM1->BDTR = TIM_BDTR_MOE; // enable main output
   TIM1->EGR = TIM_EGR_UG; // force timer update
   /* TIM1 CC_EnableChannel */
+#ifdef USE_SERVO_1
   TIM1->CCER = (TIM_CCER_CC2E | TIM_CCER_CC2P);
+#endif
 #ifdef USE_SERVO_2
   TIM1->CCER |= (TIM_CCER_CC1E | TIM_CCER_CC1P);
 #endif

+ 9 - 5
src/main.c

@@ -22,8 +22,8 @@
 /* Private includes ----------------------------------------------------------*/
 /* Private typedef -----------------------------------------------------------*/
 /* Private define ------------------------------------------------------------*/
-#define PHOTO_LEVEL_ON  (200)
-#define PHOTO_LEVEL_OFF (2000)
+#define PHOTO_LEVEL_ON  (100)
+#define PHOTO_LEVEL_OFF (1000)
 
 /* Private macro -------------------------------------------------------------*/
 /* Private variables ---------------------------------------------------------*/
@@ -47,22 +47,24 @@ int main(void)
   /* Initialize onBoard Hardware */
   Board_Init();
 
+#ifdef USE_SERVO_1
   Servo_1_ON;
   Servo_1_CHNL = SERVO_INIT_VAL;
   Servo_1_OFF;
+#endif
 
 #ifdef USE_SERVO_2
   Servo_2_ON;
   Servo_2_CHNL = SERVO_INIT_VAL;
   Servo_2_OFF;
-
+#endif
+/*
   if ((Select_Port->IDR & Select_Pin) == 0) {
     Flag.ONE_CHANNEL = 1;
   } else {
     Flag.ONE_CHANNEL = 0;
   }
-#endif
-
+*/
   /* if light is on, wait for off */
   while (photo_Value <= PHOTO_LEVEL_OFF) {
     //IWDG->KR = 0xAAAA;
@@ -72,6 +74,7 @@ int main(void)
   /* Infinite loop */
   while (1)
   {
+#ifdef USE_SERVO_1
     /* wait for light on */
     while (photo_Value > PHOTO_LEVEL_ON) {
       //IWDG->KR = 0xAAAA;
@@ -91,6 +94,7 @@ int main(void)
     Servo_1_ON;
     Servo_1_CHNL = SERVO_INIT_VAL;
     Servo_1_OFF;
+#endif
     
 #ifdef USE_SERVO_2
     /* wait for light on */