diff options
Diffstat (limited to 'testhal/STM32/PWM-ICU')
-rw-r--r-- | testhal/STM32/PWM-ICU/main.c | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/testhal/STM32/PWM-ICU/main.c b/testhal/STM32/PWM-ICU/main.c index 3f7b6423e..1fd56c33a 100644 --- a/testhal/STM32/PWM-ICU/main.c +++ b/testhal/STM32/PWM-ICU/main.c @@ -89,7 +89,7 @@ int main(void) { palSetPad(IOPORT3, GPIOC_LED);
/*
- * Initializes the PWM driver 1.
+ * Initializes the PWM driver 1 and ICU driver 4.
*/
pwmStart(&PWMD1, &pwmcfg);
palSetPadMode(IOPORT1, 8, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
@@ -98,26 +98,32 @@ int main(void) { chThdSleepMilliseconds(2000);
/*
- * Starts the channel 0 using 25% duty cycle.
+ * Starts the PWM channel 0 using 75% duty cycle.
*/
- pwmEnableChannel(&PWMD1, 0, PWM_PERCENTAGE_TO_WIDTH(&PWMD1, 2500));
+ pwmEnableChannel(&PWMD1, 0, PWM_PERCENTAGE_TO_WIDTH(&PWMD1, 7500));
chThdSleepMilliseconds(5000);
/*
- * Changes the channel 0 to 75% duty cycle.
+ * Changes the PWM channel 0 to 50% duty cycle.
*/
- pwmEnableChannel(&PWMD1, 0, PWM_PERCENTAGE_TO_WIDTH(&PWMD1, 7500));
+ pwmEnableChannel(&PWMD1, 0, PWM_PERCENTAGE_TO_WIDTH(&PWMD1, 5000));
+ chThdSleepMilliseconds(5000);
+
+ /*
+ * Changes the PWM channel 0 to 25% duty cycle.
+ */
+ pwmEnableChannel(&PWMD1, 0, PWM_PERCENTAGE_TO_WIDTH(&PWMD1, 2500));
chThdSleepMilliseconds(5000);
/*
- * Changes PWM period to half second and duty cycle to 50%.
+ * Changes PWM period to half second the duty cycle becomes 50%
+ * implicitly.
*/
pwmChangePeriod(&PWMD1, 5000);
- pwmEnableChannel(&PWMD1, 0, PWM_PERCENTAGE_TO_WIDTH(&PWMD1, 5000));
chThdSleepMilliseconds(5000);
/*
- * Disables channel 0.
+ * Disables channel 0 and stops the drivers.
*/
pwmDisableChannel(&PWMD1, 0);
pwmStop(&PWMD1);
|