LDMICRO TUTORIAL

 

 

MedTronic LDMICRO TUTORIAL

 

 

LDMICRO / PIC, AVR, 8051 and ARDUNIO

Programming with LADDER Diagram 

 

Author: Eng.Medhat Saber Ahmed (MedTronic)

 

Ladder: It is a graphical programming language, in the form of a diagram,

Which, because it is easy to create and interpret and represents physical connections between

Electronic components (sensors and actuators), ends up being widely used

In an industrial environment.

In a simple LADDER diagram, we can find three types of

Basic elements:

1) CONTACT:

It is the element that represents the sensor, i.e. the signal input in the logic control block. can Be one switch, a reflective sensor, a limit switch Or even the contact of an auxiliary relay.

S1, S2

 

 

2) COIL (coil): It is the actuating element, that is, the element activated or turned off by the control block


Logical control. It could be a contactor, a

Motor, a lamp, a hearing actuator, etc...

 

 

 

3) MEMORY: or Internal Relay: This is the

Representation of the state of a contact or

Coil in memory, without direct connection to

External elements.

 

There are also other auxiliary elements that allow you to carry out more complex operations.

Complex tasks, such as timing, counting and data manipulation.

 

These elements will be discussed in the second part of this tutorial.

 

See an example of a LADDER diagram:
For this diagram, we have control
Of  3 elements, these being M1, MOT and
CIL1. These elements can be
COILS (ACTUATORS) or
MEMORIES (internal relays).
Elements S1, S2, BE, VC and S3 only
Appear on the left side of the diagram,
In square bracket format [ ], which
Assumes that they are sensors
(Appetizer).
In the first line, we observe that the
Program rule defines that output M1 will activate only if the sensors
S1 and S2 are BOTH turned on.
In the second line of this program, it is observed that the rule determines that the MOT output will turn on if BE is OFF 
(Bar means inversion) and if M1 or MOT is activated 
(At least one of these).
In the third line, it is observed that the CIL1 actuator will activate if the FC sensor
Is OFF (again look at the bar), and if sensor S3 is
Activated.
 
There are also some other important rules about programming
LADDER:
1) It is not permitted (or at least recommended) to use the same
Coil (output) on more than one line, as the rules will conflict. Per
Example, we could not insert in the previously represented diagram
Another line that would activate the CIL1 actuator.
 
2) There is the possibility, in some variations of the language, of using
SET and RESET command (on and off) that determines when
a given actuator will turn on or off.
 
3) There are special blocks that allow you to time, detect pulse, edge,
Counting and other features. This may vary depending on the language
Used.
 
LADDER FOR PIC MICROCONTROLLER: THE LDMICRO
 
The LADDER language was born out of the need to facilitate programming
In industrial environments, referring to a high-level and easy-to-use language
Be used. However, there is a program, (LDMICRO) by Jonathan Westhues,
Which allows LADDER programming of microcontrollers, which enables
Study and implementation of very low-cost controls.
This software is very versatile, it does not require installation (just run the
Ldmicro.exe file in a Windows environment or compatible emulator), and is free
Distribution, as we can see in the window below, extracted from the HELP of the
Program in question:

 

LADDER FOR PIC MICROCONTROLLER – THE LDMICRO
The LADDER language was born out of the need to facilitate programming
in industrial environments, referring to a high-level and easy-to-use language
be used. However, there is a program, (LDMICRO) by Jonathan Westhues,
Which allows LADDER programming of microcontrollers, which enables
Study and implementation of very low-cost controls.
This software is very versatile, it does not require installation (just run the
ldmicro.exe file in a Windows environment or compatible emulator), and is free
Distribution, as we can see in the window below, extracted from the HELP of the

 
 
Program in question: 
LDMICRO works as follows:
 
1) Start the executable program (LDMICRO.EXE). The following screen will be displayed: 
 

 

 

It is in this environment that you can generate the LADDER program to
Microcontroller.
To insert a coil, press L.

 
 
You will notice that the edited line will be built (or complemented) with the
Indicated coil. It is allowed to insert more than one bobbin for the same line.

 

By double-clicking on the created coil, the dialog box will open. 
 
 
Coil property: 
If the coil is defined (in the Source field)
As INTERNAL RELAY, the name of the coil
In the ladder diagram will be preceded by the
Letter R. Example: If the coil name is new
(As in the example above), and if this is
Set to Internal Relay, will be displayed
As Renew.
If the coil is set to PIN ON
MCU, the coil name will be preceded by the
Letter Y (in the case of the example, Ynew). 
Please note that when entering a contact or
Coil, the position of the cursor will be respected
(Flashing bar) to define the location of the
Insertion. That is, to insert a coil or
Contact below another, first position the cursor in a horizontal position.
 
To enter a contact:
Position the cursor at the desired location, and press C.

 
To enter a contact:
Position the cursor at the desired location, and press C.
 
