# Need help micrologix program!!!



## elliottclark (Apr 28, 2020)

I am having trouble with the final program I have to develop for school. My questions for those willing to nudge me in the right direction is: How do I get 4 inputs each requiring 4 bits to work on a single word? How do I enter this into the data table? The program is a 4 digit thumbwheel whos status needs to be moved and displayed on a LED display.

Thanks in advance for your help.


----------



## paulengr (Oct 8, 2017)

Pull up the data monitor on the input image table. Just double click it in the tree. Now you normally see a table of bits in rows and columns. Pointing your mouse shows you the syntax like I:3.2 for each bit. The WORD for each row is on the left side. That’s the I:3 part as an example. Just read what is right in front of you on the screen.

Now look for the box labeled radix and click the drop down. Change the radix from the default (bits) to integers. Now you see words, not bits. Nothing magic happened. Data monitor just lets you display tables in different formats. Structured for instance on timers shows the breakdown into words and bits.

Another hint. Remember how the SCAN works? The PLC reads and writes I/O into the input Image TABLE and out from the outout image TABLE. They are just memory tables. They are exactly like creating integer N tables except these are built in, like the S (system) image table. The PLC treats all these tables the same way.

Review the section of the user manual on data types.

As far as dealing with BCD arithmetic, there are commands for the conversion. If you have to do it manually find a copy of Donald Knuth, the Art of Computer Programming, volume 1. It is the “bible” for programmers.


----------



## just the cowboy (Sep 4, 2013)

Look at masked move. 
Grab first 4 input bits and move, convert BCD to INT
repeat 3 times

Repeat in reverse to output


----------



## elliottclark (Apr 28, 2020)

just the cowboy said:


> Look at masked move.
> Grab first 4 input bits and move, convert BCD to INT
> repeat 3 times
> 
> Repeat in reverse to output


so when i use a mmv i can manipulate where in the 16 bit word i want the 4 desired bits to end up?


----------



## just the cowboy (Sep 4, 2013)

Yes you can pick what bits you want out of the word. You can then bit shift them if needed with a bit shift.


----------



## elliottclark (Apr 28, 2020)

just the cowboy said:


> Yes you can pick what bits you want out of the word. You can then bit shift them if needed with a bit shift.



Is there a way to do multiple bit shifts with one false to true transition. For instance how would I move the first four bits into the last four bits position.


----------



## paulengr (Oct 8, 2017)

elliottclark said:


> Is there a way to do multiple bit shifts with one false to true transition. For instance how would I move the first four bits into the last four bits position.



Look up operators. Or do the math. Divide by 16, 256, or 4096 to right shift 4, 8, or 12 bits. The barrel shifter is just faster than the software divide but that’s a performance thing.


Sent from my iPhone using Tapatalk


----------



## elliottclark (Apr 28, 2020)

paulengr said:


> Look up operators. Or do the math. Divide by 16, 256, or 4096 to right shift 4, 8, or 12 bits. The barrel shifter is just faster than the software divide but that’s a performance thing.
> 
> 
> Sent from my iPhone using Tapatalk


looks like i will be stuck doing the math. Due to covid-19 I am limited to the use of the free software made available by the generous people at Allen Bradley.


----------



## paulengr (Oct 8, 2017)

The FRD instruction takes up to four digits to convert from BCD. You might be juggling bits for nothing unless they are out of order or you need digits individually.


----------



## elliottclark (Apr 28, 2020)

paulengr said:


> The FRD instruction takes up to four digits to convert from BCD. You might be juggling bits for nothing unless they are out of order or you need digits individually.


The program is for a 4 digit thumbwheel switch which is to be displayed on led output display. Im confused with how Im supposed to represent the thumbwheel switch in my ladder program. RSLogix lite using Micrologix 1000

This whole covid-19 crap has in my opinion really hurt my educational progress. Going from actual classes and labs to what they fancy a "hybrid format" of me teaching myself online.


----------



## gpop (May 14, 2018)

Input card is 16 points.

4 thumb wheels each using 4 bits wired correctly means you already have the bits stacked so it can be copied into a word.

With out seeing the problem its hard to know which ans you require as we have no idea how you are outputting the leds. 

binary input to 7 segment would be something like this 

https://www.sanfoundry.com/plc-program-operate-seven-segment-display/

but if you are using bcd to 7 segment decoders then a straight copy will work like this 

