Skip to main content
Arduino

Return to Answer

Applied some formatting (as a result the diff looks much more extensive than it really is - use view "side-by-side markdown" to compare). (its = possessive, it's = "it is" or "it has".) Copy edited (e.g. ref. <http://en.wikipedia.org/wiki/Hertz#SI_multiples>).
Source Link

The accepted answer of jfpoilpret is very well written, perfectly valid and in 99% of the cases I will do exactly what he explains. His solutions are well within your defined parameters, so they should work very well. But what is better than "very well"? Perfection! After all, the question is about generating a exact value. As said close enough is good in most cases (arguably all), and even when dealing with something as a clocks when 1 second need to be 1 second, you still have to suffer inherited parts imperfections.

What I will suggest is not always possible. In some cases, it's possible, but with much more hassle and effort than this case. Is it worthy depend on case bya case-by-case basis. My goal is mostly to show a alternative for future refferences,references that is better in somewhat fringe cases. This is written with novice Arduino users in mind, that don't have extensive experience in electronics.

For more advanced people this probably will look too verbose and dumbed down. But I believe that, those same people probably already know it and don't need this answer. This is also aplicableapplicable to every MCUmicrocontroller and every manufactorermanufacturer and architecture. But for other MCU'smicrocontrollers you will need to consult the correct datasheet to find out propperproper registers and prescale names and values.

In your case, you need a specific frequency and the nice thing about it, is that exactly 56 Khz kHz actually can be achieved very easy (not counting practical imperfections of the parts). So this is also a perfect example case.

Generating a signal depends on the timers and clock source of MCUthe microcontroller, as explained well by jfpoilpret. His answer dealdeals with the problem of one point of view only and that is fiddling with timers. But you can fiddle with the clock source too, or even better with both for synergy and awesome results. By changing the parameters of the enviorenmentenvironment, in this case hacking the system and replacing the clock source, we can deal with a specific problem with much, much more ease and simplicity.

First to remind, because of toglingtoggling the pin state, you need to execute the ISR two times more than the signal frequency. This is 112 000,000 times per second. 56 000 56,000 and 16 000 000,000,000 don't add up very nicely as pointed out already. We need to change either the signal frequency or tact frequency. Let's deal for now with an immutable signal frequency and find a better clock speed.

It would be most strait-forwardstraightforward to choose a clock with some order of magnitude bigger than 56 kHz (or 112 kHz, but it is practicalypractically the same), as you only add zeros and this kind of math is simplest for most people. Unfortunately everything in this world is some kind of compromisscompromise with something. Not every value will work.

FirstThe first example is with a too low tact generator speed. If

If you choose a 56 000 hz,000 Hz clock you won't be able to do anything as you will need to call the ISR every cycle and can't do anything else. It is utterly useless. If you choose 10 times faster speed (560 Khz kHz), you will have 9 (10 cycles for the timer to reach it'sits max value - 1one cycle to call ISR function) mcumicrocontroller cycles to do your work and this quite possible can be not enough. You simply often need more computational power.

If you choose a value far too great at other hand, asas 56 Mhz MHz the MCUmicrocontroller simply can't work with it. It is way too fast. So, simply choosing bigestthe biggest value in the shop won't cut it either.

Original Arduino UNOUno R3 have a stock clock at 16 MhzMHz, so anything slower that that is garanteedguaranteed to work. NextThe next value that is an order of magnitutemagnitude bigger than 56 and lower than 16 Mhz MHz is 5,6 Mhz (5.6 Mhz for USA citizens) MHz. This will lead to be able to call the ISR every 50 cycles and will create the perfect 112 000 hz,000 Hz timer frequency. And your signal will be exactly 56 Khz kHz. You will have 49 MCU cycles to execute your program between ISR calls, but it is still around 1/3 of the speed of the original clock. One can use 112 as base and use a 11,.2 Mhz MHz clock and this will give a about 2/3 of the stock 16 Mhz MHz resonator. The ISR function will be called every 100 cycles and still generating a perfect 56 Khz kHz signal.

However two major problems exist with thisthese values.

  • FirstThe first problem severity dependseverely depends on your needs: You sacrifice about 1/3 (with 11,.2 Mhz MHz) of your maximum computational power to get the exact signal frequency that use an easy to find-to-find register value ( OCROCR iirc). You may be fine with it or you may not.

  • SecondThe second problem is a hard showstopper: ThisIt is very easy to find values, but very often they simply do not exist as manufactoreda manufactured clock source. This is FarnellFarnell's resonator web page , that simply lack both 5,.6 Mhz MHz and 11,.2 Mhz MHz.

To circumvent this we can look at available resonator values and find out something else that can be used to generate exactly desired values. If we divide 56 by 4 we get 14 and luckily there is a 14 MhzMHz resonator. This provideprovides us with much higher speed and more power and with equally easy to find register value. To call the ISR 112 000,000 times per second we need to put value of decimal 124 or heximalhexadecimal 0x7C in the OCR register, so with counting 124 cycles + 1 for calling the ISR, we get our desired perfect value.

  1. ISR - Interrupt Service Routine (this is the code that is executed only on generated interrupts)

    ISR - interrupt service routine (this is the code that is executed only on generated interrupts)

  2. How big your program can be, depend ot the memory size! Nothing to do with clock speed. Nothing to do with how often you call ISR.

    How big your program can be depends on the memory size! It has nothing to do with the clock speed and has nothing to do with how often you call the ISR.

  3. When MCU start with program command a counter is incremented, if interrupt is generated ,the ISR is called and this value is stored in special register. When ISR code complete, value of the program counter is restered from this special register and the program continue from where it was interrupted as if it was never happend.

    When the microcontroller starts with program command a counter is incremented. If an interrupt is generated, the ISR is called and this value is stored in a special register. When the ISR code completes, the value of the program counter is restored from this special register and the program continues from where it was interrupted as if it had never happened.

    I will give a extremly dumbed down example, if you a purist, I warn you: Nose and eye bleeding can occur.

    I will give an extremely dumbed-down example. If you are a purist, I warn you: Nose and eye bleeding can occur.

    Imagine you have to walk from somewhere to somewhere. The step by step route instructions are your main program and it's commands. How fast you walk or run, depend on your "clock speed", but not on the route instructions (30 steps forward, 1 turn 90 grad. left, 10 steps forward, 45 grad. right, etc.) They are always the same. Now imagine a little kid or greedy corrupt local politician untie your shoes now and then. This is the event that generate a interrupt. Then you halt after your last step, kneel and tie your shoe again. This is your ISR program. Then you continue from the place you have stopped, you do not start from beginning. When you walk without a care in the world and with all the time, you don't care even if you have to tie your shoe every other step. If you however do it with time constrains, like running in 100 metters on olimpics (or running from hungry flesh eating predator), stopping and tieing your shoes can have dire consequences. The same is with MCU's. Even if you execute only 1 line of code your program will continue, albeit slow. If you don't care about speed at all, it won't be a problem. If you have to do some time related, like using other timer dependant actions, interferance can be very unwanted and problematic.

    Imagine you have to walk from somewhere to somewhere. The step-by-step route instructions are your main program and its commands. How fast you walk or run, depends on your "clock speed", but not on the route instructions (30 steps forward, 1 turn 90 grad. left, 10 steps forward, 45 grad. right, etc.) They are always the same. Now imagine a little kid or a greedy corrupt local politician untie your shoes now and then. This is the event that generates an interrupt. Then you halt after your last step, kneel and tie your shoe again. This is your ISR program.

    Then you continue from the place you have stopped; you do not start from beginning. When you walk without a care in the world and with all the time, you don't care even if you have to tie your shoe every other step. If you however do it with time constrains, like running in 100 meters on the Olympics (or running from a hungry flesh-eating predator), stopping and tieing your shoes can have dire consequences. The same is with microcontrollers. Even if you execute only one line of code your program will continue, albeit slow. If you don't care about speed at all, it won't be a problem. If you have to do some time related, like using other timer dependent actions, interference can be very unwanted and problematic.

  4. Less is more! Not always faster clock is better. Slower clocked devices use considerably less power. This can be cruicial point in battery operated device.

    Less is more! A faster clock is not always better. Slower clocked devices use considerably less power. This can be a crucial point in a battery-operated device.

  5. Needed cycles are derived from this formulae:

    The needed cycles are derived from this formulae:
    (clock speed / (prescaler value * needed ISR calling frequency)) - 1

    ( clock speed / (prescaler value * needed ISR calling frequency) ) - 1

The accepted answer of jfpoilpret is very well written, perfectly valid and in 99% of the cases I will do exactly what he explains. His solutions are well within your defined parameters, so they should work very well. But what is better than "very well"? Perfection! After all, question is about generating a exact value. As said close enough is good in most cases (arguably all), and even when dealing with something as a clocks when 1 second need to be 1 second, you still have to suffer inherited parts imperfections.

What I will suggest is not always possible. In some cases, it's possible but with much more hassle and effort than this case. Is it worthy depend on case by case basis. My goal is mostly to show a alternative for future refferences, that is better in somewhat fringe cases. This is written with novice Arduino users in mind, that don't have extensive experience in electronics. For more advanced people this probably will look too verbose and dumbed down. But I believe that, those same people probably already know it and don't need this answer. This is also aplicable to every MCU and every manufactorer and architecture. But for other MCU's you will need to consult the correct datasheet to find out propper registers and prescale names and values.

In your case, you need a specific frequency and the nice thing about it, is that exactly 56 Khz actually can be achieved very easy (not counting practical imperfections of the parts). So this is also a perfect example case.

Generating a signal depends on the timers and clock source of MCU, as explained well by jfpoilpret. His answer deal with the problem of one point of view only and that is fiddling with timers. But you can fiddle with clock source too, or even better with both for synergy and awesome results. By changing the parameters of the enviorenment, in this case hacking the system and replacing the clock source, we can deal with specific problem with much, much more ease and simplicity.

First to remind, because of togling the pin state, you need to execute ISR two times more than signal frequency. This is 112 000 times per second. 56 000 and 16 000 000 don't add up very nicely as pointed already. We need to change either the signal frequency or tact frequency. Let's deal for now with immutable signal frequency and find a better clock speed. It would be most strait-forward to choose a clock with some order of magnitude bigger than 56 (or 112 but is practicaly the same), as you only add zeros and this kind of math is simplest for most people. Unfortunately everything in this world is some kind of compromiss with something. Not every value will work.

First example is with too low tact generator speed. If you choose a 56 000 hz clock you won't be able to do anything as you will need to call the ISR every cycle and can't do anything else. It is utterly useless. If you choose 10 times faster speed (560 Khz), you will have 9 (10 cycles for timer to reach it's max value - 1 cycle to call ISR function) mcu cycles to do your work and this quite possible can be not enough. You simply often need more computational power.

If you choose value far too great at other hand, as 56 Mhz the MCU simply can't work with it. It is way too fast. So, simply choosing bigest value in the shop won't cut it either.

Original Arduino UNO R3 have a stock clock at 16 Mhz, so anything slower that that is garanteed to work. Next value that is order of magnitute bigger than 56 and lower than 16 Mhz is 5,6 Mhz (5.6 Mhz for USA citizens). This will lead to be able to call the ISR every 50 cycles and will create perfect 112 000 hz timer frequency. And your signal will be exactly 56 Khz. You will have 49 MCU cycles to execute your program between ISR calls, but it is still around 1/3 of the speed of the original clock. One can use 112 as base and use 11,2 Mhz clock and this will give a about 2/3 of the stock 16 Mhz resonator. ISR function will be called every 100 cycles and still generating perfect 56 Khz signal.

However two major problems exist with this values.

  • First problem severity depend on your needs: You sacrifice about 1/3 (with 11,2 Mhz) of your maximum computational power to get exact signal frequency that use easy to find register value ( OCR iirc). You may be fine with it or you may not.

  • Second problem is a hard showstopper: This very easy to find values, very often simply do not exist as manufactored clock source. This is Farnell resonator web page , that simply lack both 5,6 Mhz and 11,2 Mhz.

To circumvent this we can look at available resonator values and find out something else that can be used to generate exactly desired values. If we divide 56 by 4 we get 14 and luckily there is a 14 Mhz resonator. This provide us with much higher speed and more power and with equally easy to find register value. To call the ISR 112 000 times per second we need to put value of decimal 124 or heximal 0x7C in OCR register so with counting 124 cycles + 1 for calling ISR, we get our desired perfect value.

  1. ISR - Interrupt Service Routine (this is the code that is executed only on generated interrupts)
  2. How big your program can be, depend ot the memory size! Nothing to do with clock speed. Nothing to do with how often you call ISR.
  3. When MCU start with program command a counter is incremented, if interrupt is generated ,the ISR is called and this value is stored in special register. When ISR code complete, value of the program counter is restered from this special register and the program continue from where it was interrupted as if it was never happend.
    I will give a extremly dumbed down example, if you a purist, I warn you: Nose and eye bleeding can occur.
    Imagine you have to walk from somewhere to somewhere. The step by step route instructions are your main program and it's commands. How fast you walk or run, depend on your "clock speed", but not on the route instructions (30 steps forward, 1 turn 90 grad. left, 10 steps forward, 45 grad. right, etc.) They are always the same. Now imagine a little kid or greedy corrupt local politician untie your shoes now and then. This is the event that generate a interrupt. Then you halt after your last step, kneel and tie your shoe again. This is your ISR program. Then you continue from the place you have stopped, you do not start from beginning. When you walk without a care in the world and with all the time, you don't care even if you have to tie your shoe every other step. If you however do it with time constrains, like running in 100 metters on olimpics (or running from hungry flesh eating predator), stopping and tieing your shoes can have dire consequences. The same is with MCU's. Even if you execute only 1 line of code your program will continue, albeit slow. If you don't care about speed at all, it won't be a problem. If you have to do some time related, like using other timer dependant actions, interferance can be very unwanted and problematic.
  4. Less is more! Not always faster clock is better. Slower clocked devices use considerably less power. This can be cruicial point in battery operated device.
  5. Needed cycles are derived from this formulae:
    ( clock speed / (prescaler value * needed ISR calling frequency) ) - 1

The accepted answer of jfpoilpret is very well written, perfectly valid and in 99% of the cases I will do exactly what he explains. His solutions are well within your defined parameters, so they should work very well. But what is better than "very well"? Perfection! After all, the question is about generating a exact value. As said close enough is good in most cases (arguably all), and even when dealing with something as a clocks when 1 second need to be 1 second, you still have to suffer inherited parts imperfections.

What I will suggest is not always possible. In some cases, it's possible, but with much more hassle and effort than this case. Is it worthy depend on a case-by-case basis. My goal is mostly to show a alternative for future references that is better in somewhat fringe cases. This is written with novice Arduino users in mind that don't have extensive experience in electronics.

For more advanced people this probably will look too verbose and dumbed down. But I believe that, those same people probably already know it and don't need this answer. This is also applicable to every microcontroller and every manufacturer and architecture. But for other microcontrollers you will need to consult the correct datasheet to find out proper registers and prescale names and values.

In your case, you need a specific frequency and the nice thing about it, is that exactly 56 kHz actually can be achieved very easy (not counting practical imperfections of the parts). So this is also a perfect example case.

Generating a signal depends on the timers and clock source of the microcontroller, as explained well by jfpoilpret. His answer deals with the problem of one point of view only and that is fiddling with timers. But you can fiddle with the clock source too, or even better with both for synergy and awesome results. By changing the parameters of the environment, in this case hacking the system and replacing the clock source, we can deal with a specific problem with much, much more ease and simplicity.

First to remind, because of toggling the pin state, you need to execute the ISR two times more than the signal frequency. This is 112,000 times per second. 56,000 and 16,000,000 don't add up very nicely as pointed out already. We need to change either the signal frequency or tact frequency. Let's deal for now with an immutable signal frequency and find a better clock speed.

It would be most straightforward to choose a clock with some order of magnitude bigger than 56 kHz (or 112 kHz, but it is practically the same), as you only add zeros and this kind of math is simplest for most people. Unfortunately everything in this world is some kind of compromise with something. Not every value will work.

The first example is with a too low tact generator speed.

If you choose a 56,000 Hz clock you won't be able to do anything as you will need to call the ISR every cycle and can't do anything else. It is utterly useless. If you choose 10 times faster speed (560 kHz), you will have 9 (10 cycles for the timer to reach its max value - one cycle to call ISR function) microcontroller cycles to do your work and this quite possible can be not enough. You simply often need more computational power.

If you choose a value far too great at other hand, as 56 MHz the microcontroller simply can't work with it. It is way too fast. So, simply choosing the biggest value in the shop won't cut it either.

Original Arduino Uno R3 have a stock clock at 16 MHz, so anything slower that that is guaranteed to work. The next value that is an order of magnitude bigger than 56 and lower than 16 MHz is 5.6 MHz. This will lead to be able to call the ISR every 50 cycles and will create the perfect 112,000 Hz timer frequency. And your signal will be exactly 56 kHz. You will have 49 MCU cycles to execute your program between ISR calls, but it is still around 1/3 of the speed of the original clock. One can use 112 as base and use a 11.2 MHz clock and this will give a about 2/3 of the stock 16 MHz resonator. The ISR function will be called every 100 cycles and still generating a perfect 56 kHz signal.

However two major problems exist with these values.

  • The first problem severely depends on your needs: You sacrifice about 1/3 (with 11.2 MHz) of your maximum computational power to get the exact signal frequency that use an easy-to-find register value (OCR iirc). You may be fine with it or you may not.

  • The second problem is a hard showstopper: It is very easy to find values, but very often they simply do not exist as a manufactured clock source. This is Farnell's resonator web page that simply lack both 5.6 MHz and 11.2 MHz.

To circumvent this we can look at available resonator values and find out something else that can be used to generate exactly desired values. If we divide 56 by 4 we get 14 and luckily there is a 14 MHz resonator. This provides us with much higher speed and more power and with equally easy to find register value. To call the ISR 112,000 times per second we need to put value of decimal 124 or hexadecimal 0x7C in the OCR register, so with counting 124 cycles + 1 for calling the ISR, we get our desired perfect value.

  1. ISR - interrupt service routine (this is the code that is executed only on generated interrupts)

  2. How big your program can be depends on the memory size! It has nothing to do with the clock speed and has nothing to do with how often you call the ISR.

  3. When the microcontroller starts with program command a counter is incremented. If an interrupt is generated, the ISR is called and this value is stored in a special register. When the ISR code completes, the value of the program counter is restored from this special register and the program continues from where it was interrupted as if it had never happened.

    I will give an extremely dumbed-down example. If you are a purist, I warn you: Nose and eye bleeding can occur.

    Imagine you have to walk from somewhere to somewhere. The step-by-step route instructions are your main program and its commands. How fast you walk or run, depends on your "clock speed", but not on the route instructions (30 steps forward, 1 turn 90 grad. left, 10 steps forward, 45 grad. right, etc.) They are always the same. Now imagine a little kid or a greedy corrupt local politician untie your shoes now and then. This is the event that generates an interrupt. Then you halt after your last step, kneel and tie your shoe again. This is your ISR program.

    Then you continue from the place you have stopped; you do not start from beginning. When you walk without a care in the world and with all the time, you don't care even if you have to tie your shoe every other step. If you however do it with time constrains, like running in 100 meters on the Olympics (or running from a hungry flesh-eating predator), stopping and tieing your shoes can have dire consequences. The same is with microcontrollers. Even if you execute only one line of code your program will continue, albeit slow. If you don't care about speed at all, it won't be a problem. If you have to do some time related, like using other timer dependent actions, interference can be very unwanted and problematic.

  4. Less is more! A faster clock is not always better. Slower clocked devices use considerably less power. This can be a crucial point in a battery-operated device.

  5. The needed cycles are derived from this formulae:
    (clock speed / (prescaler value * needed ISR calling frequency)) - 1

Source Link
zzz
  • 21
  • 4

The accepted answer of jfpoilpret is very well written, perfectly valid and in 99% of the cases I will do exactly what he explains. His solutions are well within your defined parameters, so they should work very well. But what is better than "very well"? Perfection! After all, question is about generating a exact value. As said close enough is good in most cases (arguably all), and even when dealing with something as a clocks when 1 second need to be 1 second, you still have to suffer inherited parts imperfections.

What I will suggest is not always possible. In some cases, it's possible but with much more hassle and effort than this case. Is it worthy depend on case by case basis. My goal is mostly to show a alternative for future refferences, that is better in somewhat fringe cases. This is written with novice Arduino users in mind, that don't have extensive experience in electronics. For more advanced people this probably will look too verbose and dumbed down. But I believe that, those same people probably already know it and don't need this answer. This is also aplicable to every MCU and every manufactorer and architecture. But for other MCU's you will need to consult the correct datasheet to find out propper registers and prescale names and values.

In your case, you need a specific frequency and the nice thing about it, is that exactly 56 Khz actually can be achieved very easy (not counting practical imperfections of the parts). So this is also a perfect example case.

Generating a signal depends on the timers and clock source of MCU, as explained well by jfpoilpret. His answer deal with the problem of one point of view only and that is fiddling with timers. But you can fiddle with clock source too, or even better with both for synergy and awesome results. By changing the parameters of the enviorenment, in this case hacking the system and replacing the clock source, we can deal with specific problem with much, much more ease and simplicity.

First to remind, because of togling the pin state, you need to execute ISR two times more than signal frequency. This is 112 000 times per second. 56 000 and 16 000 000 don't add up very nicely as pointed already. We need to change either the signal frequency or tact frequency. Let's deal for now with immutable signal frequency and find a better clock speed. It would be most strait-forward to choose a clock with some order of magnitude bigger than 56 (or 112 but is practicaly the same), as you only add zeros and this kind of math is simplest for most people. Unfortunately everything in this world is some kind of compromiss with something. Not every value will work.

First example is with too low tact generator speed. If you choose a 56 000 hz clock you won't be able to do anything as you will need to call the ISR every cycle and can't do anything else. It is utterly useless. If you choose 10 times faster speed (560 Khz), you will have 9 (10 cycles for timer to reach it's max value - 1 cycle to call ISR function) mcu cycles to do your work and this quite possible can be not enough. You simply often need more computational power.

If you choose value far too great at other hand, as 56 Mhz the MCU simply can't work with it. It is way too fast. So, simply choosing bigest value in the shop won't cut it either.

Original Arduino UNO R3 have a stock clock at 16 Mhz, so anything slower that that is garanteed to work. Next value that is order of magnitute bigger than 56 and lower than 16 Mhz is 5,6 Mhz (5.6 Mhz for USA citizens). This will lead to be able to call the ISR every 50 cycles and will create perfect 112 000 hz timer frequency. And your signal will be exactly 56 Khz. You will have 49 MCU cycles to execute your program between ISR calls, but it is still around 1/3 of the speed of the original clock. One can use 112 as base and use 11,2 Mhz clock and this will give a about 2/3 of the stock 16 Mhz resonator. ISR function will be called every 100 cycles and still generating perfect 56 Khz signal.

However two major problems exist with this values.

  • First problem severity depend on your needs: You sacrifice about 1/3 (with 11,2 Mhz) of your maximum computational power to get exact signal frequency that use easy to find register value ( OCR iirc). You may be fine with it or you may not.

  • Second problem is a hard showstopper: This very easy to find values, very often simply do not exist as manufactored clock source. This is Farnell resonator web page, that simply lack both 5,6 Mhz and 11,2 Mhz.

To circumvent this we can look at available resonator values and find out something else that can be used to generate exactly desired values. If we divide 56 by 4 we get 14 and luckily there is a 14 Mhz resonator. This provide us with much higher speed and more power and with equally easy to find register value. To call the ISR 112 000 times per second we need to put value of decimal 124 or heximal 0x7C in OCR register so with counting 124 cycles + 1 for calling ISR, we get our desired perfect value.

N.B.

  1. ISR - Interrupt Service Routine (this is the code that is executed only on generated interrupts)
  2. How big your program can be, depend ot the memory size! Nothing to do with clock speed. Nothing to do with how often you call ISR.
  3. When MCU start with program command a counter is incremented, if interrupt is generated ,the ISR is called and this value is stored in special register. When ISR code complete, value of the program counter is restered from this special register and the program continue from where it was interrupted as if it was never happend.
    I will give a extremly dumbed down example, if you a purist, I warn you: Nose and eye bleeding can occur.
    Imagine you have to walk from somewhere to somewhere. The step by step route instructions are your main program and it's commands. How fast you walk or run, depend on your "clock speed", but not on the route instructions (30 steps forward, 1 turn 90 grad. left, 10 steps forward, 45 grad. right, etc.) They are always the same. Now imagine a little kid or greedy corrupt local politician untie your shoes now and then. This is the event that generate a interrupt. Then you halt after your last step, kneel and tie your shoe again. This is your ISR program. Then you continue from the place you have stopped, you do not start from beginning. When you walk without a care in the world and with all the time, you don't care even if you have to tie your shoe every other step. If you however do it with time constrains, like running in 100 metters on olimpics (or running from hungry flesh eating predator), stopping and tieing your shoes can have dire consequences. The same is with MCU's. Even if you execute only 1 line of code your program will continue, albeit slow. If you don't care about speed at all, it won't be a problem. If you have to do some time related, like using other timer dependant actions, interferance can be very unwanted and problematic.
  4. Less is more! Not always faster clock is better. Slower clocked devices use considerably less power. This can be cruicial point in battery operated device.
  5. Needed cycles are derived from this formulae:
    ( clock speed / (prescaler value * needed ISR calling frequency) ) - 1
lang-cpp

AltStyle によって変換されたページ (->オリジナル) /