making a PLC

tny

Member
Join Date
Jun 2005
Location
usa
Posts
105
hi all,
i am trying to make a simple PLC with 89c52, and i coded a OS-like program for it, so i created my own language like STL.
now it can handle bit based operations as A,AN,O,ON,S,R,= and ondelay timers.
all but the timers work well. but the timer sensitivity belong to the code lenght of the PLC program 'cos in the OS of the plc, i count 100ms interrupt signals, so with a long program, an 10s on delay timer sets its output aprox, at 10,3 - 10,5 seconds.

do you know how real PLCs handle this timing?
 
I believe They base it upon a dependency on the RTC If you were to say build a plc from a PC based on the 8085 instruction set. you would set the number of ticks from the clock crystal by calling int 1Ah where Cx= high portion of the count, Dx=low portion of the count, Al =0 if 24 hours has not passed since last read Greater than 0 otherwise. This handles the accuracy of the RTC average is 18.2 ticks then to read those registers you would call function 02h of INt 1ah Ch =hours CL=minutes Dh=seconds DL=daylight savings option.

THats for standard PC's
on PLC's they have seperate memeroy locations/registers that generate the same principal and again it would be based on a similar signal to the processor usually of the clock crystal which will vibrate at a set pattern per capacitative/resistive circuit. This signal to a 8086 processor is named RTC on a PLC I'm not sure what they call the signal; but its principal is the same. For example on An SLC or micr0logix those bits get contained in S:42 for example but I have no idea where you can get the actual Clock signal counter. to modify how many ticks per second. I don't recognize the microprocessor your using to know its addressing. the only other method i've seen is using the execution cycle and a nested for, next loop that does a series of calculations thus creating a delay equal 1 second. but this method varies too often with processor speeds.
 
Last edited:
Use the hardware counters or counter interrupts. You should be able to write a small interrupt that increments a 32 bit variabe once every 10 milliseconds or even every millisecond and store it in a variable called tick. The 32 bit variable would be saved away the first time the timer is activated in a variable like tick0. While the timer is active you do this calculation every time the timer is checked.

(tick-tick0)>preset

Since tick and tick0 are read directly from the hardware you should be OK.

Note, the tick0 and the preset are stored in the software timer and these should be 32 bit variables.

You are probably checking and reseting the timer every time it times out. This is a no no because you lose accumulated time every time you reset or restart the timer. You should have only one hardware timer that all software timers use and the hardware timer never gets reset.

It is possible that you don't have a 32 bit timer. In this case you need to fake it. Every interrupt you must increment the 32 bit timer tick. You do this in a similar way

tick = HWclock - LastHWClock;
LastHWclock = HwClock.

Note that the HWclock is NEVER reset and neither is tick. Tick can only by incremented.

BTW, did you make your STL compile down to 8051 machine code or did you use a byte code interpreter?
 
Last edited:

Similar Topics

Hi, i need to make: 1- A PLC Program on Omron PLC CP2E-N using high speed counter E6C3-AG5B 360P/R 2M(Absolute) ,to Reject bottles on Conveyor...
Replies
4
Views
877
What do you use for making a list of all the plc's in your plants. I am using excel. I have made a list of the equipment name, processor name, if...
Replies
9
Views
2,299
Hello, I want to make a histogram of an input (y-axis) is plotted against time (x-axis). Using OB35 (100 ms), I want use DB1 (boolean, length...
Replies
12
Views
2,590
hi guys, i have just signed up to this site after reading through it with much interest over the last few weeks. i am as the thread title...
Replies
30
Views
7,094
Back
Top Bottom