You are not registered yet. Please click here to register!


 
 
plc storereviewsdownloads
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.
 
Try our online PLC Simulator- FREE.  Click here now to try it.

New Here? Please read this important info!!!


Go Back   PLCS.net - Interactive Q & A > PLCS.net - Interactive Q & A > LIVE PLC Questions And Answers

Reply
 
Thread Tools Display Modes
Old December 15th, 2011, 05:26 AM   #1
MOeZ
Lifetime Supporting Member
Singapore

MOeZ is offline
 
MOeZ's Avatar
 
Join Date: Nov 2009
Location: singapore
Posts: 101
Indirect Addressing Advanced Exercise from PLCDEV.com

Dear All,

When i read sample exercise with code and explanation, i think i understand about Indirect Addressing partially. but when i look at exercise #2 below, i realize i am totally don't have idea how to start? Could anybody give me an idea to solve this Question 2? Thanks!


P.S admit this is my HW.

Exercise #2 (Advanced)
  1. Create a DB with an array of 10 real numbers. Populate the array with random values.
  2. Create a function that will return the max number in the array and its position. Use the indirect addressing method of your choice.
__________________
Everything Should be made as simple as possible, but not simpler.
Albert Einstein
  Reply With Quote
Old December 15th, 2011, 08:17 AM   #2
James Mcquade
Member
United States

James Mcquade is offline
 
Join Date: Oct 2007
Location: Tennessee
Posts: 3,073
pmmdavid,

You are letting the entire assignment overwhelm you.
There are two excersises, so treat them individually.

develop the 10 part data array. get it working and understand how it works.
excercise #2 will be much more simple and easier.

regards,
james
  Reply With Quote
Old December 15th, 2011, 08:23 AM   #3
MOeZ
Lifetime Supporting Member
Singapore

MOeZ is offline
 
MOeZ's Avatar
 
Join Date: Nov 2009
Location: singapore
Posts: 101
Indirect Addressing Advanced Exercise from PLCDEV.com

I still don't have any idea. Could you give me hint to start? Thanks!
__________________
Everything Should be made as simple as possible, but not simpler.
Albert Einstein
  Reply With Quote
