<?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>Adding a multiplexer on SAADC Example - nRF52840 SDK16</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/60381/adding-a-multiplexer-on-saadc-example---nrf52840-sdk16</link><description>Hi everyone, 
 I was looking at the SAADC example and I need to modify it in order to fit my design. I want to perform analog readings from eight sensors using an eight-channel multiplexer. 
 I will keep the timer/PPI arrangement and I want after each</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 21 Apr 2020 13:36:23 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/60381/adding-a-multiplexer-on-saadc-example---nrf52840-sdk16" /><item><title>RE: Adding a multiplexer on SAADC Example - nRF52840 SDK16</title><link>https://devzone.nordicsemi.com/thread/245855?ContentTypeID=1</link><pubDate>Tue, 21 Apr 2020 13:36:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3b6c825c-15fa-4a62-8567-0ab00369131f</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;Yeah, I had to edit that post 6 times to make as &amp;quot;easy&amp;quot; to read as it is now. It&amp;#39;s a bit abstract, but it is a good solution, especially at higher sample rates. Even at 100sps you will get a more reliable adc.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;The RTC will have a lot of lower current consumption than a TIMER, but it has a minimum time resolution of 30.51µs. If you can use a multiple of 30.51µs then the RTC is the best option.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Adding a multiplexer on SAADC Example - nRF52840 SDK16</title><link>https://devzone.nordicsemi.com/thread/245849?ContentTypeID=1</link><pubDate>Tue, 21 Apr 2020 13:17:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:44b20c73-ec7b-4179-9da4-7a9bf9f35942</guid><dc:creator>Nikosant03</dc:creator><description>&lt;p&gt;Woo, too much information but it looks like a robust solution... I will try it and return with feedback.&lt;/p&gt;
