2014-01-17 09:31 AM
Hi all,
I'd like to see a PWM with my oscilloscope, but I see nothing and I can't understand why. Can you help me? Thanks in advantage <I>int main(void)
{
TIM_Config();
GPIO_Configuration();
/* Infinite loop */
while (1)
{
}
}
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* GPIOB clock enable */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource6, GPIO_AF_2); // TIM3 Channel1 PA6 AF2
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; // Or UP for open-collector sources
GPIO_Init(GPIOD, &GPIO_InitStructure);
}
/********************************/
static void TIM_Config(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
__IO uint16_t CCR1_Val = 40961;
uint16_t PrescalerValue = 0;
/* TIM3 clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
/* ----------------------------------------------------------------------- */
TIM_DeInit(TIM3);
/* Compute the prescaler value we want TIM3 clk @8Mhz => Presc = 8*/
PrescalerValue = (uint16_t) ((SystemCoreClock) / 8000000) - 1;
/* Time base configuration */
TIM_TimeBaseStructure.TIM_Period = 100;
TIM_TimeBaseStructure.TIM_Prescaler = 0;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
/* Prescaler configuration */
TIM_PrescalerConfig(TIM3, PrescalerValue, TIM_PSCReloadMode_Immediate);
/* Output Compare Timing Mode configuration: Channel1 */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Timing;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = CCR1_Val;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OC1Init(TIM3, &TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Disable);
/* TIM3 enable counter */
TIM_Cmd(TIM3, ENABLE);
}
</I>
2014-01-18 10:51 AM
Have you an example code for TIM stm32f3?
I write and post a lot of things, when I need them I Google for them. I could write some additional ones, but don't have a scope with me.2014-01-18 11:06 AM
Probably I going to understand the problem, just a clarification if possible:
GPIO_PinAFConfig(GPIOA, GPIO_PinSource11, GPIO_AF_10) is referring to PA11 on board?2014-01-18 03:25 PM
PA11 TIM4_CH1
2014-01-19 12:46 PM
Clive with your code my oscilloscope see: PA6 and PA7 (TIM3) 1Khz, PA11 and PA12 nothing.
2014-01-19 03:55 PM
Did you make SB21 and SB22?
PA11/PA12 are normally assigned to the USB DP/DM function.2014-01-20 02:22 AM
Thanks Clive.