Note that a field defined by square brackets --] [--- will appear with the name
Xnew. Double click on this item to open the properties box.
Contact.

 
In the source field, you can define whether the contact is an internal relay
(Memory). In this case, note that the contact name will be preceded by the
Letter R. If set to INPUT PIN (default), the contact is a sensor, a
Digital signal input. In this case, the contact name will be preceded by the
Letter X (as in the example above: Xnew).
If you want to use a coil as a contact (this is possible in ladder),
Just activate the OUTPUT PIN option. In this case the name of the inserted element
Will be preceded by the letter Y.
The [/] box defines that the input will be negated (with inverted logic),
That is, it activates by zeroing the contact, and deactivates by turning on the contact.
 
 
 
 
 
Practice:

 
Now try to assemble the following LADDER diagram using the resources
Mentioned above:
 
After editing this program (note that the elements used are
Only and exactly XBOTLIGA, XBOTDESL, YMOTOR). There must not be
No other elements in the program.
 
SAVING
After writing your program, save it by clicking FILE -> SAVE AS...
Save as a file with the LD extension.
 
SIMULATING
With the program saved, to simulate the program, click SIMULATE
    
SIMULATION MODE, and later on SIMULATE
START REAL TIME
 
SIMULATION.

 
From this moment on, observe in the panel at the bottom of the window the
State of contacts and coils. Just DOUBLE CLICK on the item
To change your state.
Test by changing the state of the sensors, and see if the program works.
 
COMPILING.
 
To generate a HEX file from this program, simply follow these
Steps:
 
1) Click on SETTINGS
MICROCONTROLER and define which
Microcontroller to be used. For better operation, click
 
SETTINGS
MCU PARAMETERS and set the clock crystal value
Used. The default is 4MHz.
 
2) Now double-click on each
 
DIGITAL IN or DIGITAL OUT element of the
Bottom of the window, associating each
CONTACT or COIL to a pin of the
Microcontroller.
 
3) Now click on COMPILE
 
COMPILE
AS.. And indicate the name of the file to be
 
 
Generated. IMPORTANT: Don't forget to
Place the HEX extension. Ex: PROG.HEX.
If you do not enter the extension, it will be
Harder to find it later with the program
Recording (EPIC, ICPROG, etc...)
 
 
 
 
Most used commands:
Insert new line shift V or shift 6
Insert a semicolon comment
Detects rising edge/
Detect falling edge\
Timer to turn off F
Timer to turn on
Timer to turn on T retentive
Incremental counter U
Decremental counter I
Circular counter J
Compare equality =
Compare whether it is bigger >
Compare whether it is smaller <
Compare whether it is greater or equal.
Compare whether it is less or equal,
Insert L COIL
Insert Contact C
Insert E counter reset
Load variable with value M
Insert sum + operation
Insert subtraction operation -
Inserts multiplication operation. *
Inserts division operation D
Analog P reading
 
Exercises:
 
Try running the following LADDER programs on the microcontroller:
 
Exercises:
Try running the following LADDER programs on the microcontroller:

 
1)
Note: To insert a line, use SHIFT + V
Note the CORRECT names of the items involved:
XB1: Button 1 of the two-manual system.
XB2: Button 2 of the bi-manual system.
XEMERGENCY: Emergency button. If OK, it is at 1. Pressed at 0.
YMORSA: VISE actuator, which holds the part. Call with a bot. press.
YPRENSA: PRESS actuator, only turns on when pressed. the 2 buttons.
YBUZZER : Audible alert. It must indicate emergency triggered (at zero).
RPISHING: Auxiliary relay that will flash every 400 ms.
 
2) Try adding a part sensor to the above system. If the part does not
    Is detected, the walrus should not start.
 
3) Now also add a beep indicating whether a button has been
    Pressed and the part was not placed.
 
2) Try creating the ladder scheme for a garage door. Use the
Following elements:
 
 

 
XBOTAO: Remote control button.
XOPEN: End of travel sensor that determines that the gate is
Open
XCLOSED: End-of-stroke sensor that determines that the gate is
Closed
XIMPACTO: Impact sensor. Detects that the gate has collided with something.
YMOT_OPEN: Motor that moves the gate towards opening.
YMOT_FECHA: Motor that moves the gate towards closing.
Use your creativity. Simulate the program in the ladder environment, and on the station
w/ PIC microcontroller. Good job.
 
PART 2: DESCRIPTION OF LDmicro COMMANDS
 
1. Comment insertion
2. Contact insertion
3. Rising edge (pulse) detection
4. Falling edge (pulse) detection
5. Power-on timer
6. Shutdown timer
7. Retentive power-on timing
8. Increment counter
9. Decrement counter
10. Circular counter
11. Comparison – equal
12. Comparison – different
13. Comparison – bigger
14. Comparison – greater or equal
15. Comparison – smaller
16. Comparison – less than or equal
17. Open circuit
18. Closed circuit
19. Main (general) control relay
20. Insert coil
21. Enter counter/timer reset
22. Data movement (attribution)
23. Addition (16 bits)
24. Subtraction (16 bits)
25. Multiplication (16 bits)
26. Division (16 bits)
27. Shift Register
28. Table (look-up)
29. Table of values ​​(linear association)
30. String formatted by serial
31. Insert serial output
32. Insert input via serial
33. Activate PWM
34. Insert A/D reading
35. Sets value as persistent in EEPROM
 
Translation of LDmicro's HELP, document by Jonathan Westhues, carried out by    
 
 
 MedTronic, in December 2023

 

 

 

 

 

 

 

 

 

 

 

 

                                                                                                                                                                                  

Post a Comment

Previous Post Next Post