AnsweredAssumed Answered

STM32F030x PWM output onto PB.6 TIM16_CH1N (AF2) ??? how???

Question asked by chris.chris.001 on Dec 27, 2015
Latest reply on Dec 27, 2015 by wolff.roger
Hello,

Unable to enable PWM on PB.6 using TIM16 (TIM16_CH1N) for STM32F0 STM32F030x
(File also attached)

1. Table DocID024849 Rev 2 (STM32F030x) shows AF2 column TIM16_CH1N functionality;
2. "Normal" methods for enabling PWM on TIM16_CH1N do not seem to work. (I'm sure I have some funky error in the code, please help.)
3. I want to enable a 50/50 PWM; I expect to measure 3.3v/2 on PB6.
4. I've tried a bunch of different scenarios to try to enable the pin.  Code is below and attahed.
5.  Please advise any suggestions to fix.
6. Question: what is good ST document to refer to to better understand the TIM16_CH1N functionality?
7. Is it correct to ASSUME that the N in TIM16_CH1N is NEGATIVE polarity ??? (If not what does N mean?)


Thanks in advance,
-Chris

=====

/****************************************************/<br>/****************************************************/<br>void TIM16_RCC_Configuration(void)<br>{<br>    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);<br>    RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM16, ENABLE);<br>}<br><br>/****************************************************/<br>/****************************************************/<br>void TIM16_GPIO_Configuration(void)<br>{<br>    GPIO_InitTypeDef GPIO_InitStructure;<br><br>    // PB.06 TIM16_CH1N<br>    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;<br>    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;<br>    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;<br>    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;<br>    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;<br>    GPIO_Init(GPIOB, &GPIO_InitStructure);<br><br>    GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_2);<br><br>}<br><br>/****************************************************/<br>/****************************************************/<br>void TIM16_Configuration(void)<br>{<br>    TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;<br>    TIM_OCInitTypeDef TIM_OCInitStructure;<br>    NVIC_InitTypeDef            NVIC_InitStructure;<br><br>  // Set up TIM4_CH4 to be a 1 Hz time base (1PPS)<br>    TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);<br><br>    TIM_TimeBaseStructure.TIM_Prescaler = 24000 - 1;  // 24 MHz / 24000 = 1 KHz<br>    TIM_TimeBaseStructure.TIM_Period = 1000 - 1; // 1 KHz / 1000 = 1 Hz<br>    TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;<br>    TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;<br>    TIM_TimeBaseInit(TIM16, &TIM_TimeBaseStructure);<br><br>    // Channel 4 configuration = PB.09 TIM4_CH4<br>    TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;<br>    //TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;<br>    //TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;<br>    TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;<br>    TIM_OCInitStructure.TIM_Pulse = (TIM_TimeBaseStructure.TIM_Period + 1) / 2; // 50% Duty<br>    TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;<br><br>    //TIM_OC4Init(TIM16, &TIM_OCInitStructure);<br>    TIM_OC1Init(TIM16, &TIM_OCInitStructure);<br>    // turning on TIM4 and PWM outputs<br>    TIM_Cmd(TIM16, ENABLE);<br>    TIM_CtrlPWMOutputs(TIM16, ENABLE);<br><br>      //NVIC_InitStructure.NVIC_IRQChannel = TIM16_IRQn;<br>    //NVIC_InitStructure.NVIC_IRQChannelPriority = 0x01;<br>    //NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;<br>    //NVIC_Init(&NVIC_InitStructure);<br><br><br>    //TIM_GenerateEvent(TIM16, TIM_EventSource_Update);<br>}<br><br>/****************************************************/<br>/****************************************************/<br>void TIM16_InitializePWMChannel(void)<br>{<br>    int  i,j;<br><br>    TIM16_RCC_Configuration();<br><br>    TIM16_GPIO_Configuration();<br><br>    TIM16_Configuration(); // 1Hz Output<br><br>}<br>


Outcomes