Go Down

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

Burak93

Does anyone know if this library broke on arduino 1.6?

I've used this library for outputting 4 PWM signals for my custom aquarium LEDs, it worked fine for over a year.
(running on an arduino mega2560 with a WizNet 5500 ethernet board on top)
Now I wanted to make some changes, recompiled the code using the latest arduino libraries on Arch linux and it simply doesn't work anymore. No errors, but only pin 11 seems to work (but not properly), pins 5 / 6 and 44 simply give no signal as far as I can tell.
Using analogWrite instead of pwmWriteHR turns on the LEDs without problems.

Does anyone have any clue as to what the cause might be?

Wouter
Hello Wouter,
did you solce your problem? i have also the same problem with the library, it only works for pin 11 and 12 but i need one more pwm output. I wrote a simple code to test it and measured the output with oscilloscope.


Code:

#include <PWM.h>

int led = 11;                // the pin that the LED is attached to

int32_t frequency = 100; //frequency (in Hz)

void setup()
{
  InitTimersSafe();

  //sets the frequency for the specified pin
  bool success = SetPinFrequencySafe(led, frequency);

  if (success) {
    pinMode(13, OUTPUT);
    digitalWrite(13, HIGH);
  }
  pwmWrite(led, 0);
  delay(2);
  SetPinFrequencySafe(led, frequency);
  pwmWrite(led, 127);

}

void loop()
{

}

raschemmel

#121
Apr 22, 2016, 03:02 am Last Edit: Apr 22, 2016, 04:39 am by raschemmel
Does anyone know which Reply# in this thread would have a working code example of how to get  a PWM frequency of 10 khz ? All I need is a simple pot => analog input A0 that converts that to duty cycle at 10 khz.
Thanks
I installed the library but not sure how to use it and this thread is really long.

Nevermind. I found one here

Code: [Select]
  #include <PWM.h>
int32_t frequency = 10000; // frequency (in Hz)
 int sensorValue =0;

void setup()
{
  // put your setup code here, to run once:
  InitTimersSafe();
  bool success = SetPinFrequencySafe(9, frequency);
  if(success) {
    pinMode(13,OUTPUT);
    digitalWrite(13,HIGH);
   }
 }

void loop()
   {
    // put your main code here, to run repeatedly:
    int sensorValue = analogRead(A0);
    pwmWrite(9,sensorValue/4);
    delay(30);
    }
Arduino UNOs, Pro-Minis, ATMega328, ATtiny85, LCDs, MCP4162, keypads,<br />DS18B20s,74c922,nRF24L01, RS232, SD card, RC fixed wing, quadcopter

adityan1991

How can I generate 1 MHz signal with this function??

I'm a novice .. Pls Help.

raschemmel

I don't know. Did you try it (try changing the frequency to 1000000?)
Arduino UNOs, Pro-Minis, ATMega328, ATtiny85, LCDs, MCP4162, keypads,<br />DS18B20s,74c922,nRF24L01, RS232, SD card, RC fixed wing, quadcopter

68tjs

#124
Apr 30, 2016, 10:23 am Last Edit: Apr 30, 2016, 10:25 am by 68tjs
Do you thinks it is possible to generate a 1MHz PWM signal with a 16 MHz system frequency ?
What is the result of 16 MHz divide by 256 ?

You should have a look on 328p (or 2560) datasheet !
You will found PWM frequency formula.

raschemmel

#125
May 05, 2016, 07:15 am Last Edit: May 05, 2016, 03:19 pm by raschemmel
Quote
Hello everyone. I am very new to Arduino, so please go easy on me if this is stupid question. I have loaded the sketch and it is working flawlessly for me. The only thing i would like to change is being able to very the frequency using a pot. I don't have to generate a specific frequency, I just need a linear signal from 10Hz to 200Hz, that i can also vary to Duty Cycle. I have a couple other questions, but I'll tackle them one at a time. Thank you in advance for a great resource and any help you can offer.
I could tell you if you start your post. I can't tell you here because your question is not relevant to THIS post. This post is the PWM Library and the frequency is set ONE TIME in SETUP, so you can't change it with a pot.

Start your own post. You can't post on Reply#125 of someone else's post to ask a totally different question.  That is called POST HIJACKING . (which is a violation of forum policy)

DELETE YOUR POST BY CLICKING ON THE '"More" link in the lower right and select REMOVE.

If you don't , the Global Moderator will.

Then choose a forum Topic section and start a topic to ask your question.
Arduino UNOs, Pro-Minis, ATMega328, ATtiny85, LCDs, MCP4162, keypads,<br />DS18B20s,74c922,nRF24L01, RS232, SD card, RC fixed wing, quadcopter

meninas92

Hi i have tried to contact the supporter of the library "runnerup". i have some minor fixes to the library i have created a zip compatible with newer versions of arduino. does anyone knows how to contact runnerup?

raschemmel

Arduino UNOs, Pro-Minis, ATMega328, ATtiny85, LCDs, MCP4162, keypads,<br />DS18B20s,74c922,nRF24L01, RS232, SD card, RC fixed wing, quadcopter

junktronix

I'm curious what you fixed.  I've noticed that occasionally the PWM doesn't start immediately.  The PWM output will be high or low for 5-10mS before the pulses start.

Hi i have tried to contact the supporter of the library "runnerup". i have some minor fixes to the library i have created a zip compatible with newer versions of arduino. does anyone knows how to contact runnerup?

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy