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?
Forcing PWM channel active
- Giovanni
- Site Admin
- Posts: 14893
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: Forcing PWM channel active
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
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
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?
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?
- Giovanni
- Site Admin
- Posts: 14893
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: Forcing PWM channel active
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
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
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):
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.
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.