Simple State Machine

Go To Last Post
37 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I wanted to implement a state machine to blink LED on and off using the tool YAKINDU;

I have problem integrating the code generated from YAKINDU into my main function in Atmel Studio, i did complied but nothing happens to PB7 when i test it;

(the problem is PB7 should toggle at max speed but nothing happens to it......)

(the state machine should toggle the state from off to on on each run...)

/*
 * yakindublink.c
 *
 * Created: Thursday-07-09-17 1:10:22 AM
 * Author : Gulzar
 */ 
#define F_CPU 16000000UL
#include <avr/io.h>
#include <avr/delay.h>

#include  "my_gen.h"
#include  "Light_Switch.c"
Light_Switch h1;
int main(void)
{	
	light_Switch_init(&h1);h1.internal.operate_raised=true;
	DDRB|=(1<<7);
	while (1) 
    {
		light_Switch_enter(&h1);
		
		light_Switch_runCycle(&h1);light_Switch_exit(&h1);
		
			if(h1.iface.on==false)
			{
			sb(PORTB,7);	}
			else{cb(PORTB,7);}
				
		//_delay_ms(100);
    }
}
	#define sb(ADDRESS,BIT) (ADDRESS |= (1<<BIT))		   		// set bit   to 1
	#define cb(ADDRESS,BIT) (ADDRESS &= ~(1<<BIT))	

 

 

AVR Rocks but can be Bricked too smiley

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

AVR Rocks but can be Bricked too smiley

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have a pretty basic tutorial on state machines here:

 

https://sites.google.com/site/ka...

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
light_Switch_init(&h1)

Curious syntax! h1 is clearly an object of the Light_Switch class so why not simply h1.init() or, more to the point, why does it not initalise in the c'tor?

 

Anyway the #include of a .c file looks highly suspicious!

 

Also I followed you link and saw this picture:

 

Generated Java source code

 

so that seems to suggest the class *does* have a .init() method ?!?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

But that's Java - maybe it's lost something in translation ... ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

My favourite FSM tutorialhttp://www.avrfreaks.net/comment...

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i need c code generated by yakindu to be integrated with atmel studio and implement hardware PB7 as on and off.

AVR Rocks but can be Bricked too smiley

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So have you stepped through your code - either in the debugger or a simulator - to see what's happening?

 

Are you sure you have the Yakindu stuff correct?

https://groups.google.com/forum/embed/?place=forum/yakindu-user#!forum/yakindu-user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
#include  "Light_Switch.c"

That still looks very wrong. Where have you found instructions that told you to #include a .c file?

 

BTW do you really need a state machine generator to handle a "light switch". Surely it's something like:

typedef enum {
    SWITCH_OFF,
    SWITCH_ON
} switch_state_t;

switch_state_t switch_state = SWITCH_OFF;

int main(void) {
    init();
    while (1) {
        if (some_input) {
            switch(switch_state) {
                case SWITCH_OFF:
                    light_the_light();
                    switch_state = SWITCH_ON;
                    break;
                    
                case SWITCH_ON:
                    extinguish_the_light();
                    switch_state = SWITCH_OFF;
                    break;
            }
        }
    }
}

Why would I need a "generator" for something this simple?

 

Presumably your intention is to actually use the generator for a state machine that is far more complex ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have some very complex state machine for automatic startup/shut down and much more for start/st0p/housekeeping functions of genset. So complicated things can be done only if simple things are done well...

 

direct c is not a good idea because changing one transition can be a ripple effect on all code.

AVR Rocks but can be Bricked too smiley

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So, when you said in your opening post:

I wanted to implement a state machine to blink LED on and off using the tool YAKINDU;

What you really meant is,

I am doing the blinky example in YAKINDU

yes?

 

Before getting into a tool like that, are you already experienced in microcontroller development in general (which includes debugging), and setting-up & using an Atmel Studio poject?

 

EDIT

 

"blinky example" aka "light switch example" in this tutorial:

 

https://www.itemis.com/en/yakindu/state-machine/documentation/tutorials/

Last Edited: Mon. Sep 11, 2017 - 07:56 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

engineer.pk wrote:
direct c is not a good idea because changing one transition can be a ripple effect on all code.

Sounds strange. IMO, this is one of the things (if "done right") that state machines actively avoids.

 

do see two advantages of using a tool like YAKINDU:

 

1) For large state machines it might simplify things, and

2) Creating (graphical) documentation is part of the "coding process". Documenting is not a separate step/activity.

"He used to carry his guitar in a gunny sack, or sit beneath the tree by the railroad track. Oh the engineers would see him sitting in the shade, Strumming with the rhythm that the drivers made. People passing by, they would stop and say, "Oh, my, what that little country boy could play!" [Chuck Berry]

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Other potential advantages of a tool:

 

3) You can simulate the design.

