<?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 resign pins in saadc example</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/57043/how-to-resign-pins-in-saadc-example</link><description>Hi 
 I&amp;#39;m not familiar with C language, I tested the saadc example in SDK, it worked well in P0.02 
 But I dont see how they set CH[X].PSELP or CH[X].PSELN (V(p) and V(n)) in main.c 
 I dont know how to implement this code to work with other ADC pins.</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 19 Feb 2020 15:30:14 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/57043/how-to-resign-pins-in-saadc-example" /><item><title>RE: how to resign pins in saadc example</title><link>https://devzone.nordicsemi.com/thread/235249?ContentTypeID=1</link><pubDate>Wed, 19 Feb 2020 15:30:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e02770dc-5dde-48e8-bc00-b4310794fa36</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Cindy&lt;/p&gt;
&lt;p&gt;Sorry for not getting back to you.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I couldn&amp;#39;t find the old example unfortunately, but it was quite simple and I should be able to&amp;nbsp;create something similar shortly. I will get back to you by the end of the week with a similar example.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to resign pins in saadc example</title><link>https://devzone.nordicsemi.com/thread/235014?ContentTypeID=1</link><pubDate>Tue, 18 Feb 2020 20:16:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3f6c9cc8-b8c3-41b4-af80-e94b11b8c683</guid><dc:creator>Cindy</dc:creator><description>&lt;p&gt;[quote userid="2116" url="~/f/nordic-q-a/57043/how-to-resign-pins-in-saadc-example/232994"][/quote]&lt;/p&gt;
&lt;p&gt;Instead it should be enough to set up the TIMER, PPI and GPIOTE modules to toggle a pin when the timer overflows, and then you just change the compare value of the timer to change the frequency of the pin.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I made an example showing how to do this a while back and I will see if I can find it, hopefully by tomorrow.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Hi did you find the example?&lt;/p&gt;
&lt;p&gt;Cindy&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to resign pins in saadc example</title><link>https://devzone.nordicsemi.com/thread/232994?ContentTypeID=1</link><pubDate>Thu, 06 Feb 2020 09:51:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:07f6f2ff-5f52-4658-b52e-7cbb10ccdc46</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Cindy&lt;/p&gt;
&lt;p&gt;If you need to generate a square wave of varying frequencies I don&amp;#39;t think the PWM peripheral is the best choice, since the PWM is designed for applications where you use a fixed base frequency and modulate a signal on top of this.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Instead it should be enough to set up the TIMER, PPI and GPIOTE modules to toggle a pin when the timer overflows, and then you just change the compare value of the timer to change the frequency of the pin.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I made an example showing how to do this a while back and I will see if I can find it, hopefully by tomorrow.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Are you saying the speaker is louder when you use it with Arduino than when you use the Nordic kit?&lt;/p&gt;
&lt;p&gt;Some speakers need a particular hardware configuration to get optimal performance, but this is normally mentioned in the datasheet.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to resign pins in saadc example</title><link>https://devzone.nordicsemi.com/thread/232879?ContentTypeID=1</link><pubDate>Wed, 05 Feb 2020 14:57:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8973eaf2-08bd-4a2d-87f4-fefb1e9cfee0</guid><dc:creator>Cindy</dc:creator><description>&lt;p&gt;the reason why I want to adjust the frequency is that my speaker isn&amp;#39;t very loud with current code, I thought it&amp;#39;s because the frequency is too high so the speaker can&amp;#39;t have a high decibel level.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/1526.frequncy.PNG" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Yesterday, I&amp;nbsp;tried pwm_library,&amp;nbsp;&lt;pre class="ui-code" data-mode="text"&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 28. */
    app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_1CH(1000L, 28);

    /* 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, 10) == NRF_ERROR_BUSY);


    while (true)
    {

    // Configure pin 5 as output
    nrf_gpio_cfg_output(4);
    // Set pin 5 high
    nrf_gpio_pin_set(4);
    nrf_delay_ms(1000);
    // Set pin 5 low
    nrf_gpio_pin_clear(4);
    nrf_delay_ms(1000);

    }

}


/** @} */&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;quot;app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_1CH(1000L, 28);&amp;quot; (1kHz)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;by changing the perid of time, I think I changed the frequncy?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;But it&amp;#39;s still not very loud. Please let me know if I did it right?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;btw, I tested this speaker with Arduino, I used their &lt;em&gt;tone&lt;/em&gt; function.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Here&amp;#39;s the description of their tone function&lt;/span&gt;&lt;/p&gt;
&lt;div class="paragraph"&gt;
&lt;p&gt;&lt;em&gt;Generates a square wave of the specified frequency (and 50% duty cycle) on a pin. A duration can be specified, otherwise the wave continues until a call to&amp;nbsp;&lt;a href="https://www.arduino.cc/reference/en/language/functions/advanced-io/noTone"&gt;noTone()&lt;/a&gt;. The pin can be connected to a piezo buzzer or other speaker to play tones.&lt;/em&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;div class="paragraph"&gt;
&lt;p&gt;&lt;em&gt;Only one tone can be generated at a time. If a tone is already playing on a different pin, the call to&amp;nbsp;&lt;code&gt;tone()&lt;/code&gt;&amp;nbsp;will have no effect. If the tone is playing on the same pin, the call will set its frequency.&lt;/em&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;div class="paragraph"&gt;
&lt;p&gt;&lt;em&gt;&lt;/em&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;div class="paragraph"&gt;&lt;/div&gt;
&lt;p&gt;&lt;span&gt;So I think I need a simple square wave.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Could it because the speaker doesn&amp;#39;t get enough current?&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;a href="https://media.digikey.com/pdf/Data%20Sheets/CUI%20Inc%20All%20Brands%20PDFs/CCV-084B16-SMT.pdf"&gt;https://media.digikey.com/pdf/Data%20Sheets/CUI%20Inc%20All%20Brands%20PDFs/CCV-084B16-SMT.pdf&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;here&amp;#39;s the datasheet of the speaker I&amp;#39;m using.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thanks for your help.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Cindy&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to resign pins in saadc example</title><link>https://devzone.nordicsemi.com/thread/232825?ContentTypeID=1</link><pubDate>Wed, 05 Feb 2020 12:33:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:02f1a794-bdbe-476c-8668-e5d41247a3c7</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Cindy&lt;/p&gt;
&lt;p&gt;Do you just need a 2kHz square wave, or do you want to use the PWM for more sophisticated sounds?&lt;/p&gt;
&lt;p&gt;Normally the base clock of the PWM is much higher than then output frequency of the signal, to allow you a better PWM resolution.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to resign pins in saadc example</title><link>https://devzone.nordicsemi.com/thread/232134?ContentTypeID=1</link><pubDate>Fri, 31 Jan 2020 15:58:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6ce6802e-11e1-4927-89fa-361dbe305bb8</guid><dc:creator>Cindy</dc:creator><description>&lt;p&gt;Thanks for your help, it&amp;#39;s all very helpful.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/5611.frequency.PNG" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;is there any way I can change the clock to a lower frequency, it seems 125kHz is the lower frequency this function can do?&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/frequency2.PNG" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;because I want to use a speaker here, I want the frequency is around 2kHz.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;maybe I didn&amp;#39;t do it right, please correct me.&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Cindy&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to resign pins in saadc example</title><link>https://devzone.nordicsemi.com/thread/232018?ContentTypeID=1</link><pubDate>Fri, 31 Jan 2020 08:56:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6b7c9633-e6fc-48db-98d5-6dc23044f386</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Cindy&lt;/p&gt;
&lt;p&gt;You can just replace &amp;quot;LED_1&amp;quot; with the GPIO number of your choice.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;For instance, to use P0.08 set it like this:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;#define OUTPUT_PIN 8&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;The duty cycle is set by calling the &lt;em&gt;pwm_update_duty_cycle(uint8_t duty_cycle)&lt;/em&gt; function with a number between 0 and 100.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to resign pins in saadc example</title><link>https://devzone.nordicsemi.com/thread/231932?ContentTypeID=1</link><pubDate>Thu, 30 Jan 2020 14:33:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7162c944-ade3-4b83-8001-b695c2d0dee9</guid><dc:creator>Cindy</dc:creator><description>&lt;p&gt;Can you make an example of how to change it into a non-LED pin? what about the duty cycle?&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/7043.output.PNG" alt=" " /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to resign pins in saadc example</title><link>https://devzone.nordicsemi.com/thread/231823?ContentTypeID=1</link><pubDate>Thu, 30 Jan 2020 09:56:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0ebb111a-7b68-4f68-9aa4-6852734448b8</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Cindy&lt;/p&gt;
&lt;p&gt;To change the output pin you just have to change the OUTPUT_PIN define on line 61 of main.c to something else.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Any pin can be used, as long as it&amp;#39;s not used for something else.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Which pins are used for buttons and LED&amp;#39;s is printed on the back of the nRF52DK.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to resign pins in saadc example</title><link>https://devzone.nordicsemi.com/thread/231694?ContentTypeID=1</link><pubDate>Wed, 29 Jan 2020 14:35:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:49866ca8-a160-462b-9ce1-553849d338ba</guid><dc:creator>Cindy</dc:creator><description>&lt;p&gt;Thanks, I made it work with another example. I see in the pwm_simple it used LED_1 (How can I change it to another pin? does non-ADC pin works?), but I&amp;nbsp;don&amp;#39;t see how they set duty_cycle here.&amp;nbsp;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1580332018961v1.png" alt=" " /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to resign pins in saadc example</title><link>https://devzone.nordicsemi.com/thread/231595?ContentTypeID=1</link><pubDate>Wed, 29 Jan 2020 10:16:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:54543a2c-e190-4084-bbc9-64a669b8f6d6</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Cindy&lt;/p&gt;
&lt;p&gt;The &lt;em&gt;pwm_simple&lt;/em&gt; example was made before SES was the main IDE, and as such there is no SES project file for this example.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;What you can do is open some other simple peripheral project in SES, and copy inn the code from the main.c file in the &lt;em&gt;pwm_simple&lt;/em&gt; example.&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to resign pins in saadc example</title><link>https://devzone.nordicsemi.com/thread/231594?ContentTypeID=1</link><pubDate>Wed, 29 Jan 2020 10:14:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:77d5a5f1-e879-4f84-b0c0-aadda3496ae2</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Cindy&lt;/p&gt;
&lt;p&gt;Yes, this is quite normal. In single ended mode the full range of the ADC is actually -REF to REF, and if there is some offset error or noise you will occasionally see negative values when the input is 0V.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to resign pins in saadc example</title><link>https://devzone.nordicsemi.com/thread/231448?ContentTypeID=1</link><pubDate>Tue, 28 Jan 2020 14:40:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e1700191-d9e0-4ceb-9a4c-6b5ade9a41a3</guid><dc:creator>Cindy</dc:creator><description>&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/4024.Capture.PNG" alt=" " /&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/8231.Capture1.PNG" alt=" " /&gt;does&amp;nbsp;pwm_simple has ses version? how can I open it in ses?&lt;/p&gt;
&lt;p&gt;it doesnt have ses folder like other examples&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/28081/is-there-a-simple-example-how-to-set-a-pwm-driver/110654#110654"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/28081/is-there-a-simple-example-how-to-set-a-pwm-driver/110654#110654&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to resign pins in saadc example</title><link>https://devzone.nordicsemi.com/thread/231440?ContentTypeID=1</link><pubDate>Tue, 28 Jan 2020 14:22:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e7ea0778-2971-4e40-a7a0-f5f26fbc32d8</guid><dc:creator>Cindy</dc:creator><description>&lt;p&gt;thanks, that&amp;#39;s very helpful. but I assume the default negative pin is GND, but when I connect the GND to P0.02, it shows negative value, is that normal?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to resign pins in saadc example</title><link>https://devzone.nordicsemi.com/thread/231417?ContentTypeID=1</link><pubDate>Tue, 28 Jan 2020 13:24:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1ad7794f-0750-4228-b421-bf5098b65aba</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Cindy&lt;/p&gt;
&lt;p&gt;These parameters can be found in the channel_config struct, which is used to initialize the ADC channel inside the saadc_init() function.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;By default this function will just use the default settings, defined by the&amp;nbsp;NRFX_SAADC_DEFAULT_CHANNEL_CONFIG_SE(PIN_P) macro, but you can override the various parameters after initializing the struct if you like.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;As an example, to override the positive pin, you just run the following code:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;channel_config.pin_p = NRF_SAADC_INPUT_AIN1;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Then the full saadc_init() function would look like this:&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/support-attachments/beef5d1b77644c448dabff31668f3a47-08e3e0e7a81f4018ac6d6587e5eab406/pastedimage1580217875721v2.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>