1

I used the code from this project... to build an oscilloscope-like project. It worked fine with Uno and Nano.

Later I tried to do the same with a Mega, but I don't know what's wrong. It's not working! Maybe due to some pin or port number mismatch (I think so...). Because it has some low level code like:

------------------------------------------------------
// set up 8 MHz timer on pin 9    
pinMode (9, OUTPUT); 
// set up Timer 1    
TCCR1A = _BV (COM1A0);  // toggle OC1A on Compare Match    
TCCR1B = _BV(WGM12) | _BV(CS10);   // CTC, no prescaling    
OCR1A =  0;       // output every cycle    
---------------------------------------------------------

And like:

Data.Values[i]=PINC;

I have very little knowledge about these registers.

Please help me port this code to Mega and make it work...

2

There is some concept you would have to learn before you can go from Arduino Uno to Mega.
Because your project is designed to operate on Arduino Uno R3, the registers operations like below are specific to the microcontroller in Arduino Uno - in this case ATmega328P-PU - datasheet here TCCR1A = _BV (COM1A0); // toggle OC1A on Compare Match TCCR1B = _BV(WGM12) | _BV(CS10); // CTC, no prescaling OCR1A = 0;
You can find description of registers in mentioned datasheet in chapter 19. TC0 - 8-bit Timer/Counter0 with PWM
Now, you grab another datasheet - one which describes ATmega2560 (yes, this is microcontroller which is sitting in Arduino Mega), find corresponding pin (like OC1 in Uno - check the drawing below): Arduino Uno R3 and find proper pin and corresponding register from ATmega2560 datasheet. Take a look at the schematic picture first, select one of OCx pins and configure what is needed. Pins from Aruino Mega with OCR functionality:
Arduino Mega and
Ard Mega
You need to learn what registers are, and what they can do. Can be a little demanding task, but believe me - this will give you supernatural powers in microcontrollers world ;)

2
  • Thank you very much for giving some idea about the origin of the problem, and definitely I will work on that. But, time being, I have some time constraints on the project. So, can anybody tell me how to set that 8MHz timer on any of mega pins... Also please give me some information on 'PINC' – Thirumalesh Dec 26 '17 at 15:54
  • @Thirumalesh Please realize that this is not a free design house, homework-answering service or an on-line technical encyclopedia, copied out to you on demand. People will help you take the next step if your question shows that you've done as much as you possibly could on your own - which your post doesn't. – KIIV Dec 26 '17 at 19:36

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.