When I measure the voltage of Pin 9 with a DMM, I get 2.5V on my Arduino Uno. On my Arduino Nano, I get 2.2V. The frequency of 30.64 Hz is correct, however.
I'm pretty positive that neither board is broken or damaged, because digitalWrite() can give me 5V.
int PWM_Pin_1 = 9;
int PWM_Pin_2 = 10;
void setup() {
// put your setup code here, to run once:
pinMode(PWM_Pin_1, OUTPUT);
pinMode(PWM_Pin_2, OUTPUT);
TCCR1B = TCCR1B & B11111000 | B00000101; //Change frequency of D9 and D10 to be 30.64 Hz.
}
void loop() {
// put your main code here, to run repeatedly:
analogWrite(PWM_Pin_1, 125);
analogWrite(PWM_Pin_2, 125);
}
You can't reliably measure a PWM signal with a DMM. A scope must be used for that.
PWM is a digital signal (not a varying voltage) that switches between the supply and ground of the processor. A DMM tries to average that to a voltage, and how it averages depends on the DMM.
An Uno uses a (backflow protection) mosfet to switch between USB supply and external supply (if used). Therefore VCC (5volt) of an Uno is closer to the USB supply voltage than a (classic) Nano, which uses a basic Schottky diode with a ~0.4volt drop for the same function.
Leo..
Try the code below, you should measure the same dc voltage on the PWM pin as you measure on the modules +5 volt pin.
PS: it is your original code with just the PWM value changed.
For any PWM output value, it should measure PWM / 255 * VCC
where VCC = supply voltage
int PWM_Pin_1 = 9;
int PWM_Pin_2 = 10;
void setup() {
// put your setup code here, to run once:
pinMode(PWM_Pin_1, OUTPUT);
pinMode(PWM_Pin_2, OUTPUT);
TCCR1B = TCCR1B & B11111000 | B00000101; //Change frequency of D9 and D10 to be 30.64 Hz.
}
void loop() {
// put your main code here, to run repeatedly:
analogWrite(PWM_Pin_1, 255);
analogWrite(PWM_Pin_2, 255);
}
So I was having trouble getting my scope to work properly so I switched my DMM to DC as @WattsThat recommended and it worked fine? Thank you!
Sorry if this is a dumb follow up, but my intention was to drive a device that requires an AC square wave to drive it. The device will get damaged if it gets a DC voltage for a long period of time. Will I be safe driving the device with this PWM method? I'm only wondering since the AC setting on the DMM didn't measure the voltage but the DC setting did.
PWM Is a unipolar signal with its output range between zero and VCC volts. True AC signals are bipolar with the range being equal positive and and negative voltage levels.
What is the device youāre driving? Does it need a true AC bipolar signal?
Before trying this PWM method, I tried just oscillating two digital Arduino pins. I got the same result, like around 2.2V which i could measure with the AC setting of my DMM, and that did not damage the device. However, it did not darken the device to it's max opacity.
So that's why I wanted to try this PWM method for more reliable results. So it's possible that it won't get damaged if I just PWM this device directly since just oscillating the pins didn't damage it, but I'm not sure.
That shutter is fine with PWM, just donāt allow the output to go any higher than required to make it fully dark, that should be around 200 counts on the analog output, according to Adafruit and never allow 255 as that is steady dc with no pulsing.
Why are you lowering the PWM frequency to 30 Hz? Thatās just slightly above where humans perceive flicker. Iām also not sure why two pins of PWM, you only need one, connecting the device between PWM and GND. If
Have you tried it at the default PWM frequency without a capacitor? If that does not work, Iād add a simple low pass r/c filter of 10k and 0.1uf.