{"id":8,"date":"2017-03-19T19:30:49","date_gmt":"2017-03-20T02:30:49","guid":{"rendered":"https:\/\/sysprogs.com\/tutorials\/?p=8"},"modified":"2018-04-25T13:55:52","modified_gmt":"2018-04-25T20:55:52","slug":"using-triggers-to-synchronize-capture","status":"publish","type":"post","link":"https:\/\/sysprogs.com\/analyzer2go\/tutorials\/triggers\/","title":{"rendered":"Using Triggers to Synchronize Captured Signals"},"content":{"rendered":"<p>This tutorial shows how to use triggers to capture the signal values around the interesting events. Before you begin, follow the <a href=\"https:\/\/sysprogs.com\/analyzer2go\/tutorials\/signals\/\">basic Analyzer2Go tutorial<\/a> to get started with Analyzer2Go.<\/p>\n<p>We will use 2 STM32F4Discovery boards: one will generate a basic signal using its GPIO ports and the other one will be used by Analyzer2Go as a logic analyzer to capture the signals. We will run the following program on the first board:<\/p>\n<pre class=\"\">\u00a0\u00a0\u00a0 __GPIOD_CLK_ENABLE();\r\n\u00a0\u00a0 \u00a0GPIO_InitTypeDef GPIO_InitStructure;\r\n\r\n\u00a0\u00a0 \u00a0GPIO_InitStructure.Pin = GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14;\r\n\r\n\u00a0\u00a0 \u00a0GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;\r\n\u00a0\u00a0 \u00a0GPIO_InitStructure.Speed = GPIO_SPEED_HIGH;\r\n\u00a0\u00a0 \u00a0GPIO_InitStructure.Pull = GPIO_NOPULL;\r\n\u00a0\u00a0 \u00a0GPIO_InitStructure.Alternate = GPIO_AF2_TIM4;\r\n\u00a0\u00a0 \u00a0HAL_GPIO_Init(GPIOD, &amp;GPIO_InitStructure);\r\n\u00a0\u00a0 \u00a0\r\n\u00a0\u00a0 \u00a0for (;;)\r\n\u00a0\u00a0 \u00a0{\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12, GPIO_PIN_SET);\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0for (int i = 0; i &lt; 100; i++)\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0{\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0HAL_GPIO_WritePin(GPIOD, GPIO_PIN_13, GPIO_PIN_SET);\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0HAL_GPIO_WritePin(GPIOD, GPIO_PIN_13, GPIO_PIN_RESET);\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0}\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12, GPIO_PIN_RESET);\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0for (int i = 0; i &lt; 100000; i++)\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0asm(\"nop\");\r\n\u00a0\u00a0 \u00a0}<\/pre>\n<p>The program will generate a positive edge on PD12 followed by 100 pulses on PD13. We will use Analyzer2Go to see how uniform the generated signal will be.<\/p>\n<ol>\n<li>Start Analyzer2Go and select your board type. Then load the program shown below into the generator board and connect the PD12 and PD13 signals on it to the inputs on the second board. Analyzer2Go will show that for most of the time both signals are idle and sometimes a short sequence of pulses appears:<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-40\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2017\/03\/01-nosig.png\" alt=\"\" width=\"1339\" height=\"823\" srcset=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2017\/03\/01-nosig.png 1339w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2017\/03\/01-nosig-300x184.png 300w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2017\/03\/01-nosig-768x472.png 768w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2017\/03\/01-nosig-1024x629.png 1024w\" sizes=\"(max-width: 1339px) 100vw, 1339px\" \/><\/li>\n<li>As we are only interested in the signals inside the 100-pulse sequence, we will set a rising edge trigger on the signal that goes high before the pack and low after it. To do that, simply click in the &#8220;T&#8221; column of the corresponding row:<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-41\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2017\/03\/02-triggered.png\" alt=\"\" width=\"1339\" height=\"823\" srcset=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2017\/03\/02-triggered.png 1339w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2017\/03\/02-triggered-300x184.png 300w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2017\/03\/02-triggered-768x472.png 768w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2017\/03\/02-triggered-1024x629.png 1024w\" sizes=\"(max-width: 1339px) 100vw, 1339px\" \/>Analyzer2Go will now capture the signals exactly around each rising pulse. The trigger mechanism is designed to capture even very rare events &#8211; once it starts waiting for a trigger, it will keep recording and discarding the data on all channels. Once the trigger is detected, the captured data will be aligned so that the trigger is exactly in the middle of it. As a result, you will see a quick sequence of frames, each one centered around the trigger pulse.<\/li>\n<li>You will notice that once in a while it looks like the 100-pulse signal is slightly irregular. You can study it by pressing &#8220;Pause&#8221; and navigating back to the irregular frame using the &#8220;Back&#8221; button:<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-42\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2017\/03\/03-irregular.png\" alt=\"\" width=\"1103\" height=\"823\" srcset=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2017\/03\/03-irregular.png 1103w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2017\/03\/03-irregular-300x224.png 300w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2017\/03\/03-irregular-768x573.png 768w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2017\/03\/03-irregular-1024x764.png 1024w\" sizes=\"(max-width: 1103px) 100vw, 1103px\" \/><\/li>\n<li>You can select the irregular pulse to measure its length:<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-43\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2017\/03\/04-lag.png\" alt=\"\" width=\"1103\" height=\"823\" srcset=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2017\/03\/04-lag.png 1103w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2017\/03\/04-lag-300x224.png 300w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2017\/03\/04-lag-768x573.png 768w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2017\/03\/04-lag-1024x764.png 1024w\" sizes=\"(max-width: 1103px) 100vw, 1103px\" \/><\/li>\n<li>The irregular pulse generated by the board might be caused by the CPU handing interrupts. You can verify it by configuring the interrupt handler to set another signal to 1 on entry and reset it back to 0 on exit:\n<pre class=\"\">void SysTick_Handler(void)\r\n{\r\n\u00a0\u00a0 \u00a0HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_SET);\r\n\u00a0\u00a0 \u00a0HAL_IncTick();\r\n\u00a0\u00a0 \u00a0HAL_SYSTICK_IRQHandler();\r\n\u00a0\u00a0 \u00a0HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_RESET);\r\n}<\/pre>\n<\/li>\n<li>Upload the modified code to the generator board and capture the extra signal. You will see that the lag always coincides with the timer interrupt:<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-44\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2017\/03\/05-isr.png\" alt=\"\" width=\"1103\" height=\"823\" srcset=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2017\/03\/05-isr.png 1103w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2017\/03\/05-isr-300x224.png 300w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2017\/03\/05-isr-768x573.png 768w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2017\/03\/05-isr-1024x764.png 1024w\" sizes=\"(max-width: 1103px) 100vw, 1103px\" \/><\/li>\n<li>You can use the Frequency and Trigger Settings button to review and change the trigger settings used by Analyzer2Go: <img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-45\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2017\/03\/06-scope.png\" alt=\"\" width=\"530\" height=\"629\" srcset=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2017\/03\/06-scope.png 530w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2017\/03\/06-scope-253x300.png 253w\" sizes=\"(max-width: 530px) 100vw, 530px\" \/><\/li>\n<\/ol>\n<p>Starting from\u00a0version 2.0 Analyzer2Go is compatible with the Cypress\u00a0SuperSpeed Explorer Kit, supporting\u00a0continuous\u00a0capture at 200MHz\u00a0via the fast USB 3.0 interface. Check out\u00a0the\u00a0<a href=\"https:\/\/sysprogs.com\/analyzer2go\/tutorials\/superspeed\/\">SuperSpeed tutorial<\/a>\u00a0for details.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to use triggers to capture the signal values around the interesting events. Before you begin, follow<\/p>\n","protected":false},"author":1,"featured_media":47,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[12,13],"_links":{"self":[{"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/posts\/8"}],"collection":[{"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/comments?post=8"}],"version-history":[{"count":4,"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/posts\/8\/revisions"}],"predecessor-version":[{"id":303,"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/posts\/8\/revisions\/303"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/media\/47"}],"wp:attachment":[{"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/media?parent=8"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/categories?post=8"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/tags?post=8"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}