Old December 15th, 2011, 08:28 AM   #4
L D[AR2,P#0.0]
Lifetime Supporting Member
United Kingdom

L D[AR2,P#0.0] is offline
 
Join Date: Nov 2006
Location: UK
Posts: 6,241
Write the pseudo code first.
  Reply With Quote
Old December 15th, 2011, 09:09 AM   #5
MOeZ
Lifetime Supporting Member
Singapore

MOeZ is offline
 
MOeZ's Avatar
 
Join Date: Nov 2009
Location: singapore
Posts: 101
FUNCTION FC 1 : INT

VAR_INPUT
rRandom_Data : ARRAY [1 .. 10 ] OF Real ;
END_VAR

Then hue.
__________________
Everything Should be made as simple as possible, but not simpler.
Albert Einstein
  Reply With Quote
Old December 15th, 2011, 09:40 AM   #6
L D[AR2,P#0.0]
Lifetime Supporting Member
United Kingdom

L D[AR2,P#0.0] is offline
 
Join Date: Nov 2006
Location: UK
Posts: 6,241
That is not pseudo code, it is a function definition with an input.
Here's my interpretation of psuedo code for your problem:

for i:=1 to 10 do
rRandom_Data[i]:=RND(i);
end_for

Just how random do the random numbers have to be ?

Last edited by L D[AR2,P#0.0]; December 15th, 2011 at 09:42 AM.
  Reply With Quote
Old December 15th, 2011, 09:44 AM   #7
L D[AR2,P#0.0]
Lifetime Supporting Member
United Kingdom

L D[AR2,P#0.0] is offline
 
Join Date: Nov 2006
Location: UK
Posts: 6,241
Having re-read the assignment, there is no mention of creating a function to populate the DB, so you could create the DB in the editor and fill in the random values manually....
  Reply With Quote
Old December 19th, 2011, 09:54 AM   #8
MOeZ
Lifetime Supporting Member
Singapore

MOeZ is offline
 
MOeZ's Avatar
 
Join Date: Nov 2009
Location: singapore
Posts: 101
Indirect Addressing Assignment

I have create DB area with manually fill real value.
Q1.
DATA_BLOCK "Prefill values"
TITLE = Shared DB containing random values


STRUCT
Value : ARRAY [1 .. 10 ] OF REAL ;
END_STRUCT ;

BEGIN
Value[1] := 0.000000e+000;
Value[2] := 0.100000e+000;
Value[3] := 0.200000e+000;
Value[4] := 0.300000e+000;
Value[5] := 0.400000e+000;
Value[6] := 0.500000e+000;
Value[7] := 0.600000e+000;
Value[8] := 0.700000e+000;
Value[9] := 0.800000e+000;
Value[10] := 1.000000e+000;
END_DATA_BLOCK

Q2. Create a function that will return the max number in the array and its position. Use the indirect addressing method of your choice.

for this Q, how do i get the position of DB index? any hint please
__________________
Everything Should be made as simple as possible, but not simpler.
Albert Einstein
  Reply With Quote
Old December 19th, 2011, 11:52 AM   #9
L D[AR2,P#0.0]
Lifetime Supporting Member
United Kingdom

L D[AR2,P#0.0] is offline
 
Join Date: Nov 2006
Location: UK
Posts: 6,241
Start with the psuedo code:

Code:
//Initialise max value and position as first value in array
//max:=Value[1];
//pos:=1;
//Loop looking for max value, saving position when found
//For i:=2 to 10 do
//  if Value[i] > max then
//     Begin
//       max:= Value[i];
//       pos:= i;
//     end;
//  end_if;
//end_for;
  Reply With Quote
Old December 19th, 2011, 12:38 PM   #10
L D[AR2,P#0.0]
Lifetime Supporting Member
United Kingdom

L D[AR2,P#0.0] is offline
 
Join Date: Nov 2006
Location: UK
Posts: 6,241
Next, break down lines of pseudo code to lines of STL:

e.g.

Code:
//Initialise max value and position as first value in array
//max:=Value[1];
//pos:=1;
      L     "PreFill Values".Values[1]
      T     #max
      L     1
      T     #pos
  Reply With Quote
Old December 19th, 2011, 12:46 PM   #11
L D[AR2,P#0.0]
Lifetime Supporting Member
United Kingdom

L D[AR2,P#0.0] is offline
 
Join Date: Nov 2006
Location: UK
Posts: 6,241
Next, implement the for loop leaving out the processing inside the loop:

Code:
//For i:=2 to 10 do
// ..
//end_for;

      L     2
FL:   T     #ii
      L     10
      >I    
      JC    endf

//..

      L     #ii
      +     1
      JU    FL
endf: NOP   0
  Reply With Quote
Old December 19th, 2011, 01:05 PM   #12
L D[AR2,P#0.0]
Lifetime Supporting Member
United Kingdom

L D[AR2,P#0.0] is offline
 
Join Date: Nov 2006
Location: UK
Posts: 6,241
Now introduce a temp variable x for assigning Values[i] for later processing and noting that:

1) the array is indexed from 1 to 10 but it starts at DBD0 so to compute the correct address you must subtract 1 from the index
2) Indirect addressing starts at the bit level so to compute a byte offset multiply by 8, a word/int offset multiply by 16, and a dword/real offset multiply by 32. For brevity the multiplcation is implemented using SLD 3/4/5

Code:
//For i:=2 to 10 do
// x:=Values[i];
// ..
//end_for;

      L     2
FL:   T     #ii
      L     10
      >I    
      JC    endf

//Let x:=Values[i]  for convenience
      OPN   "PreFill Values"            //open value db
      L     #ii                         //fetch array index 
      +     -1                          //correct for zero based addressing 
      SLD   5                           //shift 3 for bytes,4 for words,5 dwords/reals
      LAR1  P#DBX 0.0                   //point to base of array
      +AR1                              //add offset calculated from index
      L     D [AR1,P#0.0]
      T     #x                          //x=Values[i]



      L     #ii
      +     1
      JU    FL
endf: NOP   0
  Reply With Quote
Old December 19th, 2011, 01:23 PM   #13
L D[AR2,P#0.0]
Lifetime Supporting Member
United Kingdom

L D[AR2,P#0.0] is offline
 
Join Date: Nov 2006
Location: UK
Posts: 6,241
Now add in the comparison processing, leaving out the processing between the Begin and End

Code:
//For i:=2 to 10 do
// x:=Values[i];
//  if Values[i] > max then
//     Begin
//..
//     end;
//  end_if;
//end_for;

      L     2
FL:   T     #ii
      L     10
      >I    
      JC    endf

//Let x:=Values[i]  for convenience
      OPN   "PreFill Values"            //open value db
      L     #ii                         //fetch array index 
      +     -1                          //correct for zero based addressing 
      SLD   5                           //shift 3 for bytes,4 for words,5 dwords/reals
      LAR1  P#DBX 0.0                   //point to base of array
      +AR1                              //add offset calculated from index
      L     D [AR1,P#0.0]
      T     #x                          //x=Values[i]
//..
      L     #max                        //if x > max
      >R    
      JCN   enif
//Begin
//..
//end

enif: NOP   0

      L     #ii
      +     1
      JU    FL
endf: NOP   0
  Reply With Quote
Old December 19th, 2011, 01:26 PM   #14
L D[AR2,P#0.0]
Lifetime Supporting Member
United Kingdom

L D[AR2,P#0.0] is offline
 
Join Date: Nov 2006
Location: UK
Posts: 6,241
Finally, add in the Begin..End processing.

Code:
//For i:=2 to 10 do
// x:=Values[i];
//  if Values[i] > max then
//     Begin
//       max:= Value[i];
//       pos:= i;
//     end;
//  end_if;
//end_for;

      L     2
FL:   T     #ii
      L     10
      >I    
      JC    endf

//Let x:=Values[i]  for convenience
      OPN   "PreFill Values"            //open value db
      L     #ii                         //fetch array index 
      +     -1                          //correct for zero based addressing 
      SLD   5                           //shift 3 for bytes,4 for words,5 dwords/reals
      LAR1  P#DBX 0.0                   //point to base of array
      +AR1                              //add offset calculated from index
      L     D [AR1,P#0.0]
      T     #x                          //x=Values[i]
//..
      L     #max                        //if x > max
      >R    
      JCN   enif
//Begin
      L     #x
      T     #max
      L     #ii
      T     #pos
//end
enif: NOP   0

      L     #ii
      +     1
      JU    FL
endf: NOP   0
  Reply With Quote
Old December 19th, 2011, 08:29 PM   #15
MOeZ
Lifetime Supporting Member
Singapore

MOeZ is offline
 
MOeZ's Avatar
 
Join Date: Nov 2009
Location: singapore
Posts: 101
Many Thanks LD!

Quote:
Originally Posted by L D[AR2,P#0.0] View Post
Finally, add in the Begin..End processing.
Many Thanks LD . Now i know more about what u meant pseudo code. But give me a time to understand your code and will test it todays until i get idea.

Thanks again!
__________________
Everything Should be made as simple as possible, but not simpler.
Albert Einstein
  Reply With Quote
Reply
Jump to Live PLC Question and Answer Forum

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Topics
Thread Thread Starter Forum Replies Last Post
Indirect Bit Addressing 5000 vs 500 intradave LIVE PLC Questions And Answers 1 June 28th, 2011 06:08 PM
Indirect addressing - RSLogix 500 doesn't always work wildcatherder LIVE PLC Questions And Answers 23 October 28th, 2009 12:57 PM
PLC5 and Indirect Addressing kdcui LIVE PLC Questions And Answers 3 October 23rd, 2008 10:46 AM
Indirect addressing with GX Developer DairyBoy LIVE PLC Questions And Answers 7 June 14th, 2007 05:14 AM
I/O Indirect Addressing - PLC 5/80E relms LIVE PLC Questions And Answers 8 February 23rd, 2005 05:10 PM


All times are GMT -4. The time now is 08:53 PM.


.