<?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>ADC Measurements and Servo Motion Tracking.</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/55374/adc-measurements-and-servo-motion-tracking</link><description>Hello, 
 I am struggling to solve 2 problems , 
 1st : 
 I have 4 AAA cells (2 in series each ) to make a good power source ! 
 The Problem : 
 I have to measure the battery voltage(Input Line) to blink a LED when it falls below 2.0V , The Experiment</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 06 Jan 2020 12:41:30 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/55374/adc-measurements-and-servo-motion-tracking" /><item><title>RE: ADC Measurements and Servo Motion Tracking.</title><link>https://devzone.nordicsemi.com/thread/227658?ContentTypeID=1</link><pubDate>Mon, 06 Jan 2020 12:41:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:63d1bd96-2536-4d44-9c1b-cb448d4d5580</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;A TIMER runs on the 16MHz peripheral clock, but you&amp;nbsp;can lower the frequency by using the&amp;nbsp;&lt;a title="  PRESCALER  " href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/timer.html?cp=4_2_0_23_4_5#register.PRESCALER"&gt;PRESCALER&lt;/a&gt;&amp;nbsp;register. A prescaler divides the 16MHz clock by an integer number between 0 and 9, as set in the PRESCALER register. A prescaler of 0 yields 16MHz and a prescaler of 8 yields 16/8 = 2MHz.&lt;br /&gt;&lt;br /&gt;You need to use two compare values, one to set the PWM frequency(top value) and one to set the duty cycle.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;First, you need to set the PWM frequency of 50Hz (20ms period). With a 16MHz clock you need to count for 16MHz/50hz = 320000 ticks.&amp;nbsp;If you use&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/timer.html?cp=4_2_0_23_4_6#register.CC-0"&gt;CC[0]&lt;/a&gt;&amp;nbsp;as the TOP value, you need to set it to 320000. This will generate an event after the TIMER has counted for 320000 ticks of the 16MHz clock.&amp;nbsp;&lt;br /&gt;At this point, we need to do two things, (1) clear the&amp;nbsp;TIMER value to 0, and (2) set the output pin high. You can automatically clear the TIMER by setting the&amp;nbsp;&lt;span&gt;COMPARE0_CLEAR bit in the&amp;nbsp;&lt;a title="  SHORTS  " href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/timer.html?cp=4_2_0_23_4_0#register.SHORTS"&gt;SHORTS&lt;/a&gt;&amp;nbsp;register.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Second, you need to set the duty cycle. You can use&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/timer.html?cp=4_2_0_23_4_7#register.CC-1"&gt;CC[1]&lt;/a&gt;&amp;nbsp;to control the duty cycle by setting it to a value from 1 to 320000, where 160000 will yield a duty-cycle of 50%. You must use this event to set the output pin low.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;By changing the value of CC[1] you change the duty cycle, and you have a resolution of ~18-19 bits.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;The gpiote example in the SDK explains how you can use any peripheral event to control the output of a GPIO.&amp;nbsp;&lt;br /&gt;The timer example explains how to use the timer.&amp;nbsp;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ADC Measurements and Servo Motion Tracking.</title><link>https://devzone.nordicsemi.com/thread/226477?ContentTypeID=1</link><pubDate>Fri, 20 Dec 2019 06:38:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cf88b23d-744b-4c04-bd5e-821390d0f0f4</guid><dc:creator>german_wings</dc:creator><description>&lt;p&gt;Hello Devzone ,&lt;/p&gt;
