Hi people need some help here. Im using the AVR_PWM library to control a solenoid at a specific frequency of 340Hz. (TCU was controlling at this Freq)
I have got this to work so far via using fixed duty cycles (10, 20 , 30, 40 etc) using a push button. However i have progressed to where i am now using a 5k linear POT to control the duty cycle from 0 to 100%.
This works fine and i have achieved this but i get this problem where the duty cycle and frequency jump around and "spazz out" for lack of a better word. it can happen either when cycling the POT or even when the POT is not touched
This only happens when using the AVR_PWM library while controlling duty with a POT not when using a button for fixed duty cycles.
If AVR_PWM library is not used i can use a POT as intended but this will be a the stock Nano D9 pin frequency of 490Hz.
I have tried a combo of delays ranging from 50 to 150ms which don't seem to alleviate the issue
hi gilshultz i did adjust and still got the problem. i also attached an led to the pin being tested and i can see the led flicker at all duty cycles but it is more noticeable at the lower duty cycles as im less blinded by the light.
tired led test with NO avr pwm library and of course no flicker. super weird
It is possible the background interrupts are causing problems. I have seen that a few times in the past. I am not familiar with the AVR_PWM library so I do not think I can be of any more help.
Check for bad connections to the pot, the analog input, or a noisy pot (quite common with cheap ones).
Print out analogRead values, and look for sudden large jumps, either with the pot stationary, wiggling the wiring, or while slowly turning the pot shaft.
MD_PWM library also generates a PWM signal on any AVR pin. You may be able to use this to isolate whether the problem is in the hardware or software. Start here if interested : PWM on any I/O Pin – Arduino++ (wordpress.com). I know it produces rock solid scope traces in my projects.
Just for the record the MD_PWM 300Hz limit is set in the header file so changing it to 330Hz would be no problem. The limit is a practical solution to the problem of excessive resource being devoted to processing interrupts and so it is defined as a constant value in the library, easily changed if needed.