<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Pwm minimum frequency setting</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/22292/pwm-minimum-frequency-setting</link><description>hi,
I would like to use pwm to output the 1HZ waveform to drive the motor, but when I set the frequency to be 1HZ, I can not find the device and cause 51822 to reset.
This is my code: 
 Motor_Pwm_Init(1000000,1,1);
 Motor_Duty_Set(50,50);

 void</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 24 May 2017 12:43:12 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/22292/pwm-minimum-frequency-setting" /><item><title>RE: Pwm minimum frequency setting</title><link>https://devzone.nordicsemi.com/thread/87652?ContentTypeID=1</link><pubDate>Wed, 24 May 2017 12:43:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:83912e78-8df1-4f58-8860-993ca741dfb1</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Could it be a timeout from the WDT that is causing the issues?&lt;/p&gt;
&lt;p&gt;See &lt;a href="https://devzone.nordicsemi.com/question/60125/my-device-is-freezing-and-restarting/"&gt;this post&lt;/a&gt; about how to debug and find the reason for the reset.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Pwm minimum frequency setting</title><link>https://devzone.nordicsemi.com/thread/87651?ContentTypeID=1</link><pubDate>Wed, 24 May 2017 11:40:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:83bf4654-c830-4c5c-9d65-b5f60fe42ef5</guid><dc:creator>muyang</dc:creator><description>&lt;p&gt;Through repeated tests, I found the problem is that when I only set a pin of duty, it is working properly, but the two set at the same time duty, the program stuck, and then reset&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;uint8_t Motor_Duty_Set(uint32_t DutyLeft,uint32_t DutyRight)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;{
uint8_t TimeOut = 0;
//wdt_feed();
while (app_pwm_channel_duty_set(&amp;amp;PWM1,(uint8_t) 0, DutyLeft) == NRF_ERROR_BUSY)
{
wdt_feed();
#if 0
if(TimeOut ++ &amp;gt; 200)
{
TimeOut = 0;
return 0;	
}
#endif
}&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;wdt_feed();
#if 0
while (app_pwm_channel_duty_set(&amp;amp;PWM1,(uint8_t) 1, DutyRight) == NRF_ERROR_BUSY)
{
	#if 0
	if(TimeOut ++ &amp;gt; 200)
	{
		TimeOut = 0;
		return 0;	
	}	
	#endif
}
#endif
//wdt_feed();
//return 1;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;So that you can work and output the correct 1hz waveform, should I only open the left, the right side of the code shielded&lt;/p&gt;
&lt;p&gt;But when I try to set the duty cycle of both channels, the device is reset, the code is as follows&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;uint8_t Motor_Duty_Set(uint32_t DutyLeft,uint32_t DutyRight)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;{
uint8_t TimeOut = 0;
//wdt_feed();
while (app_pwm_channel_duty_set(&amp;amp;PWM1,(uint8_t) 0, DutyLeft) == NRF_ERROR_BUSY)
{
wdt_feed();
#if 0
if(TimeOut ++ &amp;gt; 200)
{
TimeOut = 0;
return 0;	
}
#endif
}&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;wdt_feed();
#if 1
while (app_pwm_channel_duty_set(&amp;amp;PWM1,(uint8_t) 1, DutyRight) == NRF_ERROR_BUSY)
{
	#if 0
	if(TimeOut ++ &amp;gt; 200)
	{
		TimeOut = 0;
		return 0;	
	}	
	#endif
}
#endif
//wdt_feed();
//return 1;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;enter code here
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Pwm minimum frequency setting</title><link>https://devzone.nordicsemi.com/thread/87650?ContentTypeID=1</link><pubDate>Wed, 24 May 2017 11:13:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a530450b-c9ce-4654-ab24-09c8f50fb231</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;I used the pwm_library example in the SDK. This is the main.c code I used:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdbool.h&amp;gt;
#include &amp;lt;stdint.h&amp;gt;
#include &amp;quot;nrf.h&amp;quot;
#include &amp;quot;app_error.h&amp;quot;
#include &amp;quot;bsp.h&amp;quot;
#include &amp;quot;nrf_delay.h&amp;quot;
#include &amp;quot;app_pwm.h&amp;quot;

APP_PWM_INSTANCE(PWM1,1);                   // Create the instance &amp;quot;PWM1&amp;quot; using TIMER1.


 void Motor_Pwm_Init(uint32_t freq,uint32_t MotorLeft_Polarity,uint32_t MotorRight_Polarity)
{

    uint32_t err_code;

    app_pwm_disable(&amp;amp;PWM1);
    app_pwm_uninit(&amp;amp;PWM1);
    app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_2CH(freq,3,4);   //set pwm frequency  

    pwm1_cfg.pin_polarity[0] = MotorLeft_Polarity;                  //Polarity of active state on pin.
    pwm1_cfg.pin_polarity[1] = MotorRight_Polarity;

    err_code = app_pwm_init(&amp;amp;PWM1,&amp;amp;pwm1_cfg,NULL);           //  Init the PWM
    APP_ERROR_CHECK(err_code);

    app_pwm_enable(&amp;amp;PWM1);  

}

uint8_t Motor_Duty_Set(uint32_t DutyLeft,uint32_t DutyRight)
{
    uint8_t TimeOut = 0;
    //wdt_feed();
    while (app_pwm_channel_duty_set(&amp;amp;PWM1,(uint8_t) 0, DutyLeft) == NRF_ERROR_BUSY)
    {

    }
    
    while (app_pwm_channel_duty_set(&amp;amp;PWM1,(uint8_t) 1, DutyLeft) == NRF_ERROR_BUSY)
    {

    }
}

int main(void)
{
    
    Motor_Pwm_Init(1000000,1,1);
    Motor_Duty_Set(50,50);
    
    while (true)
    {

    }

}


/** @} */
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Pwm minimum frequency setting</title><link>https://devzone.nordicsemi.com/thread/87649?ContentTypeID=1</link><pubDate>Wed, 24 May 2017 11:11:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a5fe4ca6-5966-4561-8898-bc21e38343d4</guid><dc:creator>muyang</dc:creator><description>&lt;p&gt;Can you send me your project&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Pwm minimum frequency setting</title><link>https://devzone.nordicsemi.com/thread/87648?ContentTypeID=1</link><pubDate>Wed, 24 May 2017 11:09:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2d7ff0df-04b0-44f7-acca-6084dd886997</guid><dc:creator>muyang</dc:creator><description>&lt;p&gt;Freq this parameter you fill how much? I really can not run here when the 1HZ&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Pwm minimum frequency setting</title><link>https://devzone.nordicsemi.com/thread/87647?ContentTypeID=1</link><pubDate>Wed, 24 May 2017 10:58:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:338899ec-0340-49de-811c-6b330bed86e4</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I get 1 Hz with the code you posted. Note that you will only get 1 Hz on the &lt;code&gt;MOTOR_LEFT_PIN&lt;/code&gt; since you are only setting the duty cycle to 50% on that pin/channel.&lt;/p&gt;
&lt;p&gt;You can modify the Motor_Duty_Set() function to also set the duty cycle for the &lt;code&gt;MOTOT_RIGHT_PIN&lt;/code&gt; pin/channel like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;uint8_t Motor_Duty_Set(uint32_t DutyLeft,uint32_t DutyRight)
{
    uint8_t TimeOut = 0;
    wdt_feed();
    while (app_pwm_channel_duty_set(&amp;amp;PWM1,(uint8_t) 0, DutyLeft) == NRF_ERROR_BUSY)
    {

    }

    while (app_pwm_channel_duty_set(&amp;amp;PWM1,(uint8_t) 1, DutyLeft) == NRF_ERROR_BUSY)
    {

    }

}
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Pwm minimum frequency setting</title><link>https://devzone.nordicsemi.com/thread/87646?ContentTypeID=1</link><pubDate>Wed, 24 May 2017 03:30:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:448fe47d-6071-498c-a5cb-3382b14e434b</guid><dc:creator>muyang</dc:creator><description>&lt;p&gt;I want to output 1HZ what should i do?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Pwm minimum frequency setting</title><link>https://devzone.nordicsemi.com/thread/87645?ContentTypeID=1</link><pubDate>Wed, 24 May 2017 03:17:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:47a93836-701a-4843-84d8-e5eadd6b8bb9</guid><dc:creator>muyang</dc:creator><description>&lt;p&gt;I have been tested to find the minimum frequency can be set to 4HZ, I would like to change with a small time found 51822 reset&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>