0
\$\begingroup\$

can any body saying to me what is that the difference between a micro controller with 1 MHZ and 200 MHZ clock in a timer project or in a project that record sound by micro in a sdcard or in a servo motor project or in a counter project that use a laser and a sensor? surely clock is an important factor in a micro but where? please explain in a simple example. can i say that in program viewpoint clock is the rate of all program repeat and checking all 'if' and do all loops and...

\$\endgroup\$
  • 4
    \$\begingroup\$ It is important literally everywhere within the MCU. You could have easily answered your question in 10 seconds on Google - e.g. wiki page. \$\endgroup\$ – Tom Carpenter May 7 '17 at 18:54
  • \$\begingroup\$ @TomCarpenter thank you but not sufficient. \$\endgroup\$ – Ehsan F May 7 '17 at 19:01
  • \$\begingroup\$ You'll need to clarify your question then. It is really not clear what information you are looking for. Please try to explain what it is that you do/don't understand and what information you seek. \$\endgroup\$ – Tom Carpenter May 7 '17 at 19:03
  • \$\begingroup\$ @TomCarpenter for example in blink project or in a servo motor project never i don`t set clock of micro avr. please say a project that clock is important and why. \$\endgroup\$ – Ehsan F May 7 '17 at 19:14
  • \$\begingroup\$ Perhaps, @EhsanF you use C or other high-level languages, where you call a function something like "delay()", and pass to it a number of microseconds, or milliseconds. If you program at a more fundamental level, then you must configure counters yourself, and count clock cycles to do a similar delay. \$\endgroup\$ – glen_geek May 7 '17 at 19:20
2
\$\begingroup\$

In simple terms, you can think of the clock rate as the minimum time to execute a simple operation like 1+1 or i=0. So something like 1+10+2-100 might take around 4 clock cycles to complete. So a 1 Mhz clock rate will get you around 1,000,000 of these simple instructions per second and if your program's logic is simple then you will probably not need to use all of those calculations each second. On the other hand, the 200 Mhz clock rate will get you almost 200,000,000 instructions per-second. I'll let you think about how this works for the other examples but for the laser timer this will mean that you can count to much higher numbers in the 200 Mhz microcontroller under the same conditions which means you'll have a much better resolution of time. This can mean reacting to things faster or doing more math in the same amount of time.

The reality is more complex than this and modern compilers are excellent at making things more efficient so it can be hard to actually estimate by looking at your code how long something will take to run but this concept is generally good enough.

\$\endgroup\$
1
\$\begingroup\$

clock rates typically determine the processing power of your particular mcu.

however, in many applications, you may not need that much processing power. high clock rates can be a challenge also in producing slow timer outputs. or other considerations (like current consumption which tends to be higher at higher clock rates) may dominate.

quite often, I run my mcus at the lowest possible clock rate.

\$\endgroup\$
0
\$\begingroup\$

its like driving your car at 10 miles an hour or 100 miles an hour, how fast is the road going by, how fast is your odometer running.

it is like tempo in music, you can play the song fast or you can play it slow, but every note is positioned based on a time scale, then you adjust the time scale.

A 16 bit timer can count to 65536 right? If that timer runs at 1Mhz then the timer counts to 65536 in 65536/1000000 = 65.5ms, but if I were running at 100mhz then it would be 65536/100000000 = 655us for the same timer to roll over. If I had a 32 bit timer and set that timer to count down from 1000000-1 then at 1Mhz it would rollover and restart (if I set it to) every second. I could use that timer to tell me when to change the state of an led, so the led would be on for one second, then off for one second. Now if I keep everything else the same but change the clock to be 100mhz now the timer rolls over 100 times faster, the led instead of changing state every second changes state 100 times a second now we see a glow if anything we cant see it change state with our eyes.

\$\endgroup\$

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