0

Following is the code block from my script. It uses timer1. Why it is not compatible with Arduino Mega?

TCCR1A = theTCCR1A; // 0b10000010;
  /*10 clear on match, set at BOTTOM for compA.
   00 compB disconected initially, toggled later to clear on match, set at BOTTOM.
   00
   10 WGM1 1:0 for waveform 15.
   */
  TCCR1B = 0b00011001;
  /*000
   11 WGM1 3:2 for waveform 15.
   001 no prescale on the counter.
   */
  TIMSK1 = 0b00000001;
  /*0000000
   1 TOV1 Flag interrupt enable.
   */
  sei();             // Enable global interrupts.
  // Set outputs pins.
  DDRB   = 0b00000110; // Set PB1 and PB2 as outputs.
  pinMode(13, OUTPUT); // Set trigger pin to output

migrated from stackoverflow.com Nov 26 '18 at 17:21

This question came from our site for professional and enthusiast programmers.

  • Here I set pb1 and pb2 as output. But they don't get high or low as per my code. It works well with Arduino uno – Vivek Vijayan Nov 20 '18 at 17:17
  • 2
    Remember that comments are not part of the Q&A. The problem you are having should be in the question as an edit. But, really, you ought to just research this on the specific SE I mentioned. – user15483 Nov 20 '18 at 17:29
0

It's not working because code you write is code that will work only on ATmega328. Every ATmega328 chip will run this code without any problem. If you want that Mega does same task as Uno, then you have to rewrite whole code and use Arduino functions(such as pinMode, digitalRead etc..) or read ATmega2560 datasheet and use ATmega2560 registers. Also Search for ATmega2560 pin layout, you'll need it if you want use registers.

  • 1
    pinMode and digitalRead are not AVR functions. They are Arduino functions. – gre_gor Nov 21 '18 at 16:47

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.