ST (IEC 61131) Coding Question

friendlyfire

Member
Join Date
Jan 2008
Location
Comox
Posts
14
Hi gang,
What a great forum, I've learned a great deal from all the posts and thoughtful responses.

I'm developing a controller using the ST language. I haven't settled on a hardware platform and am for the moment using the TwinCat software from Beckhoff to get a head start on the design. I'm impressed with the power of the language and capabilties of the software tool. I have a couple of questions about coding in ST.

a) is there a really good book that goes beyond providing an overview of IEC 61131 languages and into details of how best to implement real control solutions? I checked Amazon and saw a couple of options but it would be nice to have some recommendations.

b) I've written some code to run a counter at a variable frequency. This may become the engine generating the pulse sequence to a stepper motor. I'm used to VHDL (for gate arrays) and it is normal in that environment to pull whatever bits you need from a counter, but in ST it doesn't seem to be easy to grab just one bit. To be specific, in this case I just want to pull out the least significant bit of the counter and feed this to an ouput (so it will be a square wave at the frequency of the signal driving the counter). Optionally I will use other bits which present square waves at various divisions of the driving signal...


The counter is a WORD variable. I can write some kind of hack something like

IF INT(counter/2)*2 = counter then
pulse:=1;
ELSE
pulse:=0;
END_IF

but this seems very clumsy

Am I missing a quick way to connect one bit of a word variable to a boolean? In VHDL it would look something like pulse:=counter[0] if my memory serves correctly.

thanks
 
I think you can treat an integer or word effectively as a structure of bits. So:

TestInt: INT;

TestInt.2 := TestInt.1 AND TestInt.0;

TestInt bit 2 equals TestInt bit 1 and TestInt bit 0.

This type of thing builds in my copy of TwinCAT. I don't have anything to actually test it on, though.

Keith
Keith
 

Similar Topics

Hello, I have a small programming task that I need help solving. I have to: * Create an analog input (4-20v)and a digital output * The analog...
Replies
45
Views
25,182
I was poking through the Stackoverflow PLC Tag when I saw this answer to a question about converting a Real to a DWord and back again. What...
Replies
8
Views
2,928
I am looking for some expert advice. I have always made function blocks both with inputs and outputs and without inputs or outputs. I make the...
Replies
21
Views
6,825
Hello and happy new year! I would like to further understand who needs to design by this standard and is it a requirement for everyone or only...
Replies
3
Views
1,795
So Ladder is easy to read graphically, most everything can be coded in ladder, and it represents wiring diagrams the closest. SCL and ST are good...
Replies
5
Views
1,759
Back
Top Bottom