cancel
Showing results for 
Search instead for 
Did you mean: 

timer hall sensor mode - why doesnot it function corectly?

mehmet.karakaya
Associate III
Posted on December 29, 2010 at 23:30

timer hall sensor mode - why doesnot it function corectly?

9 REPLIES 9
lowpowermcu
Associate II
Posted on May 17, 2011 at 14:19

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üfter

mehmet.karakaya
Associate III
Posted on May 17, 2011 at 14:19

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 example

lowpowermcu
Associate II
Posted on May 17, 2011 at 14:19

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 register

TIM_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üfter

mehmet.karakaya
Associate III
Posted on May 17, 2011 at 14:19

hello MCU Lüfter ,

in your example interfacing and slave timers are both timer2

( it confused me )

I found another solution

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 :)

lowpowermcu
Associate II
Posted on May 17, 2011 at 14:19

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

alexandernath9
Associate II
Posted on May 17, 2011 at 14:19

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. nath

mehmet.karakaya
Associate III
Posted on May 17, 2011 at 14:19

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 interrupt

alexandernath9
Associate II
Posted on May 17, 2011 at 14:19

The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6Zg&d=%2Fa%2F0X0000000bqz%2F5SJj8lj6yvKX3F6kwdLKZrCOPAeBXPAV9isTYnlgta4&asPdf=false
mehmet.karakaya
Associate III
Posted on May 17, 2011 at 14:19

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 sensors

void 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);

}