I'm trying to use the analogWave library to output a square wave for a PWM signal to an electric motor driver. That seems to work fine.
The problem is that it seems to mess up the timer that is required for the millis() (and micros()) function call. millis() now returns a constant value. Is there any way to either tell the analogWave to use a different timer mechanism or to access a different timer to get a millisecond tick count from the arduino board?
Hey Stefan. Thanks for the input. The reason that I had tried the analogWave library was that I wanted a PWM frequency of around 15 - 20 kHz. Using the PWM described in the link you provided seems to do that without messing up the timer that supports the millis() call.
(I said "seems to do that" because I don't have an oscilloscope to verify the actual frequency, but my system works as expected.)
Stefan,
At your suggestion, I tried using pulseIn to measure the length of the high and low parts of the square wave when setting the frequency to 20 kHz. They always sum to 50 microsec at various duty cycles, so I was able to confirm the 20 kHz output frequency.
When running motors and I need a PWM, this is how I do it. (Done it)
Notice in the valueChange() function there is a setPercentage() call that's where you would put in your PWM value. The knob, in this example, is setting freq.