This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Now need pwm_driver demo5 duty ratio, is there any way to 1/6 or 1/8?

How do you do Now need pwm_driver demo5 duty ratio, is there any way to 1/6 or 1/8?PWM and phase difference is 4 road? Ask for a few days, change seq_values [], but how to change?Try to success.

image description

  • Hello: Nrf_drv_pwm_sequence_values_update () this function how to update the const nrf_pwm_values_individual_t / * * / seq_values [] duty ratio of the array?

  • You can create a new array of nrf_pwm_values_individual_t , and the use this to update the pwm duty ratio.

    static nrf_pwm_values_individual_t /*const*/ seq_values_new[] =
    {
        { 2000 ,      0,      0,      0 },
        {      0, 0x8000,      0,      0 },
        {      0,      0, 0x8000,      0 },
        {      0,      0,      0, 0x8000 }
    };
    
    nrf_pwm_values_t new_pwm_values; 
    
    new_pwm_values.p_individual = seq_values_new;
    
     nrf_drv_pwm_sequence_values_update(&m_pwm0,1,new_pwm_values);
    
  • Hello: Although this can be updated, but the number or dead, not according to my bluetooth receive digital to the array, because the static, is there a way to do The static nrf_pwm_values_individual_t const / * * / seq_values_new [] = { {2000 | vale, 0, 0, 0}. {0, 0 x8000, 0, 0}. {0, 0, 0 x8000, 0}. {0, 0, 0, 0 x8000} };

  • You only need to declare the static nrf_pwm_values_individual_t seq_values_new[] once. Declare this at top of main.c, after the includes.

    And when you receive a new value over BLE, and want to use it to update the PWM duty cycle, you can do it like this:

    uint32_t vale = value_from_BLE;
    
    seq_values_new[0].channel_0 = (2000 | vale);
    
    nrf_pwm_values_t new_pwm_values; 
    
    new_pwm_values.p_individual = seq_values_new;
    
    nrf_drv_pwm_sequence_values_update(&m_pwm0,1,new_pwm_values);
    
  • seq_values_new[0].channel_0 = (0x8000|2778|m_demo1_top/2); seq_values_new[0].channel_2 = (0x8000|2778|m_demo1_top/2); nrf_pwm_values_t new_pwm_values;

    new_pwm_values.p_individual = seq_values_new;
        
    nrf_drv_pwm_sequence_values_update(&m_pwm0,1,new_pwm_values);
    

    m_demo1_top from BLE, There are two problems. 1, seq_values_new [0]. Channel_0 did not change 2, seq_values_new [0]. Channel_2 = (0 x8000 | 2778 | m_demo1_top / 2);This setting change cycle and duty cycle

Related