How do I change the frequency of the PWM function?
By default it is at 500Hz, I need to change it to 200Hz.
It does not look like the frequency control has been brought out as an input the the VI. I found this which explains the interworks of the PWM Set Frequency but I am not sure the exact context. Maybe this is used inside the PWM Set Duty Cycle VI? I have not looked at this on a system with LINX installed. https://www.labviewmakerhub.com/doku.php?id=learn:libraries:linx:spec:pwm_set_frequency
What device are you connecting to in which you are using the PWM on? If is is a Raspberry Pi you may want to check out the LINX Raspberry Pi Addons by MediaMongrels. It may have the functionality you are looking for.
I am using arduino UNO.
My application needs 200Hz.
I was using the Serial library, but it is very unstable and communication is dropping all the time.
With LINX it is very stable, but it doesn't have this function.
The NI Library for arduino also does not have this PWM frequency setting.
Here's this tip for NI to apply for this library.
Can we change this frequency (NI library)?
Hey, Rodrigo (Brasileiro?)
i don't the requirements for your application but i had to "build" an inverter to modulate motor frequency using PWM, however, i used combined the square wave function. which allows you to set desired frequency.
So i kind of made a workaround using square wave function to set frequency and PWM to set dutycycle.
Since for my application frequency was most important than dutycycle, it worked ok for a MVP.
Let us know if this helps
Hi jorgemondadori (sim, Brasileiro),
I had already done the test with this generator, but it didn't work as expected.
In my application I need to vary the duty cycle (5%, 10%, 25%, 50%, 75%, 100%).
In this case, how would I change the frequency by changing the bytes?
Could you prepare a step by step?
Hey, Rodrigo, just had a look at this topic recently.
It sounds like it is a internal AVR timer thing.
When you declare on arduino IDE the pins you can change such configuration. However you won't be able (as far as i understand) to change specifically to 200Hz. I measured the output of a pwm with an oscilloscope, and in fact it is not 500 Hz default, it is 490 Hz. The website i linked explains how to set Timers.
If you don`t need to chang you frequency during execution, you can modify the Linx firmware to set those different frequencies and pins.
Thanks Jorge for your help, but to apply the PWM I needed I applied the code below.
It worked very well, but I wanted to do this through LINX, as its serial communication is much more stable and robust.
In my LabVIEW code, serial communication with the arduino is blocking communication at all times (I have to close all of LabVIEW, disconnect the arduino and sometimes I needed to restart the PC), so I want to change the frequency to LINX.
How do I change the frequency from PWM to LINX?
How do I change your Byte Frame for this?
Rodrigo, i don't know how to do that since it is not implemented in LINX.
even if we could do that, you probably won't be able to achieve 200Hz, only step associated to timers.
with that in mind, it may be the reason why they did not implemented the library, because could impact on other functions.
with these in mind, let me ask you something:
The code you showed us, is the main funcionality of your application? You could send variable values using LINX by creating a CustomCommand and sending the value of delayMicroseconds.
do you mind explaining what are you trying to do instead of how are you trying to do?
this way we could evaluate your requirements and open other possibilities.
My application is simple, I have a Mosfet that I sometimes apply PWM at 75% and at other times 25% at 200Hz.
This mosfet controls a resistive load of 5A or 30A or 50A (depending on my application).
Yes, I could have done the same programming I did in arduino in LINX, applying delays, but as there was a ready-made PWM function I thought I could use it to reduce my code (without needing to create sub VIs).
And another, I was curious why this LINX PWM wouldn't let you change the frequency (everything has a reason), but you clarified this doubt for me.