Go Down

Topic: 2 PWM outputs (Read 1 time) previous topic - next topic


Hello world,

I want 2 PWM outputs with a different period, adjustable on a analog input.
1 is OK i found in the examples and tutorials, and i'm using the timer1 library.
Now I want to have a second PWM output with a different period. If i'm going to study on timer2, or so, is that affecting any timing in the uno ??



With PWM, the usual important parameter is duty cycle, not frequency.
Can you explain why you need a different frequency?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.


For a machine i'm workig at I want to control a powersupply by a PWM signal of appr. 230Hz with a dutycycle of 10% - 90 %.
second I want to use the arduino to control a pulstrain with a variable duty cycle and a variable period. This is for scientific research. I do not know the reason but a scientist asked me to program it. I could use 2 aurduino's but that is to easy. I use Timer1 and i beleive there are three ! 


This is how I think you can get 230Hz PWM.  I'm fairly new, so someone please correct me if I'm wrong.

Using 8-bit timer/counter 2:
TOP of 136
Prescaler of 256
Fast PWM mode.  Set on compare match, clear when the timer is cleared.

You should get a PWM frequency of 229.7Hz or approximately 230Hz.  Perhaps you can change the PWM frequency on the fly by modifying TOP, but I've never tried that, and I can't see any practical purpose for changing the PWM frequency.


Yes I'm going to try something like that. But the question is does timer2 affect anything else?


My experience is that modifying Timer/Counter2 doesn't affect any other Arduino functionality.

Modifying 16-bit timer0 does affect some other Arduino functions though.  To quote another user who helped me in another topic;

If anything in your code depends on the standard Arduino setup of Timer 0, it won't work if you change the settings of Timer 0.  This includes the functions micros(), millis(), delay(), maybe others.

Go Up