2015-12-26 11:54 PM
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
>
#tim16-tim16_ch1n-pwm-stm32f030x
2015-12-27 04:13 AM
2015-12-27 05:19 AM
Complimentary output.
Enable the N side of the channel? /** * @brief Fills each TIM_OCInitStruct member with its default value. * @param TIM_OCInitStruct: pointer to a TIM_OCInitTypeDef structure which will * be initialized. * @retval None */ void TIM_OCStructInit(TIM_OCInitTypeDef* TIM_OCInitStruct) { /* Set the default configuration */ TIM_OCInitStruct->TIM_OCMode = TIM_OCMode_Timing; TIM_OCInitStruct->TIM_OutputState = TIM_OutputState_Disable; TIM_OCInitStruct->TIM_OutputNState = TIM_OutputNState_Disable;TIM_OCInitStruct->TIM_Pulse = 0x0000000; TIM_OCInitStruct->TIM_OCPolarity = TIM_OCPolarity_High; TIM_OCInitStruct->TIM_OCNPolarity = TIM_OCNPolarity_High;
TIM_OCInitStruct->TIM_OCIdleState = TIM_OCIdleState_Reset; TIM_OCInitStruct->TIM_OCNIdleState = TIM_OCNIdleState_Reset;
}
2015-12-27 09:29 AM
Hi, Roger,
Thanks for your reply. Regarding the PB.6/TIM16_CH1N; Thanks. Complimentary. I understand. In essensce, I think that you are telling me to 1: Enable the TIM16; 2: perform gpio PB.6 output waveform via software. Do I understand you correctly? Thanks, -Chris2015-12-27 09:32 AM
Thanks, Clive,
I'll take a look at what you state. -Chris2015-12-27 01:06 PM