{"id":2743,"date":"2017-01-30T00:00:57","date_gmt":"2017-01-30T08:00:57","guid":{"rendered":"http:\/\/192.168.3.4\/?p=2743"},"modified":"2018-01-09T06:51:28","modified_gmt":"2018-01-09T14:51:28","slug":"2743","status":"publish","type":"post","link":"https:\/\/www.cloudacm.com\/?p=2743","title":{"rendered":"Signals &#8211; Digital, Analog, and PWM"},"content":{"rendered":"<p>In this post I&#8217;ll be covering fundamental electronic signals.\u00a0 These will establish a foundation for us to work from as I begin to cover more advanced signaling technology.\u00a0 First, we will cover digital signals.\u00a0 These are the most basic since they are either on or off.\u00a0 Next, we cover RC Time circuits which allow us to use a digital port to read an analog condition.\u00a0 We&#8217;ll follow that up with analog signals and how we read them electronically.\u00a0 Next, I&#8217;ll cover pulse width modulation (PWM) as a way for us to create analog signals from a digital source.\u00a0 Lastly, we&#8217;ll explore conditioning circuits that work with analog signals to bring them into a working headroom for our devices.<\/p>\n<p>What are signals and what purpose do they serve?\u00a0 Signals are essentially voltage levels and we use them to do a whole host of things like, turn on a light, listen to music, adjust the temperature of a room, and much more.\u00a0 I won&#8217;t be going into specifics, but I will be focusing our attention of signals towards those used by devices like the raspberry pi and arduino, along with the sensors that feed them.<\/p>\n<p>As I mentioned, digital signals are basically voltage levels that are either on or off.\u00a0 Think of them like the light switch in a room.\u00a0 When the digital signal is low, the light in the room is off.\u00a0 When the digital signal is high, the light in the room is on.<\/p>\n<p><a href=\"http:\/\/192.168.3.4\/wp-content\/uploads\/2017\/01\/ATMega328DCCharacteristics.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-2746\" src=\"http:\/\/192.168.3.4\/wp-content\/uploads\/2017\/01\/ATMega328DCCharacteristics-107x300.png\" alt=\"\" width=\"107\" height=\"300\" srcset=\"https:\/\/www.cloudacm.com\/wp-content\/uploads\/2017\/01\/ATMega328DCCharacteristics-107x300.png 107w, https:\/\/www.cloudacm.com\/wp-content\/uploads\/2017\/01\/ATMega328DCCharacteristics-96x270.png 96w, https:\/\/www.cloudacm.com\/wp-content\/uploads\/2017\/01\/ATMega328DCCharacteristics.png 223w\" sizes=\"auto, (max-width: 107px) 100vw, 107px\" \/><\/a><\/p>\n<p>Devices like the raspberry pi and arduino read the digital state by detecting a voltage level above or below a given threshold.\u00a0 By and large, all digital devices use <a href=\"https:\/\/learn.sparkfun.com\/tutorials\/logic-levels\">logic levels<\/a> to determine the state of an input.\u00a0 They also use these logic levels when creating a digital output signal.\u00a0 The threshold voltages allow for clean operation in situations where noise, loss, and other factors would degrade the digital signal.\u00a0 The difference between the high state threshold and low state threshold is referred to as the gap voltage.\u00a0 The larger the gap, the more resilient to noise and loss the logic level is.<\/p>\n<p>One key benefit to using set logic levels is the accurate detection when a threshold is crossed.\u00a0 This is central to using digital inputs as a way to measure analog signals.\u00a0 To do that we use the <a href=\"https:\/\/learn.sparkfun.com\/tutorials\/photocell-hookup-guide\">RC time circuit<\/a>.<\/p>\n<p>First, lets cover what an analog signal is.\u00a0 Let&#8217;s use the room light as example again.\u00a0 Instead of the light being turned on or off with a switch, we now use a dimmer to adjust the brightness of the light.\u00a0 The varying levels of voltage is what makes it an analog signal.<\/p>\n<p><a href=\"http:\/\/192.168.3.4\/wp-content\/uploads\/2017\/01\/RC-Time.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2748\" src=\"http:\/\/192.168.3.4\/wp-content\/uploads\/2017\/01\/RC-Time.png\" alt=\"\" width=\"652\" height=\"264\" srcset=\"https:\/\/www.cloudacm.com\/wp-content\/uploads\/2017\/01\/RC-Time.png 652w, https:\/\/www.cloudacm.com\/wp-content\/uploads\/2017\/01\/RC-Time-300x121.png 300w, https:\/\/www.cloudacm.com\/wp-content\/uploads\/2017\/01\/RC-Time-604x245.png 604w\" sizes=\"auto, (max-width: 652px) 100vw, 652px\" \/><\/a><\/p>\n<p>Now back to detecting the analog signal on a digital input.\u00a0 As mentioned, the RC time circuit is used to make this possible.\u00a0 The RC time circuit consists of a variable resistor and a capacitor.\u00a0 The value of the resistor is changed by the analog input.\u00a0 When this occurs, the time it takes for the capacitor to discharge across the resistor changes.\u00a0 Here is the theory behind it.<\/p>\n<p><iframe loading=\"lazy\" title=\"R C circuit, Time Constant\" width=\"640\" height=\"360\" src=\"https:\/\/www.youtube.com\/embed\/oPJyPEv5JFA?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/p>\n<p>Our digital port is set as an output and it creates a high state.\u00a0 The analog input is setting the value of our resistor.\u00a0 We then change our digital port to an input and begin counting time.\u00a0 Initially, the digital input sees a high because the capacitor still has most of its charge.\u00a0 As we count time, the capacitor begins to discharge across the resistor.\u00a0 The speed of the discharge depends on the resistance of the resistor.\u00a0 At some point, the logic level threshold will be reached when the discharge voltage gets low enough.\u00a0 At that point the digital input will change to a low and our time counting will stop.\u00a0 The time count value is what corresponds with the analog input.\u00a0 I won&#8217;t cover how to change the resistor value from an analog input here.<\/p>\n<p>It&#8217;s a lot to take in, but it works.\u00a0 Devices that do not have analog inputs benefit greatly from this method.\u00a0 In contrast, devices that allow analog signal inputs use internal circuitry to convert the varying voltage levels to logic levels.<\/p>\n<p>This is called <a href=\"https:\/\/learn.sparkfun.com\/tutorials\/analog-to-digital-conversion\">analog to digital conversion<\/a>, commonly referred to as ADC.\u00a0 ADC chips contain complex circuits that will change varying voltage levels on the input into digital values or bits.\u00a0 The number of bits determines the quality of the readings, also known as resolution.\u00a0 ADC chips with high bit ratings are able to detect finer changes in voltage than those with lower bit ratings.\u00a0 The trade off is it takes more memory to handle higher resolution.<\/p>\n<p>The devices we&#8217;ll be using also have analog outputs.\u00a0 They do this digitally by turning an output pin on and off at a very fast rate.\u00a0 Also the rate changes depending on the analog signal it needs to recreate.\u00a0 The process is known as <a href=\"https:\/\/learn.sparkfun.com\/tutorials\/pulse-width-modulation\">pulse width modulation<\/a>, more commonly referred to as PWM.\u00a0 Analog circuits typically have a slower response time than digital ones.\u00a0 When a group of digital pulses are sent into an analog circuit, the analog circuit averages out the signal.\u00a0 The result is comparable to the original analog signal.<\/p>\n<p><a href=\"http:\/\/192.168.3.4\/wp-content\/uploads\/2017\/01\/PWMSignalAnalogResult.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2749\" src=\"http:\/\/192.168.3.4\/wp-content\/uploads\/2017\/01\/PWMSignalAnalogResult.png\" alt=\"\" width=\"455\" height=\"328\" srcset=\"https:\/\/www.cloudacm.com\/wp-content\/uploads\/2017\/01\/PWMSignalAnalogResult.png 455w, https:\/\/www.cloudacm.com\/wp-content\/uploads\/2017\/01\/PWMSignalAnalogResult-300x216.png 300w, https:\/\/www.cloudacm.com\/wp-content\/uploads\/2017\/01\/PWMSignalAnalogResult-375x270.png 375w\" sizes=\"auto, (max-width: 455px) 100vw, 455px\" \/><\/a><\/p>\n<p>This process is called signal buffering or conditioning.\u00a0 It makes the signal more representative of the original.\u00a0 This is far from creating an exact copy.\u00a0 To do that would require multiple output pins, more complex circuitry, and would utilize more memory space.\u00a0 PWM and signal conditioning gets the same work done for much less cost and resource usage.<\/p>\n<p><iframe loading=\"lazy\" title=\"\ud83d\udd0a How to make an LM386 audio amplifier circuit\" width=\"640\" height=\"360\" src=\"https:\/\/www.youtube.com\/embed\/4ObzEft2R_g?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/p>\n<p>Another form of analog signal processing is level attenuation and amplification.\u00a0 This signal balancing is needed because our devices have set ranges for analog inputs.\u00a0 If we input an analog signal that is weak, our ADC will not capture the quality.\u00a0 If our signal in is too high, we would either clip the signal peaks or damage our devices.\u00a0 Signal balancing is way to get the most out of our ADC.\u00a0 It also isolates the input signal electronically should an unexpected surge occur.\u00a0 These transients can damage our devices if allowed direct contact with them.<\/p>\n<p>That should cover the basics.\u00a0 Next I&#8217;ll be covering communications protocols.\u00a0 These are methods used by devices to send data to one another.\u00a0 There are benefits to using them which I&#8217;ll cover later.\u00a0 I hope you have enjoyed this post and look forward to seeing you again.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this post I&#8217;ll be covering fundamental electronic signals.\u00a0 These will establish a foundation for us to work from as I begin to cover more advanced signaling technology.\u00a0 First, we will cover digital signals.\u00a0 These are the most basic since they are either on or off.\u00a0 Next, we cover RC Time circuits which allow us to use a digital port to read an analog condition.\u00a0 We&#8217;ll follow that up with analog signals and how we read them electronically.\u00a0 Next, I&#8217;ll&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/www.cloudacm.com\/?p=2743\"> Read More<span class=\"screen-reader-text\">  Read More<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,6,3,8],"tags":[],"class_list":["post-2743","post","type-post","status-publish","format-standard","hentry","category-arduino","category-raspberry-pi","category-rd","category-xbee"],"_links":{"self":[{"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/posts\/2743","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2743"}],"version-history":[{"count":6,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/posts\/2743\/revisions"}],"predecessor-version":[{"id":2753,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/posts\/2743\/revisions\/2753"}],"wp:attachment":[{"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2743"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2743"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2743"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}