<?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>how to define gpio pins and generate pwm on gpio pins?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/25852/how-to-define-gpio-pins-and-generate-pwm-on-gpio-pins</link><description>Hi There,
i am new to nrf51822 and new to program this kind of controller.I searched over the website, I couldn&amp;#39;t find a good introductory documentation for programming the nrf51822, specifically the nrf51-dk. i have two problems
1.i want to connect</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 30 Oct 2017 04:39:21 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/25852/how-to-define-gpio-pins-and-generate-pwm-on-gpio-pins" /><item><title>RE: how to define gpio pins and generate pwm on gpio pins?</title><link>https://devzone.nordicsemi.com/thread/101837?ContentTypeID=1</link><pubDate>Mon, 30 Oct 2017 04:39:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a89bcdd3-f811-45de-8081-653460b97fe8</guid><dc:creator>ASHISH</dc:creator><description>&lt;p&gt;The problem is solved Sigurd THANKS FOR YOUR HELP!!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to define gpio pins and generate pwm on gpio pins?</title><link>https://devzone.nordicsemi.com/thread/101831?ContentTypeID=1</link><pubDate>Wed, 18 Oct 2017 07:28:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ccbac3dc-0ef1-4479-8ab8-4d5d6cf5ef16</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;All the GPIO have the same voltage and current specification.&lt;/p&gt;
&lt;p&gt;You only have PWM in mV when you use pin 5?&lt;/p&gt;
&lt;p&gt;You get a 3.3V PWM when using ping 9 and 11?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to define gpio pins and generate pwm on gpio pins?</title><link>https://devzone.nordicsemi.com/thread/101833?ContentTypeID=1</link><pubDate>Mon, 16 Oct 2017 10:29:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:576ea9d0-49e6-41ce-94d9-023cbad6612d</guid><dc:creator>ASHISH</dc:creator><description>&lt;p&gt;hi,Sigurd thanks for everything. i have make some changes in my code and now everything is working but i am using pin no p0.05 for pwm output and output voltage is in mv so it is not sufficient to drive the vibration motor have also used transistor. i have given my pwm signal to base of transistor and load is connected to collector side but the voltage that i found at collector is 0.7 v.when i check pin p0.09 and p0.011 i found the voltage at this pin is 3.3 v and when tried to run this pin for pwm output the pin doesn&amp;#39;t respond anything just giving the 3.3 v output.Does the nrf51822 pins have  different voltage and current specification if yes then can you tell me which pins can i use for normal pwm output.
i have used this configuration for gpio&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;  nrf_gpio_pin_set(pin_number1);
    nrf_delay_ms(10);
    nrf_gpio_pin_clear(pin_number1);
    nrf_delay_ms(20); 
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;do i need to set some parameter in my program while configuring gpio so i will get 3.3 v pwm output insted of 130 mv.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to define gpio pins and generate pwm on gpio pins?</title><link>https://devzone.nordicsemi.com/thread/101832?ContentTypeID=1</link><pubDate>Mon, 16 Oct 2017 07:31:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b02bd891-05cd-4dd3-bedb-3498db8f935b</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Have you tried debugging ? Do you get the desired behavior if you remove &lt;code&gt;__SEV(); __WFE(); __WFE();&lt;/code&gt; ?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to define gpio pins and generate pwm on gpio pins?</title><link>https://devzone.nordicsemi.com/thread/101834?ContentTypeID=1</link><pubDate>Sun, 15 Oct 2017 06:56:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f7e151d8-6b6d-41ce-9427-fdf709c19104</guid><dc:creator>ASHISH</dc:creator><description>&lt;p&gt;Thanks man, your code is working but now i want to run my vibration motor using a ir sensor.This is my code&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;int main(void)
{
    adc_config();

    uart_config();
		nrf_gpio_cfg_output(pin_number1);

    printf(&amp;quot;\n\rADC HAL simple example\r\n&amp;quot;);

    printf(&amp;quot;Current sample value:\r\n&amp;quot;);

    while (true)
    {
			  // trigger next ADC conversion
			  nrf_adc_start();
        // enter into sleep mode
        __SEV();
        __WFE();
        __WFE();
			
			  nrf_delay_ms(100);	
				printf(&amp;quot;%d\r\n&amp;quot;, (int)adc_sample); // out ADC result
		
			if(adc_sample&amp;lt;20)
			{
			
   // while(true){
   //  for(int i=0;i&amp;lt;=20;i++){
    nrf_gpio_pin_set(pin_number1);
    nrf_delay_ms(10);
    nrf_gpio_pin_clear(pin_number1);
    nrf_delay_ms(20);
 // }
}
    }

	}
