HOME  |  NEWS  |  BLOGS  |  MESSAGES  |  FEATURES  |  VIDEOS  |  WEBINARS  |  INDUSTRIES  |  FOCUS ON FUNDAMENTALS
  |  REGISTER  |  LOGIN  |  HELP
Comments
You must login to participate in this chat. Please login.

I like how this is developing. I'll keep going!

Iron

Refresh LED display at each state change

thanks for the state machines. Before I used only one state: the current state, I will try to use the current and previous state in the future project.  

 

Iron

Worked with state machines.

Iron

Thanks for answering my rookie question!

Iron

See you all tomorrow! Off to mow grass (whee)

Iron

Thanks Charles and Chuck, nice tip of the iceberg.

similar. #include plugs in a file at that point in the code;

#define plugs in the text at the end of the line whenever the text after the #define appears

Iron

Thank you very much and Good bye!

Iron

Thanks Charles and Chuck. was shanghied, but the archives are OK. See all tomorrow.

Iron

Qu for tommorow ? Is '#define' preprocessor directive similar to '#include' which is a compiler directive?

Great group collaboration! you're all hired!

Thanks all for a lively class! I look forward to tomorrow! See you then!

Iron

@cjlord

O.K. LINT a type of pre-processor that check the correct syntax.

Iron

LINT is a syntax and construct checker that will find potential problems that can sneak through a compiler w/o generating an error

Iron

https://en.wikipedia.org/wiki/Lint_%28software%29

Iron

Thanks so much again for the interesting lecture.

Iron

What's LINTS?

Only by curisity :-)

 

Iron

yes that is a better example

 

Iron

I meant:

myvar = 0;+1;

Gold

Worse still, if you have:

myvar = FOO+1;

You get:

myvar = 0; 1;

 

Gold

@cjlord multiple ;; ending a  line aren't necessarily an error, although some LINTS might complain.

as @fjgalan states, these are pre-processor directives and don't need semicolons

Iron

Sure! the #defines are simply like a 'search and replace' in a word processor.  Whatever is at the end of the line is 'plugged into' the code.  Thus if we say

#define FOO 0;

the code

myvar = FOO;

becomes

myvar = 0;;

when the compiler sees it and you get a compiler error

 

Iron

Line starting with # are comand to how the compiler should do him work, isn't code, don´t need ;

; is nedeed when you en a line of code that should be compiled by compiler.

Iron

I've seen various responses to the "Do I need a semicolon on these lines? on p8".  Could you summarize/repeat what you said during the live presentation?  Thanks.

Iron

You people are great! Looks like every question during the talk was answered by your peers.

Iron
 
 
A more efficent solution for switch-case and if stament is use arrays of pointer to functions; have and issue, never use a index greater than the end of matrix.
Iron

We will compare the results of this simple state machine to plugging the tasks into a 'stripped down' version of an RTOS (MQX). The code generated for tomorrow's slides is without an RTOS.

Iron

Thanks Charles! Will there be an RTOS associated with this very basic state machine code after its compiled, downloaded and running on the target device?

"performance of a switch-case compared to an IF statement?" You have to see how the compiler built the switch statement, it could be a sorted table, it could be sequectials, it could be just a bunch of ifs. if you have a few or alot of things, "if" can be prioritized how you want them. the switch case will be redone by the compiler and put into different orders than you have in the switch statement.

 

Iron

FSMs and Petri-Nets are great abstractions for logic/sequential machinery, which most control/reactive systems are. There are some automatic code generation tools out there. IAR Visual State does a pretty good job.

Thanks all - let me get a cup of coffee and will be back in one minute to answer questions!

Iron

Thanks Cherles, you have a great lecture. I am looking forward your next.

Iron

Thanks Charles and Digi-Key!

 

Iron

Another good session, Charles. Thanks Charles, Chuck and Digi-Key.

Iron

thansk for your info

 

Iron

Great Job Charles.

 

Iron

Thanks Charles, Chuck, and Digi-Key

Iron

Hi Charles, Can you put tomorrow's slide earler?

Iron

Thank you Charles.

Iron

Thank you for today's lecture Charles

Iron

most modern compilers make an if-then the equivalent of a switch-case (modern compilers are real good)

Iron

Great! Thanks Charles.

Iron

the rookie error of putting a ";" at the end of the define will probably be a compile-time error which is much better than a run-time problem. eh?

This is great stuff! Thanks for the webinar.

I am looking forward to tomorrows.

Iron

 

OK tell us why ";" at the end of #define is bad......


Is a question of syntax rules, the preprocessor stament (started with #) shouldn't end with ; aren´t part of code.

 

Iron

how´s the performance of a switch-case compared to an IF statement? ... does it matter that much?

Iron

? any similarity between states and rtos tasks

Iron

if you have a ; at the end of define where you are only defining a number, you dont want the switch statement case to have a ; in it...it would essentially be case #;:

 

Iron

The ; would become part of the substituted text, I believe

Gold

? What is the advantage of using previous_state/current_state compared to current_state/next_state approach?

Iron

I actually haven't heard of the watchdog being referred to as a COP... had to look it up ;-)

Iron

external System Basis chip (from Freescale) does have very long Watchdog timeout values

Iron

OK tell us why ";" at the end of #define is bad......

Hope it's a top-loader...

Gold

Harel hierarchal state charts implement FSM semantics much more robustly.

rather have a PAUSE state when opening door and then resume

Iron

missing many assignments to uc_PrevState

Iron

When you open the door and check the contents of washer and then close the door, don't you want to restart at the last known state, not IDLE?

Iron

For a total of five states

Iron

pause during motor reversal

 

Iron

There isn't any consistent management of the PrevState variable.

I envision one "FILL" state and one "DRAIN" State...

Iron

Yes it llokks like all outputs should be shut off prior to exiting the current state and entry into idle.

 

Should every state reassert all outputs?

uc_ = unsigned char - just a mnemonic for the programmer

Gold

@WherelyBird  uc_ is for unsigned char.

I would use COP in case of noisy environment that could hang the uC.

Iron

No watchdog here.

 

Iron

I would change it to be >=60, in case a bit randomly gets flipped.

isr = Interrupt Service Request

Iron

@kwoklo, Interrupt Service Routine.

Iron

Charles' question: "Do we put our COP reset here? why or why not?"

Blogger

thats seeconds not uSeconds. What's significance of the uc in uc_State variable?

got my audio back

Iron

ISR - interrupt service routine

 

Iron

why counting down the minutes but counting up the seconds?

Why do seconds Up-count and minutes down-count ?

uh oh.  no audio for me

Iron

Function call unless size or speed constraints are a big win for inline.  It's easier to set break points for debugging and catch everyone calling the function

Depends on time and mem constraints

Iron

Preferable function call however in case of very small microcontrollers in line

Iron

Generally use an array of function pointers.

Iron

It depends on the complexity of the states.  Function calls give you a clean top-level state machine.  I actually usually prefer function pointer state machines.

depends on the level of speed and complexity.  Inline code for states only requiring a few lines, function calls for anything more complex.

Iron

depends speed vs portability

 

Iron

Try to follow the "one page per function" guideline. If not many statements, do inline. Use function calls if inlining would be longer than a page and a half.

Iron

function easier to read and understand but let the compiler inline if it makes a difference with performance (inline may bloat)

Iron

It depends on the requirements is it performance or code size.

Iron

it depends on application

the simple task in line code more complex or too many lines of code I use function calls

Iron

If it's more than a few lines of code, function calls.

 

Iron

function calls make it more modular

 

Iron

function call, it is very clearly.

Iron

function calls via array of function pointers

Normally calls or function pointers.

sure (re:enums) but you have to know what your tool does. I use readability and safety over 'percieved' efficiency

Iron

depends on the systems requirements. Could use in-line code for tight code, calls if speed / size is not critical.

Iron

I like function calls to save space, unless it is only a single statement.

Iron

I like to use in line code.

Iron

I only switch to assy when required for optimization (speed or size)

Iron

in-line is better in my opinion

 

Iron

Function call is more portable

Iron

Charles' question is: What are your thoughts - in-line code or function calls?

Blogger

ANSI C requres ENUM to be an interger - which is not as effecient on a 8 bit mirco...

Iron

I like to output something to a UART (if available) in the default state, delay and then reset - if I have well defined states and shouldn't end up in default.

Iron

It depends on the product.  What do you want your device to do when it faults?

trouble with enums is that some complilers will force to a larger variable size (int) then required (byte)

Iron

i like enums, easier to add states.

Iron

Preprocessor is for compiler so no needed

Iron

its not needed but they can be there...just affects how the macro is called

Iron

No, and why it's better to use an ENUM

Iron

No semicolons for preprocesor

 

Iron

No, and parenthesis around constants make sure they are always handled properly when token-pasted into expressions.

semicolons would put your eye out

Iron

no semicolons required on #DEFINE

Iron

Not required on Define lines.

Iron

No semicollon on defines.

Iron

no semi needed for macro

Iron

would be a compiler error

Iron

Charles' question: do I need a semicolon on these lines?

Blogger

Yes! In Labview which consists of a case structure within a while loop ...

Hello from Milwaukee!

Iron

Hi from SW Michigan a few minutes late

Iron

I use state machines frequently.

Iron

the audio player keeps stopping.

 

Iron

I have used and written state machines several times.

Iron

can't live without them

Iron

@bobybacs - Timi?oara is lovely! I remember it from our eclipse tour in 1999!

Gold

 Have done some state mashines some time back

 

Iron

Used state machines and RTOS(wrote one). Presently experimenting with Quantum Leaps and state diagramming and auto-generation.

Iron

Yes. With a PIC processor.

Iron

All the worlds a state machine, (apologies to William Shakespeare).

Yes, have built simple state machines.

Iron

Yes in C and LabView

Iron

I've done many state machines

Injection molding machine

 

states machines are best things since sliced bread

Iron

I have used state macines

Iron

I've used numerous and still do when developing code.

Iron

I've done state machines for many years.

Done tons of state machines, also kow UML (and slide rules and vacume tubes!  :)

Iron

It has been awhile, but yes

Iron

Use state machines a lot.

Iron

Several decades of state machines

done some statemachines

Have built state machines before.

Iron

I have used but not built

Iron

Have worked with state machines.

Iron

Charles' question is: "have any of you built state machines before?"

Blogger

Today audio is good, no intrupttion.

Iron

@bitbanger55  Hey!  I'm in Chandler at the moment

 

Iron

Good afternoon from Rochester, NY

Iron

Hello From Toronto, ON

Iron

Hi all -Audio is live! If you don't see the audio bar at the top of the screen, please refresh your browser. It may take a couple tries. When you see the audio bar, hit the play button. If you experience audio interruptions and are using IE, try using FF or Chrome as your browser. Many people experience issues with IE. Also, make sure your flash player is updated with the current version. Some companies block live audio streams, so if that is the case for your company, the class will be archived on this page immediately following the class and you can listen then. People don't experience any issues with the audio for the archived version.

Hello from Bremen/Germany

Iron

One minute! Are you ready out there?

Iron

Greetings from Lawrence, MA.

Hi from Casoer, WY

Iron

greetings from Seattle

Iron

Hello from Toledo, OH.

Iron

Hello all

from beautiful Vermont

Iron

@Jef, where in AZ ? PHX or TUC ?

Hello from Waterloo, ON, Canada. Eight developers here in a room.

Hello from Rockwell Automation!

Greetings from Metro Boston. Soupy 81F.

Iron

hello from Timisoara, Romania

Iron

Hello from Longmont, CO

Iron

Good morning from Portland, OR. Nice day here 70°F and Overcast.

Hi ALL, Good Afternoon from Boston!

Iron

AZ checking in.  Hi, everybody.

Iron

Good afternoon from Marlborough MA.

Iron

Greetings all from SUNNY Asheville, NC! After 51" of rain so far this year, I'm not sure what to do with three days in a row of sun... I look forward to talking to you all in 10 minutes!

Iron

One more California check-in here, hi everyone.

Iron

Greetings from Vermont

Iron

Hello from sunny Atlanta.

 

Iron

hello from Mishawaka

Iron

Good morning from California

Iron

Hello and Good Morning from beautiful Valdez. A balmy 49 degrees, but the sun is up.

Hello from Toronto.

Iron

Murphy's Browser Law: Firefox will always need to update immediately before you teach a webinar...

Iron

When cases for a switch statement are contiguous (like the state machine IDs # define, or I like to use enums) many C compilers convert it to a quick vectored lookup table branch, like pointers usage and therefore same time regardless of state. This keeps the debuggable/readable single-steppable switch/case form and yet runs efficiently. Only a crude C compiler would implement it as series of chained if/then/elseif/else decision forks. That's why I usually use an enumeration for state ID codes so they are sequentially assigned.

@mark.browne that would be a 'part ii' class.  As you say, it takes understanding function pointers well.  But it does work very nicely. Thanks for pointing it out (there is a bad pun there somewhere)

Iron

hello all from cool and rainy Edmonton, Alberta.

Iron

Hello from Summerville, South Carolina. How's everyone doing? I hope everyone is having a great day.

Iron

G'day from Ontario. 

Iron

Hello from Albuquerque.

Iron

-Be sure to follow @designnews and @DigiKeyCEC on Twitter for the latest class information. We encourage you to tweet about today's class using the hashtag #CEC.

Blogger

Hello from your neighbour of the other side of Atlantic Sea; Valladolid, Spain ;-)

Iron

You can use function pointers to make state machines - this has a constant time to switch states so there is no disadvantage to the order of states.

Google: function pointers state machine

Pointers can be murkey part of C for newbie programmers so you may wish to do some study before blindly dropping this into your code.

 

-Please join our Digi-Key Continuing Education Center LinkedIn Group at http://linkd.in/yoNGeY

Blogger

Hello from Beaverton, Oregon. In case anyone didn't already know, Beaverton it a suburb of Portland, Oregon, home of Tektronix and Nike, among others.

Iron

-The streaming audio player will appear on this web page when the show starts at 2 PM Eastern time today. Note however that some companies block live audio streams. If when the show starts you don't hear any audio, try refreshing your browser. If that doesn't work, try using Firefox or Google Chrome as your browser. Some users experience audio interruptions with IE. If that doesn't work, the class will be archived immediately following our live taping.

Blogger

Hello from Binghamton, NY

Iron

Hello from Chicago, where it's going to reach 95 degrees F today.

Blogger

-Be sure to click 'Today's Slide Deck' under Special Educational Materials above right to download the PowerPoint for today's session.

Blogger

Oops - didn't mean to spoil the exercise!

This is a nice introduction, and puts some real formalization into a hands-on application. Very nice service...

Dave

Gold

I'm sure your class will help me doing it better!!

Iron

@mahood - sounds fun indeed!

@dbell5 - extra credit! I was going to ask the class about that...

Iron

I'm doing a similar project at the moment but slightly more complicated.

It has 16x2 HD44780 LCD, 16 key matrix keypad, RTC chip DS1307 to display time and date, a solenoid valve to turn water on or off and a flow meter to measure quantity of water flow and a serial printer to print report.

Need to be able to adjust time and enter qty of water to pass, display both final and instantaneous water flow on LCD as well as date and time. I have finished the hardware using PIC16F876A and in the middle of software.  I'm doing it using state machines while counting flow meter pulses through 16 bit timer1 as a counter with external clock.

It is fun

Iron

Thanks for getting the slides up!

One note: Unless I missed it, nothing updates the Minutes display; it's initialized in Wash and Rinse, but not updated in the ISR.

Gold

Sunny & warm in Minneapolis today... on its way to 95 degF.

Iron

Hi All from Jordan

 

Iron

Good morning from Panama City FL.

Iron

Good morning from Mobile, AL

@cjlord  LOL, I can relate all too well!

Iron

Yes, deadlines are a powerful incentive. But I also run on about 256 levels of interrupt currently and INT257 keep cropping up and blowing my stack...

Iron

Oh - and greetings from the somewhat steamy garden spot of the universe - Minneapolis.

 

It's an old engineering maxim - if not for trade shows - nothing would ever get finished.

Tests in the morning have the same general influence on studying; I assume that there must be something like that for the teacher.

lol  No worries.  Still have a few hours!

Iron

Danged instructor just keeps re-engineering the slides! I just sent them to be posted. They will be up shortly.

 

Iron

Morning all from Portland Oregon.  No slides yet? 

Iron

Where are the slides ?

Mr. Lord's CV looks strong. Can't wait to see his approach to FSMs.



Partner Zone
Latest Analysis
The rear window on Ford's Lightweight Concept vehicle, based on the Fusion model, is made with a material combination devised by SABIC that saves 35% of the weight. The car's overall weight is 25% lighter than a standard production 2013 Fusion.
Sherlock Ohms highlights stories told by engineers who have used their deductive reasoning and technical prowess to troubleshoot and solve the most perplexing engineering mysteries.
There is still time to get in your gadgets for the Design News and Allied Electronics second annual Gadget Freak of the Year contest. The top three gadgeteers will be awarded a total of $10,000.
Major global metropolitan areas are implementing a vast number of technology, energy, transportation, and Internet projects to make the metropolis a friendlier, greener, safer, and more sustainable place to be.
If you’ve charted the course of the electric car market over many years, then you know that we’ve always been two years away from a metamorphosis … or five years … or more.
More:Blogs|News
Design News Webinar Series
7/17/2014 11:00 a.m. California / 2:00 p.m. New York
6/25/2014 11:00 a.m. California / 2:00 p.m. New York
5/13/2014 10:00 a.m. California / 1:00 p.m. New York / 6:00 p.m. London
5/8/2014 11:00 a.m. California / 2:00 p.m. New York / 7:00 p.m. London
Quick Poll
The Continuing Education Center offers engineers an entirely new way to get the education they need to formulate next-generation solutions.
Jul 21 - 25, Design Products With Bluetooth Low Energy
SEMESTERS: 1  |  2  |  3  |  4  |  5  |  6


Focus on Fundamentals consists of 45-minute on-line classes that cover a host of technologies. You learn without leaving the comfort of your desk. All classes are taught by subject-matter experts and all are archived. So if you can't attend live, attend at your convenience.
Next Class: August 12 - 14
Sponsored by igus
Learn More   |   Login   |   Archived Classes
Twitter Feed
Design News Twitter Feed
Like Us on Facebook

Sponsored Content

Technology Marketplace

Copyright © 2014 UBM Canon, A UBM company, All rights reserved. Privacy Policy | Terms of Service