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

52832 PWM delay

I use timer+ppi+pwm model.my init code like this

void PWM_init()
{
/* ƵµÀµÄ PWM, 200Hz£¨5000us=5ms), ͨ¹ý ¿ª·¢°åLED ¹Ü½ÅÊä³ö. */
	app_pwm_config_t pwm0_cfg = APP_PWM_DEFAULT_CONFIG_1CH(250L, PWM_PIN);

	/* Çл»ÆµµÀµÄ¼«ÐÔ */
	pwm0_cfg.pin_polarity[0] = APP_PWM_POLARITY_ACTIVE_HIGH;

	/* ³õʼ»¯ºÍʹÄÜPWM. */
	err_code = app_pwm_init(&PWM0,&pwm0_cfg,pwm_ready_callback);
	APP_ERROR_CHECK(err_code);
	app_pwm_enable(&PWM0);//ʹÄÜPWM
	while (app_pwm_channel_duty_set(&PWM0, 0, 50) == NRF_ERROR_BUSY); 
}

I use some code to close and open PWM ,like this

void PWM_stop()
{
    app_pwm_disable(&PWM0);
}

void PWM_start()
{
    app_pwm_enable(&PWM0);
	while (app_pwm_channel_duty_set(&PWM0, 0, 50) == NRF_ERROR_BUSY);
}

question:I use oscilloscopes to check PWM, I find that when I start PWM,I must to wait about 260us before 52832 product PWM.

                 why I need to wait 260us?

Parents
  • Hi,

     Could you explain your measurement setup a bit more in detail?

    • Are you measuring from the moment the CPU boots until the PWM signal is produced?
    • Or are you measuring from the moment the function PWM_start() is called and until the PWM signal is produced?

    If it's the latter, how are you signaling that the function PWM_start() is called?

    Best regards

    Jared 

  • Hi, Jared.

    thank you for your answer.

    I set pin17 to output high level after "while (app_pwm_channel_duty_set(&PWM0, 0, 50) == NRF_ERROR_BUSY);"

    and then set pin17 output low level after I disable the PWM.

  • if I set pwm like this "while (app_pwm_channel_duty_set(&PWM0, 0, 100) == NRF_ERROR_BUSY)",the delay time only 2.2us.why have all this strange phenomena

  • #include <stdbool.h>
    #include <stdint.h>
    #include "nrf.h"
    #include "app_error.h"
    #include "bsp.h"
    #include "nrf_delay.h"
    #include "app_pwm.h"
    
    APP_PWM_INSTANCE(PWM1,1);                   // Create the instance "PWM1" using TIMER1.
    
    static volatile bool ready_flag;            // A flag indicating PWM status.
    
    void pwm_ready_callback(uint32_t pwm_id)    // PWM callback function
    {
    
    }
    
    int main(void)
    {
    ret_code_t  err_code;
    uint16_t value = 0XFF;
    
    app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_1CH(10,3);
    pwm1_cfg.pin_polarity[0] = APP_PWM_POLARITY_ACTIVE_HIGH;
    nrf_gpio_cfg_output(4);
    nrf_gpio_pin_clear(4);
    
    
    
    err_code = app_pwm_init(&PWM1,&pwm1_cfg, pwm_ready_callback);
    APP_ERROR_CHECK(err_code);
    app_pwm_enable(&PWM1);
    while (app_pwm_channel_duty_set(&PWM1, 0, value) == NRF_ERROR_BUSY);
    nrf_gpio_pin_set(4);
    
    
    while(true)
    {
    }
    
    }

  • #include <stdbool.h>
    #include <stdint.h>
    #include "nrf.h"
    #include "app_error.h"
    #include "bsp.h"
    #include "nrf_delay.h"
    #include "app_pwm.h"
    
    APP_PWM_INSTANCE(PWM0,1);                   // ´´½¨Ò»¸öʹÓö¨Ê±Æ÷1²úÉúPWM²¨µÄʵÀý
    
    static volatile bool ready_flag;            // ʹÓÃÒ»¸ö±ê־λ±íʾPWM״̬
    
    void pwm_ready_callback(uint32_t pwm_id)    // PWM»Øµ÷¹¦ÄÜ
    {
        ready_flag = true;
    }
    
    void ADC_PWM_START(void)
    {
    	app_pwm_enable(&PWM0);
    	while (app_pwm_channel_duty_set(&PWM0, 0, 50) == NRF_ERROR_BUSY);
    	nrf_gpio_pin_set(16);
    }
    
    void ADC_PWM_STOP(void)
    {
    	app_pwm_disable(&PWM0);
    	nrf_gpio_pin_clear(16);
    }
    
    int main(void)
    {
        ret_code_t err_code;
        
        /* 2-¸öƵµÀµÄ PWM, 200Hz£¨5000us=5ms), ͨ¹ý ¿ª·¢°åLED ¹Ü½ÅÊä³ö. */
        app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_1CH(250, 26);
        
        /* Çл»Á½¸öƵµÀµÄ¼«ÐÔ */
        pwm1_cfg.pin_polarity[0] = APP_PWM_POLARITY_ACTIVE_HIGH;
        
        /* ³õʼ»¯ºÍʹÄÜPWM. */
        err_code = app_pwm_init(&PWM0,&pwm1_cfg,NULL);
        APP_ERROR_CHECK(err_code);
        app_pwm_enable(&PWM0);//ʹÄÜPWM
       		
                
    		/* ÉèÖÃÕ¼¿Õ±È - ²»Í£ÉèÖÃÖ±µ½PWM×¼±¸ºÃ. */
    		while (app_pwm_channel_duty_set(&PWM0, 0, 0) == NRF_ERROR_BUSY);  
    		/* µÈ´ý»Øµ÷ */
    		nrf_delay_ms(25);
    		nrf_gpio_cfg_output(16);
    		nrf_gpio_pin_set(16);
    	
        while(true)
        {
    				nrf_delay_ms(1);
    				ADC_PWM_STOP();
    				nrf_delay_ms(1);
            ADC_PWM_START();								
        }
        
    }

    my code like this.it's diferent with your.please test my code on your circuit.thaks

  • Hi,

    The added delay is a result of the prolonged period. You can see this yourself by reducing the period to 10 for example.It should then take shorter time for the signal to be produced on the GPIO. It's not a delay per se, but a consequence of a bigger period.

    Jared 

  • sorry,I dont kown what you mean to reduce the period to 10.

Reply Children
Related