ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

LabVIEW Interface for Arduino Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

change PWM frequency

Hello everybody,

i've got a short question:

Is it possible to change the PWM frequency of the PWM pins out of labview? Or can I change the frequencies with an command in the LVIFA_base.pde (similar as described here:http://www.arduino.cc/playground/Main/TimerPWMCheatsheet )?

If it is possible. How can I do it.

0 Kudos
Message 1 of 7
(11,140 Views)

After playing around I found that it's possible to include the commands from http://www.arduino.cc/playground/Main/TimerPWMCheatsheet in LVIFA_base.pde . I placed them in the void setup() part under // Place your custom setup code here . Until now I don't receive timing problems, but I don't know whether there is a function in the arduino labview toolkit, that uses millis or delay on the arduino.

I am still interested in a way to set the PWM frequency out of labview.

0 Kudos
Message 2 of 7
(7,084 Views)

arzt2283,

You can use the same command but inside the case struture in the LabVIEWInterface.pde file.  Then make a corresponding VI to call in LabVIEW.  Check out how the digital write VI and firmware work for a simple example.

-Sam K

LIFA Developer

0 Kudos
Message 3 of 7
(7,084 Views)

Hi Sammy_K,

Your last comment was really useful. By modifying the LabVIEWInterface.pde code it is possible to integrate the PWM frequency modification, so the frequency can be controlled directly from Labview. (http://forum.arduino.cc/index.php/topic,117425.0.html)

Regards Valentin

0 Kudos
Message 4 of 7
(7,084 Views)

can you show your code and block?

0 Kudos
Message 5 of 7
(7,084 Views)

First you have to add PWM library (first file). Check if its working (second file).

The third file is the modified LIFA_Base. If you open it on LIFA_Base page #include <PWM.h> and InitTimersSafe(); was added.

On page LabVIEWInterface #include <PWM.h> and at Low Level - PWM Commands:

    if (command[2]==7)

   {

     SetPinFrequencySafe(command[2], command[3]); // this has to be called back for freq modulation

   analogWrite(command[2],170);

   }

   else

    {

      analogWrite(command[2], command[3]);

    }

If you call pin 7, the duty cycle value will define the frequency, duty cycle set to 170.

The fourth file is the VI.

Br, Valentin

0 Kudos
Message 6 of 7
(7,084 Views)

can you elaborate more on how to set prescalar setting to 31khz

 i tried it this way in vi , but i was not able to get a output from arduino nano 

0 Kudos
Message 7 of 7
(5,642 Views)