More CTL ticks per second

Comments

7 comments

  • Avatar
    Mark

    check out the ctl_start_timer() in STM32_ctl.c

    the bit of interest is and yes, default is 10ms

     SysTick->LOAD = (SystemCoreClock/8/100)-1; // interrupt every 10 ms
    #ifdef CTL_TASKING
      ctl_time_increment = 10; // so increment the counter by 10 to get the ms counter
    #endif

    change to

     SysTick->LOAD = (SystemCoreClock/8/1000)-1; // interrupt every 1 ms

    ctl_time_increment = 1;

    0
    Comment actions Permalink
  • Avatar
    Jolyon Latham

    Thanks Mark.

    I solved the problem using priorities in the end but this top tip will certainly come in useful.

     

    All the best.

    0
    Comment actions Permalink
  • Avatar
    Dr Danish Ali

    You can make CTL calls from within an ISR. But you must  use the ctl_enter_isr() and ctl_exit_isr() calls so that the system can know to check for a context-switch when leaving the outermost ISR:

    void ADC3_IRQHandler(void) {
        ctl_enter_isr();
        ctl_events_set_clear(&adc_es, ADC_ES_CONVERSION, 0);
        ADC3->SR = ~ADC_SR_EOC;     // on return the previously-waiting thread will execute immediately
    }

    0
    Comment actions Permalink
  • Avatar
    Dr Danish Ali

    void ADC3_IRQHandler(void) {
        ctl_enter_isr();
        ctl_events_set_clear(&adc_es, ADC_ES_CONVERSION, 0);
        ADC_TOUCHSCREEN->SR = ~ADC_SR_EOC;
        ctl_exit_isr();
    }

    0
    Comment actions Permalink
  • Avatar
    Jolyon Latham

    Danish,

    Thank you for this information, it is very helpful.

    BR,

    Jolyon

    0
    Comment actions Permalink
  • Avatar
    Anders Ruuswik

    Hi,

    I'm trapped with the same problem - I need to do a calculation every 1 ms but the ctl_time_increment is set to 10.

    I changed the counter load from TEN_MS to ONE_MS as indicated below (slightly different from the example above - hence I paste the entire function.)

    I also tried defining CTL_TASKING in the preprocessor declarations but nether changed the ctl_time_increment from 10 to 1. And I checked in real time as well so there really still is a 10ms resolution on the timer.

    Any additional help is appreciated.

     

    void ctl_start_timer(CTL_ISR_FN_t timerFn)
    {    
      userTimerISR = timerFn;    
    //  SysTick->LOAD = TEN_MS-1;
      SysTick->LOAD = ONE_MS-1;

      SysTick->VAL = 0;
    #ifdef USEPROCESSORCLOCK
      SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_TICKINT_Msk | SysTick_CTRL_ENABLE_Msk;
    #else
      SysTick->CTRL = SysTick_CTRL_TICKINT_Msk | SysTick_CTRL_ENABLE_Msk;
    #endif
    #ifdef CTL_TASKING  
      // Set PendSV priority (PendSV must have lowest priority)
      ctl_set_priority(PendSV_IRQn, ctl_lowest_isr_priority());
    #endif
      // Set SysTick priority
      ctl_set_priority(SysTick_IRQn, ctl_highest_isr_priority());
    }

    0
    Comment actions Permalink
  • Avatar
    Anders Ruuswik

    Sorry - I checked again and now it works. Maybe I misspelled CTL_TASKING or something. Just in case I copied and pasted and then it worked. I didn't think it would be possible to misspell CTL_TASKING but I guess I did. :-).

     

     

    0
    Comment actions Permalink

Please sign in to leave a comment.