&lt;p&gt;Also, I need a TIMER&amp;nbsp;or RTC to trigger the&amp;nbsp;&lt;span&gt;SAADC&amp;#39;s SAMPLE task, isn&amp;#39;t it?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Adding a multiplexer on SAADC Example - nRF52840 SDK16</title><link>https://devzone.nordicsemi.com/thread/245838?ContentTypeID=1</link><pubDate>Tue, 21 Apr 2020 12:49:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:83c17a78-de49-4673-89f0-526f2d346218</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;I just realized that we can control the MUX with a TIMER and 3 GPIOTE channels.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You&amp;#39;ll need a TIMER set up as a counter, and have the SAADC&amp;#39;s DONE event trigger the TIMER&amp;#39;s COUNT task. This will increment the TIMER once for each of the SAADC&amp;#39;s DONE events.&lt;/p&gt;
&lt;p&gt;The GPIOTE peripheral can toggle the state of a pin with an OUT task. We can then use the TIMER/COUNTER and GPIOTE to iterate through the MUX&amp;#39;s truth table without any CPU activity at all.&lt;/p&gt;
&lt;p&gt;COMPARE event on COUNT = 1, Toggle ADD0&lt;br /&gt;COMPARE event on COUNT = 2, Toggle ADD0 and ADD1&lt;br /&gt;COMPARE event on COUNT = 3, Toggle ADD0 &lt;br /&gt;COMPARE event on COUNT = 4, Toggle ADD0, ADD1, ADD2, and reset the COUNT to 0 by CLEARing the TIMER(this can be achieved through a SHORT where the last COMPARE event is coupled directly to the CLEAR task internally in the TIMER).&lt;/p&gt;
&lt;p&gt;This will create a truth table equal to the one in the MUX&amp;#39;s datasheet.&lt;/p&gt;
&lt;p&gt;The PPI peripheral can fork any EVENT to one other TASK. For the fourth COMPARE event we&amp;#39;ll need to set up somthing different to be able have the last COMPARE EVENT trigger the 3 GPIOTE TASKs. &lt;br /&gt;For that we need to use the Event Generator Unit. It&amp;#39;s a simple peripheral where TASK[x] will trigger EVENT[x]. We can use EVENTs from the EGU to fork into other TASKs.&lt;/p&gt;
&lt;p&gt;F.ex: The TIMER&amp;#39;s last COMPARE event triggers ADD0 toggle TASK,&amp;nbsp;and through the forked event, trigger EGU TASK[0]. Then we fork(again) the EGU EVENT[0] to trigger the ADD1 and ADD2 toggle TASKs. This way the last COMPARE EVENT can trigger 3 TASKS.&lt;/p&gt;
&lt;p&gt;This will toggle MUX GPIOs at most 187.5ns after the SAADC&amp;#39;s DONE event, with the MUX&amp;#39;s switching time of 24ns you&amp;#39;ll use at most ~210ns to switch the MUX, and you can therefore most likely, run the SAADC at 200ksps without issues.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Adding a multiplexer on SAADC Example - nRF52840 SDK16</title><link>https://devzone.nordicsemi.com/thread/245815?ContentTypeID=1</link><pubDate>Tue, 21 Apr 2020 10:50:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dd6a9f5b-851a-43fb-a066-83ab44396455</guid><dc:creator>haakonsh</dc:creator><description>&lt;ol&gt;
&lt;li&gt;&lt;span&gt;&lt;span&gt;nrf_saadc_int_enable(&lt;/span&gt;&lt;/span&gt;&lt;span&gt;NRF_SAADC_INT_DONE);&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;
&lt;div&gt;&lt;span&gt;&lt;span&gt;nrfx_saadc_irq_handler() is found on line 102 in nrfx_saadc.c on nRF5 SDK 16.0.&lt;br /&gt;&lt;br /&gt;Inject an&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;if&lt;/span&gt;&lt;span&gt;&amp;nbsp;(&lt;/span&gt;&lt;span&gt;nrf_saadc_event_check&lt;/span&gt;&lt;span&gt;&lt;span&gt;(NRF_SAADC_EVENT_DONE&lt;/span&gt;&lt;/span&gt;&lt;span&gt;)){} on line 183.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span&gt;&amp;nbsp;&lt;br /&gt;&lt;/span&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span&gt;Either a TIMER or an RTC, I&amp;#39;d choose an RTC with the RTC driver, f.ex RTC2.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span&gt;&lt;span&gt;Because the SoftDevice will block the SAADC ISR from executing during timing-critical radio events. If you do not get to execute the MUX change before the next SAMPLE task is triggered you&amp;#39;ve got at least one corrupt sample. Therefore you should&amp;nbsp;call nrfx_saadc_sample&lt;span&gt;() in&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;the RTC drivers callback (or the app_timer callback). Since the SAADC ISR has execution priority over any application callback you&amp;#39;re guaranteed to set the proper MUX settings before the SAMPLE task is triggered.&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ol&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Adding a multiplexer on SAADC Example - nRF52840 SDK16</title><link>https://devzone.nordicsemi.com/thread/245789?ContentTypeID=1</link><pubDate>Tue, 21 Apr 2020 09:47:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:92915c91-21e7-4487-a935-d7278afb2917</guid><dc:creator>Nikosant03</dc:creator><description>&lt;p&gt;Thanks for the guidance, I have some questions&lt;/p&gt;
&lt;p&gt;1. How do I enable the DONE event interrupt?&lt;/p&gt;
&lt;p&gt;2. Where do I find the ISR?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
[quote userid="13562" url="~/f/nordic-q-a/60381/adding-a-multiplexer-on-saadc-example---nrf52840-sdk16/245761"]You can then use a TIMER to &lt;strong&gt;manually trigger(not PPI)&lt;/strong&gt; the SAADC&amp;#39;s SAMPLE task to get the correct sample rate, and set the buffer to as many samples as you want.&amp;nbsp;[/quote]
&lt;p&gt;3.1 Do you mean the app timer (RTC1) or the timer driver?&lt;/p&gt;
&lt;p&gt;3.2 Why should I avoid PPI?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Adding a multiplexer on SAADC Example - nRF52840 SDK16</title><link>https://devzone.nordicsemi.com/thread/245761?ContentTypeID=1</link><pubDate>Tue, 21 Apr 2020 08:30:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6411b418-8dcf-4033-b572-599f6b870d3a</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;You can modify the SAADC driver&amp;#39;s ISR to check for the SAADC&amp;#39;s DONE event, and then control the MUX&amp;#39;s GPIOs accordingly. The DONE event is set after each sample, remember to enable the DONE event interrupt.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;-edit:&lt;br /&gt;You can then use a TIMER to &lt;strong&gt;manually trigger(not PPI)&lt;/strong&gt; the SAADC&amp;#39;s SAMPLE task to get the correct sample rate, and set the buffer to as many samples as you want.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Adding a multiplexer on SAADC Example - nRF52840 SDK16</title><link>https://devzone.nordicsemi.com/thread/245695?ContentTypeID=1</link><pubDate>Tue, 21 Apr 2020 06:20:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:aa03ae37-e38a-42f5-ba0f-2737314b90c2</guid><dc:creator>Nikosant03</dc:creator><description>&lt;p&gt;Hi haakonsh,&lt;/p&gt;
&lt;p&gt;&lt;a href="https://www.renesas.com/us/en/www/doc/datasheet/isl84781.pdf"&gt;THIS&lt;/a&gt;&amp;nbsp;is the datasheet of the MUX. Probably I will work on 1.8V, so the switching is 24ns for tON and 16ns for tOFF&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Adding a multiplexer on SAADC Example - nRF52840 SDK16</title><link>https://devzone.nordicsemi.com/thread/245627?ContentTypeID=1</link><pubDate>Mon, 20 Apr 2020 15:40:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1a14f509-ab7d-48f0-abe5-f4ff753f87ca</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;How fast can the mux switch? &lt;br /&gt;&lt;br /&gt;What&amp;nbsp;are the signals used to switch&amp;nbsp;the&amp;nbsp;8/16-channel mux?&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Adding a multiplexer on SAADC Example - nRF52840 SDK16</title><link>https://devzone.nordicsemi.com/thread/245524?ContentTypeID=1</link><pubDate>Mon, 20 Apr 2020 12:23:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c4201bd5-032f-488a-b0b1-a2ab49079a0a</guid><dc:creator>Nikosant03</dc:creator><description>&lt;p&gt;Hi haakonsh,&lt;/p&gt;
&lt;p&gt;Thanks for your reply. Yes, this could be an option but I would like to use the MUX as I want to have available the rest of the analog inputs for other tasks. Also,&amp;nbsp;in the future is may be required to use a 16-channel MUX, so I have to work around with this solution...&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Adding a multiplexer on SAADC Example - nRF52840 SDK16</title><link>https://devzone.nordicsemi.com/thread/245446?ContentTypeID=1</link><pubDate>Mon, 20 Apr 2020 08:24:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:44002c61-433d-45e3-a636-dc36741b86f5</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;Why do you need to use an external mux? Can&amp;#39;t you use the 8 analog input pins of the nRF52840?&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>