09-04-2016 08:05 AM
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.
09-04-2016 12:02 PM
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.
09-04-2016 12:09 PM
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.
09-04-2016 01:03 PM - edited 09-04-2016 01:04 PM
@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.
09-04-2016 01:06 PM
Thanks buddy,i will add your code to mine.Could you pls let me know on my 1st question about PWM/Duty cycle loop.
09-04-2016 02:09 PM
Sorry, that's not my area of experise. Did you write the code from scratch or is it based on some example?
09-04-2016 02:46 PM
My own with reference from random online material
09-05-2016 01:21 AM
09-05-2016 01:40 AM
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??
09-05-2016 02:00 AM
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?