2018-03-19 10:15 AM
Hi,
I'm currently using an STM32F413 and I would like to use the forced output mode on the TIM1 with 3 PWM already configured.
I followed the instructions noted in the reference manual [17.3.7] :
- CCxS bit to 00 in the TIMx_CCMRx
- write 101 in the OCxM bits
But I still can not force the state of my output pins.
Here is my code :
[CODE]
/* force OC1 output mode */
/////////////////////////////////////////////////////////////////////////////////////////////
tmpccmrx = htim1.Instance->CCMR1; /* Clear OC1M*/ tmpccmrx &= ~TIM_CCMR1_OC1M; /* CC1 channel is configured as output */ tmpccmrx &= ~TIM_CCMR1_CC1S; tmpccmrx |= TIM_OCMODE_FORCED_ACTIVE; /* Configure CCMR1 */ htim1.Instance->CCMR1 = tmpccmrx; htim1.Instance->CCER |= TIM_CCER_CC1E; htim1.Instance->CCER |= TIM_CCER_CC1NE; ///////////////////////////////////////////////////////////////////////////////////////////// /* force OC2 output mode */ ///////////////////////////////////////////////////////////////////////////////////////////// tmpccmrx = htim1.Instance->CCMR1; /* Clear OC2M*/ tmpccmrx &= ~TIM_CCMR1_OC2M; /* CC2 channel is configured as output */ tmpccmrx &= ~TIM_CCMR1_CC2S; tmpccmrx |= (0x5 << TIM_CCMR1_OC2M_Pos) ; /* Configure CCMR1 */ htim1.Instance->CCMR1 = tmpccmrx; htim1.Instance->CCER |= TIM_CCER_CC2E; htim1.Instance->CCER |= TIM_CCER_CC2NE; ///////////////////////////////////////////////////////////////////////////////////////////// /* force OC3 output mode */ ///////////////////////////////////////////////////////////////////////////////////////////// tmpccmrx = htim1.Instance->CCMR2; /* Clear OC2M*/ tmpccmrx &= ~TIM_CCMR2_OC3M; /* CC2 channel is configured as output */ tmpccmrx &= ~TIM_CCMR2_CC3S; tmpccmrx |= (0x5<< TIM_CCMR2_OC3M_Pos); /* Configure CCMR2 */ htim1.Instance->CCMR2 = tmpccmrx; htim1.Instance->CCER |= TIM_CCER_CC3E; htim1.Instance->CCER |= TIM_CCER_CC3NE;[/CODE]
I checked in debug mode that the registers are affected and yet I do not have the desired levels output.
Any idea ?Thanks in advance !
2018-03-19 10:23 AM
Set the pin to the right alternate mode.
2018-03-19 11:46 AM