Browse Source

Configure 38 kHz PWM output on A8

Clara Hobbs 6 years ago
parent
commit
31d5488170
3 changed files with 19 additions and 11 deletions
  1. 1
    1
      halconf.h
  2. 1
    1
      mcuconf.h
  3. 17
    9
      src/main.c

+ 1
- 1
halconf.h View File

111
  * @brief   Enables the PWM subsystem.
111
  * @brief   Enables the PWM subsystem.
112
  */
112
  */
113
 #if !defined(HAL_USE_PWM) || defined(__DOXYGEN__)
113
 #if !defined(HAL_USE_PWM) || defined(__DOXYGEN__)
114
-#define HAL_USE_PWM                 FALSE
114
+#define HAL_USE_PWM                 TRUE
115
 #endif
115
 #endif
116
 
116
 
117
 /**
117
 /**

+ 1
- 1
mcuconf.h View File

132
  * PWM driver system settings.
132
  * PWM driver system settings.
133
  */
133
  */
134
 #define STM32_PWM_USE_ADVANCED              FALSE
134
 #define STM32_PWM_USE_ADVANCED              FALSE
135
-#define STM32_PWM_USE_TIM1                  FALSE
135
+#define STM32_PWM_USE_TIM1                  TRUE
136
 #define STM32_PWM_USE_TIM2                  FALSE
136
 #define STM32_PWM_USE_TIM2                  FALSE
137
 #define STM32_PWM_USE_TIM3                  FALSE
137
 #define STM32_PWM_USE_TIM3                  FALSE
138
 #define STM32_PWM_USE_TIM4                  FALSE
138
 #define STM32_PWM_USE_TIM4                  FALSE

+ 17
- 9
src/main.c View File

34
 
34
 
35
 #include "ch.h"
35
 #include "ch.h"
36
 #include "hal.h"
36
 #include "hal.h"
37
-#include "ch_test.h"
37
+
38
+static PWMConfig pwmcfg = {
39
+    380000,                                  /* 1MHz PWM clock frequency. */
40
+    10,                                     /* Initial PWM period 1ms.   */
41
+    NULL,
42
+    {
43
+        {PWM_OUTPUT_ACTIVE_HIGH, NULL},
44
+        {PWM_OUTPUT_DISABLED, NULL},
45
+        {PWM_OUTPUT_DISABLED, NULL},
46
+        {PWM_OUTPUT_DISABLED, NULL}
47
+    },
48
+    0,
49
+    0
50
+};
38
 
51
 
39
 /*
52
 /*
40
  * Green LED blinker thread, times are in milliseconds.
53
  * Green LED blinker thread, times are in milliseconds.
43
 static THD_FUNCTION(Thread1, arg) {
56
 static THD_FUNCTION(Thread1, arg) {
44
 
57
 
45
     (void)arg;
58
     (void)arg;
46
-    chRegSetThreadName("blinker");
47
     while (true) {
59
     while (true) {
48
         palClearPad(GPIOC, GPIOC_LED);
60
         palClearPad(GPIOC, GPIOC_LED);
49
         chThdSleepMilliseconds(500);
61
         chThdSleepMilliseconds(500);
67
     halInit();
79
     halInit();
68
     chSysInit();
80
     chSysInit();
69
 
81
 
70
-    /*
71
-     * Activates the serial driver 2 using the driver default configuration.
72
-     */
73
-    sdStart(&SD2, NULL);
74
-
75
     /*
82
     /*
76
      * Creates the blinker thread.
83
      * Creates the blinker thread.
77
      */
84
      */
78
     chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
85
     chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
79
 
86
 
87
+    pwmStart(&PWMD1, &pwmcfg);
88
+    palSetPadMode(GPIOA, 8, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
89
+    pwmEnableChannel(&PWMD1, 0, PWM_PERCENTAGE_TO_WIDTH(&PWMD1, 5000));
80
     /*
90
     /*
81
      * Normal main() thread activity, in this demo it does nothing except
91
      * Normal main() thread activity, in this demo it does nothing except
82
      * sleeping in a loop and check the button state.
92
      * sleeping in a loop and check the button state.
83
      */
93
      */
84
     while (true) {
94
     while (true) {
85
-        //if (!palReadPad(GPIOC, GPIOC_BUTTON))
86
-        //  test_execute((BaseSequentialStream *)&SD2);
87
         chThdSleepMilliseconds(500);
95
         chThdSleepMilliseconds(500);
88
     }
96
     }
89
 }
97
 }

Loading…
Cancel
Save