Single bit energized test

Genius The original post is a little different, it compares 4 bits so if more than one is on then it sends the code to an alarm word for example: if bit 0 has been selected & any of bits 1-3 is on then this is the alarm. I suppose it's a bit like having 4 selector switches (On/Off) and if more than one is turned on alarm.
This started to be 4 possibly 8 combinations, however, it turned into a competition long code versus word comparisons versus loops (bit checks) and bit tests on 32 or more bits. The one problem is I don't think any of the contributors here really know why the alarm is an integer again I think it's down to OP not posting all relevant information and of course as we all do mis-read posts have done it a number of times lol.


I didn't post the whole code because I was only asking about the 4 bit check. I probably should have explained the code in more detail, but I thought the comments in the rungs would explain it. N7:49 is my alarm code integer. A non-zero value indicates a "hard" alarm has occurred and the program will react to it by dropping the "ok to run" bit. It is also used for my HMI panel to display the alarm code.



N7:36 is used by Ladder 10 "Fwd-Rev" as a step sequence for the subroutine. As the subroutine executes and conditions are met, this number is increased by 10 until it reaches 100 which tells the main program that it has completed the request.



The four bits I asked about are 4 track sections that this routine would apply. I am doing a check here to make sure only one area is selected. If it helps, here is the entire ladder 10 program for my "Forward - Reverse" subroutine.


One note, I am using N7:41 to N7:46 as integers to energize an output if it has a non-zero value. These are six outputs that control the track power. There is a subroutine that checks these integers and will enable the output if it has a non-zero value. I need to manipulate these outputs many times in my programs and if anyone remembers my question from over a year ago, I was latching and unlatching these which caused a mess.



This way, not only can I avoid this and not have to use a ton of bit compares, it also allows me to see where in the program the track power was turned on. What I am doing is say for example this is ladder 10 and I want to energize a track section, I will move "1000" into the integer, so I know it was the first section of ladder 10 that energized the track. If later in the same ladder it needs to energize it again, I will move "1010" into it. This has helped me debug these programs as I am developing them.



Mike
 
Actually, I think what you posted was enough to prompt other posters to come up with solutions, however, it turned out to be what if & snowballed from there.
I'm sure there was a solution in the above posts somewhere that would suit your application. We are all guilty of letting it snowball, after all, we all started with 4 bit solutions that could expand to 8 then it got silly. anyway hope you have found a solution.
 
Other than the 'getting silly' part I think it is best for programmers to know how to do things in more than one way. I have noted down some of the answers as I may need them in the future.

That is why we get so many homework postings here on how someone can do something simple but with the restriction he/she can't use a timer, or bit-shift, or array, or some other common (and easy) method.
 
Other than the 'getting silly' part I think it is best for programmers to know how to do things in more than one way. I have noted down some of the answers as I may need them in the future.

That is why we get so many homework postings here on how someone can do something simple but with the restriction he/she can't use a timer, or bit-shift, or array, or some other common (and easy) method.


Most of the time I just read some of the posts and now and then I get an idea about something I may need for something. What I am doing is no doubt unusual, you could say its somewhat a homework problem. I wanted to learn how to program and I thought a good way to program in a "real world example" would be to build a model railroad layout and write programs to control the trains. I did start with one of those trainer units with a small PLC and buttons and lights, but I am finding this approach helpful since unexpected things happen (like a machine) In one of my prior jobs, the plant was closing and all the machinery was being scrapped, so I was allowed to take any parts I wanted. I used these to construct the controls for the model railway.



When I got stuck last year and I was thinking I was using bad programming practices, I posted my problem and got some very good feedback so I scrapped all I did and started over.



At that time I was using a Micrologix 1000, I found limitations aside from it being obsolete (and I had to repair it twice for failed outputs) its I/O and memory was limited. By the time I got to writing my first train interchange program, I had the memory over 70% filled, so I knew I could not write all the desired train operations I wanted. I decided to upgrade to a Micrologix 1400 and I rebuilt my controls from scratch. (and of course purchased RsLogix Micro)



Right now I am to the point all the "support" routines are written and working. These subroutines handle things that will be needed for the train operations, such as throwing the remote switches, starting up a train and making sure its moving in the right direction, and "parking" a train in a section of track.



Mike
 
I had a customer about 10 years ago and his was HUGE... his name was Bob and was also a member on this site, he was using a 5/04 to run it, I checked and his website is no longer up and running, he was also from PA, must be something in the water up there :)
 
Mikeexplorer,

Do you have any DCC control run by the ML?

I looked a couple years ago, found nothing and haven't looked since but's it's still in the back of my mind to do it. I bought one DCC engine and it's still on a shelf.
 
Have you considered PWM for analog-ish control of speed?


I am no electrical whiz, but with a large enough ratio (I am guessing here) of capacitor's capacitance to summat like the [product of engine load and PWM cycle time], it should be possible to control the voltage (with a bit of ripple).


There are probably better ideas for circuits for PWM control of voltage, but that is the basic idea.

Or am I blowing smoke?


Of course, there are custom-built widgets that can already do this (mbed.com).
 
Mikeexplorer,

Do you have any DCC control run by the ML?

I looked a couple years ago, found nothing and haven't looked since but's it's still in the back of my mind to do it. I bought one DCC engine and it's still on a shelf.


No, this is a pure conventional layout. DCC I think is for HO scale anyway. All my locomotives I own are conventional only, some do have the fancier railsounds.


I wanted to design the programs for a conventional layout.


Mike
 
Have you considered PWM for analog-ish control of speed?


I am no electrical whiz, but with a large enough ratio (I am guessing here) of capacitor's capacitance to summat like the [product of engine load and PWM cycle time], it should be possible to control the voltage (with a bit of ripple).


There are probably better ideas for circuits for PWM control of voltage, but that is the basic idea.

Or am I blowing smoke?


Of course, there are custom-built widgets that can already do this (mbed.com).




I am using a CW80 transformer and I was able to find a schematic of it online that someone drew up. The throttle control for the transformer is a 0 to 3.3v DC input via a Potentiometer so If I take the analog output from the ML1400 and scale it with a voltage divider, it should do the trick.



The CW80's (like all Lionel transformers) are AC output (usually 0-18 volts) so I can also use the analog input to sense the output from the transformer by converting it to DC via a bridge rectifier and scaling it to 0-10VDC. Attached is the schematic of my layout with the CW80 interface.



Right now I am not doing anything with the analog, that will be later. I also tied into the buttons on the transformer so the ML1400 can ring the bell or blow the whistle.


Mike

CW80 Interface.jpg
 

Similar Topics

Hi, I've got a Micro820 that I am using to create some menus and handle an alarm buzzer for a Panelview 800 HMI. I also need it to communicate...
Replies
4
Views
2,070
I'm writing a function block using Omron CX-Programmer for a CJ2M CPU. The FB is for interfacing with Slice I/O counter cards. The counter cards...
Replies
17
Views
9,623
Hi all, I have an application where the plant PLC is communicating via Ethernet/IP to 3 different field PLC's. The Field PLC's are all Micrologix...
Replies
6
Views
3,413
Hi, I'm talking to a ControlLogix PLC using CIP over E/IP, and I'm having trouble accessing single bits inside another type (such as an integer)...
Replies
5
Views
3,851
Hi all, someone knows if is possible in SCL extract the single bit of a WORD or DOUBLE WORD defined as VAR_TEMP?? In other word I'd like to...
Replies
2
Views
7,031
Back
Top Bottom