&lt;p&gt;Let me know if there&amp;#39;s any updates or any information to help me ...&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thank You,&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ADC Measurements and Servo Motion Tracking.</title><link>https://devzone.nordicsemi.com/thread/225502?ContentTypeID=1</link><pubDate>Sun, 15 Dec 2019 06:55:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7523dd79-c456-406a-a7c0-17b1aba83336</guid><dc:creator>german_wings</dc:creator><description>&lt;p&gt;?? Any updates on this one ? That might be helpful ??&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ADC Measurements and Servo Motion Tracking.</title><link>https://devzone.nordicsemi.com/thread/224969?ContentTypeID=1</link><pubDate>Wed, 11 Dec 2019 15:19:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f3142d3e-3f96-42f9-a9f4-365433aa53f2</guid><dc:creator>german_wings</dc:creator><description>&lt;p&gt;Thank You , &lt;/p&gt;
&lt;p&gt;Here&amp;#39;s a few question I have.&lt;/p&gt;
&lt;p&gt;After going through the Documentation of PWM Driver&lt;/p&gt;
&lt;p&gt;How is Base Clock Frequency and Top Value related to PWM Period (Is there a formula)&lt;/p&gt;
&lt;p&gt;To Create a poor mans pwm I wrote a function :&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void poor_mans_pwm() // does a 10% Duty Cycle and 5%duty Cycle but cant do much except a 90Deg sweep
{
  nrf_gpio_cfg_output(4);
  while(true)
  {
    nrf_delay_ms(500);
    nrf_gpio_pin_write(4,1);
    nrf_delay_ms(1);
    nrf_gpio_pin_write(4,0);
    nrf_delay_ms(19);

    nrf_delay_ms(500);

    nrf_gpio_pin_write(4,1);
    nrf_delay_ms(2);
    nrf_gpio_pin_write(4,0);
    nrf_delay_ms(18);
  }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I really want to control my motor as simply as Arduino Can Do ! , Can You write me an example with TIMER or PWM Driver or GPIOTE whatever you find easy and at your ease to control my servo from 0 to 180Deg (I understand it might be quite a work but the Docs are really difficult for me to understand)&lt;/p&gt;
[quote userid="13562" url="~/f/nordic-q-a/55374/adc-measurements-and-servo-motion-tracking/224932"]The&amp;nbsp;&lt;a title="Timer Example" href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v16.0.0/nrf_dev_timer_example.html?cp=6_1_4_6_48"&gt;Timer Example&lt;/a&gt;&amp;nbsp;shows you how to use the TIMER and toggle an LED, that&amp;#39;s a basic PWM. You just need to modify the frequency and duty cycle.[/quote]
&lt;p&gt;How do I modify Duty Cycle ?? Frequency was spot on ! changed &lt;/p&gt;
&lt;p&gt;from here&lt;/p&gt;
&lt;p&gt;//Timer Example&lt;/p&gt;
&lt;p&gt;uint32_t time_ms = 20; //Time(in miliseconds) between consecutive compare events.&lt;/p&gt;
&lt;p&gt;I am trying to understand , I hope the Nordic Team will help me.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thank You,&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ADC Measurements and Servo Motion Tracking.</title><link>https://devzone.nordicsemi.com/thread/224932?ContentTypeID=1</link><pubDate>Wed, 11 Dec 2019 13:29:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:58a4ab23-f91e-4d61-8c95-24481ea01c10</guid><dc:creator>haakonsh</dc:creator><description>[quote user="german_wings"]Is the Analog Pin Capable of taking 5V inside it and then give me a 10Bit Resolution value i.e between 0 and 1024 ??? Can you give me a very simple example to read the analog values (as in the Arduino Snippet code). I checked the POT Reading when connected to Arduino. The Analog value the Arduino shows when converted to Voltage matches with the voltage shown on my Multimeter(I dont have an Oscilloscope)[/quote]
&lt;p&gt;You cannot measure 5V with our device, the maximum allowed voltage on any GPIO is VDD+0.3V, see&amp;nbsp;&lt;a title="Absolute maximum ratings" href="https://infocenter.nordicsemi.com/topic/ps_nrf52833/abs_max_ratings.html?cp=4_1_0_8"&gt;Absolute maximum ratings&lt;/a&gt;.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;You likely won&amp;#39;t catch transients like that on a multimeter.&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;br /&gt;The&amp;nbsp;&lt;a title="Timer Example" href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v16.0.0/nrf_dev_timer_example.html?cp=6_1_4_6_48"&gt;Timer Example&lt;/a&gt;&amp;nbsp;shows you how to use the TIMER and toggle an LED, that&amp;#39;s a basic PWM. You just need to modify the frequency and duty cycle.&lt;/p&gt;
[quote user="german_wings"]If I put these values (8/10/5) the servo does moves but jitters as in Arduino (This Problem is not visible on the Arduino Board though)[/quote]
&lt;p&gt;If you remove the ADC feedback loop from the servo control, does it still behave erratically?&lt;br /&gt;&amp;nbsp;&lt;/p&gt;
[quote user="german_wings"]Had the servo had some problem inside its circuitry it would have been apparent with arduino as well , but that is not the case. Is there something that can be done on the software side to fix this kind of issue[/quote]
&lt;p&gt;I&amp;#39;m telling you there is a certain amount of jitter in any servo, especially in cheap ones, and it stems from its control loop.&amp;nbsp;&lt;br /&gt;&amp;nbsp;&lt;/p&gt;
[quote user="german_wings"]also what do you mean by resolution ??[/quote]
&lt;p&gt;The resolution of your duty-cycle. If you have 5 decimal values between your lowest and highest value then you have less than 3bit resolution.&lt;br /&gt;&amp;nbsp;&lt;/p&gt;
[quote user="german_wings"]if PWM Library is not the right way to control the servo then what is ??[/quote]
&lt;p&gt;&amp;nbsp;Anything that will give you higher than 3bit resolution. A TIMER based one should give you more than 8bits.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ADC Measurements and Servo Motion Tracking.</title><link>https://devzone.nordicsemi.com/thread/224862?ContentTypeID=1</link><pubDate>Wed, 11 Dec 2019 09:19:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4d595f93-3e9a-4fbe-a176-37942b41a5f4</guid><dc:creator>german_wings</dc:creator><description>[quote userid="13562" url="~/f/nordic-q-a/55374/adc-measurements-and-servo-motion-tracking/224495"]create one with a&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/timer.html?cp=4_2_0_23#concept_xbd_hqp_sr"&gt;TIMER — Timer/counter&lt;/a&gt;&amp;nbsp;and a&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/gpiote.html?cp=4_2_0_20#concept_knz_kww_lr"&gt;GPIOTE — GPIO tasks and events&lt;/a&gt;.&amp;nbsp;[/quote]
&lt;p&gt;This seems to be very interesting ! , Can you give me a working example to modify and play with ?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ADC Measurements and Servo Motion Tracking.</title><link>https://devzone.nordicsemi.com/thread/224506?ContentTypeID=1</link><pubDate>Mon, 09 Dec 2019 15:06:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9d1f13da-6ad3-42cd-89e1-deb89111bdf8</guid><dc:creator>german_wings</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Thank You for your response (I was eagerly waiting for someone from Nordic to respond ! )&lt;/p&gt;
&lt;p&gt;I tried to understand your reply , but could not understand and apply it to my situation, Here is what I am thinking please validate it.&lt;/p&gt;
&lt;p&gt;Is the Analog Pin Capable of taking 5V inside it and then give me a 10Bit Resolution value i.e between 0 and 1024 ??? Can you give me a very simple example to read the analog values (as in the Arduino Snippet code). I checked the POT Reading when connected to Arduino. The Analog value the Arduino shows when converted to Voltage matches with the voltage shown on my Multimeter(I dont have an Oscilloscope)&lt;/p&gt;
&lt;p&gt;On the PWM Issue I am facing&lt;/p&gt;
&lt;p&gt;I followed Sigurds (Search : Example code for talking to the Servo) Response to another question. And used the same code to talk to I checked the Servo(SG90 Servo) Doc (I am attaching a image of the datasheet Please refer to it)&lt;/p&gt;
&lt;p&gt;Heres what I deduced&lt;/p&gt;
&lt;p&gt;1.5ms pulse (Total 20ms) will put the servo to 0 Deg (So Duty Cycle is 7.5 ~ 8)&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;2ms pulse (Total 20ms) will put the servo to +90 Deg (So Duty Cycle is 10)&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;1.0ms pulse (Total 20ms) will put the servo to -90 Deg (So Duty Cycle is 5)&lt;/p&gt;
&lt;p&gt;If I put these values (8/10/5) the servo does moves but jitters as in Arduino (This Problem is not visible on the Arduino Board though)&lt;/p&gt;
&lt;p&gt;If Sigurds Response was not correct or not the right way. Please give me an example to do a sweep in a incremental way like it does in Arduino Snippet with PWM You directed me too (I tried to fiddle with the PWM Driver example but did not understand the nrf_simple_playback function)&lt;/p&gt;
&lt;p&gt;Had the servo had some problem inside its circuitry it would have been apparent with arduino as well , but that is not the case. Is there something that can be done on the software side to fix this kind of issue , also what do you mean by resolution ?? if PWM Library is not the right way to control the servo then what is ??&lt;/p&gt;
&lt;p&gt;Thank You,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/servo_5F00_doc.png" /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ADC Measurements and Servo Motion Tracking.</title><link>https://devzone.nordicsemi.com/thread/224495?ContentTypeID=1</link><pubDate>Mon, 09 Dec 2019 14:34:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:98f3cee9-acbb-4397-a225-47550f1981b2</guid><dc:creator>haakonsh</dc:creator><description>&lt;ol&gt;
&lt;li&gt;SAADC&lt;br /&gt;&lt;br /&gt;Any ADC will output some amount of noise. With our SAADC you should expect +/- 4lsb10 on an average set-up, that&amp;#39;s +/- 4 codes at 10 bit resolution, or +/- 2 on 8-bit resolution. If you see anything more than that you have a noisy input.&lt;br /&gt;You can verify this by powering using the DK and configuring the SAADC in single-ended mode, with the positive input(&lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/saadc.html?cp=4_2_0_36_10_5#register.CH-0.PSELP"&gt;CH[0].PSELP&lt;/a&gt;) connected to VDD. The output will always vary somewhat.&lt;br /&gt;&lt;br /&gt;A potmeter&amp;#39;s wiper blades are inherently noisy when they are operated, because of poor electromechanical connection between the wiper blade and the wiper track. You can easily see large jumps in analog voltages in cheap potmeters. You can verify this with an oscilloscope.&amp;nbsp;&lt;br /&gt;un-soldered board-to-board cables have terrible electromechanical contacts that will introduce large amount of noise if they are fiddled with. They are also unshielded which makes them susceptible to Electro-Magnetic Interference.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;The output of the SAADC with respect to the input in single-ended mode is:&lt;br /&gt;&lt;br /&gt;Result = &lt;span style="text-decoration:underline;"&gt;(Vin * Gain/ Reference)&lt;/span&gt; * &lt;span style="text-decoration:underline;"&gt;(2^(resolution) - 1)&lt;/span&gt; , where resolution is in&amp;nbsp;number of bits.&lt;br /&gt;&lt;br /&gt;f.ex Vin = 2.2V , reference = 0.6V, Gain = (1/6), resolution = 10 bits:&lt;br /&gt;Result = (2.2V * 1/6)/0.6V * (2^(10) -1) = (0.367/0.6)V * 1023 = 625.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;I see that you&amp;#39;re doing a lot of averaging in your application code. The SAADC has an oversampling feature that can sample up to 256 samples and average them automatically. The output buffer will then only contain averages of up to 256 samples. See&amp;nbsp;&lt;a title="Oversampling" href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/saadc.html?cp=4_2_0_36_4_2#saadc_operationmodes_oversample"&gt;Oversampling&lt;/a&gt;&amp;nbsp;and &lt;a title="SAADC" href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v16.0.0/group__nrf__saadc.html?cp=6_1_6_9_0_30"&gt;SAADC&lt;/a&gt;&amp;nbsp;driver API docs.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;PWM&lt;br /&gt;A typical servo requires a PWM signal with a specific frequency and duty-cycle to operate, where the frequency is fixed and the duty-cycle determines the angle/rotational speed of the servo. Your servo&amp;nbsp;should have a data sheet that specifies what frequency and duty-cycles are valid, and you need to control the PWM signal accordingly. Most servos operate with a frequency of 50Hz and a duty cycle between 5-20%.&lt;br /&gt;&lt;br /&gt;From the&amp;nbsp;&lt;a title="Pulse-width modulation (PWM)" href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v16.0.0/group__app__pwm.html?cp=6_1_6_11_36"&gt;Pulse-width modulation (PWM)&lt;/a&gt;&amp;nbsp;library&amp;#39;s API docs I can see that the function&amp;nbsp;&lt;a title="app_pwm_channel_duty_set" href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v16.0.0/group__app__pwm.html?cp=6_1_6_11_36_11#ga071ee86851d8c0845f297df5d23a240d"&gt;app_pwm_channel_duty_set&lt;/a&gt;&amp;nbsp;takes a parameter called &amp;#39;duty&amp;#39; that is the duty-cycle in %(0-100). This will give you a very low-resolution PWM that might not be suitable for use with a servo. If you need a higher resolution you will need to use the&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/pwm.html?cp=4_2_0_46#concept_pzc_1pw_nr"&gt;PWM — Pulse width modulation&lt;/a&gt;&amp;nbsp;or create one with a&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/timer.html?cp=4_2_0_23#concept_xbd_hqp_sr"&gt;TIMER — Timer/counter&lt;/a&gt;&amp;nbsp;and a&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/gpiote.html?cp=4_2_0_20#concept_knz_kww_lr"&gt;GPIOTE — GPIO tasks and events&lt;/a&gt;.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Servo jitter.&lt;br /&gt;This is most likely caused by your application reacting to noise in the servos analog signal and reversing the direction of rotation. &lt;br /&gt;Note that most servos have some jitter inherent in its control circuitry.&amp;nbsp;&lt;/li&gt;
&lt;/ol&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>