cancel
Showing results for 
Search instead for 
Did you mean: 

change PWM frequency

arzt2283
Member

change PWM frequency

Message contains a hyperlink

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.

6 REPLIES 6
arzt2283
Member

Re: change PWM frequency

Message contains a hyperlink

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.

Kristoff2
NI Employee (retired)

Re: change PWM frequency

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

valentinsoti
Member

Re: change PWM frequency

Message contains a hyperlink

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

DDnoob
Member

Re: change PWM frequency

can you show your code and block?

valentinsoti
Member

Re: change PWM frequency

Message contains an attachment

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

sunny_sensei
Member

Re: change PWM frequency

Message contains an attachment

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