#endif /* NRF51 */
 //@} 
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;My ir sensor gives me values between (14 to 255)as i configured it at 8 bit resolution.i want run my vibration motor whenever i am getting ir sensor values below 20.and my vibration motor should stop when my sensor giving values above 20.but in my main code after reaching value 20 my motor is just running and code get stuck and sensor does not giving me the values what are the changes i have to make in my code to get desired output.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to define gpio pins and generate pwm on gpio pins?</title><link>https://devzone.nordicsemi.com/thread/101830?ContentTypeID=1</link><pubDate>Fri, 13 Oct 2017 13:36:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f0414bfc-c0f0-44ac-a033-5e4421f2b7d5</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;I would recommend using the PWM library for generating a PWM pulse. nrf_delay_ms will keep the CPU active, and consume much more power. nrf_delay_ms is also not very accurate.&lt;/p&gt;
&lt;p&gt;But you can get your code to work like this:&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;

#define pin_number1 1
int main(){

nrf_gpio_cfg_output(pin_number1);
    while(true){
for(int i=0;i&amp;lt;=20;i++){
    nrf_gpio_pin_set(pin_number1);
    nrf_delay_ms(10);
    nrf_gpio_pin_clear(pin_number1);
    nrf_delay_ms(20);
    }
}
}
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to define gpio pins and generate pwm on gpio pins?</title><link>https://devzone.nordicsemi.com/thread/101829?ContentTypeID=1</link><pubDate>Fri, 13 Oct 2017 13:24:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1aa8d814-f61a-4615-a969-099501eb1c23</guid><dc:creator>ASHISH</dc:creator><description>&lt;p&gt;Thanks,Sigurd i know i understand this example but i dint want to use configured pwm example and i am just generating pwm using a simple for loop.i have problem with initialization of gpio pins .i want to connect led to gpio pin and i want set that led high for 10 ms and low for 20 ms so how should i write a code for that how to declare gpio pins:
i have done this in my program but dint get any desired output :this is my code&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;int main(void)
{
#include pin_number 1
int main(){

nrf_gpio_cfg_output(pin_number1);
for(int i=0;i&amp;lt;=20;i++){
	nrf_gpio_pin_set(pin_number1);
	nrf_delay_ms(10);
	nrf_gpio_pin_clear(pin_number1);
	nrf_delay_ms(20);
	}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;what are the changes i have to make i am using pin no. 5 to connect to led what should i do?what are the initialization and functions header files that i need to include in my program? please give a demo code for this really helpful to me if you can!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to define gpio pins and generate pwm on gpio pins?</title><link>https://devzone.nordicsemi.com/thread/101828?ContentTypeID=1</link><pubDate>Fri, 13 Oct 2017 13:08:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cf1135a8-018c-4415-8f81-c25d00e6dca2</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Try something like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;/** @file
 * @defgroup pwm_example_main main.c
 * @{
 * @ingroup pwm_example
 *
 * @brief  PWM Example Application main file.
 *
 * This file contains the source code for a sample application using PWM.
 *
 *
 */

#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.

static volatile bool ready_flag;            // A flag indicating PWM status.

void pwm_ready_callback(uint32_t pwm_id)    // PWM callback function
{
    ready_flag = true;
}

int main(void)
{
    ret_code_t err_code;

    /* 1-channel PWM, 100000 microseconds period = 0.1 second , output on pin 4. */
    app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_1CH(100000L, 4);

    /* Switch the polarity of the second channel. */
    pwm1_cfg.pin_polarity[1] = APP_PWM_POLARITY_ACTIVE_HIGH;

    /* Initialize and enable PWM. */
    err_code = app_pwm_init(&amp;amp;PWM1,&amp;amp;pwm1_cfg,pwm_ready_callback);
    APP_ERROR_CHECK(err_code);
    app_pwm_enable(&amp;amp;PWM1);
    
    //DUTY CYCLE SET TO 50%
    while (app_pwm_channel_duty_set(&amp;amp;PWM1, 0, 50) == NRF_ERROR_BUSY);

   
    while (true)
    {
            // Use directly __WFE and __SEV macros since the SoftDevice is not available.

    // Wait for event.
    __WFE();

    // Clear Event Register.
    __SEV();
    __WFE();

    }

}


/** @} */
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to define gpio pins and generate pwm on gpio pins?</title><link>https://devzone.nordicsemi.com/thread/101827?ContentTypeID=1</link><pubDate>Fri, 13 Oct 2017 12:32:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:808661e9-cf7c-489a-89a4-dcd404e95177</guid><dc:creator>ASHISH</dc:creator><description>&lt;p&gt;hey,Sigurd
how to initialize gpio pins i want to generate a pwm on gpio pins so how to define pin number and its configuration in a function please give me a short example so i can understand it properly. i have already define pins but my program is not working properly this my program:&lt;/p&gt;
&lt;p&gt;#include &amp;lt;stdbool.h&amp;gt;
#include &amp;lt;stdint.h&amp;gt;
#include &amp;quot;nrf_delay.h&amp;quot;
#include &amp;quot;nrf_gpio.h&amp;quot;
#include &amp;quot;boards.h&amp;quot;
#include &amp;quot;bsp.h&amp;quot;
#include &amp;quot;nrf.h&amp;quot;
#include &amp;quot;nrf_gpio.h&amp;quot;
#include &amp;quot;nrf_delay.h&amp;quot;
#define pin_number 5
//#include &amp;quot;nrf_drv_gpiote.h&amp;quot;
#define 	NRF_GPIO_PIN_MAP(port,pin)   ((port &amp;lt;&amp;lt; 5) | (pin &amp;amp; 0x1F))
//const uint8_t leds_list[LEDS_NUMBER] = LEDS_LIST;&lt;/p&gt;
&lt;p&gt;/**&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;@brief Function for application main entry.
*/
int main(void)
{
for(int i=0;i&amp;lt;=20;i++)
{
nrf_gpio_cfg_output(5);
nrf_gpio_pin_set(5);
nrf_delay_ms(10);
nrf_gpio_pin_clear(5);
nrf_delay_ms(20);
}
whats wrong with my code ..i am using a just simple for loop for a simple pwm generation
great help appreciated!!!&lt;/li&gt;
&lt;/ul&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to define gpio pins and generate pwm on gpio pins?</title><link>https://devzone.nordicsemi.com/thread/101826?ContentTypeID=1</link><pubDate>Fri, 13 Oct 2017 07:11:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ba6a2aa2-f720-4f6c-9db8-c72152e6769c</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;You can change the duty cycle with the function &lt;code&gt;app_pwm_channel_duty_set&lt;/code&gt;, i.e to set it to 50% duty on PWM channel 0:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;while (app_pwm_channel_duty_set(&amp;amp;PWM1, 0, 50) == NRF_ERROR_BUSY);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To increase the voltage, you will need a higher voltage soruce, and use e.g. a transistor to amplify the PWM signal.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to define gpio pins and generate pwm on gpio pins?</title><link>https://devzone.nordicsemi.com/thread/101825?ContentTypeID=1</link><pubDate>Fri, 13 Oct 2017 06:26:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:46648bc2-846c-4fe1-af8a-06c1a9208d39</guid><dc:creator>ASHISH</dc:creator><description>&lt;p&gt;Thanks for your reply i have replaced the BSP_LED_0and BSP_LED_1 with gpio pins 5 and 6 and i connected pin 6 to pwm input of vibration motor.but my vibration motor is not running .the gpio pins give me pwm voltage between 0 to 2.9v.how to increases pwm output voltage? how to change the period and duty cycle in this program? what are the changes i have to make in my program?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to define gpio pins and generate pwm on gpio pins?</title><link>https://devzone.nordicsemi.com/thread/101836?ContentTypeID=1</link><pubDate>Thu, 12 Oct 2017 13:02:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3fa806b6-c3e2-4c06-9de4-f5714ce7db93</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;If you need PWM on 2 GPIO pins, use &lt;code&gt;APP_PWM_DEFAULT_CONFIG_2CH()&lt;/code&gt;. If you need PWM on 1 GPIO pin, use &lt;code&gt;APP_PWM_DEFAULT_CONFIG_1CH()&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The first argument is the period in microseconds, and second argument is the GPIO pin you want to use.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;APP_PWM_DEFAULT_CONFIG_1CH(period_in_us,#PIN_YOU_WANT_TO_USE)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In the PWM library example we have this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt; app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_2CH(5000L, BSP_LED_0, BSP_LED_1);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So you can just remove the &lt;code&gt;BSP_LED_0&lt;/code&gt;and &lt;code&gt;BSP_LED_1&lt;/code&gt;, and replace it with the GPIO pin number you want to use.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to define gpio pins and generate pwm on gpio pins?</title><link>https://devzone.nordicsemi.com/thread/101835?ContentTypeID=1</link><pubDate>Thu, 12 Oct 2017 12:56:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5a91a96a-c3cf-4f18-ab80-95ad6f4af18b</guid><dc:creator>ASHISH</dc:creator><description>&lt;p&gt;Thanks,sigurd but this example drives led using pwm and my problem is that i want to drive vibration motor using pwm waveform.so how to define gpio pins ?how to generate pwm waveform on gpio pins?can you explain me in detail how to interface vibration motor to  nrf51822?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to define gpio pins and generate pwm on gpio pins?</title><link>https://devzone.nordicsemi.com/thread/101824?ContentTypeID=1</link><pubDate>Thu, 12 Oct 2017 08:44:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d8e00a4a-e0e3-44b8-824c-edd73ea2b925</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;As an introduction, I would recommend the &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v12.3.0/nrf51_getting_started.html?cp=4_0_3_1"&gt;Getting Started guide&lt;/a&gt; and our &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v12.3.0/examples.html?cp=4_0_3_4"&gt;examples&lt;/a&gt; in the SDK.
For PWM generation on the nRF51, you should take a look at the PWM library example. You can find the example in the folder: &lt;code&gt;&amp;lt;SDK_InstallFolder&amp;gt;\examples\peripheral\pwm_library&lt;/code&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>