<?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>Configure PWM driver to have similar behaviour as an Arduino analogWrite()</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/56330/configure-pwm-driver-to-have-similar-behaviour-as-an-arduino-analogwrite</link><description>Hi, 
 I&amp;#39;m interested in passing a PWM wave form to drive a motor using an Allegro A4963 . There exists an Arduino library that does just that and in order to set speed they perform an &amp;quot; analogWrite() &amp;quot; on a certain speed. 
 How do I use the PWM driver</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 08 Jan 2020 15:09:36 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/56330/configure-pwm-driver-to-have-similar-behaviour-as-an-arduino-analogwrite" /><item><title>RE: Configure PWM driver to have similar behaviour as an Arduino analogWrite()</title><link>https://devzone.nordicsemi.com/thread/228192?ContentTypeID=1</link><pubDate>Wed, 08 Jan 2020 15:09:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0a9b4898-8a53-4a2c-a032-d47d1541df9d</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Yes, it seems you got it about right.&lt;/p&gt;
&lt;p&gt;If you are looking for a simpler PWM, I would recommend that you peek into the &amp;quot;pwm_library&amp;quot; example as well. There you will basically have a function called&amp;nbsp;app_pwm_channel_duty_set(), which takes a number from 0 to 100% where 0 would be GND and 100 would be VDD. This function is also easy to modify to use 1/1000 instead of 1/100 if you need higher accuracy.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Configure PWM driver to have similar behaviour as an Arduino analogWrite()</title><link>https://devzone.nordicsemi.com/thread/228125?ContentTypeID=1</link><pubDate>Wed, 08 Jan 2020 12:41:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:07443fb5-0e9f-4ebb-93db-14d8e9bf7739</guid><dc:creator>Or</dc:creator><description>&lt;p&gt;Following code seems to be doing the job:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;nrf_drv_pwm_config_t config =
    {
        // These are the common configuration options we use for all PWM
        // instances.
        .irq_priority = APP_IRQ_PRIORITY_LOWEST,
        .count_mode   = NRF_PWM_MODE_UP,
        .step_mode    = NRF_PWM_STEP_AUTO,
    };

config.output_pins[0] = BSP_LED_0 | NRF_DRV_PWM_PIN_INVERTED;
config.output_pins[1] = NRF_DRV_PWM_PIN_NOT_USED;
config.output_pins[2] = NRF_DRV_PWM_PIN_NOT_USED;
config.output_pins[3] = NRF_DRV_PWM_PIN_NOT_USED;
config.base_clock     = NRF_PWM_CLK_125kHz;
config.top_value      = 255;
config.load_mode      = NRF_PWM_LOAD_COMMON;
RETURN_ON_ERROR(nrf_drv_pwm_init(&amp;amp;m_pwm0, &amp;amp;config, NULL));

// This array cannot be allocated on stack (hence &amp;quot;static&amp;quot;) and it must
// be in RAM (hence no &amp;quot;const&amp;quot;, though its content is not changed).
static nrf_pwm_values_common_t /*const*/ pwm0_seq_values[1];
pwm0_seq_values[0] = value; // ** this is the value passed to &amp;quot;analogWrite()&amp;quot; **

nrf_pwm_sequence_t const pwm0_seq =
{
	.values.p_common  = pwm0_seq_values,
	.length           = NRF_PWM_VALUES_LENGTH(pwm0_seq_values),
	.repeats          = 1,
	.end_delay        = 0
};

nrf_drv_pwm_simple_playback(&amp;amp;m_pwm0, &amp;amp;pwm0_seq, 1, NRF_DRV_PWM_FLAG_LOOP);&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>