LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Can anyone spot the error in this code?

On a PC, the code behaves as expected after removing the IO nodes.  Bob is referencing that your defualt value is 1, not 1500, as your front panel indicator shows for a range.  So, if you do not set this value before you start the FPGA VI, you should be running a loop every 1ms ideally.  You should set this to be the ideal default value, say 1500.

0 Kudos
Message 11 of 17
(1,559 Views)

Dawud,

     Yes, that's what I'm saying.  I also agree with Matthew, that's also what I said.

BS

Message 12 of 17
(1,544 Views)

What frequency are seeing at the two extremes?

 

0 Kudos
Message 13 of 17
(1,530 Views)

One other thing, you should set your datatypes to match. You have the timer configured to use a 32-bit counter, but your front panel control is 16-bit. Change the control representation or the counter size so there's no coercion necessary.

0 Kudos
Message 14 of 17
(1,525 Views)

So I saw you were still having trouble in the other thread - from looking at your code, I really can't see why you would be having any issues with outputting a PWM signal by toggling the output on one of the 9474 outputs.

 

However did you know that, when in Scan Engine mode, you can right click on the C Series module in your project, and there is a tab called 'specialty digital configuration' and it actually allows you to configure the outputs as a PWM signal directly? You specify the frequency, and can then vary the duty cycle:

2016-02-02_15-17-07.png

 

For PWM on FPGA, I usually do something similar to this:

FPGA PWM.png

 

Note that the floating point operations at the end are fairly resource intensive / slow (i.e. multiple clock cycles) - it's only really there to help you see the values. This method allows you to specify both the period and duty cycle (whereas your original code only allows you to set the frequency with a 50% duty period). I don't claim for it to be the most efficient/fastest way to implement PWM either - but it should be no problem for 2kHz PWM.

 

e.g. specifying an on time of 10uSec and an off time of 90uSec gives you a duty cycle of 10% and a frequency of 10kHz (1/100uS)


LabVIEW Champion, CLA, CLED, CTD
(blog)
Message 15 of 17
(1,450 Views)

Thanks Sam. Does that facility allow you to control the frequency in code?

 

I am controlling a motor so frequency controls speed and I need variable speed.

0 Kudos
Message 16 of 17
(1,422 Views)
Typically with PWM, you keep a fixed frequency and change the duty cycle - the options are configured on the module properties and it's Scan Engine so it might not be possible to change the configuration in real-time and it's only got a fixed number of options.

I'm not really a fan of the Scan Engine so rarely use it - go for the FPGA route I showed above and you shouldn't have any troubles - that will allow you to change the frequency and duty cycle.

LabVIEW Champion, CLA, CLED, CTD
(blog)
0 Kudos
Message 17 of 17
(1,384 Views)