https://www.chegg.com/homework-help...ladder-logic-program-l2-l1-inputs-o-q33177664

Machines don't read decimal so why bother converting it.


----------



## elliottclark (Apr 28, 2020)

gpop said:


> Input card is 16 points.
> 
> 4 thumb wheels each using 4 bits wired correctly means you already have the bits stacked so it can be copied into a word.
> 
> ...


here is the problem.
https://sway.office.com/2g09MVWNm9YF3H8o?ref=Link


----------



## gpop (May 14, 2018)

ok im guessing you have a emulator and the code given for this project doesn't work as designed.

you input 1208 on the thumb wheel and the led displays show 1208 but when you press the button the light doesn't come on.

The display wheels each use 4 bits i presume bits 0-3 are referencing the first thumb wheel which is set to 1

0001 is binary for 1 thumb wheel 1
0010 is binary for 2 thumb wheel 2
0000 is binary for 0 thumb wheel 3
1000 is binary for 8 thumb wheel 4

these bit are being loaded into a word called TWS which is 16bits

Tws is a reference to a memory location it doesn't care whats in it or how it got there (plc's are not smart)

when the bits from the thumb wheels are loaded into TWS they equal 1000000000100001 when converted to decimal it equals 32801. plc doesn't care that you think it equals 1208 its all 1's and 0's as far as its concerned

Now we can do all sorts of fancy crap to convert 1000000000100001 into something we can read. Lets face it the plc has better things to be doing then breaking a word into 4 different words and doing a lot of math to reassemble it into something you can read. Plus its only being used once in equ statement so whats the point. 

In this question they simply want you to compare the settings on the thumb wheels with decimal 1208 and turn on a light if it match's.

Add a note in the program that tws 32801 = 1208 decimal then replace the 1208 (source B) with 32801

If your using a emulator simply set 1208 on the thumb wheels and look at tws in decimal as its saves having to use a binary to decimal converter.


----------



## elliottclark (Apr 28, 2020)

gpop said:


> ok im guessing you have a emulator and the code given for this project doesn't work as designed.
> 
> you input 1208 on the thumb wheel and the led displays show 1208 but when you press the button the light doesn't come on.
> 
> ...




Thank you so much. That makes a lot of sense and really helps me. One more question: how do i represent a thumbwheel switch in my program? 4 seperate inputs?


----------



## gpop (May 14, 2018)

elliottclark said:


> Thank you so much. That makes a lot of sense and really helps me. One more question: how do i represent a thumbwheel switch in my program? 4 seperate inputs?


A thumb wheel is simply 4 switch's hooked to 4 inputs (unless its analog).

0000=0
0001=1
0010=2

etc

there is no represent a thumbwheel switch in my program. The plc doesn't care whats hooked to the 4 inputs. If you want to make a note like

thumb wheel one is data 0-3
thumb wheel two is data 4-7
etc 

but that's for the programmer as a code reference the plc wont use it.


----------



## gpop (May 14, 2018)

As you have time due to covid why not practice programming and do this the long way around (haven't programmed in a while)

use XIO addressed between TWS/00 to TWS/15

use n7:1/00 as the OTE for XIO tws/00 (up to /03)
use n7:2/00 as the OTE for XIO/04 (up to /07)
use n7:3/00 as the OTE for XIO/10 (up to /13) (not sure if its 0-15 or 0-17)
use n7:4/00 as the OTE for XIO/14 (up to /017)

Now you should end up with 4 words each with one number (call them thumb wheels 1-4)

before putting them back together you then need to move the numbers to there correct position so 

n7:1 needs to be times 1000 so 1 becomes 1000 then stored in n7:5
n7:2 needs to be times 100 so 2 becomes 200 then stored in n7:6
n7:3 needs to be times 10 then stored in n7:7

Now n7:4+n7:5+n7:6+n7:7 = n7:8 

n7:8 should now contain 1208 in decimal


if you get this piece then use what the others posted earlier about masked moves, bit shifting and math to figure out a better way to end up with the same result.


----------



## elliottclark (Apr 28, 2020)

gpop said:


> As you have time due to covid why not practice programming and do this the long way around (haven't programmed in a while)
> 
> use XIO addressed between TWS/00 to TWS/15
> 
> ...




Thanks for the tips. This forum by far has the most helpful people out of all that ive ever been on.

Thanks all for your help. Only hope I get the chance to return the deed someday!!!


----------

