what is the highest priority for my timer application ?

Hi 

my application is driving a RGB LED by one wire, this is request a higher sequence , when you drive the RGB LED ,this task can not be interrupt , I am use timer3 to call this sub routine in period 30ms ,

my question is ,can I set timer 3 with highest priority 0?  does this mean there will no interrupt in any time ?

Parents
  • Hi 

    Are you using a SoftDevice in your application?

    If so interrupt priorities 0 and 1 will not be available, and there is always a chance you could get an interrupt from the SoftDevice. 

    How long is the command string that you have to send to the RGB LED, and how fast does it have to toggle at the quickest?

    A secure way to update a pin without risk of interruption is to use the PWM module to toggle the pin. Then you can prepare a list of values in RAM, and have the PWM module play it back at a predetermined speed. 

    The main drawback of this method is that you waste a bit of RAM, since each PWM sample takes up 16-bits of memory, even if you only set the output pin low or high. 

    Best regards
    Torbjørn

  • Hi  Torbjorn,

    Thank you for your prompt reply.

    Yes, I am using SoftDevice in my application.

    Send command  frequency is not very fast , MCU send it to RGB LED per 100ms ,

    and ,the length of the command string is not too long ,I think ,it is 4 LED x  24bit  (3*8bits) /LED ,

    I do not have the experience to use PWM to drive one pin to drive RGB LED, is there any samples on this application?

    by the way ,Since the highest priority interrupt 0 and 1 is used by SoftDevice ,how could you avoid PWM can not be

    interrupt by SoftDevice ? 

    Please .

  • Hi 

    If you look at the pwm_driver example in the nRF5 SDK you will find some different ways to use the PWM driver:
    \nRF5_SDK_17.1.0_ddde560\examples\peripheral\pwm_driver

    I think demo3 from this example is the one that is the most relevant for your use case, and I have included the setup code below:

    static void demo3(void)
    {
        NRF_LOG_INFO("Demo 3");
    
        /*
         * This demo uses only one channel, which is reflected on LED 1.
         * The LED blinks three times (200 ms on, 200 ms off), then it stays off
         * for one second.
         * This scheme is performed three times before the peripheral is stopped.
         */
    
        nrf_drv_pwm_config_t const config0 =
        {
            .output_pins =
            {
                BSP_LED_0 | NRF_DRV_PWM_PIN_INVERTED, // channel 0
                NRF_DRV_PWM_PIN_NOT_USED,             // channel 1
                NRF_DRV_PWM_PIN_NOT_USED,             // channel 2
                NRF_DRV_PWM_PIN_NOT_USED,             // channel 3
            },
            .irq_priority = APP_IRQ_PRIORITY_LOWEST,
            .base_clock   = NRF_PWM_CLK_125kHz,
            .count_mode   = NRF_PWM_MODE_UP,
            .top_value    = 25000,
            .load_mode    = NRF_PWM_LOAD_COMMON,
            .step_mode    = NRF_PWM_STEP_AUTO
        };
        APP_ERROR_CHECK(nrf_drv_pwm_init(&m_pwm0, &config0, NULL));
        m_used |= USED_PWM(0);
    
        // This array cannot be allocated on stack (hence "static") and it must
        // be in RAM (hence no "const", though its content is not changed).
        static uint16_t /*const*/ seq_values[] =
        {
            0x8000,
                 0,
            0x8000,
                 0,
            0x8000,
                 0
        };
        nrf_pwm_sequence_t const seq =
        {
            .values.p_common = seq_values,
            .length          = NRF_PWM_VALUES_LENGTH(seq_values),
            .repeats         = 0,
            .end_delay       = 4
        };
    
        (void)nrf_drv_pwm_simple_playback(&m_pwm0, &seq, 3, NRF_DRV_PWM_FLAG_STOP);
    }
    

    It uses a single output pin, and sets up a sequence of values that gets played back 3 times. In your case you can change the third parameter in the nrf_drv_pwm_simple_playback(..) call to 1, in order to only play the sequence one time. 

    You can also change the .top_value parameter, which will control how fast the PWM sequence is played back. The lower the value, the faster the playback. 

    Michael.lee said:

    Since the highest priority interrupt 0 and 1 is used by SoftDevice ,how could you avoid PWM can not be

    interrupt by SoftDevice ? 

    The PWM peripheral uses an EasyDMA channel, which allows it to read data from the RAM in the background even while the SoftDevice or application is using the MCU for something else. You only need to run some code to start the sequence, and then the PWM peripheral will do everything else. 

    For a more detailed description of the PWM peripheral, please read through the PWM chapter in the product specification, here

    Best regards
    Torbjørn

  • Hi Torbiorn

    This does really help

    Thank you so much,  Have good day!

    Michael

Reply Children
Related