Skip to main content
mehmet.karakaya
Associate III
May 31, 2011 7:38 PM UTC
Question

I want my TIM4 interrupt, interrupt TIM6 ISR- how ?

Posted on May 31, 2011 at 21:38

I want my TIM4 interrupt, interrupt TIM6 ISR ?

with this configuration I cannot

---------------------------------------------------------------------

  /* Enable the TIM4 gloabal Interrupt */

  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);

  NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn;

  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;  

  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

  NVIC_Init(&NVIC_InitStructure);

  /* Enable the TIM6 gloabal Interrupt */

  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);

  NVIC_InitStructure.NVIC_IRQChannel = TIM6_IRQn;

  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;    

  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

  NVIC_Init(&NVIC_InitStructure);
    This topic has been closed for replies.

    5 replies

    Tesla DeLorean
    Guru
    May 31, 2011 9:47 PM UTC
    Posted on May 31, 2011 at 23:47

    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); is a global setting, set it once, prior to initializing the individual sources.

    Your code looks reasonable. What's not happening?

    Are you initializing the timers properly, what about the service routines?

    Suggest you create a minimal demo that just does the TIM4 and TIM6 initialization and service routines.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    lowpowermcu
    Associate III
    Jun 1, 2011 8:06 AM UTC
    Posted on June 01, 2011 at 10:06

    Hi Clive,

    I think that mehmet should use priotity group 1 in order to get the preemption with

    preemtion priority equal to 0 for TIM4 and equal to 1 for TIM6. I think that using this config TIM4 can preempt (interrupt) TIM6. Isn't it ?

    Priority group has no preemption  priority !!!!

    mehmet.karakaya
    Associate III
    Jun 1, 2011 8:33 AM UTC
    Posted on June 01, 2011 at 10:33

    hello thank you ,

    my TIM4 is counting encoder pulses from servo motor

    I am building an variable named enkoder for position information

    which is updated in TIM6 ISR which is setup to 1 milisecond period

    but just during this line     enkoder=counterhi+TIM4->CNT; 

     

    sometimes the TIM4->CNT updates but counterhi is old value and there is about 10000 count difference in enkoder value and the motor gives overcurrent and stops becouse of speed control loop -

    I catch this with following line 

        if (labs(enkomem-enkoder)>500)      enkoder=counterhi+TIM4->CNT;

     

    however still 10000 difference becouse I think TIM4 ISR doesnot interrupt TIM6 ISR

    this happening every 1 or 2 minutes

    ---------------------------------------------------------------------------

    void TIM4_IRQHandler(void){

        if(TIM_GetITStatus(TIM4, TIM_IT_Update) == SET){

        TIM_ClearFlag(TIM4, TIM_FLAG_Update);

        TIM_ClearITPendingBit(TIM4, TIM_IT_Update);

        uint16_t current = TIM4->CNT;

          if ( current < 5000 ) counterhi += 10000; // Roll over in upwards direction

          else counterhi -= 10000;// Roll over in downwards direction

    }

    ---------------------------------------------------------------------------------------------

    void TIM6_IRQHandler(void){

     TIM_ClearFlag(TIM6, TIM_FLAG_Update);

     TIM_ClearITPendingBit(TIM6, TIM_IT_Update);

        enkoder=counterhi+TIM4->CNT;  at this point every 1 , 2 minute TIM4->CNT updates but counterhi doesnot

        if (labs(enkomem-enkoder)>500)      enkoder=counterhi+TIM4->CNT;

        speed = (enkomem-enkoder)*6;

        enkomem = enkoder; }

    ----------------------------------------------------------------------------

    hello lowpowermcu,

    can you please type the code sample for your suggestion

    Tesla DeLorean
    Guru
    Jun 1, 2011 11:20 AM UTC
    Posted on June 01, 2011 at 13:20

    Ok, so you have a race condition.

    So you'll want to have different preemption levels AND take steps to actively identify and mitigate the situation.

    Personally I might achieve that by giving TIM6 higher priority, storing the prior value of the high count, clearing the TIM4 Update as the last operation (ie AFTER the compare, increment/decrement), and checking the TIM4 update state in TIM6

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    choky_ndhie27
    Associate
    Oct 13, 2011 11:33 AM UTC
    Posted on October 13, 2011 at 13:33

    Hello clive1,

    I

     

    want to run

     

    a

     

    servo

     

    using the

     

    STM32

     

    Discovery

    , 

    if

     

    you

     

    have a

     

    suggestion

     

    program to

    run

     

    the

     

    servo

    ?

    or

     

    you have a

     

    simple

     

    code to

     

    run the

     

    servo

     

    on the

     

    STM32

     

    Discovery

    Thank you