Paul Kav

32 Bit data transfer

13 posts in this topic

Please help.

I am using a rotary encoder with high speed counter C235 in my program to monitor the position, and to pause the motor after a number of pulses from the encoder.

I have used a DMOV instruction to transfer the value of C235 to D0, but when I am monitoring the value in D0, it never rises above 32767 (I assume 16Bits) and I need to pause the motor at value 75000.

What am I doing wrong?

Thanks in advance

Edited by Paul Kav

Share this post


Link to post
Share on other sites

hi Paul KAV,

high-speed counter can't be transfered with a DMOV instruction, you have to use the HCMOV(16bit), DHCMOV(32bit) instructions
to transfer the counter value to a D-Register., There is also the DHSCS Instructtion to compare the counter with an given value.

 

 

Share this post


Link to post
Share on other sites

Thank you for the speedy response.

I will try this and let you know the outcome.

much appreciated

regards

Share this post


Link to post
Share on other sites

Andreas 

Thanks for the help.

I have tried to type this instruction (DHCMOV) into software (GX Works 2) but it does not recognise the instruction.

I assume I use an application instruction.

Thanks in advance

Share this post


Link to post
Share on other sites

Thanks Andreas

I have taken a look at the high speed processing instructions like you advised, unfortunately I would have to re-think the whole program if I were to use them.

Is there any other way I can transfer the value of a HSC into a 32 bit memory, so I compare the values later in my program.

Regards

Share this post


Link to post
Share on other sites

DMOV will move a 32 bit number from C235 into D0

Being 32 bit, it will use D1 and D2.

You can use DCMP to check when it reaches 75000

 

Share this post


Link to post
Share on other sites

almost...

DMOV to D0 will write to both D0 and D1 but value in D2 is not affected.

 

"when I am monitoring the value in D0, it never rises above 32767"

monitoring how exactly...? if monitoring value in your code at the DMOV instruction, it should be displayed as 32-bit.

if looking at the D0 value in the data table, default is 16-bit. would need to change the view to show 32-bit. 

btw. this is one of reasons to align 32-bit addresses to even number. PLC would also accept DMOV to D1 (so D1 and D2 would be used) but D1 is an odd address. that would prevent monitoring through data table but looking at value in the code should still be fine. 

Share this post


Link to post
Share on other sites

Lol, I meant D0 and D1.

Thanks, I might have confused him.

1 person likes this

Share this post


Link to post
Share on other sites

Thanks Everyone

The program i am writing requires 3 individual mini sequences and went something like :

1. DMOV the value of the counter C235 into D0

Then sequence one: DMOV a K value into D1 and a K Value into D2 (I did not realise D1 would be affected by DMOV  into D0)

Then a math instruction to compare the Value of D0 with D1 and again the Value of D0 with D2 to give two separate outputs.

The problem was the value in D0 would never travel over 32767 (16 bit) and my value in D1 and D2 were larger.

I have actually change the program to work with DCMP instructions, but i am interested to understand how to DMOV 32 bit data.

Regards Paul

Edited by Paul Kav

Share this post


Link to post
Share on other sites

hi paul,

to mov 32bit data just use the DMOV instruction as you did, you only should note that the other
registers you will use to hold the other values are also 32bit:

DMOV C235 D0 --> writes D0, D1
DMOV K10   D2 --> writes D2, D3
DMOV K20   D4 --> writes D4, D5
to compare values, for example C235 and K10 you can use the normal compare functions togehter with 'D' to indicate
that it should compare a 32bit value (compare functions D=, D<, D>, D<>)  e.g. 'D= D0 D2' (compare D0/C235 and D2/K10)
 

Be sure not to mix 16/32bit instructions, for example using '= D0, D2' (what is wrong) would compile, but only compare
16bit, this can work with appropriate values, so that this error is not directly noticeable, but if only the upper 16bit would differ,
the comparison would give a wrong result.

for fx5/ (gxworks3) there is an option in the compile settings that will generate a warning if the data type and the instructions
doesn't match, not sure if this option exist in gxworks2

one last note regarding the high-speed counter and why 'DMOV C235 D0' won't work as expected. This is due to the fact that the system
updates the (high-speed) counter outside the scan cycle and therefore it is not guaranteed that the read value corresponds to the current counter value.
Therefore, the high-speed counters have their own instructions for setting, resetting, comparing and reading (at least for the FX3U).

 

Share this post


Link to post
Share on other sites

that is correct...

i guess like many others, Paul gets confused with observed "result" of 
DMOV K1 D2   

since one of the D registers gets "1" and the other is zero.
on the surface this does not look different than 16-bit move instruction:
MOV K1 D2

but - they are not the same thing. to see the difference, try larger value like:

DMOV H12345678 D4

this sets 32-bit value to D4,D5. one D register will receive H1234, the other will receive H5678
aso note that 
H1234 is same as K4660 and  H5678 is same as K22136
and of course H12345678 is same as K305419896  

also note that
4660 * 65536 + 22136 = 305419896 or 
H1234 * H10000 + H5678 = H12345678
where 65536 / H10000 is a number of states for a single 16-bit register
so top digits spill over to next D register. when using DMOV K1, you did not see those higher weight digits...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now