Relay logic to Microprocessor logic

Discussion in 'Embedded Systems and Microcontrollers' started by Danno., Apr 6, 2015.

  1. Danno.

    Thread Starter Member

    Apr 6, 2015
    39
    1
    Hi
    As the title really, what would be the best way to learn how to convert something that runs on mechanical relays and cam timers to run under microprocessor control.

    I have done it in the past with ladder logic by copying the schematic and using a array of up/down counters for the can timers.

    But where would you start in something like C++ or even assembly?

    I get how relays work etc but can't get my head around where to start recreating it in code.

    Just after a gentle nudge in the right direction to start me off

    Thanks
     
  2. Papabravo

    Expert

    Feb 24, 2006
    10,140
    1,789
    Each rung of the ladder is like a small isolated problem. Here is the basic idea:

    Do Forever
    {
    1. Sample all of the inputs to the ladder
    2. Solve all of the rungs
    3. Update all of the outputs
    }

    In ladder logic, all the rungs are solved in parallel, with delays associated with mechanical relays. In code, it all happens so fast that cycle times on the order of 5 milliseconds are easily achievable.
     
  3. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,526
    2,369
    Ladder is basically Boolean logic, in fact many PLC's have the ability to switch between the graphic ladder format and a flow chart style of program development.
    Back in the late 80's I played around with the Motorola MC14500, 1 bit processor, it is an Industrial Control Unit (ICU) intended for simple PLC systems, quite interesting little IC. Now dropped for quite some time, but i think you can still get them if you feel the need to experiment for simple PLC tasks.
    Max.
     
  4. John P

    AAC Fanatic!

    Oct 14, 2008
    1,634
    224
    It's easy enough to turn relay logic into code by simply setting up if-then relationships. You'd have any combination you needed of inputs, with IF and AND and OR and NEGATE anywhere you needed them, and parentheses to keep things properly grouped. You can also set up dummy variables along the way, if it helps you to keep things logical or if you find that some combination of inputs gets used repeatedly. You'd put all the logic inside an endless loop, and the processor would keep evaluating everything and recalculating the outputs.

    Delays are a little more tricky, and there are various ways to do it. Any use of a delay() function is almost always wrong! But what you can easily do is set up a repeating interrupt which occurs (let's say) 1000 times a second, and within that routine you could count down any number of timer quantities. So any of those quantities which was found to be nonzero would be decremented at a 1000 per second rate, and when one went from nonzero to zero, you could set a flag which the logic could respond to.

    But you have to watch out for unexpected conditions. Suppose input A causes output B to become set after a 1 second delay. That's straightforward enough, but what if A goes away before the delay elapses? What if it occurs multiple times, should the delay continue or should it restart for each occurrence? What resets B? You have to have a plan for every combination. But microprocessor programming is full of situations like this.
     
  5. Papabravo

    Expert

    Feb 24, 2006
    10,140
    1,789
    You should think of it as being like running a simulator. If you have to support timers, then you need to divide time into small increments and keep track of a schedule of when events are triggered and when they expire. The resolution of the timers will have to be coordinated with your input/output scan time. For example, if your I/O scan time is every 5 milliseconds, and your timers have millisecond resolution then you have to take that into account.
     
  6. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,526
    2,369
    absf likes this.
  7. Dr Jefyll

    New Member

    Sep 8, 2014
    5
    2
    absf likes this.
  8. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    The 2716 was a cool chip back in the day. Does anyone have it in current production?

    Even the 2816 replacement got me no hits on find chips.com
     
  9. ISB123

    Well-Known Member

    May 21, 2014
    1,239
    527
  10. Dr Jefyll

    New Member

    Sep 8, 2014
    5
    2
    You could always use a much larger EPROM and simply tie the upper address lines low. The 2716's 24-pin format is physically smaller, though.

    Another cool little chip of yesteryear is the 74S288 and similar -- a byte-wide bipolar PROM in a 16-pin DIP. Only 32 locations, but fast (for the day) at 50 ns. I made some nifty state machines outa that baby, too!

    Capable of much more than 60 Hz!
     
  11. MMcLaren

    Well-Known Member

    Feb 14, 2010
    759
    116
    I have several tubes of 2716 and 2732 devices left over from the early 80's. I used them to manufacture Apple ][ Lower Case Character Generator ROMs that I traded with local Computer stores for floppy diskettes.
     
  12. absf

    Senior Member

    Dec 29, 2010
    1,492
    372
  13. absf

    Senior Member

    Dec 29, 2010
    1,492
    372
    Yes, the larger-capacity EPROMs are cheaper and they have smaller wafer sizes too. Further more my proteus simulator was not able to sim anything smaller then 27C64.

    I started designing a 512x4 PROM programmer interfaced to the Apple II+. They were used in the PS (Program Store) cards in the RP(Regional Processor) in our AXE10 telephone exchanges. I wrote several letters to Steve Ciarcia of the BYTE magazine and he helped me make some minor mods to my design and said the design should work. I wrote the software in 6502 asm codes and after 6 weeks of trials and errors, it finally worked.

    Thanks to this design, I have repaired around a hundred boards during the 80s and 90s. The chips used was 74S571 but we later found equivalent and cheaper chips from Philips 82S131 (or Signetics).

    Later, our teleprinter (teletype in US) section wanted me to program the answer-back prom used in the OKI teleprinters. They were not able to source the original prom which is Harris HM7602/3 that their programmer was able to program. I looked up the eqivalent chip of 74S288 and 82S123 and ordered some for them, but their programmer wouldn't program these chips.

    So I modified my 512x4 program hardware and software to increase the data width from 4 to 8. It just worked very well. I also did one prom for my friend in another town. His beakon (he maintain the equipment) for the airport call sign was also broken and I programmed a new one for him using this 32x8 prom.

    Allen
     
  14. absf

    Senior Member

    Dec 29, 2010
    1,492
    372
    I don't have any new 2716. Most of the the 2716 were from OKI teleprinters which are condemn or beyond repair. Some are from the broken Apple II clones which used EPROMs instead of masked PROMs. I guess I have about 40-50 of them and mostly still have program in them. I have 2 UV erasers and one of them have a timer built in.

    I also bought about 50 pieces of 27C512 from eBay for a project. But that project never make it to the finish point. Not sure how much they are worth now but I think I'd just keep them for my collections.

    Allen
     
  15. sailorjoe

    Member

    Jun 4, 2013
    361
    63
    Seems like we've strayed away from writing code to writing specialized assembly code for an interesting, but outdated chip. I thought it was an interesting chip in the '80's too, but that's not going to help our thread starter.
    Danno, there are a number of ways to approach the problem, including advanced topics like state machines and even neural networks, to press the point. But to get started, first, use what you know about how to analyze your relay logic and cams. Draw a box around all the logic so you can isolate the inputs and outputs from the logic box. These will be the inputs and outputs for the microcontroller and the software. The advice from John P and Papabravo earlier is a solid pace to start. Use If-Then code statements to detect what the inputs are doing. Note that sometimes an output could also act like an input, as in: If MotorSpeed2 is pressed And Motor1 is off Then SetMotorSpeed2. Look up and learn about pseudo code. It's a good way to start learning good programming in high level languages and also assembly language. Take a class or read a book on Java, C++, or Python programming. All of them can do what you want. Udacity.com has some good ones.
    Go get started and get back to us with specific questions. By the way, what's the application?
     
Loading...