Forcing PWM channel active

Discussions and support about ChibiOS/HAL, the MCU Hardware Abstraction Layer.
Post Reply
daniel_s
Posts: 9
Joined: Tue Dec 08, 2015 1:45 pm

Forcing PWM channel active

Post 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?
User avatar
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

Post 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
daniel_s
Posts: 9
Joined: Tue Dec 08, 2015 1:45 pm

Re: Forcing PWM channel active

Post 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?
User avatar
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

Post 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
neums
Posts: 137
Joined: Fri May 08, 2015 1:09 pm
Has thanked: 10 times
Been thanked: 5 times

Re: Forcing PWM channel active

Post by neums »

This feature whould be great. :-)
daniel_s
Posts: 9
Joined: Tue Dec 08, 2015 1:45 pm

Re: Forcing PWM channel active

Post 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.
Post Reply