2010-12-29 02:30 PM
timer hall sensor mode - why doesnot it function corectly?
2011-05-17 05:19 AM
Hi mehmet,
The reference manual says: ''The slave mode controller is configured in reset mode; the slave input is TI1F_ED.'' but I can't find it in your code. Where is it done ?MCU Lüfter2011-05-17 05:19 AM
Hello MCU Lüfter ,
thank you for answer neither the manual nor the peripheral library doestnot show how the hall sensor mode is initialized and it is too complicated for me can you please give me a code example2011-05-17 05:19 AM
Hi mehmet,
I don't have a hall sensor so I am just reading the reference manual. Let's do it together (I am just enjoying using these timers): The reference manual says: - The “interfacing timer�? captures the 3 timer input pins connected through an XOR gate to the TI1 input channel (selected by setting the TI1S bit in the TIMx_CR2 register ---> TIM2->CR2 |= 0x80; // bit TI1S - The slave mode controller is configured in reset mode; the slave input is TI1F_ED. TIM2->SMCR |= 0x0004; //write the SMS bits to 100 in the TIMx_SMCR register to select reset mode TIM2->SMCR |= 0x0040;//TI1 Edge Detector (TI1F_ED); the slave input is TI1F_ED Then enable the commutation interrupt using DIER registerTIM_ITConfig(TIM2, TIM_IT_COM, ENABLE); and in the IRQ try to toggle a GPIO pin (like GPIOC->ODR ^= GPIO_Pin_2;) to check that timer detects channels toggling. Tell me if it is OK now.MCU Lüfter2011-05-17 05:19 AM
hello MCU Lüfter ,
in your example interfacing and slave timers are both timer2 ( it confused me ) I found another solutionI look at the state of CH1 int the Timer ISR ( CC1 interrupt )
and change CC1P: Capture/Compare 1 input polarity for the next interrupt
void TIM2_IRQHandler(void){
if(TIM_GetITStatus(TIM2, TIM_IT_CC1) == SET) {
TIM_ClearFlag(TIM2, TIM_FLAG_CC1);
TIM_ClearITPendingBit(TIM2, TIM_IT_CC1);
if(GPIOA->IDR&GPIO_Pin_0) TIM2->CCER|=0x2;else TIM2->CCER&=~((int16_t)0x2);
} and same for other 2 chanles CH2 and CH3 now in above ISR I will software generate a COM interrupt for Timer 8 which is producing PWM signals conected to IGBT switches this way I will control my brushless DC motor - I hope so :)
2011-05-17 05:19 AM
Hi mehmet,
Ah sorry, Just change ''TIM_ITConfig(TIM2, TIM_IT_COM, ENABLE);'' by ''TIM_ITConfig(TIM2, TIM_IT_CC1, ENABLE);'' BTW interfacing timer is the same as slave timer and it can be TIM2... TIM1 or TIM8 is the ''master'' timer who generates the PWM signal. Thanks to correct me if it doesn't match your understanding. I have another update :) in the capture configuration you should use TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_TRC;and not TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; that is what says the reference manual ''On the “interfacing timer�?, capture/compare channel 1 is configured in capture mode, capture signal is TRC''. CC1S to ''11'': CC1 channel is configured as input, IC1 is mapped on TRC.MCU Lüfter
2011-05-17 05:19 AM
hi,
has somebody of you a working code for interfacing the hall-sensors to control a bldc with pwm? i try to do this for about one month now and it will never work :( thanks a lot a. nath2011-05-17 05:19 AM
hello ,
connect hall sensor UVW to CH1 CH2 CH3 of a free timer try capturing rising falling edges of them ( if you captured a rising edge change the polarity of IC to falling for next interrupt and vice versa ) and generate a software COM event for the PWMing timer in ST peripheral library there is an application ''6Steps'' under ''tim'' examples it shows how to disable and enable high and low order IGBTs in COM interrupt2011-05-17 05:19 AM
2011-05-17 05:19 AM
hello
this is my hallinit and timer 2 interrupt it works well but I only simulated the PWM outputs with LEDS I could see the TIM8 COM interrupt called by every change of hall sensorsvoid Hallinit(void){
TIM_ICInitStructure.TIM_Channel = TIM_Channel_1; TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising; TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1; TIM_ICInitStructure.TIM_ICFilter = 0x0; TIM_ICInit(TIM2, &TIM_ICInitStructure);TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;
TIM_ICInit(TIM2, &TIM_ICInitStructure);TIM_ICInitStructure.TIM_Channel = TIM_Channel_3;
TIM_ICInit(TIM2, &TIM_ICInitStructure); if(GPIOA->IDR&GPIO_Pin_0) TIM2->CCER|=0x2;else TIM2->CCER&=~((uint16_t)0x2); if(GPIOA->IDR&GPIO_Pin_1) TIM2->CCER|=0x20;else TIM2->CCER&=~((uint16_t)0x20); if(GPIOA->IDR&GPIO_Pin_2) TIM2->CCER|=0x200;else TIM2->CCER&=~((uint16_t)0x200); TIM_Cmd(TIM2, ENABLE);TIM_ITConfig(TIM2, TIM_IT_CC1|TIM_IT_CC2|TIM_IT_CC3, ENABLE);
} ============================= void TIM2_IRQHandler(void) { if(TIM_GetITStatus(TIM2, TIM_IT_CC1) == SET) { TIM_ClearFlag(TIM2, TIM_FLAG_CC1); TIM_ClearITPendingBit(TIM2, TIM_IT_CC1); if(GPIOA->IDR&GPIO_Pin_0) TIM2->CCER|=0x2;else TIM2->CCER&=~((int16_t)0x2); }if(TIM_GetITStatus(TIM2, TIM_IT_CC2) == SET) {
TIM_ClearFlag(TIM2, TIM_FLAG_CC2); TIM_ClearITPendingBit(TIM2, TIM_IT_CC2); if(GPIOA->IDR&GPIO_Pin_1) TIM2->CCER|=0x20;else TIM2->CCER&=~((int16_t)0x20); } if(TIM_GetITStatus(TIM2, TIM_IT_CC3) == SET) { TIM_ClearFlag(TIM2, TIM_FLAG_CC3); TIM_ClearITPendingBit(TIM2, TIM_IT_CC3); if(GPIOA->IDR&GPIO_Pin_2) TIM2->CCER|=0x200;else TIM2->CCER&=~((int16_t)0x200); } TIM_GenerateEvent(TIM8, TIM_EventSource_COM); }