10-25-2019 12:39 AM
Here are my codes
10-25-2019 01:47 AM - edited 10-25-2019 01:47 AM
@ODONG5 wrote:
Here are my codes
Ok, thanks. Here are some comments and questions:
Given your discussion of a delay previously, I'd say that number 2 is the most likely to be important point. If you remove that wait, you might speed up some timing issues. However, it won't change the intervals between movements (which is controlled by the 500us wait).
10-25-2019 03:28 AM - edited 10-25-2019 03:55 AM
Thank you for your comments.
First, I revised my code in 1-4 comments.
In comment 5, you are correct. I want to change only period of pulse, then the change of period also changes the number of pulse in interval time. The number of pulses in interval time finally decides the velocity of the motor.
In comment 6, I understood what you mean. but is it also okay with no change? right? No?
In comment 7, DIO14 and 15 are connected encoder sensor pulse. It is a quadrature encoder. So there are two pulses A, B.
The phase difference between A and B is pi/2. The motor direction change makes which pulse go first. And I can check this change by using XOR between current A and previous B.
I upload the figure to help you understand easily.
In comment 8, I add the TF control button for that output. This output has a role to set the Z1_encoder_value '0'.
In comment 9, I was worried that 500us is not proportional to while loop( DIO 14/15) time and it makes some problems. Is it wrong thing? If I delete this delay, can loop-time be proportional to 500us(outer while loop, RT) ?
I changed my code and implemented that. But, there is still the gap between reference and sensing value ( about 100ms...) .
I don't know why it is.. 😞 It is so difficult.
10-25-2019 04:05 AM
@ODONG5 wrote:
In comment 6, I understood what you mean. but is it also okay with no change? right? No?
Oops - I said I'd show an example and then forgot. But yes, it's not necessary to operate on arrays - element by element as you currently have it will work.
@ODONG5 wrote:In comment 7, DIO14 and 15 are connected encoder sensor pulse. It is a quadrature encoder. So there are two pulses A, B.
The phase difference between A and B is pi/2. The motor direction change makes which pulse go first. And I can check this change by using XOR between current A and previous B.
I initially thought there was a problem here, because the output is not always the same as the direction, but then I saw that since you only need it to be true when either A or B is changing (because of the select node) it works correctly.
@ODONG5 wrote:In comment 9, I was worried that 500us is not proportional to while loop( DIO 14/15) time and it makes some problems. Is it wrong thing? If I delete this delay, can loop-time be proportional to 500us(outer while loop, RT) ?
Regarding comment 9, you don't necessarily want the two loops to run at the same rate. It's OK for your FPGA to sample very quickly, since it will only increment when there is a changing edge. Therefore it should try and run as fast as possible to avoid missing edges. You only need the Z1 EN_Pulse indicator to be updated when you read it on the RT system, so update it often and it will always(nearly, and always compared to the RT system) be up to date.
However, on the RT system, you do need to wait, since that controls the rate of change of the "Pulse" input to the 3rd frame While loop.
I would try removing the Wait on the FPGA (in the top loop - the bottom loop waits of course control the output pulse) and see if it changes your result. (Also remove the Wait until next in the 2nd frame on RT - maybe you already did this).
10-25-2019 06:49 AM
@cbutcher 작성:
I would try removing the Wait on the FPGA (in the top loop - the bottom loop waits of course control the output pulse) and see if it changes your result. (Also remove the Wait until next in the 2nd frame on RT - maybe you already did this).
I already tried removing the Wait on the FPGA while loop for encoder, but it didn't work.
If I use another while loop in 3rd frame on RT, is there some changes?