<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Soham Chatterjee on Medium]]></title>
        <description><![CDATA[Stories by Soham Chatterjee on Medium]]></description>
        <link>https://medium.com/@csoham358?source=rss-1760c7cc5209------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*xcoS2LTmvS-G6DWN1xWbtA.png</url>
            <title>Stories by Soham Chatterjee on Medium</title>
            <link>https://medium.com/@csoham358?source=rss-1760c7cc5209------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 05:22:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@csoham358/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[A Beginner’s Guide to IoT Power Converters and Regulators]]></title>
            <link>https://medium.com/iotforall/a-beginners-guide-to-iot-power-converters-and-regulators-b74d37f11f31?source=rss-1760c7cc5209------2</link>
            <guid isPermaLink="false">https://medium.com/p/b74d37f11f31</guid>
            <category><![CDATA[makers]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[power]]></category>
            <category><![CDATA[energy]]></category>
            <category><![CDATA[iot]]></category>
            <dc:creator><![CDATA[Soham Chatterjee]]></dc:creator>
            <pubDate>Wed, 05 Dec 2018 19:47:41 GMT</pubDate>
            <atom:updated>2018-12-05T19:47:41.604Z</atom:updated>
            <content:encoded><![CDATA[<p>Power supply design can really impact an IoT device. This guide introduces power supplies, discusses their components, and suggests how to design robust and resilient power supplies.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/696/0*kwnGlec_LQdXoo6j.jpg" /></figure><p>Power is the most quintessential requirement for your IoT device. Without power, and without power being managed and distributed properly, your device can either not work or give someone a very nasty shock. In this article, I will talk about what a power converter is, ideal power sources for IoT devices, how to design one, and how you can easily measure and reduce your device’s power consumption.</p><h3>But What Is Power?</h3><p>Any IoT device will need electricity to work. Whether coming from a power outlet or a battery, your device will always require a certain amount of voltage and current. The product of those two (voltage and current) is called <em>power</em>. The amount of power that is being consumed in some time period is the device’s <em>energy</em>. It is important to understand these two terms since we will refer to them a lot for the rest of the article.</p><p>Most often, the power that your device requires will be very different from the one that is readily available. A typical IoT sensor will usually require either 5 volts or 3.3 volts and anywhere between 30 mA to 1 A. On the other hand, the power supply from your outlet can vary from anywhere between 110V (<em>e.g.</em> USA) to 240V <em>(e.g. </em>India). As you can probably imagine, connecting your mains supply directly to this sensor will not only destroy your device; it could also potentially cause fires and hurt someone. This is why we use <em>power converters</em> that can reduce the voltage level such that it can be safely connected to the sensor.</p><h3>So What Is a Power Converter?</h3><p>The best example of such a device is your mobile phone charger. I think it’s very surprising how little people think about the charger they use every day. It’s actually an amazing device it actually is. It can convert an extremely high voltage of up to 240 V and potentially even 16A to a harmless 5V and 2A. Moreover, it does not matter whether the input is 110V at 60Hz or 240V at 50Hz, it will still give the same 5V and 2A output without breaking a sweat. On the other hand, there are also a lot of cheap or fake chargers that are available that can stop working or even shock or burn you. The difference between good and bad power converters is a set of rules and regulations that are followed and tests that are conducted to make sure that your device is not only safe to use but can also endure.</p><p>It isn’t necessary for a power converter just to be able to convert power from a high voltage to a lower voltage. In fact, anything that converts power from one type of frequency, voltage, or voltage shape to another type of frequency, voltage, or current can be a power converter. However, the most common ones for IoT devices are the ones that convert a high alternating voltage to a low fixed DC voltage.</p><p>To summarise, our power supplier should be able to convert a high voltage, high current, and highly fluctuating power supply into a stable supply equivalent to what our device needs to work properly and safely at the same time.</p><h3>Security and Safety</h3><p>“Stability” and “safety” are very vague terms for someone who has to design a product that fits those criteria. Let’s dig deeper and try to iron out those terms in clear terms.</p><h3>5 Elements of Good Power Supply Design</h3><h4>1: Under Voltage Cut-off</h4><p>Like all devices, even our power converters have a range of voltages and currents within which they operate. As a designer, you can try to make this range as large as possible, but eventually, you will hit a cost/profit wall. As such, your power converter should know when the voltage that is being given to it is too low for it to convert to the required output properly and cut off the output to prevent damage to the rest of the circuit. This is especially important when you are using it to charge a battery and a low voltage can damage the battery.</p><h4>2: Over Current Protection</h4><p>A short-circuit in either your device or your power converter could cause a sudden spike in the current output of your converter. In these scenarios, your converter should open the circuit to prevent any damage to the device and the user.</p><h4>3: Surge Protection</h4><p>No power utility is perfect. There might be a few cases in which the input to your converter will have a high current or voltage. While these “surges” are usually short-lived, they can still harm your batteries and your device. They should be dealt with gracefully. The best way to do so is to ground your devices. And voilà, our fourth point:</p><h4>4: Grounding</h4><p>Grounding is very important in all modern day devices. If something goes really wrong in your device — <em>e.g. </em>a short-circuit or a loose wire shorting the case of your device — grounding is usually the last line of defense against a potentially deadly accident. In simple terms, grounding reroutes stray and excess charges from your device back into the ‘Earth’.</p><h4>5: Stability and Isolation</h4><p>The mains power is highly fluctuating (50Hz to 60Hz). Converting that to a stable 5V output supply can be very hard — and dangerous if done incorrectly. One of the best ways to achieve a good result is to use SMPS (Switch Mode Power Supply) circuits. These circuits convert power by switching ON and OFF in very high frequencies.</p><p>Isolation is also important. Since the adapters tend to be very small, it’s easy for a high voltage line to get shorted with a low voltage one, which can be deadly if someone touches the seemingly harmless 5V output part. Isolation tries to minimize that from happening by not having any electrical connection between the high voltage and the low voltage parts of the circuit. This is typically done using transformers — since the primary and secondary of a transformer is not connected to each other — and by keeping a high clearance — shortest distance in air between two conducting parts — and creepage distance — shortest distance on a solid insulating material.</p><h3>What Can Happen If The Power Is Irregular?</h3><p>Lots of nasty things can occur. At worst, a short circuit in the converter could expose your device and user to the mains voltage which can be deadly. This is where proper grounding can help minimize some of the risks by diverting the excess power away from the device.</p><p>However, even a minor failure could result in an erratic supply for your IoT device. And even though a few volts here and there might not harm your users, irregularity can cause your device to malfunction and reduce its longevity.</p><h3>What Next for IoT Power Supply Design?</h3><p>Designing a robust and resilient IoT power supply is no easy task. IoT devices can be <a href="https://www.iotforall.com/prevent-iot-device-death/">prone to failure</a>. The best way to go about designing a new converter would be to look at how some of the best people in the industry are doing it. Apple has spent years researching and designing their converters. They go above and beyond when it comes to safety. <a href="http://www.righto.com/2012/05/apple-iphone-charger-teardown-quality.html">Here</a> is a nice teardown article of an iPhone charger that explains in detail the various components of the charger and what each component does. And <a href="http://www.righto.com/2012/03/inside-cheap-phone-charger-and-why-you.html">here</a> is an article about the harmful effects of not having a good power converter.</p><p><em>This post was </em><a href="https://www.iotforall.com/beginners-guide-iot-power-supply/"><em>originally published on IoT For All</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b74d37f11f31" width="1" height="1" alt=""><hr><p><a href="https://medium.com/iotforall/a-beginners-guide-to-iot-power-converters-and-regulators-b74d37f11f31">A Beginner’s Guide to IoT Power Converters and Regulators</a> was originally published in <a href="https://medium.com/iotforall">IoT For All</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Memory Devices and How They Work]]></title>
            <link>https://medium.com/@csoham358/memory-devices-and-how-they-work-73f23e563030?source=rss-1760c7cc5209------2</link>
            <guid isPermaLink="false">https://medium.com/p/73f23e563030</guid>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[engineering]]></category>
            <category><![CDATA[electronics]]></category>
            <dc:creator><![CDATA[Soham Chatterjee]]></dc:creator>
            <pubDate>Fri, 17 Aug 2018 02:42:53 GMT</pubDate>
            <atom:updated>2018-10-14T18:03:11.200Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/576/0*QYQYkW5nEQ3Adukh.jpeg" /></figure><p>Memory devices have become so ubiquitous that very few devices can function without them. Despite this, very few of us actually understand how they work and I think we take advantage of just how easy it is to drag and drop a file into a device and have it seamlessly stored in a matter of seconds.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/889/1*tD2AQHaXT7NXGKiVGBCHpw.png" /><figcaption>Decrease in the cost of Memory over the years [16].</figcaption></figure><p>Behind this simplicity though, to store even a single bit, changes have to occur in nano meter precision, and in millisecond (and even nanosecond) periods, which shows the amount of technological advances that these seemingly ordinary and commonplace things went through in the last few decades.</p><p>In this article, I will explain a few memory devices and how they save and retrieve memory.</p><blockquote><strong><em>Note</em></strong>: This article is a bit off-topic from what I usually blog about. The reason for this article is because I came across memory devices while working on another more interesting topic: Dark Silicon and Dark Memory. If you like these kinds of articles or if you think there is any way I can improve them, do let me know!</blockquote><h3><strong>Some Basics First</strong></h3><p>Since this article will be looking at memory from a hardware perspective, there are a few things that you should know before moving on:</p><p>Firstly, memory, of any type, is stored in the forms of 0s and 1s. It does not matter if you are storing your favorite music video or a PDF file of your resume, it is always broken down into 0s and 1s (bits) in the memory. A 0 and a 1 can be represented in many different ways and different memory devices use different techniques to store them. They can be represented by voltages, magnetic fields or even capacitor charges. Since we tend to store a lot of bits, the smaller the area needed to store that bit, the more memory we can fit in a given space.</p><p>Secondly, in my opinion, there are two kinds of memory: Memory which we need to access quickly like the RAM, cache and registers and memory which we use over a long period of time like flash drives, hard disks and SSDs. Because of the way we access the memory, there is a difference in the way we store them.</p><p>Memory that needs to accessed quickly are generally not required over a long period of time. In that case we sacrifice power for faster access time. This is why most of these memory need constant power and need to refreshed periodically (they lose their stored state easily) to store memory. They are also built to be able to handle many changes to their state. On the other hand, long term memory often do not need continuous power to retain their state, however, their read and write times are much slower.</p><p>And finally, the farther away the memory is located from the device trying to access it, the longer it will take to access it. This becomes pretty evident when dealing with registers and cache and RAM.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/531/1*DwIsN_VQwDpgpQqwgjWatQ.png" /><figcaption>A few other benchmarks for memory access times [17].</figcaption></figure><p>Since the registers are present in the CPU itself, they can be accessed the fastest. The L1 cache is the next closest thing to the CPU and it takes a slightly longer time to access it. The next closest thing is the L2 cache which can take 4 times as long to access as compared to the L1 cache and 48 times (!!!) as long as cache. And accessing something from the DRAM? Well, compared to a register, it can be 720 times slower (which is actually 65 nanoseconds!) [1]. The scale at which these things run is insane and I really commend the people who did the research and implementations that lead to such results.</p><p>Ok, so now that we know some of the basics, let’s dive in and see what these things are made of to help them achieve such results.</p><h3><strong>CACHE</strong></h3><p>There are two ways in which we have implemented cache and I’ll talk a bit about both of them. Remember, that the cache has to be fast and should be able to handle a large number of read/write operations.</p><p><strong>SRAM</strong></p><p>The Static Random Access Memory is a type of cache that is implemented using 6 transistors. SRAMs are extremely fast and since they are static, the memory does not need to be refreshed unlike SDRAMs. However, they do need continuous power to maintain their memory state. But being a static memory, their power requirements are quite less and definitely lesser than SDRAMs. SRAMs are also very expensive as compared to SDRAMs and hence only a small portion of the cache (usually registers, L1 and L2) will be made with SRAMs (differs in each manufacturer) [2].</p><p>SRAMs are a type of flip-flop and use 4 of their 6 transistors as an inverter to store a bit of memory. The other two transistors control access to the memory. There are SRAMs that are implemented with more transistors (8T, 10T) and with lesser (4T). 8T will take more space to store a bit than a 6T SRAM but will utilize less power [3]. Where they are used depends on what you want to optimize. For example, L1 cache is more optimized for speed and will be different from L2 which is more optimized for size [2].</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/573/1*APLgrErggdnqPBaDgRpRIw.png" /><figcaption>Construction of a 6T SRAM cell. P1, P2, N1 and N2 form an inverter and N2 and N4 act as access transistors. [18] has a really nice explanation of how memory is written and read from a cell like this.</figcaption></figure><p>The SRAM has three operations: Write (used to store memory), Read (used to retrieve memory) and Hold (used to save memory). How they do it is a bit complex and I won’t get into the details in this article (maybe I will write another one for it), but the figures should help you get a sense of how they function ([18]). Furthermore, if you wish to learn how to build an SRAM memory of your own, then you can follow<a href="http://thefragmentationparadox.blogspot.com/2014/12/sram-memories.html"> this</a> great article.</p><p><strong>SDRAM/DRAM</strong></p><p>SDRAM is the acronym for Synchronous Dynamic Random Access Memory. The major difference between an SDRAM and a DRAM is that an SDRAM has a clock that is synchronized to the CPU clock. SDRAMs can also pipeline instructions which makes them faster and more efficient than simple DRAMs [4]. This is why DRAMs have mostly become obsolete and have been replaced with SDRAMs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/177/1*ppx0nnI_dqozFHQd0LfUsg.png" /><figcaption>SDRAM implementation [19]</figcaption></figure><p>SDRAMs are implemented using a transistor and a capacitor. The state of the capacitor (charged/uncharged) is what is used to store a bit. This however has two implications. Firstly, since the charge of the capacitor can get depleted quickly, it has to be recharged over time. So not only is an SDRAM volatile (needs power to maintain its memory), but it is also Dynamic (charge needs to be periodically refreshed).</p><p>Secondly, every READ operation on a bit of memory (using a sense amplifier) causes the charge on the capacitor (if it is present) to be depleted. This means that the data must be written back after every read operation [5]. This process consumes both power and time hence making the SDRAM much slower and power hungry than the SRAM.</p><p>SDRAMs have undergone many iterations over the years and newer versions are called DDRx SDRAM, where the DDR stands for Double Data Rate. Newer DDR versions are generally faster and use less power [6].</p><h3><strong>FLASH DRIVES AND SSDs</strong></h3><p>Pen/Thumb/Flash drives, whatever you call them, and SSDs are probably the memory devices that we interact with the most physically. They are non-volatile, meaning that they don’t need power to maintain their memory and while they are slower than the other memory devices I mentioned before, they are much cheaper and hence used to store larger amounts of memory.</p><p>Flash memory is of two types: NOR flash and NAND flash. NOR flash has faster read speed and slower WRITE and ERASE speed as compared to NAND flash. This is why it is mostly used for storing programs in devices (since programs are read more often than written).</p><p>On the other hand, NAND memory has faster WRITE and ERASE speed than READ speed and hence used for general storage purposes [8]. Furthermore, NOR requires more space to store a bit while NAND is more compact, making NAND memory cheaper per bit. This is why NAND flash is more suited for making flash drives with. To know more about the difference between the implementation of those two, you can take a look at [9].</p><p>Flash memory, like SRAMs, use transistors to store bits. However, unlike the transistors in SRAMs which lose the charge when power is removed, flash memory can retain it. It does this by using something called a floating gate terminal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/592/1*07HChLpMNuwj6jHPwgaCDg.png" /><figcaption>Structure of a Floating Gate Transistor. The Floating Gate is surrounded by a Metal Oxide Layer that prevents charges from escaping when power is removed [9].</figcaption></figure><p>Unlike in a normal transistor where there is only one gate, a floating gate transistor has a secondary gate that ‘floats’ or is insulated from the control gate.</p><p>When we want to store a bit, we apply a voltage to the control gate. The electrons pass through the insulator layer and gets trapped in the floating gate. These charges remain lodged in the floating gate even after power is removed. In fact, the charge on the floating gate can last for years [10]!</p><p>The process of writing or erasing data can cause the floating gate to ‘wear off’ and reduce its ability to store memory over many read/write cycles. Think of it as writing on a piece of paper, erasing it and then writing on top of it again. After a while, it becomes impossible to write anything on it again.</p><p>Flash drives do have controllers that make sure that memory gets distributed among a lot of transistors to prolong the life of the gate [11]. Moreover, like the paper example from before, erasing a transistor does not remove the charges completely and some of the charges in the floating gate can still persist (just like erasing a piece of paper can still leave some traces). This can be used for good (to retrieve lost data), but it can also be used for bad (like reading private/deleted documents).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*9h1YQymPYESTiN5a7cH6xg.png" /><figcaption>SLC has only a single voltage refernce allowing it to store only 1 bit [21].</figcaption></figure><p>Before moving on, I also wanted to mention that SSDs and SD cards (micro and mini too) also use the same NAND flash memory technology to store information. The reason they can store so much information in such a small space (which is not possible [20]) is because in most modern flash memory, a multi-level cell (MLC) or even a triple-level cell (TLC and TLC+) design is used.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/509/1*Fmv9qb41pV1yeCZoBKRDlA.png" /><figcaption>MLC has more reference points allowing it to store more bits in the same space [21].</figcaption></figure><p>This means that unlike what I mentioned previously (SLC), two bits (MLC) or more (TLC &lt; 3 bits&gt;; TLC+ &lt; 4 bits&gt;) bits of information can be stored in a single cell (transistor). This allows more information to be packed into the same area, making it cheaper to manufacture. However, at the same time, there is an increase in power consumption and error rate (although it can be reduced using clever software techniques). MLC and TLC memory is much slower as compared to SLC and is less robust (shorter lifespans).</p><p>Even though many companies hesitate to mention what kind of storage level they use [12], it shouldn’t be surprising to know that TLC is what is usually used for regular products and eMLC is used for products that need to be more robust and resilient (very few products actually use SLC) [13].</p><h3><strong>HARD DISKS</strong></h3><p>Despite advances in Solid State Memory technologies, Hard Disk Drives (HDD) are still the largest (in terms of memory) and are the cheapest storage devices available. Unlike all the previous memory devices we saw, which have no moving parts, HDDs use a spinning magnetic disc to store information.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/344/1*5tLPfR8OxIMmJ4veDt6p6A.png" /><figcaption>Hard Disk Tracks and Sectors [23].</figcaption></figure><p>An HDD is made up of two main components: A magnetic disc and an arm. The magnetic disc contains tracks which are further divided into sectors. The sectors are further divided into domains. Each domain can be either magnetized or demagnetized to represent a bit [14].</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/442/0*XnSfLMAIkz-199mx.jpg" /><figcaption>Surface of a HDD under a microscope [22].</figcaption></figure><p>To save data, domains are magnetized using a magnetized pin on the end of the arm head. To read data, the arm head moves over the disk and gets either attracted or deflected from it. This motion is turned into bits.</p><p>I think that the wonderful thing about this technology is just how precise the motor controlling the arm needs to be. The arm head often moves at speeds of up to 15,000 RPM and may be present at distance as small as a few nanometers above the disc [15]. Voice coils, which can be easily controlled and are not affected by temperature changes, are used to achieve such precision.</p><p>However, this also means that even small dust particles can cause the arm head to move out of place resulting in a disk crash. Moreover, disk capacity is often increased, not by adding more discs but by packing more tracks into the same area. This may increase the likelihood of a disk crash as the arm head will need to move much closer to the disk surface.</p><h3><strong>IN CONCLUSION,</strong></h3><p>This was just meant to be an article that tells you about how different kinds of memory devices are implemented. I know that I have not mentioned a lot of devices, like the CD, floppy disc and registers [7] which paved the way for the devices we have now. Moreover, I have just touched up on the basics of how memory is stored, because there are so many tiny details and systems in these devices that explaining all of them will probably require me to write a book. I have mentioned some links in the reference section that you can check out if you want to know more details about them.</p><blockquote>If you liked this article please follow me and give me a clap…or two…or 40. If you didn’t then I would love to hear your feedback!</blockquote><blockquote>You can follow me on twitter (<a href="https://twitter.com/csoham358">@csoham358</a>) also read some of my other articles <a href="https://csoham.wordpress.com/">here</a></blockquote><h3>REFERENCES</h3><p>[1]<a href="https://mechanical-sympathy.blogspot.com/2013/02/cpu-cache-flushing-fallacy.html"> https://mechanical-sympathy.blogspot.com/2013/02/cpu-cache-flushing-fallacy.html</a></p><p>[2]<a href="https://superuser.com/questions/724504/processors-cache-l1-l2-and-l3-are-all-made-of-sram"> https://superuser.com/questions/724504/processors-cache-l1-l2-and-l3-are-all-made-of-sram</a></p><p>[3]<a href="https://en.wikipedia.org/wiki/Static_random-access_memory#Design"> https://en.wikipedia.org/wiki/Static_random-access_memory#Design</a></p><p>[4]<a href="https://www.electronics-notes.com/articles/electronic_components/semiconductor-ic-memory/sdram-synchronous-dram-what-is.php"> https://www.electronics-notes.com/articles/electronic_components/semiconductor-ic-memory/sdram-synchronous-dram-what-is.php</a></p><p>[5]How to use SDRAMs in FPGAs — <a href="https://alchitry.com/blogs/tutorials/sdram-verilog">https://alchitry.com/blogs/tutorials/sdram-verilog</a></p><p>[6]<a href="https://www.electronics-notes.com/articles/electronic_components/semiconductor-ic-memory/sdram-synchronous-dram-what-is.php"> https://www.electronics-notes.com/articles/electronic_components/semiconductor-ic-memory/sdram-synchronous-dram-what-is.php</a></p><p>[7]<a href="https://electronics.stackexchange.com/questions/275832/how-do-registers-work-in-a-cpu"> https://electronics.stackexchange.com/questions/275832/how-do-registers-work-in-a-cpu</a></p><p>[8] NAND and NOR flash performance comparisons — <a href="https://www.edn.com/design/systems-design/4321127/What-is-the-difference-between-NAND-and-NOR-Flash-">https://www.edn.com/design/systems-design/4321127/What-is-the-difference-between-NAND-and-NOR-Flash-</a></p><p>[9] How NAND and NOR memory works — <a href="http://www.iue.tuwien.ac.at/phd/windbacher/node14.html">http://www.iue.tuwien.ac.at/phd/windbacher/node14.html</a></p><p>[10]<a href="https://howflashdriveworks.wordpress.com/how-does-flash-drive-work/"> https://howflashdriveworks.wordpress.com/how-does-flash-drive-work/</a></p><p>[11]<a href="https://www.quora.com/How-does-a-flash-drive-pen-drive-store-data"> https://www.quora.com/How-does-a-flash-drive-pen-drive-store-data</a></p><p>[12]<a href="http://forums.sandisk.com/t5/All-SanDisk-USB-Flash-Drives/How-to-know-which-SanDisk-flash-drives-use-MLC-NAND-and-which/td-p/353259"> http://forums.sandisk.com/t5/All-SanDisk-USB-Flash-Drives/How-to-know-which-SanDisk-flash-drives-use-MLC-NAND-and-which/td-p/353259</a></p><p>[13]<a href="https://www.mydigitaldiscount.com/everything-you-need-to-know-about-slc-mlc-and-tlc-nand-flash.html"> https://www.mydigitaldiscount.com/everything-you-need-to-know-about-slc-mlc-and-tlc-nand-flash.html</a></p><p>[14]<a href="http://www.adrc.com/ckr/hddworks.html"> http://www.adrc.com/ckr/hddworks.html</a></p><p>[15]<a href="https://www.bleepingcomputer.com/tutorials/how-hard-drives-work/"> https://www.bleepingcomputer.com/tutorials/how-hard-drives-work/</a></p><p>[16] Another great discussion of the evolution of memory devices with many graphs showing the decrease in the prices of memory for a lot of devices — <a href="https://hblok.net/blog/posts/tag/ssd/">https://hblok.net/blog/posts/tag/ssd/</a></p><p>[17] An amazing article by Peter Norvig — <a href="http://norvig.com/21-days.html#answers">http://norvig.com/21-days.html#answers</a></p><p>[18] Great Explanation of how Reading and Writing to a 6T SRAM works — <a href="https://allthingsvlsi.wordpress.com/2013/04/19/6t-sram-operation/">https://allthingsvlsi.wordpress.com/2013/04/19/6t-sram-operation/</a></p><p>[19] Difference between DRAM and SRAM — <a href="http://qr.ae/TUN73k">http://qr.ae/TUN73k</a></p><p>[20] How so much memory is fit in a small SD card — <a href="https://electronics.stackexchange.com/questions/14055/how-can-so-many-memory-cells-fit-on-microsd-card">https://electronics.stackexchange.com/questions/14055/how-can-so-many-memory-cells-fit-on-microsd-card</a></p><p>[21] White paper analysing MLC and SLC flash memory — <a href="https://www.touchdynamic.com/pdf/SLC_vs_MLC.pdf">https://www.touchdynamic.com/pdf/SLC_vs_MLC.pdf</a></p><p>[22] <a href="https://www.texaspowerfulsmart.com/atomic-force/nfmm-characterization-of-magnetic-domains.html">https://www.texaspowerfulsmart.com/atomic-force/nfmm-characterization-of-magnetic-domains.html</a></p><p>[23] <a href="https://www.datarecovery.net/articles/hard-drive-sector-damage.aspx">https://www.datarecovery.net/articles/hard-drive-sector-damage.aspx</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=73f23e563030" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Beginner’s Guide to Moore’s Law]]></title>
            <link>https://medium.com/@csoham358/beginners-guide-to-moore-s-law-3e00dd8b5057?source=rss-1760c7cc5209------2</link>
            <guid isPermaLink="false">https://medium.com/p/3e00dd8b5057</guid>
            <category><![CDATA[electronics]]></category>
            <category><![CDATA[moores-law]]></category>
            <category><![CDATA[internet-of-things]]></category>
            <category><![CDATA[quantum-computing]]></category>
            <category><![CDATA[iot]]></category>
            <dc:creator><![CDATA[Soham Chatterjee]]></dc:creator>
            <pubDate>Mon, 12 Mar 2018 13:30:47 GMT</pubDate>
            <atom:updated>2018-10-04T18:42:06.515Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/479/0*URsIWYrBI_SvlLWc." /></figure><p>Any digital circuit will always have one of two states: ON or OFF, 1 or 0. And digital circuits work by switching between these states to perform calculations, send information and learn about other connected devices. So, it makes sense for digital circuits to have switches to easily transition between states, amplify signals and read the switch states from other circuits.</p><p>Before the 1950’s, this was done using vacuum tubes. They were huge evacuated tubes that used electron emissions from a filament or plate to control the flow of current. Not all tubes were evacuated though, some used gases and smaller ones used photosensitive materials and magnetic fields to control the flow of electrons. But, they all had a few things in common: they were expensive, consumed a lot of power and gave off too much heat. They were very unreliable too, and required a great deal of maintenance. And because they were huge, there was a limit to how small “computers” could be made simply because there was a limit to how small vacuum tubes could be manufactured.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/0*yufrcAFgskOp6JfO." /><figcaption>Vacuum Tubes</figcaption></figure><p>This prompted researchers at Bell Labs to find an alternative. We needed a device that was cheap, consumed less or no power and did not heat up. But most importantly, the device had to be easy to manufacture, have fast switching speeds and be small. The researchers: John Bardeen and Walter Brattain led by William Shockley, invented the transistor in 1947.</p><p>The transistor was not only small, but it had less resistance and no moving parts(hence little losses), and it was reliable and gave off little to no heat.</p><p>Pretty soon, the whole world was crazy over transistors! Everyone was working on them and new developments in transistor performance, size and reliability were happening almost every month.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/864/0*tzho7X5cUyga2EX8." /><figcaption>The Transistor</figcaption></figure><p>Jack Kilby, from Texas Instruments, was one of the first to show the world how to put many of these transistors on a single wafer (piece of Silicon). In 1959, he patented the first IC or Integrated Circuit (although his was made using a Germanium wafer). By the 1960’s, transistors were getting ever smaller, and we were manufacturing complicated ICs and building faster and smaller “computers”.</p><p>About this time, Gordon Moore, co-founder of Fairchild Semiconductor and Intel published a paper, stating that the number of components per Integrated Circuit would double every year for the next decade. In 1975, he reviewed his forecast and said that the number of components would now double every two years. This came to be known as Moore’s Law.</p><p>And it has proved accurate over several decades. More importantly, Moore’s Law has been a very critical part of manufacture and design of chips. Researchers in AMD and Intel have long set goals and targets based on Moore’s Law. Computers too have gotten smaller and faster due to advancements in chip designs forced by Moore’s Law.</p><p>More than a prediction, Moore’s Law has become a goal, a standard, so to speak, that manufacturers aim to achieve.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*g3vKfFpancLiFP_l." /></figure><p>To put it into perspective, one of the first semiconductor process (the length from the Source to Drain in a mosfet), in 1971 was 10 um (or 100,000 times smaller than a meter). In 2001, it was 130 nm nearly 80 times smaller than it was 1971!</p><p>As of 2017, the smallest transistor process is 10 nm! The diameter of a human hair is 100 um or nearly 10,000 larger than how small transistors are today!</p><p>Note: The definition for process has slightly changed now and today it is defined as the size of the gate length or the half pitch between two identical components.</p><p><strong>But there is a problem!</strong></p><p>With such small scale, comes more technical challenges. Overcoming these challenges not only needs a lot of time and research, but a lot of money and investments too. And as such, Moore’s Law is actually slowing down, and people fear that it might soon stop!</p><p>It took Intel about two and a half years to go from a 22 nm process in 2012 to 14 nm in 2014 and three years to go from there to 10 nm in 2017.</p><p>And that makes sense, as Moore’s Law is not really a law, but a prediction, or a forecast. And while it has been a goal that manufacturers have sought to achieve and keep, it has become increasingly difficult to do so. Perhaps it is now time to do another revision of the law, or maybe even discard it all together and sought out a more realistic alternative.</p><p>Moore himself has been quoted in 2015 saying that, “I see Moore’s law dying here in the next decade or so”.</p><p><strong>So what are some of these problems?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/257/0*CndJm6Z92DHyGuCC." /></figure><p><strong>Quantum Tunneling:</strong> As we get smaller and smaller, quantum properties and effects come into the picture. Due to the quantum nature of subatomic particles, electrons and atoms to behave in different, sometimes unintuitive ways.</p><p>As we reduce the size of a transistor, the size of its depletion layer also decreases. The Depletion layer is important as that is what stops the flow of electrons.</p><p>Researchers have calculated that a transistor smaller than 5 nm will not be able to stop the flow of electrons due to tunneling of electrons in its depletion region. Due to tunneling, the electrons will not perceive the depletion region and it will ‘tunnel’ through it as if it did not exist. And a transistor that cannot stop the flow of electrons is pretty useless.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/259/0*4fKwUtwXBAGfg8u9." /></figure><p><strong>Size of Atom:</strong> Moreover, we are now slowly approaching the size of an atom itself and you cannot build a transistor smaller than an atom! The Silicon atom has a diameter of around 1 nm and right now we are manufacturing transistors with gates at about 10 times that size. In a few years, not taking into account quantum effects, we will not be able to go any smaller considering that we are reaching the physical limit of how small something can be.</p><p><strong>Heating and Current Effects:</strong> What probably worries manufacturers more than the previous two problems is the heating effects that is caused by the small size of transistors. As we go smaller, transistors tend to get more “leaky”, meaning that even in their OFF state, they let some current pass through. This is called the leakage current.</p><p>If we take the leakage current to be 100 nA and a CPU to have 100 million transistors, then the leakage current will be 10A. And that will drain a phone battery in minutes.</p><p>A higher gate voltage can reduce the amount of leakage current, but that causes more heating effects. Even without considering that, each clock tick itself dissipates a huge amount of heat.</p><p>Manufacturers have to play around with these properties and get them just right to prevent these effects. And doing so is proving harder and harder as processes become smaller.</p><p>The high leakage current has also lead to the problem of Dark Silicon and Dark Memory. This is where, even though we may have a lot of transistors in a chip, most of them have to be kept OFF to prevent the chip of overheating and melting.</p><p>All those OFF transistors are taking space that could be used to place other components. Which begs the question: Do we really need to go smaller, or do we improve our current chip design?</p><p>Taking all this into account, Intel’s own CEO and the International Technology Roadmap for Semiconductors has said that 5 nm is probably the best we can do.</p><p><strong>5 nm is expected to make its debut in 2021. So what can we expect after that?</strong></p><p>One way to figure out what to do is by studying what happened when we reached the end to other similar laws.</p><p><strong>Dennard’s Scaling</strong> — Dennard Scaling was considered to be a sister law to Moore’s Law. It was formulated by Robert Dennard in 1974 and states that as transistors get smaller, their power density also decreases. This means that as transistors get smaller, the amount of voltage and current needed to operate them will also decrease. This law allowed manufacturers to both reduce the size of transistors and increase clock speeds by huge jumps every iteration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/0*Xsd-8ahBE4SPhHm8." /></figure><p>However, around 2007, Dennard’s Scaling broke down. This is because at smaller sizes, leakage currents causes transistors to heat up and that creates further losses.</p><p>You might have noticed that clock speeds have not risen in the last decade, despite the fact that transistors have gotten smaller, and this is due to the breakdown of Dennard Scaling. The high losses at higher clock speeds is also why smartphone chips use a lesser clock speed (usually 1.5 GHz).</p><p><strong>Better Pipelining</strong> — Moore’s Law can be thought of trying to cut down a forest using an axe. Every two years, we add a new person to help us cut trees using another axe. This helps us cut trees faster. But that is not the only way we can improve our tree cutting performance. We can for instance, spend time sharpening existing axes. And that is one of the areas that we will focus on more after Moore’s Law ends.</p><p>By improving current chip implementations and having better pipelining of instructions, we can improve the performance of our chips. To learn more about chip performance, you can read another article of mine here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*NoAR7UENLRzitEi-." /></figure><p>This is more generally called as Koomey’s Law which is still going very strong. Koomey’s Law says that the number of calculations per joule of energy will keep doubling every 1.5 years. And this is expected to keep going up until at least 2048, when Landauer’s principle and simple laws of thermodynamics will stop further improvements. Currently, computers are about 0.00001% efficient by Landauer Limits.</p><p>Traditional programming languages like Java, C++ and Python were built to run only on a single device. But as devices get smaller and cheaper, we can run the same program on many chips (concurrently or parallely) thus further improving performance. In this regard, languages like Go are going to take a more prominent role.</p><p><strong>Better Materials</strong> — Most importantly, researchers around the world are figuring out newer and innovative ways to build smaller and faster transistors. Materials like Gallium Nitride and Graphene have been shown to have lesser losses at faster switching frequencies.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kIcrXb0xb5SfrFMO." /></figure><p><strong>Quantum Computing</strong> — A more likely solution is Quantum Computers. Many companies like D-Wave and Rigetti Computing are working extensively in this field and more importantly, the law for scaling up of Qubits hasn’t even started!</p><p>The way we got around Dennard Scaling is by putting more cores in a single chip to improve performance. And I think that we will find some similar alternatives when Moore’s Law breaks down.</p><p>Researchers in UK have already built transistors that are 1 atom thick and 10 atoms wide using Graphene. But the commercial viability of such transistors have not been investigated. Quantum Computing too has shown great promise as they can have more than 1 state at a time (unlike other computers). Any time we hit a roadblock, we innovate and find alternatives or work arounds for them and I am sure that we will do the same for Moore’s Law too.</p><blockquote><em>If you liked this article please follow me and give me a clap…or two…or 40. If you didn’t then I would love to hear your feedback!</em></blockquote><blockquote>You can follow me on twitter (<a href="https://twitter.com/csoham358">@csoham358</a>) also read some of my other articles <a href="https://csoham.wordpress.com/">here</a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3e00dd8b5057" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Beginner’s Guide to RISC and CISC Architectures]]></title>
            <link>https://medium.com/@csoham358/a-beginners-guide-to-risc-and-cisc-architectures-fc9af424db3b?source=rss-1760c7cc5209------2</link>
            <guid isPermaLink="false">https://medium.com/p/fc9af424db3b</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[electronics]]></category>
            <category><![CDATA[engineering]]></category>
            <dc:creator><![CDATA[Soham Chatterjee]]></dc:creator>
            <pubDate>Mon, 05 Feb 2018 16:07:24 GMT</pubDate>
            <atom:updated>2018-10-14T18:02:06.075Z</atom:updated>
            <content:encoded><![CDATA[<p>Electrical Engineering is all about abstraction. We hide complex details and features and work on high level objects to make our work easier. However, this also means that most often, we do not know how something works internally, even though we might know how to use it, like op-amps.</p><p>And one place, where we probably see the most abstraction is in the microcontroller/processor area.</p><p>I have been studying the hardware behind programmable chips recently to figure out how they work, particularly, how a program is converted into hardware signals. And it is a mess down here!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*LZDmCSo4LQlKJamJ." /></figure><p>As you break down more and more layers of abstraction, it feels like you are opening Pandora’s Box and all sorts of weird and complex architectures and processing units come up.</p><p>But at the same time, it is beautiful. I mean, how does a program that we write in C, say, to add two numbers, cause changes in the chip in the hardware level that causes certain pins to go up and down and finally give us something as simple and complex as the sum!</p><p>While studying about that, I came across three terms that are although very neglected, are highly important when it comes to understanding and designing microprocessor architectures: Instruction Set, RISC and CISC. But before we learn about that, we have to understand how a microprocessor really works.</p><h3><strong>Instruction Sets</strong></h3><p>Imagine you are training a dog. You teach it to understand certain specific instructions like ‘sit’ or ‘fetch’ and then associate those words with certain tasks. So that later on, when you say ‘fetch’, and throw a ball, the dog will fetch it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/0*YF_lTbljVuXHhO1x." /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*LtCoXOMopuwNFe4H." /></figure><p>A CPU (and I will use this term to mean both microcontrollers and processors in general) works in a similar way. There are certain instructions that the CPU knows and when we give them those instructions, different transistors inside it switch ON and OFF to perform those instructions.</p><p>The instructions that we input are in the form of 1’s and 0’s, or opcode. Since it is hard for us to remember combinations of 1’s and 0’s, we tend to use shorthand’s for those instructions, called assembly language, and a compiler converts it into opcode.</p><p>The number of instructions that a particular CPU can have is limited and the collection of all those instructions is called the Instruction Set.</p><p>The Instruction Set is very important. High-level programming languages are designed based on how the instruction set is and a proper design of hardware and instruction set can determine how fast the CPU is.</p><h3><strong>CPU Performance</strong></h3><p>The performance of a CPU is the number of programs it can run in a given time. The more the number of programs it can run in that time, the faster the CPU is.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pkJm0OufWM_p_cBQo96-9w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/380/0*Ov2qC_TROzrdLCdH." /></figure><p>The performance is determined by the number of instructions that a program has: more instructions, more time to perform them. It also depends upon the number of cycles (clock cycles) per instructions.</p><p>This means that there are only two ways to improve the performance: Either minimize the number of instructions per program, or reduce the number of cycles per instruction.</p><p>We cannot do both as they are complementary; optimizing one will sacrifice the other. And the optimizations that we have to make are embedded deep in the instruction set and the hardware of the CPU.</p><p>It is because of this that the CPU industry is divided between two very big players backing one of the either techniques. While many Intel CPU’s are CISC architecture based, all Apple CPUs and ARM devices have RISC architectures under the hood.</p><h3><strong>CISC ARCHITECTURE</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/276/0*h8IYlR74C-I2aXEt." /></figure><p>CISC is the shorthand for Complex Instruction Set Computer. The CISC architecture tries to reduce the number of Instructions that a program has, thus optimizing the Instructions per Program part of the above equation. This is done by combining many simple instructions into a single complex one.</p><p>In the dog analogy, “Fetch” can be thought of as a CISC instruction. When a dog “Fetches” a ball, it is actually doing a series of instructions that include: “Follow the ball” then “Pick it up” followed by “Go back to human” and finally, “Give human the ball”.</p><p>It is obvious that giving a dog a single “fetch” instruction is easier and faster than giving it four separate instructions. And this is why initial CPU manufacturers like Intel designed CISC processors.</p><p>To illustrate a CISC instruction, let’s take the MUL instruction.</p><p>This instruction takes two inputs: the memory location of the two numbers to multiply, it then performs the multiplication and stores the result in the first memory location.</p><blockquote><strong>MUL 1200, 1201</strong></blockquote><p>Where MUL takes the value from either two memory locations (say 1200 and 1201) or two registers, finds their product and stores the result in location 1200.</p><p>This reduces the amount of work that the compiler has to do as the instructions themselves are very high level. The instructions take very little memory in the RAM and most of the work is done by the hardware while decoding instructions.</p><p>Since in a CISC style instruction, the CPU has to do more work in a single instruction, so clock speeds are slightly slower. Moreover, the number of general purpose registers are less as more transistors need to be used to decode the instructions.</p><h3><strong>RISC ARCHITECTURE</strong></h3><p>On the other hand, Reduced Instruction Set Computer or RISC architectures have more instructions, but they reduce the number of cycles that an instruction takes to perform. Generally, a single instruction in a RISC machine will take only one CPU cycle. This might be like a “sit” instruction that we give to a dog.</p><p>Multiplication in a RISC architecture cannot be done with a single MUL like instruction. Instead, we have to first load the data from the memory using the LOAD instruction, then multiply the numbers, and the store the result in the memory.</p><blockquote><strong>Load A, 1200</strong></blockquote><blockquote><strong>Load B, 1201</strong></blockquote><blockquote><strong>Mul A, B</strong></blockquote><blockquote><strong>Store 1200, A</strong></blockquote><p>Here the Load instruction stores the data from a memory location like 1200 into a register A or B. Mul multiplies values in the two registers stores it in A. Then finally we store the value of A in 1200 (or any other memory location). Note that in RISC architectures, we can only perform operations on Registers and not directly on the memory. These are called addressing modes.</p><p>This might seem like a lot of work, but in reality, since each of these instructions only take up one clock cycle, the whole multiplication operation is completed in fewer clock cycles (I discuss more on this later).</p><p>However, the time advantage is not without its disadvantages. Since RISC has simpler instruction sets, complex High-Level Instructions needs to be broken down into many instructions by the compiler. While the instructions are simple and don’t need complex architectures to decode, it is the job of the compiler to break down complex high level programs into many simple instructions.</p><p>This puts a lot of stress on the software and the software designers, while reducing the work needed to be done by the hardware.</p><p>Since the decoding logic is simple, transistors required are lesser and more number of general purpose registers can be fit into the CPU.</p><h3><strong>COMPARISON</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/299/0*g-f77aDURFz1bekw." /></figure><p>While CISC tries to complete an action in as few lines of assembly code as possible, RISC tries to reduce the time taken for each instruction to execute.</p><p>For example, the MUL operation on two 8-bit numbers in the register, in 8086 which is a CISC device can take as much as 77 clock-cycles (<a href="http://www.oocities.org/mc_introtocomputers/Instruction_Timing.PDF">link</a>), whereas the complete multiplication operation in a RISC device like a PIC takes only 38 cycles (<a href="http://www.piclist.com/techref/microchip/math/mul/8x8.htm">link</a>)! That makes it nearly twice as fast!</p><p>P.S.: Although I should be fair and say that it is not always possible to fairly compare two different kinds of microprocessors and microcontrollers and there might be other factors at play here.</p><p>Since CISC instructions take a more number of cycles to execute, parallelism and pipelining of instructions is much harder. In RISC however, since all instructions take one cycle, pipelining instructions is easier.</p><p>However, the compiler plays an important role in RISC systems, and its ability to perform this “code expansion” can hinder performance.</p><h3><strong>SO WHICH IS BETTER?</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/254/0*b_gez3mHCDoYUwhO." /></figure><p>There is really no “better” architecture, each has its own advantages and disadvantages that make it useful in different applications. CISC is most often used in automation devices whereas RISC is used in video and image processing applications.</p><p>When microprocessors and microcontroller were first being introduced, they were mostly CISC. This was largely because of the lack of software support present for RISC development.</p><p>Later a few companies started delving into the RISC architecture, most notable, Apple, but most companies were unwilling to risk it (pun intended) with an emerging technology.</p><p>Fast forward a few decades and the CISC architecture was becoming extremely unwieldy and difficult to improve and develop. Intel however had a lot of resources at their hand and were able to plow through most of the major roadblocks. They were doing this mainly to make all their hardware and software back compatible with their initial 8086 processors.</p><p>Nowadays however, the boundary between RISC and CISC architectures are very blurred and in most cases it is not important. ARM devices, PICs and almost all smartphone manufacturers use RISC devices as they are faster and less resource and power hungry. The only completely CISC device still in existence is probably the Intel x86 series.</p><blockquote>If you liked this article please follow me and give me a clap…or two…or 40. If you didn’t then I would love to hear your feedback!</blockquote><blockquote>You can follow me on twitter (<a href="https://twitter.com/csoham358">@csoham358</a>) also read some of my other articles <a href="https://csoham.wordpress.com/">here</a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fc9af424db3b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Data Correlation can make or break your Machine Learning Project]]></title>
            <link>https://medium.com/data-science/data-correlation-can-make-or-break-your-machine-learning-project-82ee11039cc9?source=rss-1760c7cc5209------2</link>
            <guid isPermaLink="false">https://medium.com/p/82ee11039cc9</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[data-analysis]]></category>
            <dc:creator><![CDATA[Soham Chatterjee]]></dc:creator>
            <pubDate>Thu, 24 Aug 2017 13:06:25 GMT</pubDate>
            <atom:updated>2023-05-03T13:06:23.231Z</atom:updated>
            <content:encoded><![CDATA[<h3>Good Data and Machine Learning</h3><p><strong>Note:</strong> <strong>I no longer write on Medium; please visit my </strong><a href="https://tinyml.substack.com/"><strong>Substack page</strong></a><strong> for my latest blogs and articles.</strong></p><p>Deep Learning has become a hammer of sorts that can nail down almost any Machine Learning (ML) problem.</p><p>Deep learning is solving many problems that most other ML algorithms cannot. But many people in the ML field believe that it can solve any problem as long as you stack up enough layers and neurons.</p><p>Thinking this way is easy for a few reasons. Frameworks like Keras and TensorFlow are easily available. Amazon AWS and GCP offer cheap computational power. And the ML community is very open and supportive.</p><p>These days, anyone can take a few online courses or read a few papers. Then they can create, say, a convolutional neural network (CNN) to recognize Handwritten digits. And then call themselves an ML engineer.</p><p>Even I am guilty of doing the same, and I have done so with very little money and a laptop worth less than $500.</p><p>But people have forgotten the two most important parts of Machine Learning: Math and Data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*MMQLAfII2jEB91-y.png" /></figure><p>Machine Learning is, after all, Data Driven AI, and your model will be only as good or as bad as the data you have.</p><p>In general, you can’t have a dataset of car images and expect to use it to classify cats and dogs. You can’t use linear regression to train a model on a dataset that does not have a linear correlation.</p><p>In this article, I will focus on data and data correlation. Your data should drive your choice of an ML algorithm. Your choice shouldn’t depend on how state-of-the-art an algorithm is, but rather on your data set.</p><h3><strong>So how important is data?</strong></h3><p>The importance of data cannot be overstated. Here’s an example.</p><p>Energy Disaggregation uses ML to find the kind of electrical devices you might have in your home. It uses features like meter data, weather, locality etc.</p><p>When I was working on a project to do the this, my Neural Network couldn’t predict the electrical devices. No matter how wide or deep a network I made, I could hardly get an accuracy above 55%.</p><p>It took me a long time to realize that it wasn’t a problem with my model, but rather a problem with my data.</p><p>To do this project, I was using a dataset that I found on the Internet. The data was neither properly labeled, nor was it good. There were some very erratic power values that did not correspond to the weather data at the same time.</p><p>All this meant that no matter how good my model was, it could have never done its job as the data itself was bad!</p><h3>What is good data?</h3><p>It’s very hard to answer a question like that. I’ve learned not use data unless it’s from a verifiable source.</p><p>A verifiable source could be from open data sources like Kaggle or KDNuggets. Also, open source datasets from a company or a country. You can also use datasets that researchers have used in their work.</p><p>Sometimes getting the right data can be the hardest part of a project. This is especially true if you are trying to do something new.</p><p>For most of my ML projects, I had to get data from Ph.D. scholars and researchers. Do not hesitate to ask experts for data!</p><p>Even with verified data, you still need to check if it is good or not. Visualization is handy for this.</p><h3>Visualization and Data</h3><p>Data visualization lets you see what the data looks like. You can see if the features correspond to the output. It also helps you find the kind of data correlation you have.</p><p>Software packages like NumPy, Pandas and Matplotlib are great for visualization.</p><p>For example, the two images below show power usages of two homes for a 24 hour period.</p><p>The rise and fall of the curve in the first image shows the increase in power usage in the mornings and evenings. You can also see there is less power usage during the night.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*aEBm9pGGw7BpyT4V." /><figcaption>Image 1: A good Electricity Power Consumption Graph</figcaption></figure><p>The second image has an erratic curve and “noisy” or irregular data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*vqWe5Z-cRSw71a5R." /><figcaption>Image 2: Irregular Electricity Power Consumption Data</figcaption></figure><p>If I were training a model to predict power usage, I’d use the data for the first image.</p><p>Data visualization helps you understand if the data you are using will help your purpose or not.</p><h3><strong>Data Correlation</strong></h3><p>Earlier in this post, I mentioned that you can’t use linear regression to model a nonlinear dataset.</p><p>The opposite is also true. If you have a linear correlated dataset you need a simple model like linear regression. Even the best CNN will give you a poor result.</p><p>Data correlation is the way in which one set of data may correspond to another set. In ML, think of how your features correspond with your output.</p><p>For example, the image below visualizes a dataset of brain size versus body size. Notice that as the body size increases, so does the brain size. This is known as a linear correlation. In a simple definition of linear correlation, the data follows a straight line.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*fq-NjzLmZDTJPTAj." /><figcaption><em>Brain Weight Vs. Body Weight</em></figcaption></figure><p>Not all data is linearly correlated. The following image shows a curve of ice cream sales versus temperature. It has an inverted U shaped graph. Why?</p><p>It could mean that if it’s hot enough, people might not want to leave their homes to go buy ice cream. Or there could be another reason. So using Linear Regression doesn’t make sense for this dataset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/683/0*1SbUUWfohJG21LKc." /><figcaption>Ice Cream Sales vs. Temperature</figcaption></figure><p>It becomes very hard to figure out how data correlates if you have more than two features. Data visualization can help find how individual features may correlate with the output.</p><h3>Filtering data</h3><p>Not all data is relevant to your project.</p><p>A good example for this is the <a href="https://www.kaggle.com/c/titanic">Kaggle Titanic competition</a>. Kaggle is an online community of data scientists at all levels. They host ongoing competitions to help learn and practice data science.</p><p>In the Kaggle Titanic competition, you are asked to analyze which people are likely survivers. There are a lot of features in this challenge. You can also make many features by combining the features that are already present.</p><p>You can see the correlation of sex with survival, and age with survival. From these visualizations it becomes very obvious how sex and age played a very big role in deciding who might have survived aboard the Titanic.</p><p>Visualizations can also help you filter out useless features. For instance, there is no correlation between embarked port and survival. In this case, we leave it out.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/902/0*Orn3mRTPmPPQRIVK." /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/878/0*9E2iafjfCd7aoauV." /></figure><h3>Getting to the Math</h3><p>Visualisation is great. But if you are someone who’d rather see numbers and stats, then there are other ways to find out how data correlates.</p><p>Pearson’s Correlation Coefficient helps you find out the relationship between two quantities. It gives you the measure of the strength of association between two variables. The value of Pearson’s Correlation Coefficient can be between -1 to +1.</p><p>1 means that they are highly correlated and 0 means no correlation. -1 means that there is a negative correlation. Think of it as an inverse proportion.</p><p>The t-test is a correlation coefficient testing for any correlation between two values.</p><p>Other popular correlation coefficients include</p><ul><li>Spearman rank order correlation</li><li>Pearson’s Rank Correlation.</li></ul><p>All these coefficients have advantages and drawbacks. It’s important to know when to use them.</p><p>Note that if you have a large dataset and if you get a small coefficient, say 0.4, then it’s not necessarily bad. The dataset might have a large statistically significant correlation.</p><p>Also note that correlation may not mean causation.</p><p>Because two variables are related, does not mean that one directly caused the other.</p><p>People aboard the Titanic did not die because they were male and aged 28. Rather, a large number of them died because officers were saving “Women and Children First”.</p><p>The importance of data correlation has an effect when you have a dataset with many features. It’s tempting to think that a larger number of features will help a model make better predictions. But that’s incorrect.</p><p>If you try to train a model on a set of features with no or very little correlation, you will get inaccurate results.</p><p>The age of the person who wrote a handwritten digit in <a href="https://en.wikipedia.org/wiki/MNIST_database">MNIST</a> could be a feature. But it wouldn’t help make better predictions.</p><p>When dealing with multidimensional datasets, it’s important to filter out non-correlated features. Instead, it’s better to use fewer highly correlated features to train a model.</p><p>Datasets with more features or higher dimensions is a recent problem. These days, data collection and storage has never been easier. More often than not, many datasets have features with similar information. This acts as noise in the system and increases complexity.</p><p>Some features also have very little variance. If your output has a lot of variance, then do you think a feature with a low variance will improve your model? NO! To figure out the importance of each feature in a dataset, we use rank correlation.</p><h3>Rank correlation</h3><p>Rank correlation is a technique that compares which features correlate with the output.</p><p>One popular rank correlation method in ML is the Principal Component Analysis. It’s a technique to find patterns in high dimensional data. Basically, it “will simplify data of higher dimensions into lower dimensions.” You can read more about it <a href="https://coolstatsblog.com/2015/03/21/principal-component-analysis-explained/">here</a>.</p><p>With fewer dimensions, data visualisation also becomes easier.</p><p>Other powerful tools to find data correlation are Random Forests and Decision Trees. They work by finding out the statistical usages of each feature. This makes it easier to figure out what the most important features are.</p><h3>How to figure out which algorithm to use?</h3><p>Data correlation and visualisation can help you decide which ML algorithm to use.</p><p>Take a look at the brain vs body size data again. Both a neural network and linear regression will be able to fit this data. But, linear regression is less computationally expensive and will train faster than a neural network.</p><p>If your data does not have a linear correlation, you could consider using polynomial regression, SVMs or Random Forests.</p><p>But, on large datasets, these might be more computationally expensive to train than a small neural network.</p><p>When working on Image Recognition problems, it’s always better to use Convolutional Neural Networks (CNN). But, NLP and time series problems are better modeled by Recurrent Neural Networks and LSTMs (Long Short Term Memory).</p><p>Choosing an algorithm also depends on whether you are doing regression or classification.</p><p>Neural networks are amazing at classification tasks but not for regression. A simple SVM might perform better.</p><p>That’s all Folks!</p><blockquote>If you liked this article please follow me and give me a clap…or two…or 40. If you didn’t then I would love to hear your feedback!</blockquote><blockquote>You can follow me on twitter (<a href="https://twitter.com/csoham358">@csoham358</a>) also read some of my other articles <a href="https://csoham.wordpress.com/">here</a></blockquote><p>Sources:</p><p>The brain size vs body size image was taken from Siraj Raval’s tutorial on implementing linear regression from scratch.</p><p>The Titanic Graphs were sourced from Ahmed Besbes blog on How to score 0.8134 in Kaggle Titanic Challenge.</p><p>Other diagram were taken from an article on data correlation from mathsisfun.com</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=82ee11039cc9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/data-correlation-can-make-or-break-your-machine-learning-project-82ee11039cc9">Data Correlation can make or break your Machine Learning Project</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Beginner’s Guide to Control Systems and Controllers]]></title>
            <link>https://medium.com/@csoham358/a-hackers-guide-to-understanding-controllers-62fb26bed952?source=rss-1760c7cc5209------2</link>
            <guid isPermaLink="false">https://medium.com/p/62fb26bed952</guid>
            <category><![CDATA[electrical-engineering]]></category>
            <category><![CDATA[electronics]]></category>
            <category><![CDATA[engineering]]></category>
            <category><![CDATA[electricity]]></category>
            <category><![CDATA[controller]]></category>
            <dc:creator><![CDATA[Soham Chatterjee]]></dc:creator>
            <pubDate>Wed, 16 Aug 2017 18:06:27 GMT</pubDate>
            <atom:updated>2018-10-04T18:47:09.195Z</atom:updated>
            <content:encoded><![CDATA[<p>Hey! In this article, I’ll be talking about <strong>controllers</strong>: What they are, what are their types and why we use them. Controllers are one of the most important, but often, the most neglected part of a system design and even I didn’t know much about them until I had to use them in a project I was working on very recently. While I was researching into controllers, I did not come across any good material on them and most of what was online was written in terms of what might be asked during an exam, but not in terms of designing and making your own project. So this article will be more of a hacker’s guide of sorts to understand controllers and implementing them in projects.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*GRp2CLpXVcNYN7zf4w6uIA.jpeg" /></figure><p>I was recently building a robot that would take a position as input and it would then move to that position. This was a simple project in which the robot could move only in one direction, that is, forwards and backwards and it would calculate its distance from a wall and that would be it’s position. It was supposed to be an easy project that shouldn’t have taken more than a few hours to complete, but even after three days, my robot would still not stop at the position given to it as input. There would always be an error of a few centimeters. It took me a long time to realize that what I was missing was a <strong>feedback loop</strong> and an <strong>error corrector</strong> in my system. Both these problems are solved by a very simple device(or code, which we’ll talk about later) called a controller.</p><p>Controllers are very important, but neglected at the same time. They are used in systems to change and maintain a system state. In my case, it was to change the position accurately and maintain it. Pretty much any electrical, mechanical, robotic, embedded…any system really, has a controller in them. Motors use controllers to to maintain speed, quad copters use them to maintain height or to stay level, cars use them to move and robots use them to pick up objects and perform tasks. Controllers are so versatile, that despite being decades old, we still haven’t found an alternative for them(partly because we don’t need to).</p><h3>So what is a controller?</h3><p>Formally, a controller can be a digital/analog circuit or a software, that tries to keep a variable like temperature, speed, position or angle set at a certain value called the <strong>set point</strong> or the <strong>set value</strong>. A controller does this by having a <strong>feedback loop</strong> that looks at an <strong>error signal</strong>(which is the difference between the real signal and the desired signal). The job of the controller is to <strong>minimize that error signal</strong>. If a motor is spinning too fast, reducing the error will reduce the speed, if the temperature is too low, it will increase the temperature etc.</p><p>It is very important to have that feedback loop as that is what will tell the controller whether it is at the desired set value or not. Once it reaches the set value, the controller will try to keep the system at the set value.</p><p>We use controllers because it helps keep our system stable. <strong>Stability </strong>means that the system will stay at the set point. If the motor on a crane wasn’t stable(at the same speed), then a crane operator would never be able to pick up or move any object. Stability in a system is important and a controller helps us maintain that. You also want your system to be <strong>robust</strong> and <strong>disturbance resistant</strong>. If your robot moves from a carpeted floor to a slippery marble floor then the friction changes, but you still want your robot to perform similarly. This ability to perform the same task under different conditions, environments or disturbances makes the system robust.</p><p>Another thing that we might want to look at while designing a system is <strong>optimality</strong>: Is the system performing at its optimal state? If a robot is moving from point A to point B, is it taking the shortest path? This is an optimality problem and controllers can be designed to take that into account.</p><p>As you can see, controllers are very robust and versatile objects. Now that we have pretty much understood what a controller is, and why we might want to use one, let’s start designing our own controller.</p><p><strong>Note</strong>: The following sections are a bit math intensive, but it shouldn’t be a problem if you know your basic maths really well. I have tried my best to explain everything I do, but in case you do find anything that I have not explained well enough or if I have made some mistake, do mention it in the comments.</p><h3>Designing the simplest controller</h3><p>When I was first trying to design a position robot, it was always a few centimeters off from the set value or my desired position. What I did at that time was design what is probably the world’s simplest controller, which looked kind of like this:</p><p>Let’s say that our desired position is = y</p><p>Let’s say our current position is = x</p><p>So our error is = e = y-x</p><p>What this means is that if e is positive, then our car still hasn’t reached the set value or has probably stopped before it has reached the set value. If e is negative, then it has overshot the set value and we need to make the car move backwards.</p><p>Let the speed of the car be = U</p><p>So what if we design a controller like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/209/0*e9im24as5_cBcANx." /></figure><p>What this system of equations means is that if our error is greater than 0, or our robot has not reached the desired point yet, then we set the robot’s speed to Umax. This will make the robot move towards the desired position. In case the robot has a negative error, we will have to move it backwards and so we set its speed to -Umax. And, if the error is 0, then the robot has already reached it’s position and it does not have to move. Seems reasonable right? I mean, intuitively, that is what we want our robot to do. Or is it?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/622/0*bgXthO69DTQgPJio." /></figure><p>A system like this will give an output as shown above. Here the value on the y-axis represents the error and the x-axis the time. The reason for such an output is simple: At first, the speed of the car increases and we accelerate until we hit zero error. But, the speed of our robot is still pretty high, it’s still at Umax, so we overshoot and now the error becomes negative. At this point, our controller switches the speed to -Umax and eventually we start going backwards, gaining speed and we overshoot again. And this gets repeated over and over.</p><p>This kind of control is known as Bang-Bang Control. When we switch between two extremes, the controller reacts harshly to even small errors and causes the kind of output we see.</p><h3>So what were the problems in this system?</h3><p>Well, for one, our response to the error signal e was constant. But this should not be the case. Instead the closer we are to the set value or the smaller our error signal is, our response needs to get smaller and smaller, until it is zero when we get to the set point.</p><p>Another thing you might have noticed was that our response, U, was jerky or unstable. It would randomly change values that would cause the response to change rapidly over time.</p><p>None of these are characteristics that we want a controller to have. A controller should not only be robust and stable, but it should also have a very smooth response. In short, we want our response to be large when the error signal is large and we want the response to decrease with a decrease in the error signal, that is, we want the response to be proportional(or inversely proportional) to the error signal.</p><h3>The Proportional Controller</h3><p>In the previous problem we saw that the response was same irrespective of the error signal. However, we want a controller that has an output that is proportional to the error. To model that, we use a proportional controller. The formula of a proportional controller looks something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/67/0*DWm4p2gPVPzbAkba." /></figure><p>where e is the error signal, and kp is called the <strong>proportionality gain</strong>.</p><p>In this case, a small error will yield a smaller value of U, and a large error will yield a larger value of U. Also, in the case where e is negative, the value of U will also be negative. So we get a nice and smooth response unlike our Bang-Bang controller in the previous example.</p><p>Say we want our robot to move 60 mm or 6 cm. So we make our set point as 6 cm and we run the program. We get an output like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/561/0*-XxHr4v2DGwaUK1A." /></figure><p>Amazing right! We got a smooth response and the system is stable. Well, not really. If you check the graph properly, you’ll see that our position is actually 5.8 and not 6. This is because once our error signal decreases up to a certain level, the value of ekp becomes very less. This means that the value of U becomes very less and no changes occur. This error is more or less constant and is known as the <strong>steady state error</strong>. So what if we increase the value of kp? We could do that, but that would cause our value to overshoot again. So, even though the system will have a <strong>smooth response</strong>, it will not achieve <strong>tracking</strong>, or it will not be able to reach the correct value of set point.</p><p>The proportionality gain tends to act like a spring, by increasing the value, the system tends to overshoot. But the advantage of the proportional controller is that for a large error, it gives a very <strong>fast response</strong> and this will come in handy when we will design more complex systems.</p><p>But for now, we need a system that can further reduce the error and get the real value closer to the desired value.</p><h3>The Integral Controller</h3><p>If you look at the graph of the proportional controller, it actually did a good job at reducing the error quickly in the beginning, but then, it lost steam and was not able to reduce the error any further. And for a large value of Kp, our controller overshoots.</p><p>While we are using the value of error to define our response, what we are not taking into account is the amount of error buildup over time(marked in red). By trying to reduce this buildup of error over time, we should be able to get our error down to zero as this error will also include the steady state error of we got from the P controller.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/555/0*IcQuc_b2J4haAJp3." /></figure><p>An Integral can be used to calculate this error buildup over time. The I Controller looks something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/134/0*6iVtn7nUuHX1goBn." /></figure><p>That might look like a confusing equation so we’ll break it down into parts. The first part is U which is our systems response. This is followed by Ki which is our <strong>Integral Gain constant</strong>. That is followed by the integral symbol. We integrate form 0, the starting time to t, our ending time. e(t) is our <strong>error signal as a function of time</strong>, which is a fancy way of saying that it represents our error at any given time. What the integration part means is that we sum up all the error values from 0 to t and then we multiply it with our <strong>Integral Constant</strong>.</p><p>The I controller on its own has a very <strong>slow response</strong>. This is because it needs the error to build up before it can start working. So an I controller on its own will act like a damped system. We can overcome this however by using the fast responsiveness characteristic of the P controller. Hence we define a PI or a Proportional-Integral Controller as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/206/0*-UnxTCyiOyzHANp3." /></figure><p>All I did was add the equation of the P and I controller to get the above equation. The PI controller takes into account both the effects of the proportion of error and the integral of the error over time. By changing the values of Kp and Ki, we can change the amount of proportional and integral response we want our system to have. I’ll talk about how to choose the values of Kp and Ki later. But for now, its safe to know that our system will be able to <strong>reduce all errors</strong> and <strong>maintain stability</strong>. In fact, PI controllers are so good at their job that more than half of the controllers used today are PI controllers. Everything from the cruise control in your car to the speed regulators in your fan uses a PI controller.</p><p>However, we still haven’t solved one problem: The problem of a <strong>smooth response</strong>. A PI controller does have a smooth response, and it is smooth enough for most systems, but for many sensitive systems, you might need a slower response time. For example, to design a system that mixes chemicals in specific amounts, you might want to mix the chemicals slowly and you definitely do not want the quantities to overshoot their desired values. To do this, we add a derivative term in our system.</p><h3>The Derivative Controller</h3><p>The derivative of our error gives the slope of the error signal at that time. The slope represents the rate of change of our error at that time. The derivative controller looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/101/0*2G9aKX_5UztBqFMv." /></figure><p>Kd is the <strong>derivative gain</strong> and it acts as a <strong>damper</strong> that makes sure that our system response is slow and that it never overshoots the set value. By combining P and D controllers, we get a PD controller:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/172/0*tc7qkXXNIbIjZ1Wc." /></figure><p>These controllers are widely used in aerial robotic applications. By choosing appropriate values of Kp and Kd, we can get a <strong>stable system that does not overshoot</strong>. Some points to consider for PD controllers are:</p><p>1)If we choose a small value for Kd, the system might overshoot like so</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/615/0*DqPIHP0qSD8oMfJz." /></figure><p>2)If we increase the value of Kp too much, we will have a system with a fast response, but we will also have oscillations in the system like so</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/0*CYg6JqgTv3r4-wc-." /></figure><p>3)If however, we have a system with a large value of Kd, then we will have an over damped system like so</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/696/0*6Ni7O0ldJVGorrPC." /></figure><h3>Enter PID controllers</h3><p>We now know what P, PI and PD controllers are. To have a system where you can take advantage of the different properties of P, I and D, we use a PID controller. By choosing smaller or larger values of the constants, we can give the system more or less properties of different controllers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/292/0*pIMStU_rgxYXUp9T." /></figure><p>There are essentially, 3 parts to that equation that you can tweak while designing a system. They are the Proportional Gain or Kp, the Integral Gain Ki and the Derivative Gain Kd. Tweaking these different values have the following effects:</p><p><strong>Kp</strong>: It has a Fast Response, it improves Stability, But there is a constant Steady State Error and there is no tracking. A small value of Kp increases stability, but causes a large steady state error. A larger value tends to make the system overshoot.</p><p><strong>Ki</strong>: Improves tracking, but it has a very slow rate of response and may cause oscillations. It also increases the disturbance rejection of the system.</p><p><strong>Kd</strong>: By increasing the derivative gain, we tend to make the system overdamped. The derivative is also sensitive to noise as the slope at a time will change if you have a noisy signal.</p><p>OK, So now that we know what a controller is, what the different parameters are and how tweaking each parameter can cause a different output, we can now finally move on to learning how to implement controllers. But before that, I should probably answer the next question first.</p><h3>What’s the difference between a Controller and a Micro-controller?</h3><p>Many people don’t know the answer to this, and after searching online for the better part of a day, even I could not find any material online that properly answers this question, so I’ll try my best to answer it.</p><p>A controller and a micro-controller are actually quite different from each other. A micro-controller is a device that can be used to control a system. It has I/O ports that can take both digital and analog inputs and outputs and based on some input signals, it does some calculations and gives an output signal. While a micro-controller is a hardware device, a controller, is a mathematical process or function that can be used to get a desired result. This means that a PID controller can be implemented inside a micro-controller and most of the time, that is what is done today. For example, in my example robot project, I had a distance sensor that could measure the position of my robot, this would be given as feedback to my micro-controller that would then calculate the error and the value of response and tell the wheels of my robot to move based on that.</p><h3>How to Implement a Controller</h3><p>We’ll be implementing a controller using a micro-controller. We’ll be implementing a motor speed controlling system. To do so, we’ll need to first tell the micro-controller what speed to maintain. We also need a feedback loop that tells the micro-controller what speed the motor is running at currently. To change the speed of the motor we usually control the voltage using a converter.</p><p>Using these two values we can calculate the error value. This error value will then need to be fed into the equation for whatever controller you want to use. By tweaking the values of Kp, Ki and Kd, we can make sure that when we change the speed of the motor, there are reduced oscillations and that the system is stable. The value outputted by the controller can be then given into the voltage converter which will in turn change the speed of the motor.</p><blockquote>If you liked this article please follow me and give me a clap…or two…or 40. If you didn’t then I would love to hear your feedback!</blockquote><blockquote>You can follow me on twitter (<a href="https://twitter.com/csoham358">@csoham358</a>) also read some of my other articles <a href="https://csoham.wordpress.com/">here</a></blockquote><p>Sources:</p><p>Many of the images in this tutorial were taken from online courses on Coursera and edX. The courses were “Aerial Robotics” by Prof. Vijay Kumar from the University of Pennsylvania and “Control of Mobile Robots” by Dr. Magnus Egerstedt from Georgia Institute of Technology. They are both amazing courses and are highly recommended</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=62fb26bed952" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>