Go Down

Topic: PWM frequency library (Read 237274 times) previous topic - next topic

dtr

My problem posted just above is solved by texmit's fix earlier in this thread: http://forum.arduino.cc/index.php?topic=117425.msg2854538#msg2854538

That fix was posted almost a year ago. Too bad the library owner seems to have orphaned it. It's a mighty useful one.

karlinbcn

Hi.
First of all please accept my apologies if I'm not able to explain my doubts in a right way. I'm pretty new to arduino and PWM is hard to understand for me.

First:
Is it possible with this library to generate fractional frequencies? I mean 5.2Hz 34.23Hz and so on.
I ask this because I see in the examples that is always an integer, in fact defined as int32_t

Second:
I don't understand how the instructions works...
SetPinFrequencySafe(led, frequency); Set Led Pin to frequency Hz
Then if success we turn the pin ON and HIGH... At this moment is the signal in the pin?

In  pwmWrite(led, brightness); What is brightness, is it not the frequency? Is it the duty cycle?

Third:
To change the frequency in running time is SetPinFrequencySafe needed or pwmWrite can do the job?



Thanks and best regards




EdwardHarry

#167
Jun 07, 2017, 10:23 am Last Edit: Jun 07, 2017, 10:33 am by EdwardHarry
Dear Brothers, firstly sorry for bad english, my arduino is Arduino MEGA 2560, i want to learn how to change frequency and search the library for it, and find the google code link below :

https://code.google.com/p/arduino-pwm-frequency-library/downloads/list

and downloaded the  5th Version of it >> unzip it in the arduino.ide library on my computer, im sure that i follow this step of adding library :

https://www.arduino.cc/en/guide/libraries

btw my arduino.ide version is 1.8.2

why i cannot compile or even upload the example program ?
it said :

Arduino: 1.8.2 (Windows Store 1.8.3.0) (Windows 10), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

C:\Users\*****\Arduino\sketch_jun07a\sketch_jun07a.ino:1:17: fatal error: PWM.h: No such file or directory

 #include <PWM.h>

                 ^

compilation terminated.

exit status 1
Error compiling for board Arduino/Genuino Mega or Mega 2560.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.


my teacher said that i must search the library for arduino mega instead of arduino uno (?), is that right ? is there any solution ?

ballscrewbob

Your teacher is wrong i'm afraid as both the UNO and MEGA use similar AVR architecture.

There is a good comparison link HERE

Clearly The mega has more pins due to the difference in processor but the lib should still be capable of handling that aspect.
It may not be the answer you were looking for but its the one I am giving based on either experience, educated guess, google or the fact that you gave nothing to go with in the first place so I used my wonky crystal ball.

CrossRoads

More likely the library has been put in the wrong location.
Using <PWM.h> requires the files to be in the /libraries folder.
Using "PWM.h" requires the files to be in same folder as the sketch.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

oyakodon

Hi Everyone, I'm new here ;]

Just wanted to say that this is an excellent PWM library and you guys are an awesome community!

I was wondering if anyone has tried using interrupts with this library? Let's say to just count the number of positive-edge pulses, then if a threshold is reached, stop the pwm?

Perhaps something along the lines of ISR(Timer1_compa_vect)?

Thanks,
Oyakodon

hugoabreu

Hi there,

Do you guys think that's possible to make a Frequency sweep with this librarie?

I was trying to build one, but I'm not sure of what I am missing, or if it is possible indeed.

please, If you want to take a look in my code bellow:

Code: [Select]

     FPWM = lgf[lx]; // This is the frequency of the PWM that im obtainning from another function.

     Init: InitTimersSafe();
   //sets the frequency for the specified pin
     success = SetPinFrequencySafe(SPWM, FPWM);
   //initialize all timers except for 0, to save time keeping functions
   
   if (success)   //here its where I would change my PWM frequency, if success.
   {
     cdelay = 1;
     VL = 0;
     sumvL = 0;
     if (readFlag == 1)
     {
       readFlag = 0;
     }
     while (VL <= cdelay)
     {
       //use this functions instead of analogWrite on 'initialized' pins
       pwmWrite(SPWM, LPWM);  // more precisely here.
       if (readFlag == 1)
       {
         sumvL = sumvL + analogVal;
         VL++;
         readFlag = 0;
       }
     }
     Vs[lx] = sumvL / VL;
   }
   else
   goto Init; //If success is not ok I would go back to InitTimersSafe() line.
   
Thank you for the attention and sorry for bad english.

ballscrewbob

It may not be the answer you were looking for but its the one I am giving based on either experience, educated guess, google or the fact that you gave nothing to go with in the first place so I used my wonky crystal ball.

hugoabreu

Hi.

This code I've put its inside the for loop. I didn't put everything couse, its too long and it doesn't matter.

My main question is if you think that we can change frequencies of PWM inside a for loop.

Ty

ballscrewbob

@hugoabreu

All code matters.
Without it nobody can tell if its good or bad or could be improved in any way or even broken into better segments etc.

And yes it should be possible to call a change inside a loop.
However you should realise that in doing so timers and interrupts could also be changed with unforeseen results unless you account for them.


It may not be the answer you were looking for but its the one I am giving based on either experience, educated guess, google or the fact that you gave nothing to go with in the first place so I used my wonky crystal ball.

Prithul

Thanks a lot. This library is AWESOME.

I was able to get 100kHz PWM with 16 bit resolution!

Go Up