Created
June 16, 2014 14:51
-
-
Save gamazeps/20ededf78bc2e2ceb442 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Simple PWM example */ | |
/* | |
* PWMD3 is a HAL defined variable of type PWMDriver - it is associated with | |
* TIM3. | |
*/ | |
#include "ch.h" | |
#include "hal.h" | |
static PWMConfig pwmcfg = { | |
200000, /* 200Khz PWM clock frequency */ | |
1024, /* PWM period 0.005 second */ | |
NULL, /* No callback */ | |
/* Only channel 1 enabled */ | |
{ | |
{PWM_OUTPUT_ACTIVE_HIGH, NULL}, | |
{PWM_OUTPUT_ACTIVE_HIGH, NULL}, | |
{PWM_OUTPUT_ACTIVE_HIGH, NULL}, | |
{PWM_OUTPUT_ACTIVE_HIGH, NULL}, | |
}, | |
0 | |
}; | |
int main(void) { | |
halInit(); | |
chSysInit(); | |
uint16_t i = 1; | |
/* Enables PWM output (of TIM3, channel 1) on LED connected to PC6 */ | |
palSetPadMode(GPIOC, 6, PAL_MODE_ALTERNATE(2)); | |
pwmStart(&PWMD3, &pwmcfg); | |
while (TRUE) { | |
if (i >= 1024) { | |
i = 1; | |
} else { | |
i *= 2; | |
} | |
pwmEnableChannel(&PWMD3, 0, i); | |
chThdSleepMilliseconds(50); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment