plcdp Posted September 10, 2012 Report Posted September 10, 2012 Hello, I am having a bit of a problem with the BMOV command. I am using a FX3U PLC. I am trying to take a current value of a timer and move once per cycle to a block of registers to then pull an average from it. For some reason it moves the data to the head register, but no more. [bMOV T0 D300 K50] is the syntax. Am I doing something wrong here? Thank you, -Dave Quote
bobtalbot Posted September 10, 2012 Report Posted September 10, 2012 I think you want to use indexing, ie first time move to D300 then D301, then D302...etc. I believe what you are doing is moving T0-T49 to D300-D349 Quote
panic mode Posted September 11, 2012 Report Posted September 11, 2012 correct, you need to use index register. on some CPUs number of Z registers is quite limited so check programming manual. basic form is [MOV T0 D300Z0] where Z0 is index register Quote
plcdp Posted September 11, 2012 Author Report Posted September 11, 2012 I see...thanks very much. -Dave Quote
JRoss Posted September 11, 2012 Report Posted September 11, 2012 You might consider using the SFWR and SFRD instructions which are essentially FIFO stack control. Use SFWR to push the value into the stack, then once the stack is full, use SFRD to pull the oldest value out to discard it. In the instruction, the first register of the block is your stack length, so you'll want to start with D299. Quote
plcdp Posted September 11, 2012 Author Report Posted September 11, 2012 This actually sound like what I want, I basically want to save 50 consecutive pieces of data and pull an average from them. The FIFO stack will be ideal because the oldest data will fall off. Thanks very much, -Dave Quote
JRoss Posted September 11, 2012 Report Posted September 11, 2012 No problem. I've used that setup for averaging, and it works pretty well. Just make sure to only average the values that are in the stack. For example, what will you do when you only have five pieces of data? Quote
plcdp Posted September 11, 2012 Author Report Posted September 11, 2012 One more thing, I would want to use a word shift instead of a bit shift to move the current accumulated time of a timer...correct? Thanks again for the help, -Dave Quote
JRoss Posted September 11, 2012 Report Posted September 11, 2012 Yes and no. If you want the stack functionality, use SFWR (shift write) and SFRD (shift read). If all you want to do is cycle the values through the stack, then use word shift (WSFR or WSFL). Bit shift cycles the bits within a word or range of bits. A word shift instruction would be simpler for your application, because you would only need the one instruction to push the new value in and the old value out. The SFWR and SFRD instructions give you the added advantage of knowing how many values are in the stack. If you are averaging cycle times and don't have to worry about having a half-full stack, then word shift is the way to go. Just realize that the average will be off for the first forty-nine cycles after you implement the code, unless you put in your own counter. In my application, I was averaging tank level over time, and needed to reset the average any time there was a power cycle, as it would throw off the average if the tank was manually filled or emptied while power was down. I had to reset the stack, and needed the average to be accurate, even when there was only one value in the stack. Quote
plcdp Posted September 11, 2012 Author Report Posted September 11, 2012 I got ya. Thanks for all the help, I have this working well now. Thanks again, -Dave Quote
Crossbow Posted September 15, 2012 Report Posted September 15, 2012 Handled... We won't hear from that IP address again... Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.