Incrementing Registers

  • Hello


    i am interested in trying to increment Registers to create myself a buffer. i have 6 registers that get populated. i need this over 120 registers to give me quater second intervals.


    is there a way to increment registers and not thier values?


    this way i can then go to the controller through the IP adress and copy the numreg.vr file for analyss in excel for graphing

  • Yep, just use indirect addressing. Kind of like a pointer in C.


    Example:

    Code
    R[1]=10 !This is our address to point to. Point at R[10].
    R[R[1]]=5 !R[10] is now 5
    R[1]=11 !Now point at R[11]
    R[R[1]]=6 !R[11] is now 6

    Check out the Fanuc position converter I wrote here! Now open source!

    Check out my example Fanuc Ethernet/IP Explicit Messaging program here!

  • how would that work in a loop sorry?


    if R[1]=10
    then you are right i can set R[R[1]]=5 !so that R[1] is = 5 instead of 10 now, but if say i had:


    lbl[1]
    if R[1] =20, JMP LBL[20]
    R[1]=R[1]+1


    R[80]=Something-Something
    R[81]=Something-Something
    R[83]=Something-Something


    jump lbl[1]
    lbl[20]


    how do i proceed to increment 80,81,83 register?


    i kind of just want to add a line in after like this:


    lbl[1]
    if R[1] =20, JMP LBL[20]
    R[1]=R[1]+1


    R[80]=Something-Something !R[80] needs to be a variable i can increment and update throughout the program so it changes to 80,86,72,78, and so on
    Above Register +6
    R[81]=Something-Something
    R[83]=Something-Something


    jump lbl[1]
    lbl[20]

  • One way of doing it would be to use indirect addressing for the 6 variables you're recording. I.E,


    R[1]=1
    R[2]=80
    lbl[1]
    if R[1] =20, JMP LBL[20]
    R[1]=R[1]+1


    R[R[2]]=Something-Something
    R[2]=R[2]+1
    R[R[2]]=Something-Something
    R[2]=R[2]+1
    .
    .
    .



    jump lbl[1]
    lbl[20]

  • Try something like:


    R[150]=1
    R[151]=21
    R[152]=41
    ...
    R[155]=101
    LBL[1]
    IF (R[150]=20), JMP LBL 20
    R[R[150]]=something
    R[R[151]]=something
    ...
    R[R[155]]=something
    R[150]=R[150]+1
    R[151]=R[151]+1
    ...
    R[155]=R[155]+1
    JMP LBL 1


    LB 20
    whatever your doing next



    This way you aren't overwriting your registers your incrementing through while recording your data. It does burn through a bunch of registers though so make sure you know how many you have available

  • You said you wanted 1/4 second intervals. So you will need to add a ": Wait .25 (sec)" at the end of each loop.


    The last two examples are good. Personally, I like to use a For loop in these situations for cleaner code, but JMP's & LBL's will accomplish the same thing. The For loop will eliminate about 3 lines of code and more clearly show where the loop starts and ends. It works like this:


    : For R[150]=1 to 20;


    ..... all of your code here


    : Wait .25 (sec) ;


    :ENDFOR;

    Edited once, last by HawkME ().

  • thanks everyone with a combination of your guys help i managed to populate a graph over 120 registers. i thougth it would be easier then that but it hurt my brain :waffen100:

Advertising from our partners