<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>state machine on Bald Engineer</title><link>https://www.baldengineer.com/tag/state-machine</link><description>Recent content in state machine on Bald Engineer</description><generator>Hugo</generator><language>en-US</language><lastBuildDate>Tue, 10 Apr 2018 05:19:26 +0000</lastBuildDate><atom:link href="https://www.baldengineer.com/tag/state-machine/index.xml" rel="self" type="application/rss+xml"/><item><title>Soft Power Controller State Machine</title><link>https://www.baldengineer.com/software-power-controller-state-machine.html</link><pubDate>Wed, 21 Jun 2017 13:00:43 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=6516</guid><description>Previously I looked at the hardware needed to build a Raspberry Pi soft power supply. This week I’m looking the state machine for the microcontroller. Why is such a complicated circuit necessary? I am replacing a Super Famicom (SNES) motherboard with the Pi. The trick is, I want to use the original power switch to turn the Pi on and off.&#10;This requirement presents a problem. When the switch goes into the “OFF” position, power needs to stay on long enough for the Pi to properly shutdown. So the switch itself can’t provide power to the Pi directly. With minor changes, the code in this state machine could be made to work with push buttons as well. If I add that feature in the future, I’ll update the code on the RPSPC GitHub project.<p><img src="https://www.baldengineer.com/wp-content/uploads/2017/06/soft-power-controller-state-diagram.jpg" alt="Soft Power Controller State Machine"/></p></description></item><item><title>Microcontroller state machine with enum tutorial</title><link>https://www.baldengineer.com/state-machine-with-enum-tutorial.html</link><pubDate>Wed, 29 Jul 2015 13:00:07 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=5251</guid><description>Flag variables are great, and totally not evil, when you just have two states: ON or OFF. What about when you have multiple states? Is there an option better than creating multiple flag variables?&#10;The C-language has a declaration type just for this purpose. It is called an enumeration, or enum.&#10;Setting up a state machine with enum is a surprisingly simple. Arduino and embedded programmers should use them!&#10;All you need to do is create descriptive tag names, and let the compiler assign them an integer value. Unlike a #define which is just a macro replacement, the compiler treats an enum as your personal variable type.<p><img src="https://www.baldengineer.com/wp-content/uploads/2015/07/state-machines-with-enum-tutorial.jpg" alt="Microcontroller state machine with enum tutorial"/></p></description></item></channel></rss>