I set the PWM frequency on MEGA 2560 like this:

  TCCR2A = 0;           
  TCCR2B = 0;           
  TCNT2  = 0;          

  TCCR2A = _BV(COM2A1)  
           | _BV(COM2B1)  
           | _BV(WGM20);  
     TCCR2B = (TCCR2B & 0b11111000) | 0x02; 

it works good, now I want to use timer1 on PWM and I changed the code like follow but no work:

TCCR1A = 0;           
  TCCR1B = 0;        
  TCNT1  = 0;          

  TCCR1A = _BV(COM1A1)  
           | _BV(COM1B1)  
           | _BV(WGM10);  

  TCCR1B = (TCCR1B & 0b11111000) | 0x02;

What's wrong with the changes?

I added 'TOP = ICR1', and when I tested, the ICR1's value effected both the PWM's frequency and duty cycle, how to avoid ICR1 effect dutu cycle?

  • what is your question? ..... what does this mean? but no work ................ are the two timers interchangeable? – jsotola Feb 2 at 1:53
  • I don't know much, I just mechanically changed 2 as 1 relatively. – laoadam Feb 2 at 1:57
  • Thank you jsotola. I'm using a pair RC remote control module to test some thing, when I set Timer2 on MEGA 2560 , the communication is OK. It is no communication when I modified the timer set from timer2 to timer1. – laoadam Feb 3 at 2:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.