-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is this lbrary exact the same as the TimerOne library, but for TimerTwo? #3
Comments
Hi, yes my library is very simular to the Timer1. But Timer1 is a 16 Bit timer and Timer2 only 8 Bit. So the resolution is lower. But it should work. |
Ok.. I´m testing timerone and your´s timertwo together now.. In the timeone library there´s this function that enables output pwm on a timer 1 pin, for instance, a led on pin 9:
or with just the first two arguments, without period:
It actuallys outputs a pwm signal on a led attached to pin 9, for instance. But with yours, if I write the same code, but for timer2, like this:
or
I get nothing on the led, and with a scope I see no pwm on the pin 11.. why is that? What can I do so it outputs a pwm signal that I can use just like the timer one library? Can you help me out on this? Thanks! Here´s the complete code for timerone (pin9) that I want to use with timer two on pin 11#include <TimerOne.h> // https://github.com/PaulStoffregen/TimerOne // This example creates a PWM signal with a variable duty cycle. constexpr int fanPin = 9; // Uno Timer1 OC1A pin // Set the high frequency period and the minimum pulse float dutyCycle = 0; void loop(void) void updateSettings(void) {
} } |
Timer2 must be explicitly started with the API start(). Could you please try this? Seems to me there is a difference between Timer1 and Timer2. Timer1 is automatically started by calling initialize(). This is not really clear from the documentation. After analyzing the Timer1 example: start() is never called. In my example, however, it is. |
Hi! ok, I did like this, to make that code for both timers, and still the same result... the led on pin 11 never lits... void setup(void) { Timer2.init(basePeriod); Serial.begin(9600); ... inside the code: Timer1.setPeriod(myPeriod); Anything else I could try??? |
Ok this is strange. I will try it in the evening on the Arduino Board. As
far as I have more information. I will let you know.
Rimbaldo ***@***.***> schrieb am So., 25. Juni 2023, 14:13:
… Hi! ok, I did like this, to make that code for both timers, and still the
same result... the led on pin 11 never lits...
void setup(void) {
Timer1.initialize(basePeriod); // us
Timer2.init(basePeriod);
Timer2.start();
Timer2.enablePwm(TimerTwo::PWM_PIN_11, 127);
Serial.begin(9600);
}
... inside the code:
Timer1.setPeriod(myPeriod);
Timer1.pwm(ledPin9, (dutyCycle * 1023UL / 100));
Timer2.setPeriod(myPeriod);
Timer2.setPwmDuty(TimerTwo::PWM_PIN_11, (dutyCycle * 1023UL / 100));
Anything else I could try???
—
Reply to this email directly, view it on GitHub
<#3 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABG65UZSBS2DM5VBR5DHSOLXNATOXANCNFSM6AAAAAAYE6PP2M>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Ok Pin 11 is wrong. Pin 3 is correct. Fixed also some other things. This code with the updated Timer.h and Timer.cpp is now working on my board:
|
Hi! I'm driving a BLDC motor with 3 pwm pins. So I have to use Timer1 and Timer2 to adjust this pins at the same time. Is your library exactly the same as the TimerOne, library, adapted to the Timer2? I mean, Can I use the same functions for both? I noticed in your's there's a little difference on some names and commands... If I use both at the same time, with the right values, could I have the same output for Timer1 and Timer2 pins at the same frequencies, duties, at the same time?
The text was updated successfully, but these errors were encountered: