2017-01-02 09:14 AM
Hello,
i am working on a bldc motor project for school, and for start to understand whats happening inside the IRQ handler, i have configured timer2 on ch1,2,3 with 3 emulated hardware signals, imitating the CW of a bldc motors
The hall emulated signals are coming from another development board. The signals are bellow
These signals ( H1,H2,H3) are feed into a STM32F407 device, on PA0, PA1 and PA2 which are Ch1,2,3 of the TIMER2
i have prepared only the initialization of the timer2 to see if the hall signals trigger the CC1 event in the irq handler, but its not triggering.
I've put a small toggle on a PC1 pin just to see when its triggering inside the TIM2_IRQhandler,
But there is no triggering,
At this point Timer1 is not initialized, i just want to see how it behaives on the hall signals.
I am missing something? Of does the Timer2 takes some kind of feedback from TIM1 in order to trigger CC1 event?
void timer2_setup(void){ GPIO_InitTypeDef GPIO_InitStructure; RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 |GPIO_Pin_2; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_PinAFConfig(GPIOA, GPIO_PinSource0, GPIO_AF_TIM2); GPIO_PinAFConfig(GPIOA, GPIO_PinSource1, GPIO_AF_TIM2); GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_TIM2); //**** PC1 is used for toggle in IRQ handlers to see with logic analyzer GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 ; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ; GPIO_Init(GPIOC, &GPIO_InitStructure); NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 7; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 7; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); TIM_TimeBaseStructure.TIM_Prescaler = 126; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseStructure.TIM_Period = 65530; TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_RepetitionCounter = 0; TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); TIM_SelectHallSensor(TIM2, ENABLE); TIM_SelectInputTrigger(TIM2, TIM_TS_TI1F_ED); TIM_SelectSlaveMode(TIM2, TIM_SlaveMode_Reset); TIM_SelectMasterSlaveMode(TIM2, TIM_MasterSlaveMode_Enable);TIM_ICInitStructure.TIM_Channel = TIM_Channel_1 ;
TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_BothEdge; TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_TRC;// listen to T1, the HallSensorEvent TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;// Div:1, every edge TIM_ICInitStructure.TIM_ICFilter = 0; TIM_ICInit(TIM2, &TIM_ICInitStructure); // Enable CC1 interrupt requestTIM_ITConfig(TIM2, TIM_IT_CC1, ENABLE);TIM_Cmd(TIM2, ENABLE); }void TIM2_IRQHandler(void){if (TIM_GetITStatus(TIM2, TIM_IT_CC1) != RESET)
{ GPIO_ToggleBits(GPIOC,GPIO_Pin_1); // Toggle the pin for logic analyzer TIM_ClearITPendingBit(TIM2, TIM_IT_CC1); }}
2017-01-26 01:46 AM
Hi
Anton.Bogdan
,Thanks for sharing the solution.This will be helpful for other users.
Khouloud