Ver código fonte

Configure 38 kHz PWM output on A8

Clara Hobbs 7 anos atrás
pai
commit
31d5488170
3 arquivos alterados com 19 adições e 11 exclusões
  1. 1
    1
      halconf.h
  2. 1
    1
      mcuconf.h
  3. 17
    9
      src/main.c

+ 1
- 1
halconf.h Ver arquivo

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

+ 1
- 1
mcuconf.h Ver arquivo

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

+ 17
- 9
src/main.c Ver arquivo

@@ -34,7 +34,20 @@
34 34
 
35 35
 #include "ch.h"
36 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 53
  * Green LED blinker thread, times are in milliseconds.
@@ -43,7 +56,6 @@ static THD_WORKING_AREA(waThread1, 128);
43 56
 static THD_FUNCTION(Thread1, arg) {
44 57
 
45 58
     (void)arg;
46
-    chRegSetThreadName("blinker");
47 59
     while (true) {
48 60
         palClearPad(GPIOC, GPIOC_LED);
49 61
         chThdSleepMilliseconds(500);
@@ -67,23 +79,19 @@ int main(void) {
67 79
     halInit();
68 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 83
      * Creates the blinker thread.
77 84
      */
78 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 91
      * Normal main() thread activity, in this demo it does nothing except
82 92
      * sleeping in a loop and check the button state.
83 93
      */
84 94
     while (true) {
85
-        //if (!palReadPad(GPIOC, GPIOC_BUTTON))
86
-        //  test_execute((BaseSequentialStream *)&SD2);
87 95
         chThdSleepMilliseconds(500);
88 96
     }
89 97
 }

Carregando…
Cancelar
Salvar