07-24-2018 05:07 AM
Hi,
I am trying to simulate some signals in LabVIEW and send to a compact RIO
I have to be able to create a variety of signals (sine, square, triangle etc) to then append onto each other before sending to the RIO. I have called this the current control.
I also have to have some other signals also being sent to the RIO throughout the program's operation with the option to stop and start these signals using buttons from my main GUI: currently I only have 3 signals named (Hall A, Hall B, Hall C).
These Hall Signals operate in a pattern. The pattern needs to change direction dependant on the polarity of the current control signal that is generated once it is sent to the RIO. The particular direction does not matter at this point.
However, it seems as my program is running, the current control seems to delay at points before continuing and I am not sure why this is. I also need to be able to stop and start the hall signals during the program's operation, however this does not seem to function properly at longer 'hall effect times' (see program) due to the method I have used in my program.
I am also not entirely certain the current control is correct. I want to be able to create one cycle of each of these signals for a set amount of time, but I do not think this 'time' is correct. Would appreciate a second set of eyes.
If you guys spot anything else, feel free to suggest anything that would improve the way I'm doing it.
Cheers.
07-24-2018
06:31 AM
- last edited on
10-16-2024
01:42 PM
by
Content Cleaner
Hey mrtea,
I had a quick look at your code. But had problems reading it because the VI is so big. Generally, I have the impression that you want to know about the State Machine Architecture. As it looks like you tried to re-create it's functionality (-:
In your FPGA code I noticed the StopProgram and StopProgram2 buttons. You could use one button and a Local Variable referencing it instead: Creating Local Variables, Using Local and Global Variables Carefully
07-24-2018 07:47 AM
I will work on making a slightly more readable version that is a tad easier to understand the method I have done things.
On a different note, in FPGA world, is the 'wait' function the best way of adding an accurate duration to a pulse. Say if I have a digital pattern of:
H H H L L L (3 high, 3 low)
And for each I extend it by a certain time period using the 'wait' function to make it "stay" at each state for this time period.
07-24-2018 11:11 AM
Hopefully the structure is a bit more clear now. Don't worry too much about the Host side of things. That code just creates and appends multiple signals together.
I tried to structure it in an event driven master slave structure where each event is the 'Add', 'Clear' etc cases I have. However, I couldn't find a way to send the entire signal array that was created to the FPGA side. Only a single value of the created array was ever sent when I selected an event. I ended up just keeping it just as the case structure you see because it seemed to work.
I will put a lot of it into subVi s later but just prefer to see everything for now as I am editing and debugging etc.
I have also multiple other signals into the FPGA side. I have all of them in while loops which run in parallel. I did it like this so I can just stop one while loop to stop that signal being sent whilst keeping all other signals being sent. Is there a better way to do this?
I still think the way I am using the pattern functions are wrong however. Will put a simplified version of that for input tomorrow if it is not clear as is.
Cheers
07-25-2018
02:05 AM
- last edited on
10-16-2024
01:43 PM
by
Content Cleaner
@mrtea wrote:
On a different note, in FPGA world, is the 'wait' function the best way of adding an accurate duration to a pulse. Say if I have a digital pattern of:
H H H L L L (3 high, 3 low)
And for each I extend it by a certain time period using the 'wait' function to make it "stay" at each state for this time period.
Yes. Except you need high-speed execution of a loop that contains non-deterministic nodes as well. Some functions on the FPGA are not deterministic. Luckily, if one doesn't know which one that are, LabVIEW helps. There are several more options than the simple plain wait function:
Some of these are based on Clock/Derived Clock you define in/on your cRIO. Also a handy feature.
07-25-2018 02:27 AM
@mrtea wrote:
I will put a lot of it into subVi s later but just prefer to see everything for now as I am editing and debugging etc.
Well, this is more general advice: Even if you don't believe me now, making your code modular helps you editing and debugging a lot!
By separating the different functionalities of your program into independent modules, you can have a much better overview about the different parts, debug them a lot better, and understand their high-level "cooperation" much easier. Of course this needs you to plan your application's structure a bit, as you need to think about your desired functionality, and then design a subVI for each one. Although this seems like a burden, it helps a lot. As each SubVI has a well defined function and(!) interface, you cannot trick yourself into thinking "it works". But enough of this.
@mrtea wrote:
I have also multiple other signals into the FPGA side. I have all of them in while loops which run in parallel. I did it like this so I can just stop one while loop to stop that signal being sent whilst keeping all other signals being sent. Is there a better way to do this?
I am not sure if I understand this question. The parallel while loops are not in the code you posted, right? If you speak about the FPGA code, then this seems to be a reasonable solution (depending on the exact implementation of course). If I understand it correctly, I'd have one (never-ending) while loop per signal, with a case structure inside, that determines if the signal is active (=outputting a timed signal) or inactive (=outputting a constant 0). As you don't need to worry about CPU usage on your FPGA, you can run it like this. In case you want to be able to gracefully shut down your FPGA application, you need additional code of course.
@mrtea wrote:
I still think the way I am using the pattern functions are wrong however. Will put a simplified version of that for input tomorrow if it is not clear as is.
Looking forward to it!
07-25-2018 09:36 AM
Ah, your earlier advice helped to make the timings a bit more accurate.
And yes when I was talking about the parallel loops, I did mean on the FPGA side of my code. Sorry if that wasn't clear.
I have posted a snippet of my code using the patterns. Ignore the buttons as all they do is exit the code. My question is, if I have my Rio acting under a 40MHz internal clock. I understand this to mean that it is able to sample at a 40MHz rate.
If I wanted to then plot one cycle of a signal that is (for example) 50Hz. It should have a period of 0.02s. This seems to work ok the way I have plotted it. However, this is not what I get off an oscilloscope when putting it out to the Rio.
Is there something I've done wrong at the very basic level in my code?
Cheers again.
07-26-2018
03:14 AM
- last edited on
10-16-2024
01:46 PM
by
Content Cleaner
@mrtea wrote:
I have posted a snippet of my code using the patterns. Ignore the buttons as all they do is exit the code. My question is, if I have my Rio acting under a 40MHz internal clock. I understand this to mean that it is able to sample at a 40MHz rate.
This depends on the I/O channel you are using. Generally, digital IO is fast, analog channels are slower. According to the data sheet the AO can do max. 345k Samples/second accumulated over all channels.
What you also need to take into account is the execution rate of your FPGA code. E.g. having an FPGA I/O node writing to a DO takes 1 clock tick, a normal while loop around it needs 3 clock ticks. That's 4 clock ticks in total, leading to a loop rate of 10MHz. See Why is Our FPGA DAQ Limited to kHz Range when the On-Board Clock is 40 MHz?.
@mrtea wrote:
If I wanted to then plot one cycle of a signal that is (for example) 50Hz. It should have a period of 0.02s. This seems to work ok the way I have plotted it. However, this is not what I get off an oscilloscope when putting it out to the Rio.
Is there something I've done wrong at the very basic level in my code?
So what do you see on your scope? Can you post a screenshot/photo in case it is harder to explain? Looking at your FPGA code, I noticed the "HallEffectTime(uSec)" control which is effectively the loop rate and set to "0". Is this intended? Are you updating it from somewhere? I also noticed that your latest VI generates analog waveforms (like a sine wave), but your inner-most FPGA loop outputs to a digital channel. So your host generates e.g. 0, 0.2, 0.4, 0.6, 0.8, whereas your myRIO outputs 0, 0, 0, 1, 1. Is that intended as well?
I think we should take a step back and rethink your application's architecture. Do your three hall effects always have the same waveform? Is it sine/square/triangle or are that just demo waveforms? Have a look at Waveform Generation with CompactRIO, there are lots of examples in there, it might be very handy for you.
07-26-2018 04:49 AM - edited 07-26-2018 04:54 AM
Sorry for the confusion. All the digital signals that I am running in the FPGA side of the code is working perfectly now as I want it. The hall effects that you are referring to will be a set of digital signal patterns being sent to the digital IO. The HallEffectTime(uSec) control will be being controlled from the Host Side eventually, but otherwise is working very accurately as I require it to.
The latest snippet of code I attached most recently is a smaller section of the host code where I am trying to generate an analogue signal to then send to analogue output module (NI 9263). It is the only thing that is blatantly not working as expected right now. Think of my previous attachment as a completely independent problem for now. The problem is that when trying to plot one cycle of a 100Hz signal (this being an arbitrary frequency with an easy to see time period) at the 40Mhz clock (setting the analogue frequency control to 100 and the Sampling frequency control to 40,000,000) , I was getting a time period of ~1.7seconds which is obviously incorrect.
What you said on this point makes sense however. I had not taken into account the rate of the module itself as well as the possible extra ticks of the while loops.
I am using:
- Compact Rio Chassis (NI 9157) base clock 40Mhz
- Analogue Output Module (NI 9263) clock 100kS/second/channel
So just these in combination will limit my sample rate to 100kHz? where Hz is samples per second just to be 100% (just in case I am going crazy)
So after your reply, I had lowered the sampling frequency control to 50000Hz and kept the analog frequency at 100Hz in hope that I would capture a 0.1s time period. However, when I do this, I instead get a sine wave of 1.5ms.
Is this all a matter of trying to match the sampling frequency of the wave I am creating to the sampling rate of the Rio then... Is there a way to accurately find what the actual sample rate is so I might be able to match it, or am I very misguided here?
I will have a look at the Waveform Generation with CompactRio that you last linked as it does seem to have something on possible use on first glance.
Will report back with findings.
07-26-2018
07:49 AM
- last edited on
10-16-2024
01:47 PM
by
Content Cleaner
Here is an attached update of what I mean. I have been looking at the DDS Waveform Generation post you linked to me as it seems like a valid method of approaching this on the surface but am still not 100% sure how it works just yet. Is it possible to concatenate multiple signals together using this method to create a larger more complex signal of more than one type of signal (eg sine , cos, triangle concatenated)