aboutsummaryrefslogtreecommitdiffstats
path: root/testhal/STM32/PWM
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2011-03-31 10:21:52 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2011-03-31 10:21:52 +0000
commita58a524d4c7e58d03a0fa3698f09fb17985a70bc (patch)
tree561b345be6af1915bff26496f4dab45fdf666c2c /testhal/STM32/PWM
parent8cdc7bd8f3987116d89c0a9d1a624127f8652ac0 (diff)
downloadChibiOS-a58a524d4c7e58d03a0fa3698f09fb17985a70bc.tar.gz
ChibiOS-a58a524d4c7e58d03a0fa3698f09fb17985a70bc.tar.bz2
ChibiOS-a58a524d4c7e58d03a0fa3698f09fb17985a70bc.zip
Improvements to the PWM driver.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2853 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'testhal/STM32/PWM')
-rw-r--r--testhal/STM32/PWM/main.c40
1 files changed, 17 insertions, 23 deletions
diff --git a/testhal/STM32/PWM/main.c b/testhal/STM32/PWM/main.c
index c42b15939..ef08b792c 100644
--- a/testhal/STM32/PWM/main.c
+++ b/testhal/STM32/PWM/main.c
@@ -21,33 +21,21 @@
#include "ch.h"
#include "hal.h"
-/*
- * Red LEDs blinker thread, times are in milliseconds.
- */
-static WORKING_AREA(waThread1, 128);
-static msg_t Thread1(void *arg) {
-
- (void)arg;
- while (TRUE) {
- palClearPad(IOPORT3, GPIOC_LED);
- chThdSleepMilliseconds(500);
- palSetPad(IOPORT3, GPIOC_LED);
- chThdSleepMilliseconds(500);
- }
- return 0;
-}
-
static void pwmpcb(PWMDriver *pwmp) {
(void)pwmp;
+ palSetPad(IOPORT3, GPIOC_LED);
}
static void pwmc1cb(PWMDriver *pwmp) {
(void)pwmp;
+ palClearPad(IOPORT3, GPIOC_LED);
}
static PWMConfig pwmcfg = {
+ 10000, /* 10KHz PWM clock frequency. */
+ 10000, /* Initial PWM period 1S. */
pwmpcb,
{
{PWM_OUTPUT_ACTIVE_HIGH, pwmc1cb},
@@ -55,8 +43,6 @@ static PWMConfig pwmcfg = {
{PWM_OUTPUT_DISABLED, NULL},
{PWM_OUTPUT_DISABLED, NULL}
},
- PWM_COMPUTE_PSC(STM32_TIMCLK1, 10000), /* 10KHz PWM clock frequency. */
- PWM_COMPUTE_ARR(10000, 1000000), /* PWM period 1S. */
0
};
@@ -76,9 +62,9 @@ int main(void) {
chSysInit();
/*
- * Creates the blinker thread.
+ * LED initially off.
*/
- chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
+ palSetPad(IOPORT3, GPIOC_LED);
/*
* Initializes the PWM driver 1.
@@ -88,9 +74,9 @@ int main(void) {
chThdSleepMilliseconds(2000);
/*
- * Starts the channel 0 using 50% duty cycle.
+ * Starts the channel 0 using 25% duty cycle.
*/
- pwmEnableChannel(&PWMD1, 0, PWM_PERCENTAGE_TO_WIDTH(&PWMD1, 5000));
+ pwmEnableChannel(&PWMD1, 0, PWM_PERCENTAGE_TO_WIDTH(&PWMD1, 2500));
chThdSleepMilliseconds(5000);
/*
@@ -100,10 +86,18 @@ int main(void) {
chThdSleepMilliseconds(5000);
/*
+ * Changes PWM period to half second and duty cycle to 50%.
+ */
+ pwmChangePeriod(&PWMD1, 5000);
+ pwmEnableChannel(&PWMD1, 0, PWM_PERCENTAGE_TO_WIDTH(&PWMD1, 5000));
+ chThdSleepMilliseconds(5000);
+
+ /*
* Disables channel 0.
*/
pwmDisableChannel(&PWMD1, 0);
-
+ pwmStop(&PWMD1);
+ palSetPad(IOPORT3, GPIOC_LED);
/*
* Normal main() thread activity, in this demo it does nothing.