本文整理汇总了C++中pwmStart函数的典型用法代码示例。如果您正苦于以下问题:C++ pwmStart函数的具体用法?C++ pwmStart怎么用?C++ pwmStart使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pwmStart函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pwmOutputStart
/**
* @brief Starts the PWM output.
* @note The pwmStart() function used in this code is not
* the original ChibiOS HAL function, but modified
* one with STM32_TIM_CR1_CEN flag removed.
* @return none.
*/
void pwmOutputStart(void) {
#if STM32_PWM_USE_ADVANCED
/* Get dead-time generator value for TIM1. */
uint32_t bdtr_dt = pwmOutputGetBDTRDeadTime(g_pwmOutput[PWM_OUT_ROLL].dt_cmd_id & PWM_OUT_DT_ID_MASK);
pwmcfg_d1_d8.bdtr |= bdtr_dt;
#endif
pwmStart(&PWMD1, &pwmcfg_d1_d8);
#if STM32_PWM_USE_ADVANCED
/* Clear bdtr_dt value from previous calculation. */
pwmcfg_d1_d8.bdtr &= ~bdtr_dt;
/* Get dead-time generator value for TIM8. */
bdtr_dt = pwmOutputGetBDTRDeadTime(g_pwmOutput[PWM_OUT_PITCH].dt_cmd_id & PWM_OUT_DT_ID_MASK);
pwmcfg_d1_d8.bdtr |= bdtr_dt;
#endif
/* Configure TIM8 as master timer: */
pwmcfg_d1_d8.cr2 = STM32_TIM_CR2_MMS(1); // Master mode set to Enable;
pwmStart(&PWMD8, &pwmcfg_d1_d8);
switch (g_pwmOutput[PWM_OUT_YAW].dt_cmd_id & PWM_OUT_DT_ID_MASK) {
case PWM_OUT_DT750NS:
pwmOutTIM4_5_DT = PWM_OUT_TIM4_5_DT_US7;
break;
case PWM_OUT_DT1000NS:
pwmOutTIM4_5_DT = PWM_OUT_TIM4_5_DT_1US;
break;
case PWM_OUT_DT2000NS:
pwmOutTIM4_5_DT = PWM_OUT_TIM4_5_DT_2US;
break;
case PWM_OUT_DT3000NS:
pwmOutTIM4_5_DT = PWM_OUT_TIM4_5_DT_3US;
break;
case PWM_OUT_DT4000NS:
pwmOutTIM4_5_DT = PWM_OUT_TIM4_5_DT_4US;
break;
case PWM_OUT_DT5000NS:
pwmOutTIM4_5_DT = PWM_OUT_TIM4_5_DT_5US;
break;
default:
pwmOutTIM4_5_DT = PWM_OUT_TIM4_5_DT_5US;
}
pwmStart(&PWMD4, &pwmcfg_d4);
pwmStart(&PWMD5, &pwmcfg_d5);
/* Configure TIM5 as slave timer: */
PWMD5.tim->SMCR =
STM32_TIM_SMCR_SMS(6) | // Trigger Mode;
STM32_TIM_SMCR_TS(3); // Trigger event comes from TIM8;
/* Configure TIM4 as slave timer: */
PWMD4.tim->SMCR =
STM32_TIM_SMCR_SMS(6) | // Trigger Mode;
STM32_TIM_SMCR_TS(3); // Trigger event comes from TIM8;
/* Switch to center-aligned mode 1 and start timers. */
PWMD5.tim->CR1 |= (STM32_TIM_CR1_CMS(1)); // This is a slave timer - do not start;
PWMD4.tim->CR1 |= (STM32_TIM_CR1_CMS(1)); // This is a slave timer - do not start;
PWMD1.tim->CR1 |= (STM32_TIM_CR1_CMS(1) | STM32_TIM_CR1_CEN);
PWMD8.tim->CR1 |= (STM32_TIM_CR1_CMS(1) | STM32_TIM_CR1_CEN); // Start TIM8, TIM4 and TIM5 simultaneously;
}
示例2: InitPWM
void InitPWM(void) {
/*
* Initializes the PWM drivers
*/
pwmStart(&PWMD3, &pwmcfg);
pwmStart(&PWMD4, &pwmcfg);
pwmStart(&PWMD5, &pwmcfg);
// pwmStart(&PWMD8, &pwmcfg);
}
示例3: bldcInit
/* This function will start the PWM generator.
*/
extern void bldcInit(void) {
bldc.scheme = &pwmScheme;
bldc.state = 0; //Default to first state
bldc.nextState = 0;
bldc.directionFwd = TRUE;
bldc.stateChangeInterval = MS2RTT(20);
bldc.prevStateChange = halGetCounterValue();
bldc.nextStateChange = bldc.prevStateChange + bldc.stateChangeInterval;
bldc.pwmOutT0 = 0;
bldc.pwmOutT1 = 0;
bldc.stateCount = sizeof(pwmScheme)/3;
bldc.dutyCycle = 1800;
palWriteGroup (PWM_OUT_PORT, PWM_OUT_PORT_MASK, PWM_OUT_OFFSET, PWM_OFF);
palSetGroupMode (PWM_OUT_PORT, PWM_OUT_PORT_MASK, PWM_OUT_OFFSET, PAL_MODE_OUTPUT_PUSHPULL);
palSetPadMode (GPIOA, GPIOA_PIN1, PAL_MODE_INPUT_ANALOG);
pwmStart(&PWMD1, &pwmcfg);
// ADC trigger channel. This will trigger the ADC read at 95% of the cycle,
// when all the PWM outputs are set to 0
pwmEnableChannel (&PWMD1, PWM_ADCTRIG_CH, PWM_PERCENTAGE_TO_WIDTH(&PWMD1, PWM_MAX_DUTY_CYCLE));
// Start the ADC
adcStart(&ADCD1, NULL);
}
示例4: goToPos
void goToPos(int32_t new_pos){
if(new_pos == position)
return;
config.frequency = clk_freq;
config.period = clk_freq / initial_freq;
config.callback = cb;
current_freq = initial_freq;
config.channels[0] = {PWM_OUTPUT_DISABLED, NULL};
config.channels[1] = {PWM_OUTPUT_DISABLED, NULL};
config.channels[2] = {PWM_OUTPUT_DISABLED, NULL};
config.channels[3] = {PWM_OUTPUT_DISABLED, NULL};
config.channels[channel] = {PWM_OUTPUT_ACTIVE_HIGH, NULL};
config.cr2 = 0;
config.dier = 0;
dir_positive = new_pos > position;
target_position = new_pos;
dir_pin.assign(dir_positive);
ramp_length = (new_pos > position) ?
((max_pos_freq - initial_freq) / ramp) :
((max_neg_freq - initial_freq) / ramp);
pwmStart(driver, &config);
pwmEnableChannel(driver, channel, 10);
pwmEnablePeriodicNotificationI(driver);
}
示例5: main
int main(void)
{
halInit();
chSysInit();
palSetPadMode(GPIOB, 0, PAL_MODE_ALTERNATE(2)); // alt mode is PWM-enabled TIM3
palSetPadMode(GPIOB, INAPIN, PAL_MODE_OUTPUT_PUSHPULL); // set INA to be an output
palSetPadMode(GPIOB, INBPIN, PAL_MODE_OUTPUT_PUSHPULL); // set INB to be an output
pwmStart(&PWMD3, &pwmcfg); // TIM3 for motors
while (TRUE) {
// one direction (possibly forward)
pwmEnableChannel(&PWMD3, 3, 500);
palSetPad(GPIOB, INAPIN);
palClearPad(GPIOB, INBPIN);
chThdSleepMilliseconds(3000);
// the other direction (possibly backward)
pwmEnableChannel(&PWMD3, 3, 500);
palSetPad(GPIOB, INBPIN);
palClearPad(GPIOB, INAPIN);
chThdSleepMilliseconds(3000);
}
}
示例6: palSetPadMode
void PwmBacklight::Init()
{
palSetPadMode(BACKLIGHT_PORT, BACKLIGHT_PIN, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
pwmStart(&PWMD4, &pwmconfig);
FadeIn();
}
示例7: convStart
void convStart( void )
{
/*
pwmStart( &PWMD2, &pwmCfg );
palSetPadMode( GPIOA, 0, PAL_MODE_STM32_ALTERNATE_PUSHPULL );
palSetPadMode( GPIOA, 1, PAL_MODE_STM32_ALTERNATE_PUSHPULL );
//palSetPadMode( GPIOA, 2, PAL_MODE_STM32_ALTERNATE_PUSHPULL );
pwmEnableChannel(&PWMD2, 0, PWM_PERCENTAGE_TO_WIDTH( &PWMD2, 9500 ) );
pwmEnableChannel(&PWMD2, 1, PWM_PERCENTAGE_TO_WIDTH( &PWMD2, 3030 ) );
//pwmEnableChannel(&PWMD2, 2, PWM_PERCENTAGE_TO_WIDTH( &PWMD2, 3030 ) );
*/
// Start PWM peripherial.
pwmStart( &CONV_PWM, &pwmCfg );
// Init PWM pins.
palSetPadMode( CONV_PORT, CONV_BUCK_PIN, PAL_MODE_STM32_ALTERNATE_PUSHPULL );
palSetPadMode( CONV_PORT, CONV_BOOST_PIN, PAL_MODE_STM32_ALTERNATE_PUSHPULL );
// Set zero active period.
pwmEnableChannel(&CONV_PWM, PWM_BOOST_CHAN, PWM_PERCENTAGE_TO_WIDTH( &CONV_PWM, 0000 ) );
pwmEnableChannel(&CONV_PWM, PWM_BUCK_CHAN, PWM_PERCENTAGE_TO_WIDTH( &CONV_PWM, 0000 ) );
// Init ADC.
palSetGroupMode(CONV_ADC_PORT, PAL_PORT_BIT( CONV_BUCK_FB_PIN ) |
PAL_PORT_BIT( CONV_BOOST_FB_PIN ) |
PAL_PORT_BIT( CONV_INPUT_FB_PIN ),
0, PAL_MODE_INPUT_ANALOG);
adcStart( &ADCD1, NULL );
adcStartConversion( &ADCD1, &adcGroup, adcSamples, ADC_BUF_DEPTH );
}
示例8: ow_bus_active
/**
* @brief Put bus in active mode.
*/
static void ow_bus_active(onewireDriver *owp) {
pwmStart(owp->config->pwmd, owp->config->pwmcfg);
#if defined(STM32F1XX)
palSetPadMode(owp->config->port, owp->config->pad,
owp->config->pad_mode_active);
#endif
}
示例9: main
/*
* Application entry point.
*/
int main(void) {
/*
* System initializations.
* - HAL initialization, this also initializes the configured device drivers
* and performs the board-specific initializations.
* - Kernel initialization, the main() function becomes a thread and the
* RTOS is active.
*/
halInit();
chSysInit();
pwmStart(&PWMD1, &pwmcfg);
/*
* Activates the serial driver 2 using the driver default configuration.
*/
palSetPadMode(GPIOA, 9, PAL_MODE_ALTERNATE(2));
/*
* Creates the blinker thread.
*/
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
/*
* Normal main() thread activity, in this demo it does nothing except
* sleeping in a loop and check the button state.
*/
while (true) {
if (TRUE) //(!palReadPad(GPIOC, GPIOC_BUTTON))
//TestThread(&SD1);
chThdSleepMilliseconds(5000);
}
}
示例10: palSetPadMode
void PwmBacklight::Init()
{
palSetPadMode(GPIOB, 6, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
pwmStart(&PWMD4, &pwmconfig);
FadeIn();
}
示例11: pwmStart
PWMPlatform::PWMPlatform() {
pwmStart(&PWMD1, &MOTOR_PWM_CONFIG);
palSetPadMode(GPIOC, 6, PAL_MODE_ALTERNATE(4));
palSetPadMode(GPIOC, 7, PAL_MODE_ALTERNATE(4));
palSetPadMode(GPIOC, 8, PAL_MODE_ALTERNATE(4));
palSetPadMode(GPIOC, 9, PAL_MODE_ALTERNATE(4));
}
示例12: pwm2sub_node
msg_t pwm2sub_node(void * arg) {
Node node("pwm2sub");
Subscriber<PWM2Msg, 5> sub(callback);
(void) arg;
chRegSetThreadName("pwm2sub");
palSetPad(DRIVER_GPIO, DRIVER_RESET);
chThdSleepMilliseconds(500);
pwmStart(&PWM_DRIVER, &pwmcfg);
node.subscribe(sub, "pwm2");
for (;;) {
if (!node.spin(Time::ms(100))) {
// Stop motor if no messages for 100 ms
chSysLock()
;
pwm_lld_enable_channel(&PWM_DRIVER, 0, 0);
pwm_lld_enable_channel(&PWM_DRIVER, 0, 0);
chSysUnlock();
}
}
return CH_SUCCESS;
}
示例13: demo_led_init
void demo_led_init(void)
{
/*
* PWM configuration structure.
* Cyclic callback enabled, channels 1 and 4 enabled without callbacks,
* the active state is a logic one.
*/
static const PWMConfig pwmcfg = {
100000, /* 100kHz PWM clock frequency. */
128, /* PWM period is 128 cycles. */
NULL,
{
{PWM_OUTPUT_ACTIVE_HIGH, NULL},
{PWM_OUTPUT_ACTIVE_HIGH, NULL},
{PWM_OUTPUT_ACTIVE_HIGH, NULL},
{PWM_OUTPUT_ACTIVE_HIGH, NULL}
},
/* HW dependent part.*/
0,
0
};
/*
* Initializes the PWM driver 4, routes the TIM4 outputs to the board LEDs.
*/
pwmStart(&PWMD4, &pwmcfg);
palSetPadMode(GPIOD, GPIOD_LED4, PAL_MODE_ALTERNATE(2)); /* Green. */
palSetPadMode(GPIOD, GPIOD_LED3, PAL_MODE_ALTERNATE(2)); /* Orange. */
palSetPadMode(GPIOD, GPIOD_LED5, PAL_MODE_ALTERNATE(2)); /* Red. */
palSetPadMode(GPIOD, GPIOD_LED6, PAL_MODE_ALTERNATE(2)); /* Blue. */
}
示例14: motor_init
void motor_init(void) {
pwmStart(&PWMD2, &pwmcfg);
pwmEnableChannel(&PWMD2, 0, PWM_PERCENTAGE_TO_WIDTH(&PWMD2, 500)); // 1mS Pulse
pwmEnableChannel(&PWMD2, 1, PWM_PERCENTAGE_TO_WIDTH(&PWMD2, 500)); // 1mS Pulse
pwmEnableChannel(&PWMD2, 2, PWM_PERCENTAGE_TO_WIDTH(&PWMD2, 500)); // 1mS Pulse
pwmEnableChannel(&PWMD2, 3, PWM_PERCENTAGE_TO_WIDTH(&PWMD2, 500)); // 1mS Pulse
}
示例15: pwmStop
bool Pwm_chibios::init(void)
{
pwmStop(driver_);
pwmStart(driver_, &config_);
pwmEnablePeriodicNotification(driver_);
pwmEnableChannelNotification(driver_, channel_);
return true;
}