Page 1 of 1
Forcing PWM channel active
Posted: Tue Dec 08, 2015 1:57 pm
by daniel_s
Hi,
I'm starting to use ChibiHAL for PWM purposes (mainly motor controlling) at the moment.
Currently I'm looking for a possibility to force a PWM Channel active (or inactive), which is possible by setting "Output Compare 1 mode" in TIMx_CCMR1 register.
It seems, that access is neither possible via ChibiStructure PWMConfig nor via any specific function.
Do you have any advice for me?
Re: Forcing PWM channel active
Posted: Tue Dec 08, 2015 2:09 pm
by Giovanni
Hi,
pwmDisableChannel() disables the channel putting it in idle (0% duty cycle) and disables the callback. Forcing it to active is equivalent to putting it to 100% duty cycle, isn't it?
Giovanni
Re: Forcing PWM channel active
Posted: Tue Dec 08, 2015 2:23 pm
by daniel_s
Hi Giovanni,
you are right. But in my current configuration, I want to drive a motor with block commutation. An example for one commutation step is as follows:
- CH1 and CH1N are acting as PWM channels, activation via pwmEnableChannel() for Channel 1
- CH2 inactive, CH2N active, activation could be done by applying pwmDisableChannel() to Channel 2
- CH3 and CH3N inactive, both should be inactive, no possiblity to do that except register access?
Re: Forcing PWM channel active
Posted: Tue Dec 08, 2015 2:28 pm
by Giovanni
That is a specific feature of the timer so it cannot be part of the high level API. The right thing would be adding an STM32-specific API to the low level driver.
Such API would be named this way: pwmSTM32DoSomethingX(). For example pwmSTM32KillChannelX().
Feel free to propose a solution for it, just consider compatibility with other functionalities.
Giovanni
Re: Forcing PWM channel active
Posted: Tue Dec 08, 2015 2:53 pm
by neums
This feature whould be great.

Re: Forcing PWM channel active
Posted: Thu Dec 10, 2015 8:32 am
by daniel_s
I think, that there are lots of functions, that would be necessary in this context. A function, that implements descripted behaviour, would look like this (derived from STCube):
Code: Select all
#define STM32_TIM_CCMR1_OC1M(n) ((((n) & 7) << 4) |(((n) >> 3) << 16))
void pwm_lld_stm32_force_oc1_configX(PWMDriver *pwmp, uint32_t activity_level)
{
uint32_t tmpccmr1;
tmpccmr1 = pwmp->tim->CCMR1;
//Reset the OC1M bits
tmpccmr1 &= ~TIM_CCMR1_OC1M;
tmpccmr1 |= STM32_TIM_CCMR1_OC1M(activity_level);
pwmp->tim->CCMR1 = tmpccmr1;
}
Please note, that a plausibility check for parameter "activity_level" is missing. Macro TIM_CCMR1_OC1M can be found in respective STM32 device header file.