I need a project or what do YOU use arduino's for?

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: I need a project or what do YOU use arduino's for?

Post by adafruit_support_mike »

greywuuf wrote:I do not understand why the look up table witll be usefull when they dont add up
I think I just managed to see the code with a 'beginner's mind'.. without all the shortcuts and "well, I know what I meant" programmers get when they look at their own work.

From that frame of reference, those comments suck. They sort of hint at a relationship between the input (the array index) and the output (the bit vector), but only give enough information to be confusing.

Let's see if I can do a better job:

Code: Select all

                    //   INPUT        OUTPUT
char LUT[16] = {    // ----------   -----------
    B00000000,      // 0 (00:0:0)   00:0:0:0000
    B01010101,      // 1 (00:0:1)   01:0:1:0101
    B10101010,      // 2 (00:1:0)   10:1:0:1010
    B11111111,      // 3 (00:1:1)   11:1:1:1111
//     ...             |  || | |    || | | |  |
//  array index  ------+  || | |    || | | ++++--  extra output bits
//  current state  -------++ | |    || | +-------  output to ch1
//  input from ch2  ---------+ |    || +---------  output to ch2
//  input from ch1  -----------+    ++-----------  next state
};
The machine in question has four states (00, 01, 10, 11), four input symbols arranged as two 1-bit channels (0:0, 0:1, 1:0, 1:1), and sixteen transitions.

The only part of the LUT output that absolutely has to be there is the two-bit 'next state' value. The rest is 'augmented data', which is programmer-speke for 'extra stuff I threw in because I could'. The smallest chunk of data you can get from an 8-bit microprocessor is a byte, the ID of the next state only uses two bits of that byte, so we're free to use the other six bits as state-dependent output.

User avatar
xl97
 
Posts: 201
Joined: Mon Jul 27, 2009 12:51 pm

Re: I need a project or what do YOU use arduino's for?

Post by xl97 »

nice thread, Im going to go back and re-read in depth to understand all the table stuff..

@greywuuf- when I first learned about Finite State Machine coding approach.. this link helped me 'understand' how you were in certain transitions/states..etc..

maybe it will help: http://digital-diy.com/general-programm ... hines.html

helped me be able to play .wav files (in a loop) as well as be able to update my MA7221 chips without 'bumping' into each other

greywuuf
 
Posts: 43
Joined: Thu Oct 25, 2012 1:53 am

Re: I need a project or what do YOU use arduino's for?

Post by greywuuf »

Thank you for the link, I beleive it will help.
I have also decided I came into this with preconceived notions that were incorrect, I was expecting a state machine to be able to be generic and fixed ( like say a truth table ) in that we could only have logical states for any input condition ( well that is true but I mean like predefined conditions that are always the same ) I believe now that I need to define what is going to happen when certain conditions are met in order to complete the "next" state condition. for example there is no set or correct condition that exists for a 4 state machine with channel one input one and two and channel two input one present...... I am going to have to define what I want to happen when that condition is true... whats holding me up is that I am trying to build a general machine with no clear Idea of what I want it to do.

Thank you all for the extreme patience you have extended me and the help and guidance you have offered. I will try to repay you, by coding testing and researching and not expecting to be " spoon fed"

one day I hope to be able to answer some one elses question in a helpful manner.

Thank you
Dan

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: I need a project or what do YOU use arduino's for?

Post by adafruit_support_mike »

It looks like you're heading in the right direction.

You're right that there isn't a single, global lookup table that tells you what to do for any pattern of input. Instead, each state effectively has its own lookup table, and playing "which lookup table do I want to use next?" is a significant part of the game.

Don't worry that it's taking time to get the ideas straight.. this is the bones of computing stripped bare, with all the challenges and none of the convenience padding. There are whole mid-level college classes devoted to this stuff. You've shown a lot of determination in coming back to the ideas again and again and trying to make them work. I've been where you are, and know how frustrating it can be.

The longer we go, the better I understand your take on the ideas, and that (hopefully) lets me offer better suggestions.

On that subject, let's try a simpler machine to emphasize the 'which lookup table do I use?' part: Two states, two input symbols, no extra stuff:

- If you're in state 0 and see a 0, stay in state 0
- If you're in state 0 and see a 1, move to state 1
- If you're in state 1 and see a 0, stay in state 1
- If you're in state 1 and see a 1, move to state 0

You could rewrite that with two lookup tables:

LUT_0: { 0:"use LUT_0 next", 1:"use LUT_1 next" }
LUT_1: { 0:"use LUT_1 next", 1:"use LUT_0 next" }

If we start with LUT_0 (an arbitrary choice) and see the input stream '1011000100', the machine does the following:

Code: Select all

using   input   result
-----   -----   ---------------
LUT_0     1     use LUT_1 next
LUT_1     0     use LUT_1 next
LUT_1     1     use LUT_0 next
LUT_0     1     use LUT_1 next
LUT_1     0     use LUT_1 next
LUT_1     0     use LUT_1 next
LUT_1     0     use LUT_1 next
LUT_1     1     use LUT_0 next
LUT_0     0     use LUT_0 next
LUT_0     0     use LUT_0 next
How would you use such a machine? I'm not sure.. the basic action is 'stay where you are until you see a 1, then change', so I guess you could use it to control traffic lights.

Let's say state 0 means "red light on the north/south street, check north/south sensor for waiting traffic" and state 1 means "red light on the east/west street, check east/west sensor for waiting traffic". The input 1 would mean "traffic is waiting at whatever light is currently red".

From there, the machine decides:

- If no one is waiting, there's no reason to change the light.
- If someone is waiting, change the light to let them through.

If each state polls its sensor every 30 seconds, you get a basic traffic control system that doesn't keep people waiting when there's no cross-traffic.

So.. I guess that makes it an "alternate if possible, but take whatever's available" machine.

For comparison, a simple truth table wouldn't handle traffic as gracefully. You'd have two inputs for "traffic is waiting at the north/south stoplight" and "traffic is waiting at the east/west stoplight", and those would give you a table like so:

Code: Select all


                      NORTH/SOUTH

                     NO         YES
               +-----------------------
EAST/     NO   |  action-1    action-2
WEST      YES  |  action-3    action-4


action-1 (no traffic waiting either way):   Turn east/west lights green
action-2 (traffic waiting on north/south):  Turn north/south lights green
action-3 (traffic waiting on east/west):    Turn east/west lights green
action-4 (traffic waiting both ways):       ???
The table only allows you one answer for what to do when traffic is waiting both ways, so one road would have an advantage over the other. If you choose "Turn east/west lights green" for action-4, people could be backed up for a mile on the north/south road, but the light will still change as soon as a car arrives on the east/west road.

greywuuf
 
Posts: 43
Joined: Thu Oct 25, 2012 1:53 am

Re: I need a project or what do YOU use arduino's for?

Post by greywuuf »

AHA, another peek at my thinking process, I am a hardware guy ( simple) and not a software guy ... people always mess up the equation. When I speak of truth tables I am thinking of the simple logic one for N/OR gates and such such, where there is ONLY certain possible inputs and there is ONLY one acceptable answer than CAN be for any combination of inputs..... the idea of actually being able to say what I wanted to happen when an input combination occured took a long while to sink.. I felt is if I had to be missing something.! at first it seemed simple inputs all zero state zero input binary 1 state one .... I could not figure what logicly came next when adding more inputs than states.... now I know there is no concrete unisversal "correctness" that is just going to be ( like the answer to a math problem) it is more like I am saying "what happens when......" and you are telling me " I don't know.....what does happen? it is your story "

wow, being bull headed is sometimes a very long road.

thank you again,

Dan

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”