<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.element14.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>Tutorial FRDM-KL25Z: ADC with the Freescale Freedom Board</title><link>https://community.element14.com/products/arduino/w/documents/10989/tutorial-frdm-kl25z-adc-with-the-freescale-freedom-board</link><description /><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>Tutorial FRDM-KL25Z: ADC with the Freescale Freedom Board</title><link>https://community.element14.com/products/arduino/w/documents/10989/tutorial-frdm-kl25z-adc-with-the-freescale-freedom-board</link><pubDate>Tue, 01 Nov 2016 21:21:44 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:f990c4ed-dcc7-414a-b689-7efe35579430</guid><dc:creator>FreescaleTools_and_Software</dc:creator><comments>https://community.element14.com/products/arduino/w/documents/10989/tutorial-frdm-kl25z-adc-with-the-freescale-freedom-board#comments</comments><description>Current Revision posted to Documents by FreescaleTools_and_Software on 11/1/2016 9:21:44 PM&lt;br /&gt;
&lt;p style="margin:0;text-align:left;background-color:#ffffff;text-indent:0px;color:#333333;"&gt;&lt;span style="font-family:tahoma, arial, helvetica, sans-serif;color:#ff6600;font-size:15px;"&gt;&lt;em&gt;This tutorial was extracted from Erich Styger blog&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;a class="jive-link-external-small" href="http://mcuoneclipse.wordpress.com/" rel="nofollow" style="color:#355491;font-size:15px;" target="_blank"&gt;http://mcuoneclipse.wordpress.com&lt;/a&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;with his agreement.&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;text-align:left;background-color:#ffffff;text-indent:0px;color:#333333;"&gt;&lt;a href="/servlet/JiveServlet/downloadImage/102-51144-4-105550/Freescale.bmp"&gt;&lt;span&gt;&lt;a href="https://community.element14.com/resized-image/__size/175x85/__key/communityserver-wikis-components-files/00-00-00-02-65/0815.contentimage_5F00_76428.bmp"&gt;&lt;img alt="image" src="/cfs-file/__key/communityserver-wikis-components-files/00-00-00-02-65/0815.contentimage_5F00_76428.bmp" style="max-height: 85px;max-width: 175px;" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/a&gt; &lt;span class="Apple-converted-space"&gt;&lt;/span&gt;&lt;a href="/servlet/JiveServlet/downloadImage/102-51144-4-105551/Kinetis-L.jpg"&gt;&lt;span&gt;&lt;a href="https://community.element14.com/resized-image/__size/87x85/__key/communityserver-wikis-components-files/00-00-00-02-65/8420.contentimage_5F00_76429.jpg"&gt;&lt;img loading="lazy" alt="image" src="https://community-storage.element14.com/communityserver-components-secureimagefileviewer/communityserver/wikis/components/files/00/00/00/02/65/8420.contentimage_76429.jpg-87x85.jpg?sv=2016-05-31&amp;amp;sr=b&amp;amp;sig=Ybvw1c%2FxugDPqSDIzoFxTCPmXFHKuw5%2Be8WowIK7Ot8%3D&amp;amp;se=2026-08-28T23%3A59%3A59Z&amp;amp;sp=r&amp;amp;_=lw3vl9FqzfR9tHJgP7g6Lg==" style="max-height: 85px;max-width: 87px;" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/p&gt;&lt;p style="margin:0;"&gt;&amp;nbsp;&amp;nbsp; &lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;Unlike other boards from Freescale, the &lt;a class="jive-link-external-small" href="http://www.freescale.com/freedom" rel="nofollow ugc noopener" target="_blank" title="Freescale Freedom Boards"&gt;FRDM-KL25Z&lt;/a&gt; has no potentiometer or analog components on it. But in many applications an ADC conversion is needed, so here we go with a tutorial reading in an external potentiometer with Eclipse, CodeWarrior and Processor Expert. For this tutorial I have a 10k Ohm linear potentiometer connected to the Freedom board:&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&amp;nbsp; &lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;a href="http://mcuoneclipse.files.wordpress.com/2013/02/linear-potentiometer-with-the-frdm-kl25z.png" rel="nofollow ugc noopener" target="_blank"&gt;&lt;img loading="lazy" alt="Linear potentiometer with the FRDM-KL25Z" class="wp-image-6630 jiveImage size-full" height="593" src="http://mcuoneclipse.files.wordpress.com/2013/02/linear-potentiometer-with-the-frdm-kl25z.png?w=584&amp;amp;h=593" style="display:block;margin-left:auto;margin-right:auto;" width="584" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p class="wp-caption-text" style="margin:0;text-align:center;"&gt;&lt;em&gt;&lt;span&gt;Linear potentiometer with the&amp;nbsp; &lt;span&gt;&lt;span class="e14-init-shown" id="addProduct-PCKCTLn8-linked" style="white-space:nowrap;"&gt;&lt;a class="jive-link-product-addtolist" href="https://www.element14.com/community/view-product.jspa?fsku=2191861&amp;amp;nsku=28W5033&amp;amp;COM=noscript" target="_blank"&gt;&lt;span class="pf-widget-map pf-productlink-cart-icon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;a class="jive-link-product pf-embedded-product-link" href="https://www.element14.com/community/view-product.jspa?fsku=2191861&amp;amp;nsku=28W5033&amp;amp;COM=noscript" target="_blank"&gt;FRDM-KL25Z&lt;/a&gt;&lt;/span&gt;&lt;span class="e14-init-hidden" id="addProduct-PCKCTLn8-unlinked"&gt;FRDM-KL25Z&lt;/span&gt;&lt;/span&gt; &lt;/span&gt;&lt;/em&gt;&lt;/p&gt;&lt;p class="wp-caption-text" style="margin:0;"&gt;&amp;nbsp;&amp;nbsp; &lt;/p&gt;&lt;p class="wp-caption-text" style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;"&gt;&lt;a href="http://s0.wp.com/wp-includes/images/smilies/icon_idea.gif?m=1129645325g"&gt;&lt;img loading="lazy" alt=":idea:" class="jiveImage wp-smiley" src="http://s0.wp.com/wp-includes/images/smilies/icon_idea.gif?m=1129645325g" /&gt;&lt;/a&gt; &lt;em&gt;While this tutorial is for the Freedom KL25Z project, things are generic for any microcontroller supported by Processor Expert. Only the port/pins might be different.&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-size:12pt;"&gt;The black (GND) and red (3.3V) wires are connected to the ‘full range’ connectors for the potentiometer, while the white wire is connected to the current position pin. The white wire is connected to the ‘Arduino’ A0 pin of the Freedom board:&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;a href="http://mcuoneclipse.files.wordpress.com/2013/02/schematic.png" rel="nofollow ugc noopener" target="_blank"&gt;&lt;img loading="lazy" alt="Schematic with 10k Ohm Potentiometer" class="jiveImage size-full wp-image-6631" height="451" src="http://mcuoneclipse.files.wordpress.com/2013/02/schematic.png?w=584&amp;amp;h=451" style="display:block;margin-left:auto;margin-right:auto;" width="584" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p class="wp-caption-text" style="margin:0;text-align:center;"&gt;&lt;em&gt;Schematic with 10k Ohm Potentiometer&lt;/em&gt;&lt;/p&gt;&lt;p class="wp-caption-text" style="margin:0;"&gt;&amp;nbsp; &lt;/p&gt;&lt;p class="wp-caption-text" style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;h2&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;Creating the Project&lt;/span&gt;&lt;/h2&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;With CodeWarrior for MCU10.3, I create a project with the ‘New Project Wizard’ (menu &lt;em&gt;File &amp;gt; New &amp;gt; Bareboard Project&lt;/em&gt;). I give a project name, select my microcontroller (KL25Z), connection (&lt;a class="jive-link-external-small" href="http://mcuoneclipse.com/2012/09/20/opensda-on-the-freedom-kl25z-board/" rel="nofollow ugc noopener" target="_blank" title="OpenSDA on the Freedom KL25Z Board"&gt;OpenSDA&lt;/a&gt;), Toolchain (gcc) and Rapid Application Development (Processor Expert).&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;h2&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;Adding ADC Component&lt;/span&gt;&lt;/h2&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;From the Components Library I add the ADC component to the project:&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;a href="http://mcuoneclipse.files.wordpress.com/2013/02/adding-adc.png" rel="nofollow ugc noopener" target="_blank"&gt;&lt;span style="font-size:12pt;"&gt;&lt;img loading="lazy" alt="Adding ADC Component" class="jiveImage size-full wp-image-6632" height="346" src="http://mcuoneclipse.files.wordpress.com/2013/02/adding-adc.png?w=584&amp;amp;h=346" style="display:block;margin-left:auto;margin-right:auto;" width="584" /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;p class="wp-caption-text" style="margin:0;text-align:center;"&gt;&lt;em&gt;Adding ADC Component&lt;/em&gt;&lt;/p&gt;&lt;p class="wp-caption-text" style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p class="wp-caption-text" style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;em style="font-family:tahoma,arial,helvetica,sans-serif;"&gt;&lt;a href="http://s0.wp.com/wp-includes/images/smilies/icon_idea.gif?m=1129645325g"&gt;&lt;img loading="lazy" alt=":idea:" class="jiveImage wp-smiley" src="http://s0.wp.com/wp-includes/images/smilies/icon_idea.gif?m=1129645325g" /&gt;&lt;/a&gt; If the Component Library view is not open, use the menu Processor Expert &amp;gt; Show Views.&amp;nbsp; &lt;/em&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-size:12pt;"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-size:12pt;"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;h2&gt;&lt;span style="font-size:12pt;"&gt;Configuring ADC Component&lt;/span&gt;&lt;/h2&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-size:12pt;"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-size:12pt;"&gt;With the component added, it shows with an error marker as I need to configure it first:&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-size:12pt;"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-size:12pt;"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;a href="http://mcuoneclipse.files.wordpress.com/2013/02/added-adc-component.png" rel="nofollow ugc noopener" target="_blank"&gt;&lt;span style="font-size:12pt;"&gt;&lt;img loading="lazy" alt="Added ADC Component" class="wp-image-6634 jiveImage size-full" height="247" src="http://mcuoneclipse.files.wordpress.com/2013/02/added-adc-component.png?w=584&amp;amp;h=247" style="display:block;margin-left:auto;margin-right:auto;" width="584" /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;p class="wp-caption-text" style="margin:0;text-align:center;"&gt;&lt;em&gt;Added ADC Component&lt;/em&gt;&lt;/p&gt;&lt;p class="wp-caption-text" style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p class="wp-caption-text" style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;First, to configure the pin to be used. According to the schematics, the A0 pin is connected to ADC0_SE8/PTB0:&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;a href="http://mcuoneclipse.files.wordpress.com/2013/02/selecting-adc-pin.png" rel="nofollow ugc noopener" target="_blank"&gt;&lt;img loading="lazy" alt="Selecting ADC Pin" class="jiveImage size-full wp-image-6636" height="389" src="http://mcuoneclipse.files.wordpress.com/2013/02/selecting-adc-pin.png?w=584&amp;amp;h=389" style="display:block;margin-left:auto;margin-right:auto;" width="584" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p class="wp-caption-text" style="margin:0;text-align:center;"&gt;&lt;em&gt;Selecting ADC Pin&lt;/em&gt;&lt;/p&gt;&lt;p class="wp-caption-text" style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p class="wp-caption-text" style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;Next to configure the conversion time. For this I click the ‘…’ button:&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;text-align:center;"&gt;&lt;em style="font-family:tahoma,arial,helvetica,sans-serif;"&gt;&lt;a href="http://s0.wp.com/wp-includes/images/smilies/icon_exclaim.gif?m=1129645325g"&gt;&lt;img loading="lazy" alt=":!:" class="jiveImage wp-smiley" src="http://s0.wp.com/wp-includes/images/smilies/icon_exclaim.gif?m=1129645325g" /&gt;&lt;/a&gt; I need to click *into* the field to show the ‘…’ button.&lt;/em&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;/p&gt;&lt;p style="margin:0;text-align:center;"&gt;&lt;a href="http://mcuoneclipse.files.wordpress.com/2013/02/conversion-time1.png" rel="nofollow ugc noopener" target="_blank"&gt;&lt;img loading="lazy" alt="Conversion Time Setup" class="jiveImage wp-image-6637 size-full" height="389" src="http://mcuoneclipse.files.wordpress.com/2013/02/conversion-time1.png?w=584&amp;amp;h=389" width="584" /&gt;&lt;/a&gt;&amp;nbsp; &lt;/p&gt;&lt;p class="wp-caption-text" style="margin:0;text-align:center;"&gt;&lt;em&gt;Conversion Time Setup&lt;/em&gt;&lt;/p&gt;&lt;p class="wp-caption-text" style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p class="wp-caption-text" style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;This opens a dialog where I can specify the conversion time. I select one of the available values from the right side (e.g. double clicking on it):&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;a href="http://mcuoneclipse.files.wordpress.com/2013/02/conversion-time-selection.png" rel="nofollow ugc noopener" target="_blank"&gt;&lt;img loading="lazy" alt="Conversion Time Selection" class="wp-image-6638 jiveImage size-full" height="410" src="http://mcuoneclipse.files.wordpress.com/2013/02/conversion-time-selection.png?w=584&amp;amp;h=410" style="display:block;margin-left:auto;margin-right:auto;" width="584" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p class="wp-caption-text" style="margin:0;text-align:center;"&gt;&lt;em&gt;Conversion Time Selection&lt;/em&gt;&lt;/p&gt;&lt;p class="wp-caption-text" style="margin:0;"&gt;&amp;nbsp; &lt;/p&gt;&lt;p class="wp-caption-text" style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;"&gt;&lt;a href="http://s0.wp.com/wp-includes/images/smilies/icon_idea.gif?m=1129645325g"&gt;&lt;img loading="lazy" alt=":idea:" class="jiveImage wp-smiley" src="http://s0.wp.com/wp-includes/images/smilies/icon_idea.gif?m=1129645325g" /&gt;&lt;/a&gt; &lt;em&gt;The Conversion Time specifies how fast the AD conversion shall be performed. This has of course an impact on the timing and quality of the conversion. For this tutorial, we simply select a timing.&amp;nbsp; &lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;h2&gt;&lt;span style="font-size:12pt;"&gt;Generating Code&lt;/span&gt;&lt;/h2&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-size:12pt;"&gt;With everything configured, I use the ‘Generate Code’ button:&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-size:12pt;font-family:tahoma,arial,helvetica,sans-serif;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;a href="http://mcuoneclipse.files.wordpress.com/2013/02/code-generation.png" rel="nofollow ugc noopener" target="_blank"&gt;&lt;img loading="lazy" alt="Code Generation" class="jiveImage wp-image-6640 size-full" src="http://mcuoneclipse.files.wordpress.com/2013/02/code-generation.png?w=584" style="display:block;margin-left:auto;margin-right:auto;" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p class="wp-caption-text" style="margin:0;text-align:center;"&gt;&lt;em&gt;Code Generation&lt;/em&gt;&lt;/p&gt;&lt;p class="wp-caption-text" style="margin:0;"&gt;&amp;nbsp; &lt;/p&gt;&lt;p class="wp-caption-text" style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;The generated code ends up in the Generated_Code folder of the project:&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;a href="http://mcuoneclipse.files.wordpress.com/2013/02/generated-code-folder.png" rel="nofollow ugc noopener" target="_blank"&gt;&lt;span style="font-size:12pt;"&gt;&lt;img loading="lazy" alt="Generated Code Folder" class="wp-image-6641 jiveImage size-full" src="http://mcuoneclipse.files.wordpress.com/2013/02/generated-code-folder.png?w=584" style="display:block;margin-left:auto;margin-right:auto;" /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;p class="wp-caption-text" style="margin:0;text-align:center;"&gt;&lt;em&gt;Generated Code Folder&lt;/em&gt;&lt;/p&gt;&lt;p class="wp-caption-text" style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p class="wp-caption-text" style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;In the next step, I’m going to use it in the main() inside the file ProcessorExpert.c.&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;h2&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;Doing the Conversion&lt;/span&gt;&lt;/h2&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;Instead of typing the code, I can &lt;a class="jive-link-external-small" href="http://mcuoneclipse.com/2012/03/08/dragdrop-in-processor-expert/" rel="nofollow ugc noopener" target="_blank" title="Drag&amp;amp;Drop in Processor Expert"&gt;drag&amp;amp;drop&lt;/a&gt; the method names to my source:&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&amp;nbsp; &lt;/p&gt;&lt;p style="margin:0;"&gt;&amp;nbsp; &lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;a href="http://mcuoneclipse.files.wordpress.com/2013/02/drag-and-drop-of-method.png" rel="nofollow ugc noopener" target="_blank"&gt;&lt;img loading="lazy" alt="Drag and Drop of Method" class="jiveImage size-full wp-image-6642" height="401" src="http://mcuoneclipse.files.wordpress.com/2013/02/drag-and-drop-of-method.png?w=584&amp;amp;h=401" style="display:block;margin-left:auto;margin-right:auto;" width="584" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p class="wp-caption-text" style="margin:0;text-align:center;"&gt;&lt;em&gt;Drag and Drop of Method&lt;/em&gt;&lt;/p&gt;&lt;p class="wp-caption-text" style="margin:0;"&gt;&amp;nbsp; &lt;/p&gt;&lt;p class="wp-caption-text" style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;The method Measure() needs an extra boolean argument if it shall wait for the finish of the conversion (yes, I want to wait). And I’m not interested in the error return code, so I cast it to void:&lt;/span&gt;&lt;/p&gt;&lt;div class="bar"&gt;&lt;div class="toolbar"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/div&gt;&lt;div class="toolbar"&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:courier new,courier;color:#0000ff;"&gt;/* Write your code here */ &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:courier new,courier;color:#0000ff;"&gt;(void)AD1_Measure(TRUE); &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:courier new,courier;color:#0000ff;"&gt;/* For example: for(;;) { } */&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;To get the conversion value, the method GetValue16() is used which returns the 16bit result. For the result I define a 16bit global variable:&lt;/span&gt;&lt;/p&gt;&lt;div class="bar"&gt;&lt;div class="toolbar"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/div&gt;&lt;div class="toolbar"&gt;&lt;span style="font-family:courier new,courier;color:#0000ff;"&gt;static uint16_t value;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;And do the AD conversion in an endless loop:&lt;/span&gt;&lt;/p&gt;&lt;div class="bar"&gt;&lt;div class="toolbar"&gt; &lt;/div&gt;&lt;div class="toolbar"&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:courier new,courier;color:#0000ff;"&gt;for(;;) { &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:courier new,courier;color:#0000ff;"&gt;(void)AD1_Measure(TRUE); /* do conversion and wait for the result */ &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:courier new,courier;color:#0000ff;"&gt;(void)AD1_GetValue16(&amp;amp;value); /* get the result into value variable */ &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:courier new,courier;color:#0000ff;"&gt;}&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;&lt;p style="margin:0;padding:0px;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt; &lt;/span&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;With this, it could look like this:&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;a href="http://mcuoneclipse.files.wordpress.com/2013/02/processorexpert-c.png" rel="nofollow ugc noopener" target="_blank"&gt;&lt;img loading="lazy" alt="ProcessorExpert.c" class="jiveImage size-full wp-image-6643" height="366" src="http://mcuoneclipse.files.wordpress.com/2013/02/processorexpert-c.png?w=584&amp;amp;h=366" style="display:block;margin-left:auto;margin-right:auto;" width="584" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p class="wp-caption-text" style="margin:0;text-align:center;"&gt;&lt;em&gt;ProcessorExpert.c&lt;/em&gt;&lt;/p&gt;&lt;p class="wp-caption-text" style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p class="wp-caption-text" style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;/p&gt;&lt;h2&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;Build and Debug&lt;/span&gt;&lt;/h2&gt;&lt;p style="margin:0;"&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;With the menu &lt;em&gt;Project &amp;gt; Build Project&lt;/em&gt; I compile my project. I press the ‘Debug’ button I download the program to the board and let it run.&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&lt;a href="http://s0.wp.com/wp-includes/images/smilies/icon_idea.gif?m=1129645325g"&gt;&lt;img loading="lazy" alt=":idea:" class="jiveImage wp-smiley" src="http://s0.wp.com/wp-includes/images/smilies/icon_idea.gif?m=1129645325g" /&gt;&lt;/a&gt; &lt;em style="font-size:10pt;"&gt;To watch the variable changing in the debugger while it is running, see &lt;a class="jive-link-external-small" href="http://mcuoneclipse.com/2013/01/27/live-view-for-variables-and-memory/" rel="nofollow ugc noopener" target="_blank" title="Live View for Variables and Memory"&gt;Live View for Variables and Memory&lt;/a&gt;.&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;In the Variables View, I can see how the value changes:&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;text-align:center;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;text-align:center;"&gt;&lt;a href="http://mcuoneclipse.files.wordpress.com/2013/02/value-in-variables-view.png" rel="nofollow ugc noopener" target="_blank"&gt;&lt;img loading="lazy" alt="Value in Variables View" class="wp-image-6645 jiveImage size-full" src="http://mcuoneclipse.files.wordpress.com/2013/02/value-in-variables-view.png?w=584" title="Value in Variables View" /&gt;&lt;/a&gt;&amp;nbsp; &lt;/p&gt;&lt;p class="wp-caption-text" style="margin:0;text-align:center;"&gt;&lt;em&gt;Value in Variables View&lt;/em&gt;&lt;/p&gt;&lt;p class="wp-caption-text" style="margin:0;"&gt;&amp;nbsp; &lt;/p&gt;&lt;p class="wp-caption-text" style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;/p&gt;&lt;h2&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;Using Interrupts&lt;/span&gt;&lt;/h2&gt;&lt;p style="margin:0;"&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;So far I was waiting for the conversion to be finished with the TRUE parameter to the Measure() method. By default, the ADC component already has interrupts enabled:&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;a href="http://mcuoneclipse.files.wordpress.com/2013/02/interrupts-enabled.png" rel="nofollow ugc noopener" target="_blank"&gt;&lt;img loading="lazy" alt="Interrupts Enabled" class="jiveImage size-full wp-image-6647" src="http://mcuoneclipse.files.wordpress.com/2013/02/interrupts-enabled.png?w=584" style="display:block;margin-left:auto;margin-right:auto;" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p class="wp-caption-text" style="margin:0;text-align:center;"&gt;&lt;em&gt;Interrupts Enabled&lt;/em&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&amp;nbsp; &lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;If I use interrupts and do not wait for the conversion to be finished, I get notified by the OnEnd() event:&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;a href="http://mcuoneclipse.files.wordpress.com/2013/02/onend-event.png" rel="nofollow ugc noopener" target="_blank"&gt;&lt;span style="font-size:12pt;"&gt;&lt;img loading="lazy" alt="OnEnd Event" class="jiveImage wp-image-6648 size-full" src="http://mcuoneclipse.files.wordpress.com/2013/02/onend-event.png?w=584" style="display:block;margin-left:auto;margin-right:auto;" /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;p class="wp-caption-text" style="margin:0;text-align:center;"&gt;&lt;em&gt;OnEnd Event&lt;/em&gt;&lt;/p&gt;&lt;p class="wp-caption-text" style="margin:0;"&gt;&amp;nbsp; &lt;/p&gt;&lt;p class="wp-caption-text" style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;Double-Clicking on the OnEnd() method gets me to the Events.c file, where I can fill in the code:&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;a href="http://mcuoneclipse.files.wordpress.com/2013/02/ad1_onend-hook.png" rel="nofollow ugc noopener" target="_blank"&gt;&lt;span style="font-size:12pt;"&gt;&lt;img loading="lazy" alt="AD1_OnEnd Hook" class="wp-image-6649 jiveImage size-full" height="322" src="http://mcuoneclipse.files.wordpress.com/2013/02/ad1_onend-hook.png?w=584&amp;amp;h=322" style="display:block;margin-left:auto;margin-right:auto;" width="584" /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;p class="wp-caption-text" style="margin:0;text-align:center;"&gt;&lt;em&gt;AD1_OnEnd Hook&lt;/em&gt;&lt;/p&gt;&lt;p class="wp-caption-text" style="margin:0;"&gt;&amp;nbsp; &lt;/p&gt;&lt;p class="wp-caption-text" style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;To keep things simple, I set a boolean flag:&lt;/span&gt;&lt;/p&gt;&lt;div class="bar"&gt;&lt;div class="toolbar"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div class="toolbar"&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:courier new,courier;color:#0000ff;"&gt;void AD1_OnEnd(void) &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:courier new,courier;color:#0000ff;"&gt;{ &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:courier new,courier;color:#0000ff;"&gt;extern volatile bool AD_finished; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:courier new,courier;color:#0000ff;"&gt;AD_finished = TRUE; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:courier new,courier;color:#0000ff;"&gt;}&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;&lt;p style="margin:0;padding:0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin:0;"&gt;&amp;nbsp; &lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;a href="http://s0.wp.com/wp-includes/images/smilies/icon_idea.gif?m=1129645325g"&gt;&lt;img loading="lazy" alt=":idea:" class="jiveImage wp-smiley" src="http://s0.wp.com/wp-includes/images/smilies/icon_idea.gif?m=1129645325g" /&gt;&lt;/a&gt; &lt;span style="font-family:tahoma,arial,helvetica,sans-serif;"&gt;&lt;em&gt;I have marked this variable with volatile as the variable is changed in an interrupt service routine, and used the same time from the main program. The volatile prevents the compiler to keep that variable in a register.&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;padding:0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;"&gt;I add this boolean variable to my global variables in Processor Expert.c:&lt;/span&gt;&lt;/p&gt;&lt;div class="bar"&gt;&lt;div class="toolbar"&gt;&amp;nbsp; &lt;/div&gt;&lt;div class="toolbar"&gt;&lt;p style="margin:0;padding:0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:courier new,courier;color:#0000ff;"&gt;static uint16_t value; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:courier new,courier;color:#0000ff;"&gt;volatile bool AD_finished;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;&lt;p style="margin:0;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/p&gt;&lt;p style="margin:0;"&gt;&amp;nbsp; &lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;em style="font-family:tahoma,arial,helvetica,sans-serif;"&gt;&lt;a href="http://s0.wp.com/wp-includes/images/smilies/icon_idea.gif?m=1129645325g"&gt;&lt;img loading="lazy" alt=":idea:" class="jiveImage wp-smiley" src="http://s0.wp.com/wp-includes/images/smilies/icon_idea.gif?m=1129645325g" /&gt;&lt;/a&gt; Once things are working, consider to put that AD_finished variable declaration into a header file.&lt;/em&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;em style="font-family:tahoma,arial,helvetica,sans-serif;"&gt;Then I change my loop to start the conversion without waiting, so I can do something else while the conversion is going on:&lt;/em&gt;&lt;/p&gt;&lt;div class="bar"&gt;&lt;div class="toolbar"&gt;&amp;nbsp; &lt;/div&gt;&lt;div class="toolbar"&gt;&amp;nbsp; &lt;/div&gt;&lt;div class="toolbar"&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:courier new,courier;color:#0000ff;"&gt;for(;;) { &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:courier new,courier;color:#0000ff;"&gt;AD_finished = FALSE; /* reset flag */ &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:courier new,courier;color:#0000ff;"&gt;(void)AD1_Measure(FALSE); /* AD_finished will be set to TRUE once */ &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:courier new,courier;color:#0000ff;"&gt;while(!AD_finished) { &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:courier new,courier;color:#0000ff;"&gt;/* do something else here... */ &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:courier new,courier;color:#0000ff;"&gt;} &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:courier new,courier;color:#0000ff;"&gt;/* AD_finished set to TRUE by the interrupt to indicate the result is ready */ &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:courier new,courier;color:#0000ff;"&gt;(void)AD1_GetValue16(&amp;amp;value); /* get the result into value variable */ &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:courier new,courier;color:#0000ff;"&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;color:#0000ff;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;&lt;p style="margin:0;"&gt;&lt;/p&gt;&lt;h2&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;Multiple Channels&lt;/span&gt;&lt;/h2&gt;&lt;p style="margin:0;"&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;So far I was using a single AD value. But the component (and hardware) can be configured to convert multiple channels. To read in as well the A1 pin which is mapped to PTB1 I use the ‘+’ icon to add another channel:&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;padding:0px;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt; &lt;/span&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;em style="font-size:10pt;font-family:tahoma,arial,helvetica,sans-serif;"&gt;&lt;a href="http://s0.wp.com/wp-includes/images/smilies/icon_idea.gif?m=1129645325g"&gt;&lt;img loading="lazy" alt=":idea:" class="jiveImage wp-smiley" src="http://s0.wp.com/wp-includes/images/smilies/icon_idea.gif?m=1129645325g" /&gt;&lt;/a&gt; I need to click into the field to have the ‘+’ and ‘-’ icons.&lt;/em&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;a href="http://mcuoneclipse.files.wordpress.com/2013/02/added-another-channel.png" rel="nofollow ugc noopener" target="_blank"&gt;&lt;img loading="lazy" alt="Added another channel" class="jiveImage size-full wp-image-6654" height="477" src="http://mcuoneclipse.files.wordpress.com/2013/02/added-another-channel.png?w=584&amp;amp;h=477" style="display:block;margin-left:auto;margin-right:auto;" width="584" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p class="wp-caption-text" style="margin:0;text-align:center;"&gt;Added another channel&lt;/p&gt;&lt;p class="wp-caption-text" style="margin:0;"&gt;&amp;nbsp; &lt;/p&gt;&lt;p class="wp-caption-text" style="margin:0;"&gt;&amp;nbsp; &lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;I can use the same methods as above (Measure() and GetValue16(), but as GetValue16() is using a pointer to an array of values, I need to make sure I pass the right number of items to it:&lt;/span&gt;&lt;/p&gt;&lt;div class="bar"&gt;&lt;div class="toolbar"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/div&gt;&lt;div class="toolbar"&gt;&lt;span style="font-family:courier new,courier;color:#0000ff;font-size:10pt;"&gt;byte AD1_GetValue16(word *Values)&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;The component has created a #define for the number of channels for me (CHANNEL_COUNT) which I can use for my value variable:&lt;/span&gt;&lt;/p&gt;&lt;div class="bar"&gt;&lt;div class="toolbar"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div class="toolbar"&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:courier new,courier;color:#0000ff;font-size:10pt;"&gt;static uint16_t value[AD1_CHANNEL_COUNT]; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:courier new,courier;color:#0000ff;font-size:10pt;"&gt;volatile bool AD_finished;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;To the GetValue16() method, I pass the address of the first item:&lt;/span&gt;&lt;/p&gt;&lt;div class="bar"&gt;&lt;div class="toolbar"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div class="toolbar"&gt;&lt;span style="font-family:courier new,courier;color:#0000ff;font-size:10pt;"&gt;(void)AD1_GetValue16(&amp;amp;value[0]);&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;With this, my code works with multiple channels.&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;/p&gt;&lt;h2&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;Summary&lt;/span&gt;&lt;/h2&gt;&lt;p style="margin:0;"&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;With Processor Expert, it is not very difficult to use ADC conversion. Once familiar with the concept, it is easy to add multiple channels and to use interrupt synchronization. I do not cover here advanced features like using DMA (as not supported out oft the box with Processor Expert yet), or using different conversion modes. I think this is enough for now to get you started &lt;a href="http://s2.wp.com/wp-includes/images/smilies/icon_razz.gif?m=1129645325g"&gt;&lt;img loading="lazy" alt=":razz:" class="jiveImage wp-smiley" src="http://s2.wp.com/wp-includes/images/smilies/icon_razz.gif?m=1129645325g" /&gt;&lt;/a&gt; .&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:12pt;"&gt;Happy ADCing &lt;a href="http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif?m=1129645325g"&gt;&lt;img loading="lazy" alt=":-)" class="jiveImage wp-smiley" src="http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif?m=1129645325g" /&gt;&lt;/a&gt; &lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;

&lt;div style="font-size: 90%;"&gt;Tags: avr, microchip, cortex-m0+, freescale, Cortex-M, kinetis, acquisition, cortex, frdm-kl25z, stm32, kinetis-l, cortex-m0, nxp, st, arm, adc, freedom, pic, atmel, lpc&lt;/div&gt;
</description></item></channel></rss>