05-31-2012 11:48 AM
Hi ,
I would like to generate a PWM signal with variable duty ratio of frequency 500KHz on NI FPGA.
I have attached the FPGA VI file. The code consists of two while loops in parallel. I am using FIFO to transfer data between two while loops.
The First while loop increments the duty ratio by 0.1 in every iteration and the value is written to FIFO. ( The duty ratio is reset to zero if it is greater than 1).
The second while loop reads the duty ratio and generates the PWM signal.
The problem I am facing is that the duty ratio is not getting updated and the PWM output signal is of 250 KHz instead of 500KHz.
I have verified the PWM code and it works fine when I am using a single while loop i.e., I get the 500KHz signal with the desried duty ratio (While--3).
I am not able to locate the fault. Can anyone help me with same ?
Thanks,
Deepti
05-31-2012 05:32 PM
Hi there
First of all, which HW are you using?
There are some strange things in your code:
-The timeouts:
Your FIFO memory stops waiting data only 100 ticks after it started to wait... why? If there's no a reason, you can use a -1 value wired to timeout to make the FIFO to wait undefinetely as both cycles depend on those FIFOs, so no timming probles would appear.
-The cycle loops:
You are using cycle loops inside flat sequence (flat sequence is not recommended in LabVIEW programming) instead of tick count nodes. Remember cycle loops waits untill the machine clock (in ticks) retrieves a value which is multiple of the wired value. If the machine clock is 160 (for example) when the flat sequence starts to run (ignoring structure's overhead), the cycle loop will wait nothing because a multiple has been already reached.
-Parallel Whiles
Why are you using different while cycles to achieve a PWM?
The only way you can sync parallel processes when programming for NI FPGAs is using occurrences or local variables inside a single frame of a flat sequence structure. Using a -1 wired to the timeout of the reading FIFO method could work too.
Hope this helps... see you!
06-01-2012 09:35 AM
Hi,
Thanks for the response.
1. I am using NI cRIO 9082 and the C series module NI 9401.
2. Timeout : 100 ticks
I realized that and changed my sampling time to -1. But even then I face the same problem.
3. Cycle loops: I didn't quite understand what your trying to say.
Are you suggesting to use tick counts instead of wait in flat sequence to generate PWM ?
Is it recommended to use looptimer in a while loop to control the execution rate of the loop ?
4. Parallel Whiles
I am new to LABVIEW Programming. Can you please suggest if there is a better way to generate PWM Pulses without using Parallel while loops ?
Thanks once again for the response. I appreciate your help.
Deepti
06-01-2012 09:51 AM
Hi
I have attached a file to generate PWM signal.
Is this programming method better than my previous version ?
Thanks,
Deepti
06-01-2012 01:49 PM
Hi Again!
Before looking deeper I want to know how are you measuring the output frequency? None of your codes include a way to make the signal measurable...
About the problem you have of getting a 250kHz freq instead of the 500kHz one, it has a very simple explanation. I've attached an image of a generic PWM (capture.jpg), le tme explain:
I'm not sure if you can accomplish a 500kHz PWM with the 40MHz clock, it depends on what operations you want to make inside the while loop.
There is also a block named Square wave which can help you to make a quick PWM with your cRIO.
Let me know if you have more doubts
See you!
06-01-2012 03:15 PM
Hi
1. I am using oscilloscope to measure the output frequency.
2. The vi I posted didn't have enough comments to explain clearly.
80*duty ratio gives number of ticks the PWM is supposed to be in high state. So the output stays in high state for 80*dutyratio.
Then the logic is toggled. Now it stays in low state for 80*(1- duty ratio) ticks.
3. It is possible to generate 500kHz PWM signal. The while --3 in the vi generates 500kHz PWM signal.
As suggested by you previously, I am using local variables in single frame to transfer the data between while loops. It works fine. I able to generate 500kHz signal with variable duty ratio.
Thanks once again.
Deepti