cancel
Showing results for 
Search instead for 
Did you mean: 

Hi, I wanted to use three channel on a single timer. The setup seems to work fine for the first two (ch1 and ch2) but not for ch3. it seems that even with HAL I have to manually set the bit TIM_CCER_CC3E on for ch3. Did I miss something?

KRem.1
Associate II

I use these fonction to enable all three channels:

HAL_TIM_OnePulse_Start(&htim3, TIM_CHANNEL_1);

HAL_TIM_OnePulse_Start(&htim3, TIM_CHANNEL_2);

 HAL_TIM_OnePulse_Start(&htim3, TIM_CHANNEL_3);

it have to insert this to enable ch3 but just for the channel 3.

htim3.Instance->CCMR2 = TIM_CCMR2_OC3PE| (7<<TIM_CCMR2_OC3M_Pos);

 htim3.Instance->CCER |= TIM_CCER_CC3E

I'm asking this question because I'm not sure if there is an issue with HAL or it's just me.

Best regards,

7 REPLIES 7
TDK
Guru

What chip?

If you feel a post has answered your question, please click "Accept as Solution".
KRem.1
Associate II

Stm32f103rb, the nucleo board

TDK
Guru

TIM_CHANNEL_3 is not a valid argument to HAL_TIM_OnePulse_Start.

https://github.com/STMicroelectronics/STM32CubeF1/blob/003dfc9e6c2e424c19a25df3934afaf7fce660d6/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim.c#L2689

/**
  * @brief  Starts the TIM One Pulse signal generation.
  * @param  htim TIM One Pulse handle
  * @param  OutputChannel TIM Channels to be enabled
  *          This parameter can be one of the following values:
  *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
  *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
  * @retval HAL status
  */
HAL_StatusTypeDef HAL_TIM_OnePulse_Start(TIM_HandleTypeDef *htim, uint32_t OutputChannel)

Seems like it should be included, but maybe there's a reason for it being missing.

If you feel a post has answered your question, please click "Accept as Solution".

This function (and the related "surroundings" of it) is aimed at one particular application, where one channel serves as a hardware trigger, and the other as output.

 /* Enable the Capture compare and the Input Capture channels

   (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2)

   if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and

   if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output

   in all combinations, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be enabled together

   No need to enable the counter, it's enabled automatically by hardware

   (the counter starts in response to a stimulus and generate a pulse */

See also the related examples:

Configuration of TIM5 in One Pulse Mode
===================================================
 
  - The external signal is connected to TIM5_CH2 pin (PA.01), 
    and a rising edge on this input is used to trigger the Timer.
  - The One Pulse signal is output on TIM5_CH1 (PA.00).
 
  The delay value is fixed to:
   - Delay =  CCR1/TIM5 counter clock 
           = 16383 / 18000000 [sec]
           
  The pulse value is fixed to : 
   - Pulse value = (TIM_Period - TIM_Pulse)/TIM5 counter clock  
                 = (65535 - 16383) / 18000000 [sec]
 
  The one pulse waveform can be displayed using an oscilloscope and it looks
  like this.
  
                               ____
                               |   |
  CH2 _________________________|   |__________________________________________
 
                                             ___________________________
                                            |                           |
  CH1 ______________________________________|                           |_____
                               <---Delay----><------Pulse--------------->

In other words, this is implementation of a one-shot flip-flop with delay.

This of course is only one very specific application of the OPM in timer. That's Cube/HAL for you.

Oh, and it's an excellent illustration of Cube/HAL documentation, too.

JW

KRem.1
Associate II

ok, thank you.

I may have to adapt this function.

KRem.1
Associate II

Hi,

I finally get my timer working as I wish. I went directly programming the register. In my case, I use the timer 1 to trigger the timer 3 (one pulse mode) on the microcontroler as i needed so extra feature from the timer 1 (the repetition counter).

Apparently, if an internal trigger is selected as the trigger input, it is not needed to configure a channel as an input.

I am a bit concern now, will I still be able to use other hal libraries on my project ?

R.

> will I still be able to use other hal libraries on my project ?

Probably yes, if they are not using the given timer(s). I don't use Cube/HAL.

JW