LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

TO rotate a shaft

Hi,

 

In my project i am using CRIO 9073 with NI9237,9401 and 9505.

With this setup,i gotta rotate a shaft connected to it. With my code,i am able to rotate the shaft,control the drive direction but i would like to control the PWM as well.Can someone let me know why my PWM/duty cycle loop does not work,i spent enough time debuging it but i could not.

0 Kudos
Message 1 of 15
(4,112 Views)

I haven't looked at the FPGA code, just wanted to point out a serious race condition in host.vi. (there is no guarantee that the case structure at the bottom actually executes when stopp is pressed, so why is it even there? What's the purpose of the "x+1" indicator?

Under what conditions should the two left FPGA loop stop while the two timed loops continue.

0 Kudos
Message 2 of 15
(4,085 Views)

1, The case structure works,i checked it many times.That is to stop the motor rotation when stop is pressed.

2,The encoder index z has to give one pulse for every rotation but it fails...pls help me on this.The X+1 is to serve this purpose but since the index value is always 0,that part of code does not work.

3,All the FPGA loops stops when STOP button is pressed.

0 Kudos
Message 3 of 15
(4,080 Views)

@krupa wrote:

1, The case structure works,i checked it many times.That is to stop the motor rotation when stop is pressed.

 


No. It might occasionally work, but there are no guarantees. For example if you would press the Stopp button while the local variable has already been read as FALSE but the terminal has not been read in the current iteration, the loop will stop without executing the case structure.

Even if the case structure would execute, the two terminals of the local variables inside the case will get written after the controls have been read, so the new values will not get relayed to the hardware, just to the local controls.

 

You have a prototypcal texbook race condition due to blatant overuse of local variables!

 

Here's one possibility to do it correctly. (The booleans are wired across in the FALSE case.)

 

 

The x+1 only gets written for one possible value, because it is inside a case. Once it has been written once, it can never change again to a different value.

 

 

0 Kudos
Message 4 of 15
(4,062 Views)

Thanks buddy,i will add your code to mine.Could you pls let me know on my 1st question about PWM/Duty cycle loop.

0 Kudos
Message 5 of 15
(4,057 Views)

Sorry, that's not my area of experise. Did you write the code from scratch or is it based on some example?

0 Kudos
Message 6 of 15
(4,043 Views)

My own with reference from random online material

0 Kudos
Message 7 of 15
(4,037 Views)

Hello krupa,

 

simplified the code

 

sample.png

best regards
Alexander
0 Kudos
Message 8 of 15
(4,003 Views)

Thank you so much.I will implement this and check for the result.I would like to know if the other loop also requires any simplification??

0 Kudos
Message 9 of 15
(3,997 Views)

Hello krupa,

normally the duty cycle is in my opinion always positive this is the reason why i used U16 data type. When should AI be triggered, what are the conditions you want?

best regards
Alexander
0 Kudos
Message 10 of 15
(3,991 Views)