How slower clock affects data from GPIO pins

:o :o

I purchased a cheap China Mega 2650. I did not realized the board was a copycat until found trouble with the W10 driver. I had to go toe a Chinese website to download the working USB driver.

The board main difference other that darker color and a red Pin13 light against a green light is that the clock has slower ratings. I have read that it is 14 MHz vs 16 used the original Mega. Please, correct me about the clock speeds.

How a slower clock impacts the reliability of the data? Will this have an impact on the data picked up by sensors during Digitalread or Analogread?

Please, comment.

Jose E. Calderon

jecalderon:
I purchased a cheap China Mega 2650. I did not realize this board was a copycat until I found trouble with the W10 driver. I had to go toe a Chinese website to download the working USB driver.

a driver downloaded from a Chinese web site… I would never do that… hope you are not doing your banking or important stuff on this PC…

jecalderon:
The board main difference other that darker color and a red Pin13 light against a green light is that the clock has slower ratings. I have read that it is 14 MHz vs 16 used the original Mega. Please, correct me about the clock speeds.

Yes the official Mega has a 16 MHz crystal oscillator

if you want to check the speed of your clone, you can run this small program - taken from that conversation (and curtesy of @nickgammon)

#include <avr/sleep.h>
#include <avr/wdt.h>

volatile bool wdtFired;

// watchdog interrupt
ISR (WDT_vect) 
{
   wdt_disable();  // disable watchdog
   wdtFired = true;
}  // end of WDT_vect
 
void setup () 
{ 
  noInterrupts ();           // timed sequence follows
  MCUSR = 0;     
  // allow changes, disable reset
  WDTCSR = bit (WDCE) | bit (WDE);
  // set interrupt mode and an interval 
  WDTCSR = bit (WDIE);    // set WDIE, and 16 ms seconds delay
  wdt_reset();  // pat the dog
  wdtFired = false;
  interrupts ();             

  unsigned long startTime = micros ();
  while (!wdtFired)
    { }  // wait for watchdog
  unsigned long endTime = micros ();

  Serial.begin (115200);
  Serial.println ();
  Serial.print (F("Time taken = "));
  Serial.println (endTime - startTime);
}

void loop ()  { }

this code is based on the idea that the watchdog timer is independent of processor speed and times how long it takes to wait for 16ms. if all is right, it should say something close to 16ms.

jecalderon:
How a slower clock impacts the reliability of the data? Will this have an impact on the data picked up by sensors during Digitalread or Analogread?

Please, comment.

Jose E. Calderon

that part is hardware related (reading registers) so would probably not matter much as long as the processor is used within specs (and 14Mhz does fit the spec of the ATmega 2560 (0.4 - 16MHz)). What would not work is all the timer dependant functions of the Arduino environment since they expect the F_CPU constant to help decide at which speed the board runs (you can select 8 or 16) - so all timing would be weird probably

You will want to set up a board profile for the clone. most of the board profile can copypasta from the official profile except in boards.txt where "mega.build.f_cpu=16000000L" changing this setting to match the actual frequency of your clock should correct all the timing based on f_cpu.

J-M-L:
a driver downloaded from a Chinese web site… I would never do that… hope you are not doing your banking or important stuff on this PC…

The official CH340 driver comes from a Chinese website.

sterretje: The official CH340 driver comes from a Chinese website.

there are others built from source code, reviewed and signed, for a small fee at least on mac coming from the Netherlands :)

Being a short flight from the source of all the clones (and originals as they come from Taiwan), I have several dozen of different flavours. Not one shows a crystal running at 16MHz, they all vary to a degree. The onus is on the developer to sort that out first and make corrections as necessary, which is why there is a variable that allows you to specify the frequency. You’ll note that the specification (default) is 16000000UL and not just 16. Most I’ve tested show 15880000 and using a correct factor of 0.9925 brings all timing together nicely.

Many of those crapola external resonators are spec'ed to +/-2%

So 15.88 is within spec.

I think the official boards are the same way - they also use those stupid resonators instead of a crystal. Don't get me started about the design decisions made on the official boards... They didn't even put holes to add a HC/49 crystal and caps (after removing the resonator) - you can hack one on (with a more expensive garbage-can crystal and some caps, and some very careful soldering), but it's a lot harder than it could have been, and making that option available would have literally cost nothing.

Instead of making your own board definition, just use MCUdude's MegaCore - it supports the 2560 and most other similar AVRs (the smaller versions, the 2561 and it's smaller versions, and a few other cheaper ones), and you just select the clock speed from a dropdown menu.

@DrAzzy - more info MCUdude's MegaCore please.

DKWatson: @DrAzzy - more info MCUdude's MegaCore please.

https://github.com/MCUdude/MegaCore

He also has MicroCore for t13, MiniCore for m328p and similar, and MightyCore for m1284p and similar. He is to atmega what I am to attiny.

That is also the first result on google when you search for mcudude megacore - I was sort of hoping I wouldn't have to come spoonfeed y'all when I was back at a real computer.

I just thought I'd be a newbie and get someone else to do all my research for me.

As I highlighted the text and right-clicked to copy, I could have selected Search Google instead, but it seemed much more fitting to copy and paste and then waste more time constructing the balance of the message. Then I could sit back and do nothing while somebody else .....

Enough. Thanks for the link!