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

Parents
  • You will need to change the seq_values[] to change the duty ratio. The .top_value in your code is 15625.

    E.g. for channel 0 (pin 2 in your code), you will need OR the 0x8000 with 7812 (.top_value/2), to get 1/8 duty ratio:

    static nrf_pwm_values_individual_t /*const*/ seq_values[] =
    {
        { 0x8000 | 7812 ,      0,      0,      0 },
        {      0, 0x8000,      0,      0 },
        {      0,      0, 0x8000,      0 },
        {      0,      0,      0, 0x8000 }
    };
    

    To get 1/6 ratio, you need to use 15625/3 = 5208:

    static nrf_pwm_values_individual_t /*const*/ seq_values[] =
    {
        { 0x8000 | 5208 ,      0,      0,      0 },
        {      0, 0x8000,      0,      0 },
        {      0,      0, 0x8000,      0 },
        {      0,      0,      0, 0x8000 }
    };
    

    The 0x8000 is here used to set bit 15 to 1, in order to invert the PWM output. See this post.

Reply
  • You will need to change the seq_values[] to change the duty ratio. The .top_value in your code is 15625.

    E.g. for channel 0 (pin 2 in your code), you will need OR the 0x8000 with 7812 (.top_value/2), to get 1/8 duty ratio:

    static nrf_pwm_values_individual_t /*const*/ seq_values[] =
    {
        { 0x8000 | 7812 ,      0,      0,      0 },
        {      0, 0x8000,      0,      0 },
        {      0,      0, 0x8000,      0 },
        {      0,      0,      0, 0x8000 }
    };
    

    To get 1/6 ratio, you need to use 15625/3 = 5208:

    static nrf_pwm_values_individual_t /*const*/ seq_values[] =
    {
        { 0x8000 | 5208 ,      0,      0,      0 },
        {      0, 0x8000,      0,      0 },
        {      0,      0, 0x8000,      0 },
        {      0,      0,      0, 0x8000 }
    };
    

    The 0x8000 is here used to set bit 15 to 1, in order to invert the PWM output. See this post.

Children
No Data
Related