Thanks for your reply. Sorry, I'm new Arduino user (-:
I assumed that it's the PWM library since the PWM function are not working while running the program
Could it be connect to the Java version on my PC?
The message that i get is:
[/
http://downloads.arduino.cc/packages/package_index.json file signature verification failed. File ignored.
java.lang.NullPointerException
java.lang.RuntimeException: java.lang.NullPointerException
at cc.arduino.contributions.libraries.ui.LibraryManagerUI.lambda$onUpdatePressed$0(LibraryManagerUI.java:212)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException
at cc.arduino.contributions.libraries.LibrariesIndexer.rescanLibraries(LibrariesIndexer.java:114)
at cc.arduino.contributions.libraries.LibrariesIndexer.setLibrariesFolders(LibrariesIndexer.java:106)
at processing.app.BaseNoGui.onBoardOrPortChange(BaseNoGui.java:665)
at processing.app.Base.onBoardOrPortChange(Base.java:1295)
at processing.app.Base$12.actionPerformed(Base.java:1522)
at processing.app.Base.filterVisibilityOfSubsequentBoardMenus(Base.java:1561)
at processing.app.Base.access$000(Base.java:82)
at processing.app.Base$11.actionPerformed(Base.java:1494)
at processing.app.Base.rebuildBoardsMenu(Base.java:1472)
at processing.app.Base$8.onIndexesUpdated(Base.java:1327)
at cc.arduino.contributions.libraries.ui.LibraryManagerUI.lambda$onUpdatePressed$0(LibraryManagerUI.java:210)
... 1 more
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at cc.arduino.contributions.libraries.LibrariesIndexer.rescanLibraries(LibrariesIndexer.java:114)
at cc.arduino.contributions.libraries.LibrariesIndexer.setLibrariesFolders(LibrariesIndexer.java:106)
at processing.app.BaseNoGui.onBoardOrPortChange(BaseNoGui.java:665)
at processing.app.Base.onBoardOrPortChange(Base.java:1295)
at processing.app.Base.openLibraryManager(Base.java:1346)
at processing.app.Base.lambda$rebuildImportMenu$2(Base.java:1060)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.AbstractButton.doClick(AbstractButton.java:376)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:833)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:877)
at java.awt.Component.processMouseEvent(Component.java:6533)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
at java.awt.Component.processEvent(Component.java:6298)
at java.awt.Container.processEvent(Container.java:2236)
at java.awt.Component.dispatchEventImpl(Component.java:4889)
at java.awt.Container.dispatchEventImpl(Container.java:2294)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4525)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)
at java.awt.Container.dispatchEventImpl(Container.java:2280)
at java.awt.Window.dispatchEventImpl(Window.java:2746)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.awt.EventQueue$4.run(EventQueue.java:729)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
]
Thanks,
Lior
Thanks, that's much better to be able to read the full error output in text. That is quite strange. I don't think it's related to your Java version but I'm not sure of the cause. Do you get that error only when you do Sketch > Include library > Manage libraries or do you also get it when you're trying to compile or upload your sketch?
will not cause any problems for compiling or uploading the sketch. If the code isn't working correctly that has nothing to do with that error. That error does indicate a problem with Boards Manager and possibly Library Manager this may cause you to be unable to use those features to get updatable boards/libraries notifications or install boards/libraries. Often it's possible to do those processes manually if needed so you may be able to just ignore that. I suspect it's some sort of a network issue. It's trying to verify the downloaded package index file and the verification is failing.
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.
I am using an Arduino Uno with this library. Does anyone know what causes these errors or how to fix them? Attached is an image showing the significant error periodically occurring at the beginning of the PWM signal of an output when viewed on a logic analyzer.
I have to make a project where PWM frequency should be around 8-9kHz on one pin and also servo library is involved. To test how PWM frequency library works with servo library I whipped together simple sketch with a few lines borrowed from examples. I used Arduino Nano.
When servo is attached to the pin 9 and SetPinFrequencySafe to pins 10 or 11, there is no PWM on these pins; servo works OK
When servo is attached to the pin 9 and SetPinFrequencySafe to pin 3, there is 9kHz PWM on pin 3, but when I turn the pot to change the duty cycle, the actual change happens with delay of 3-4 seconds, very weird indeed; servo works OK
So the question is, can PWM frequency library and servo library work reliably together and what pins should I use. I need 1 pin for PWM and 1 pin for servo.
Thank you beforehand,
Fred
Here is the code I used for testing
#include <PWM.h>
#include <Servo.h>
int32_t frequency = 9000; //frequency (in Hz)
int servoPin = 9;
Servo servo;
int angle = 0; // servo position in degrees
void setup()
{
//initialize all timers except for 0, to save time keeping functions
InitTimersSafe();
//sets the frequency for the specified pin
bool success = SetPinFrequencySafe(10, frequency);
//if the pin frequency was set successfully, turn pin 13 on
if(success) {
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
}
servo.attach(servoPin);
}
void loop()
{
int sensorValue = analogRead(A0);
pwmWrite (10, sensorValue / 4);
delay(30);
// scan from 0 to 180 degrees
for(angle = 0; angle < 180; angle++)
{
servo.write(angle);
delay(15);
}
// now scan back from 180 to 0 degrees
for(angle = 180; angle > 0; angle--)
{
servo.write(angle);
delay(15);
}
}
Please Help! I got the code below to work. I sent the PWM signal into Motor Driver BTS7960 43A. The motor speeds up and slows down as expected. But I want to control the DUTY CYCLE to change speed NOT the frequency. PWM Noise must not be heard so I have set the PWM frequency to 21,000hz.
Thanks
Mimics the fade example but with an extra parameter for frequency. It should dim but with a flicker
because the frequency has been set low enough for the human eye to detect. This flicker is easiest to see when
the LED is moving with respect to the eye and when it is between about 20% - 60% brighness. The library
allows for a frequency range from 1Hz - 2MHz on 16 bit timers and 31Hz - 2 MHz on 8 bit timers. When
SetPinFrequency()/SetPinFrequencySafe() is called, a bool is returned which can be tested to verify the
frequency was actually changed.
This example runs on mega and uno.
*/
#include <PWM.h>
//use pin 11 on the Mega instead, otherwise there is a frequency cap at 31 Hz
int led = 9; // the pin that the LED is attached to
int brightness = 0; // how bright the LED is
int fadeAmount = 5; // how many points to fade the LED by
int32_t frequency = 35; //frequency (in Hz)
void setup()
{
//initialize all timers except for 0, to save time keeping functions
InitTimersSafe();
//sets the frequency for the specified pin
bool success = SetPinFrequencySafe(led, frequency);
//if the pin frequency was set successfully, turn pin 13 on
if(success) {
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
}
}
void loop()
{
//use this functions instead of analogWrite on 'initialized' pins
pwmWrite(led, brightness);
hi,
I have read every post of every page but can not able to compile library with ide 1.8
getting, 'InitTimersSafe' was not declared in this scope
can someone run it in latest ides ?
Hi,
I'm seeing strange behavior of the pwmWriteHR() function on a Mega (not an official Arduino one). I'm not 100% what the board model is. It has an ATmega1280 processor though.
With attached code I see that pin 3 is getting the PWM set for pin 2 and pin 8 gets the output set for pin 7. Though I have to set a PWM value for 3 and 8 or no output will be given. So setting a value for a pin enables output but it gets the value set for the previous pin.
When I use analogWrite() I'm seeing normal behavior.
Arduino IDE 1.8.1 on Win10.
Is it my code or a library bug?
#include <PWM.h>
int led = 11;
void setup() {
Serial.begin(115200);
InitTimersSafe(); //initialize all timers except for 0, to save time keeping functions
//SetPinFrequency(led, 15625); //setting the frequency
SetPinFrequency(2, 31250);
SetPinFrequency(3, 31250);
SetPinFrequency(5, 31250);
SetPinFrequency(6, 31250);
SetPinFrequency(7, 31250);
SetPinFrequency(8, 31250);
Serial.println("TIMER1");
uint16_t frequency = Timer1_GetFrequency();
uint16_t decimalResolution = Timer1_GetTop() + 1;
uint16_t binaryResolution = GetPinResolution(led); //this number will be inaccurately low because the float is being truncated to a int
char strOut[75];
sprintf(strOut, "Frequency: %u Hz\r\n Number of Possible Duties: %u\r\n Resolution: %u bit\r\n", frequency, decimalResolution, binaryResolution );
Serial.println(strOut);
Serial.println("TIMER2");
frequency = Timer2_GetFrequency();
decimalResolution = Timer2_GetTop() + 1;
binaryResolution = GetPinResolution(led); //this number will be inaccurately low because the float is being truncated to a int
strOut[75];
sprintf(strOut, "Frequency: %u Hz\r\n Number of Possible Duties: %u\r\n Resolution: %u bit\r\n", frequency, decimalResolution, binaryResolution );
Serial.println(strOut);
Serial.println("TIMER3");
frequency = Timer3_GetFrequency();
decimalResolution = Timer3_GetTop() + 1;
binaryResolution = GetPinResolution(led); //this number will be inaccurately low because the float is being truncated to a int
strOut[75];
sprintf(strOut, "Frequency: %u Hz\r\n Number of Possible Duties: %u\r\n Resolution: %u bit\r\n", frequency, decimalResolution, binaryResolution );
Serial.println(strOut);
Serial.println("TIMER4");
frequency = Timer4_GetFrequency();
decimalResolution = Timer4_GetTop() + 1;
binaryResolution = GetPinResolution(led); //this number will be inaccurately low because the float is being truncated to a int
strOut[75];
sprintf(strOut, "Frequency: %u Hz\r\n Number of Possible Duties: %u\r\n Resolution: %u bit\r\n", frequency, decimalResolution, binaryResolution );
Serial.println(strOut);
}
unsigned int value = 0;
int value2 = 0;
int value3 = 0;
int dir = 0;
void loop() {
pwmWriteHR(2, 32000); // ?
pwmWriteHR(3, 0); // ?
pwmWriteHR(7, 5000);
pwmWriteHR(8, value);
value = (value + 10) % 65536;
value2 = (value2 + 5) % 65536;
//delay(1);
}
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 :
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.
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)?
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:
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.
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.