int a=180;
int b=0;
int c=0;
void setup()
{
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(44,OUTPUT);
pinMode(45,OUTPUT);
pinMode(46,OUTPUT);
/* TCCR5A = _BV(COM5A1) | _BV(WGM50);
TCCR5B = _BV(WGM52) | _BV(CS52) | _BV(CS50); // Prescaler = 1024
OCR5A = 156; // 20 millisecond period
OCR2B = 8;
TCCR2A = _BV(COM2A1) | _BV(COM2B1) | _BV(WGM21) | _BV(WGM20);
TCCR2B = _BV(CS22);
//TCCR2B |= (1 << CS12) | (1 << CS10);
//TCCR2B = 0x05;
OCR2A = 156;
OCR2B = 8;
*/
//TCCR5B = 0;
//TCCR5A = 0;
// Set the clock prescale to 1
//TCCR4B |= (1<<CS10);
//TCCR5B = 0b11000101;
//TCCR5B = _BV(WGM52) | _BV(CS52) | _BV(CS50);
// Set TOP to 3999.
// Frequency is 16 MHz / (prescale * (TOP+1)) == 4 kHz.
//ICR5 = 310;
// Start at 50% Duty Cycle
//OCR5A = 8;
// Set mode to 14: FastPWM using ICR for TOP
//TCCR5A |= 1<<WGM41| (1<<COM5A1);
//TCCR5B |= (1<<WGM42| (1<<WGM43)) ;
// Select non-inverting FastPWM (higher numbers give higher duty cycle)
//TCCR5A |= (1<<COM5A1);
TCCR5B = 0;
TCCR5A = 0;
// Set the clock prescale to 1
//TCCR4B |= (1<<CS10);
TCCR5B = 0b11000101;
//TCCR5B = _BV(WGM52) | _BV(CS52) | _BV(CS50);
// Set TOP to 3999.
// Frequency is 16 MHz / (prescale * (TOP+1)) == 4 kHz.
ICR5 = 310;
// Start at 50% Duty Cycle
OCR5A = 8;
// Set mode to 14: FastPWM using ICR for TOP
TCCR5A |= 1<<WGM41;
TCCR5B |= (1<<WGM42| (1<<WGM43)) ;
// Select non-inverting FastPWM (higher numbers give higher duty cycle)
TCCR5A |= (1<<COM4A1);
TCCR4B = 0;
TCCR4A = 0;
TCCR4B = 0b11000101;
ICR4 = 310;
OCR4A = 8;
TCCR4A |= 1<<WGM41;
TCCR4B |= (1<<WGM42| (1<<WGM43)) ;
TCCR4A |= (1<<COM4A1);
TIMSK4 |= (1<<OCIE4A);
sei();
Serial.begin(9600);
}
void loop()
{
//for(int i=0;i<1;i=i+1){
/* OCR4A =10;
//delay(250);
//Serial.println(OCR4A);
//OCR4A=20;
//}
delay(100);
//for(int i=0;i<1;i=i+1){
OCR4A =22;
//delay(250);
//Serial.println(OCR4A);
//OCR4A=20;
// }
delay(100);
//TCCR5B |= 0b00000000;
//TCCR5B |= (1<<CS50)| (1<<CS51)| (1<<CS52);
//TCCR5B = 0b11000101;
*/
Serial.print("Counter Ticks = ");
Serial.println(c);//TCNT5
}
ISR(TIMER4_COMPA_vect) {
c=c+1;
b=b+1;
if(c>20){
OCR4A =38;
OCR5A =30;
c=0;
}
if(b>40){
OCR4A = 8;
OCR5A = 12;
b=0;
c=0;
}
}