4) The tool can do various sanity checks.

5) It is often easier to change/maintain things in a tool than, say, a hand-drawn state diagram.

 

But you have to take time to understand the tool, and learn to use it properly - including interfacing it to the rest of your system.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

yes im using Atmel Studio since version 4.

AVR Rocks but can be Bricked too smiley

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

any one make only one example integrate c code in AS7? just for LED....?

AVR Rocks but can be Bricked too smiley

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Are you simply asking: "Has someone written and compiled C code to blink a LED in Atmel Studio 7?".

 

If so, then the answer is yes. I imagine thousands of people has done that. I am sure I have done it 50 times or so, since it is the first test to do anytime one sets up any AVR hardware.

 

Here's my latest, from the other day:

 

#include <avr/io.h>
#define F_CPU 8000000UL
#include <util/delay.h>

int main(void)
{
    DDRD = 0xFF;

    while (1) 
    {
      PORTD ^= 0xFF;
      _delay_ms(500);
    }
}

You might ask: "That's no different to AS4 code!?". You are correct.

 

So, what did you actually want to ask when you wrote:

engineer.pk wrote:
any one make only one example integrate c code in AS7? just for LED....?

"He used to carry his guitar in a gunny sack, or sit beneath the tree by the railroad track. Oh the engineers would see him sitting in the shade, Strumming with the rhythm that the drivers made. People passing by, they would stop and say, "Oh, my, what that little country boy could play!" [Chuck Berry]

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

engineer.pk wrote:
 im using Atmel Studio since version 4.

So, by now, you should be able to understand the code, and know how to use the debugger to see what it's doing ...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yakindu state machine to blink led on micro.

 

i know how to blink directly using c. but have complex state machine in yakindu and dont know how to integrate the generated code with avr using AS7.

So problem is how to integrate generated c code for Light Switch Example with AS7 to be able to run on AVR.

 

btw i toggled led using c more than thousand times but atm im not able to integrate the generated code from yakindu to AS7 to toggle led.

 

Guys the problem is how to integrate yakindu generated C code to AS7. (LIGHT SWITCH example for led on and led off for any pin on AVR) ,,,....

 

AVR Rocks but can be Bricked too smiley

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

AS7 and yakundu..... how to integrate generated c code from yakindu with AS7? how?....

AVR Rocks but can be Bricked too smiley

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It will be highly appreciated if some freak make a good simple example step by step. (yakindu generated code for state machine integrated with AS7 to blink led; led depending on state of statemachine of yakindu code)

 

AVR Rocks but can be Bricked too smiley

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

engineer.pk wrote:
Guys the problem is how to integrate yakindu generated C code to AS7.

I do not have Yakindu installed, but if you have your Yakindu generate .c and .h files I could have a look at those. If so, please ZIP them all together and attach the ZIP file to a post here.

 

 

"He used to carry his guitar in a gunny sack, or sit beneath the tree by the railroad track. Oh the engineers would see him sitting in the shade, Strumming with the rhythm that the drivers made. People passing by, they would stop and say, "Oh, my, what that little country boy could play!" [Chuck Berry]

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

https://www.4shared.com/s/f3jGpy...

 

yakindu generates two folders which i did zip and uploaded to 4shared.com;

THanks dear.

AVR Rocks but can be Bricked too smiley

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

if possible installing yakindu is highly appreciated.

 

 

https://www.4shared.com/s/fuGqxo...

 

is the state machine for on off in yakindu

AVR Rocks but can be Bricked too smiley

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

engineer.pk wrote:
https://www.4shared.com/s/f3jGpy...   yakindu generates two folders which i did zip and uploaded to 4shared.com;
 

No. Attach to a post here. I am not interested in going to a site which has a load od "Download" links where all but one are bogus or potentially malign. I said "attach the ZIP file to a post here". How can that be misunderstood?

 

 

engineer.pk wrote:
if possible installing yakindu is highly appreciated.
 

I will most definitively will not. Post the code and I'll have a look.

"He used to carry his guitar in a gunny sack, or sit beneath the tree by the railroad track. Oh the engineers would see him sitting in the shade, Strumming with the rhythm that the drivers made. People passing by, they would stop and say, "Oh, my, what that little country boy could play!" [Chuck Berry]

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

PFA

Attachment(s): 

AVR Rocks but can be Bricked too smiley

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm not really sure what you are asking for? There's a C file and two H files. You just write main.c, include the top level H file and call the functions it documents. Finally you arrange to compile both the C file you wrote and the one generated here. So what are you having a problem with as this is all obvious isn't it?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This doesn't look right:

/*! Define dimension of the state configuration vector for orthogonal states. */
#define LIGHT_SWITCH_MAX_ORTHOGONAL_STATES 1

