In Mega 2560, I use timer 5 to control pin 45 and timer 1 to control pin 12 for the red led .
When I start the timer togher, pin 12 (timer 1 ) just bright ones and always off. On the other side, timer 5 (pin 45 ) is fine.
The tricky part is when I only using one timer, its work.
What is the problem here? Is the timer conflict to each other? Thanks for your help
#include <math.h>
void setup() {
// put your setup code here, to run once:
Serial.begin (19200);
Serial.setTimeout(40);
pinMode(11,OUTPUT);
pinMode(12, OUTPUT); // Pin 12 is the PWM output of Timer 1.
pinMode(45, OUTPUT);
pinMode(13,OUTPUT);
startTimer1();
startTimer5();
}
void loop() {
// put your main code here, to run repeatedly:
}
void startTimer1() { // Start timer 1 for X-dircection PWM steps.
TIMSK1 = bit (OCIE1A); // Enable ISR TIMER1_COMPA_vect
TCCR1A = _BV(COM1A1) | _BV(COM1B1) | _BV(WGM11) | _BV(WGM10);
TCCR1B = _BV(WGM12) | _BV(WGM13) | _BV(CS12) | _BV(CS10);
OCR1A = 31250; //
OCR1B = 15625 ; //
}
void startTimer5(){
TIMSK5 = bit (OCIE5A);
TCCR5A = _BV(COM5A1) | _BV(COM5B1) | _BV(WGM51) | _BV(WGM50);
TCCR5B = _BV(WGM52) | _BV(WGM53) | _BV(CS52) | _BV(CS50);
OCR5A = 15625;
OCR5B = 7800 ;
}