/*! Define indices of states in the StateConfVector */
#define SCVI_LIGHT_SWITCH_MAIN_REGION_OFF 0
#define SCVI_LIGHT_SWITCH_MAIN_REGION_ON 0

That seems to be saying that the switch has only 1 state ?

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As Cliff said, you more or less add those three files to a Atmel Studio project you set up. Then you write a main() function in it's own file to call the state machine.

 

Now for the details:

 

The generated code seems to assume a multi-direcctory project. E.g. in light_Switch.c we find

#include "..\src\sc_types.h"

We could change this include directive so that we have a "flat" project with all files in the root project folder, i.e. just

#include "sc_types.h"

but we'd have to do that each time we generate the files. Instead I opted to set up my project so that it supports the structure assumed by the generated files. In Atmel Studio you can create sub-folders to the project folder by right-clicking the project folder and choose Add.. , New Folder. We know one of the folders should be named "src" and that sc_types.h should be placed in that folder. I then chose to have the files light_Switch.c and light_Switch.h in a folder called "light_Switch".

 

Here's a screen shot of how what the project looks like in Atmel Studio's Solution Explorer:

 

 

Finally I wrote a main() function that calls the functions that is the interface to the state machine. It builds and runs without errors, but I have not read all the documentation on what calls are actually necessary. I'll leave that to you ;-) , but do ask if something specific is unclear and we could have a try at helping you.

 

Please do understand, though, that since we've seen no-one here who immediately helped with the Yakindu details it is highly unlikely that anyone here has it installed and/or is an active user. All we're doing is looking at what you've got and trying to make sense of it based on other experiences.

"He used to carry his guitar in a gunny sack, or sit beneath the tree by the railroad track. Oh the engineers would see him sitting in the shade, Strumming with the rhythm that the drivers made. People passing by, they would stop and say, "Oh, my, what that little country boy could play!" [Chuck Berry]

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

JohanEkdahl wrote:
 it is highly unlikely that anyone here has it [Yakindu]  installed and/or is an active user. 

Indeed.

 

For support on Yakindu you need to contact them!

 

See #8.

 

This is paid-for software - so you should expect to receive support.

 

I presume, at the moment, you are evaluating it? That should include an evaluation of their documentation and their support ...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:
This is paid-for software

Perhaps..

 

There is a (€ 0) non-commercial license, but if "engineer" in "engineer.pk" means practicing engineering for a living then that is not applicable.

 

Anyway, it seems even the non-commercial license gives you "MAintenace and support". See https://www.itemis.com/en/yakind... .

"He used to carry his guitar in a gunny sack, or sit beneath the tree by the railroad track. Oh the engineers would see him sitting in the shade, Strumming with the rhythm that the drivers made. People passing by, they would stop and say, "Oh, my, what that little country boy could play!" [Chuck Berry]

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think it was #10 gave me the impression this is not a "hobby" project

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

there is java code but i don't know java. im interested in c and AS7.

 i download non commercial free version of yakindu for evaluation purpose only.

ok try to post on yakindu forums.

THANKS

 

AVR Rocks but can be Bricked too smiley

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

engineer.pk wrote:
there is java code

How on earth did Java enter the discussion?!? [rolls eyes]

 

engineer.pk wrote:
im interested in c and AS7.
 

And I told you above how to do that.

"He used to carry his guitar in a gunny sack, or sit beneath the tree by the railroad track. Oh the engineers would see him sitting in the shade, Strumming with the rhythm that the drivers made. People passing by, they would stop and say, "Oh, my, what that little country boy could play!" [Chuck Berry]

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

JohanEkdahl wrote:
How on earth did Java enter the discussion?!?

at #4

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ah, OK!

 

@engineer.pk:

Forget everything about Java. It does not apply to you.

You have C code that was generated from Jakindo.

I showed you how to get that code into a project in Atmel Studio.

"He used to carry his guitar in a gunny sack, or sit beneath the tree by the railroad track. Oh the engineers would see him sitting in the shade, Strumming with the rhythm that the drivers made. People passing by, they would stop and say, "Oh, my, what that little country boy could play!" [Chuck Berry]

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yakindu not jakindu... :)

AVR Rocks but can be Bricked too smiley

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

engineer.pk wrote:

Yakindu not jakindu... :)

If you want to play the "correct language game" then give me half an hour to collect your 20 latest miss-spellings, badly formulated sentences, mixing of tenses in one sentence etc.

 

If you want help then concentrate on that instead of being irritatingly unfocused and confusing.

 

Right now you're acting more like an Internet troll than someone that wants help.

 

I'm out.

"He used to carry his guitar in a gunny sack, or sit beneath the tree by the railroad track. Oh the engineers would see him sitting in the shade, Strumming with the rhythm that the drivers made. People passing by, they would stop and say, "Oh, my, what that little country boy could play!" [Chuck Berry]

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]