25
votes
Accepted
Why is our refresh rate consistently decreasing in logging on SD card?
I don't have certain answer for you, but a deep suspicion. If I get bored I'll confirm it. Confirmed below.
In each pass of loop(), you have:
dataFile = SD.open("log1.csv", FILE_WRITE);
...
20
votes
Accepted
Is it possible to generate an exact 15 kHz clock pulse using an Arduino?
You can get pretty close if you program Timer 1 directly (not
through the library), and have it run with the prescaler set to 1.
Ideally, you want the period of the timer in clock cycles to be:
F_CPU /...
10
votes
Is it possible to generate an exact 15 kHz clock pulse using an Arduino?
Since the timer1 library only accepts whole numbers for the µs parameter you get a error. You could skip using the library and configure the timer directly. Or you could have a look at the source code ...
6
votes
Is it possible to generate an exact 15 kHz clock pulse using an Arduino?
A better way to do the above average 15 kHz (or any other frequency) is with a phase accumulator scheme. There are no IF tests; on each tick of an interrupt, you add a step to an accumulator and ...
5
votes
Generated frequency is not as expected
digitalWrite() takes a few microseconds to execute as well. There is also some overhead around the delayMicroseconds() function.
If you need exactly 500 kHz, you would want to consider using a timer.
...
5
votes
Accepted
Measure audio frequency through pulse duration
Timer 1 overflows at 255 because that's how it has been configured by
the Arduino core, as it is intended to provide 8-bit PWM. If you want
to use the timer in normal mode, you should undo the Arduino'...
5
votes
Accepted
What is the maximum frequency input signal that I can accurately track on a GPIO pin?
As Majenko wrote, when you only rely on software to measure the frequency on a IO pin, it will always be rather slow. And it also depends on the code, that you use. Functions like digitalRead() are ...
5
votes
ATMega4809 via Nano Every marked as 20Mhz, but does this confirm it is actually at 16Mhz?
With the Nano Every they went out of their way to make it look like as much like original Nano, to the point of providing that "register emulation" feature to make it appear that it has the ...
4
votes
Generate 1khz square signal with Arduino Mega
My first question is: Is there a way to automatically control an output pin from the timer, without having to execute any line of code in my arduino program ?
Yes. It's called PWM with a 50% duty ...
4
votes
Accepted
Procedure for changing frequency of Nano or similar
You could use an internal timer.
You are using interrupts, and you are probably aware that interrupt
handling inevitably incurs some jitter. Thus, if you do not mind an
extra single CPU cycle of ...
4
votes
Tone() generates a high pitched sound when button is released
Here is the result of my investigation.
The problem is caused by two factors.
First one is the contact bounce of the switch.
Second one is inadequate pullup strength at the switch, but this may be a ...
3
votes
How the light brightness stays constant when we increase the frequency of stroboscope
To keep the same brightness, you have to keep the same duty cycle (percent of on time over off time). So to change the rate without changing the brightness, you have to increase
delayMicroseconds(...
3
votes
Accepted
Generate 1khz square signal with Arduino Mega
As explained in the previous answer, you forgot to account for the time
taken by the CPU to handle the interrupt prologue. As a general rule, if
you want consistent timing, you should never reset the ...
3
votes
Accepted
How can arduino read a frequency higher than 16Mhz?
How can arduino read frequencies higher than 100Hz? How does it achieve that?
Interrupts (if you want to do it in software) or a magical piece of hardware called the Input Compare peripheral that is ...
3
votes
Accepted
Clock frequency VS cycle time
The execution time of your loop() will be slightly longer when the CPU
runs at 8 MHz v.s. 16 MHz, but I don't expect the difference
to be significant. CPU-bound functions, such as digitalWrite(), will
...
3
votes
Accepted
Will an Arduino UNO operating at 16mHz communicate with UART / I2C with an STM32 operating at a different frequency?
Tell me, does the difference in clock frequencies of microcontrollers affect the operation of buses between them?
No it doesn't. Or not much any way. It may affect the accuracy of clock generation1, ...
3
votes
Is it possible to generate an exact 15 kHz clock pulse using an Arduino?
I can get within 5 Hz of 15,000 using a 16 MHz clock on a Nano, Uno or 2560. Here is the code...
// RTM_TimerCalc 1.20
// Timer-1 Mode_14_16Bit_Fast_TOP_is_ICR
TCCR1B = 0x18; // 0001 1000, Disable ...
3
votes
Accepted
Arduino 75kHz output frequency setup
First you have to compute, from your desired frequency, the number of
CPU cycles per period of the signal:
F_CPU / 75 kHz = 16,000 kHz / 75 kHz ≈ 213.33
Since the timers can only count up to an ...
2
votes
Accepted
How to add prefactor to clock frequency at compile time?
1 and 3 can be solved by putting it in one of the initialization sections. 2 can be solved by creating and using a board.txt entry with the appropriate FCPU.
#include <avr/power.h>
void ...
2
votes
Accepted
Read frequency of input in digital pins
100 Hz is pretty trivial. See my page about timers.
This sketch can detect frequencies up to about 5 MHz:
// Timer and Counter example
// Author: Nick Gammon
// Date: 17th January 2012
// Input: ...
2
votes
Accepted
Writing Data through Pin at certain frequency
If I understand correctly, you want to output a synchronous serial bit
stream at 1 MHz. Something like this:
___ ___ ___
clk __/ \___/ \___/ \___⋅⋅⋅
______ _______ ...
2
votes
Accepted
6 channel PWM with 2 - 5 kHz frequency
Judging from your mentioning 62.5 kHz as the base frequency for
pins 5 and 6, I assume you are talking about an Arduino Uno or
something similar.
If you set the timer 0 to phase ...
2
votes
Accepted
How to run atmega328p at 8, 4 and 1 mhz?
If you run your MCU at 8 MHz, everything will run at this frequency: not
only the CPU core but also the timers, including Timer 0 which is used
for millis(), delay(), etc. So you will have to use a ...
2
votes
Maximum frequency of digital signal in Arduino Uno?
Nick Gammon's code worked fine for me. Here is an oscilloscope picture of the waveform I've got from his code:
His code above (from Nick Gammon, on Jan 25 '16 at 20:33) worked excellent for me. I used ...
2
votes
Is it possible to generate an exact 15 kHz clock pulse using an Arduino?
In answer to a comment from the OP asking for another microcontroller that can do this, and in addition to Majenko's reply comment:
A SAMD21G running at 48 MHz (as seen on some Arduinos) can make 15 ...
2
votes
analogRead() doesn't read more than 500Hz
You have 4 calls to analogRead() in your loop. At about 112 µs per
call, that's already taking 448 µs. Add to that the time taken by the
floating point calculations, and you are likely to end up with ...
2
votes
Accepted
Arduino, generating smaller frequency than 31Hz
For this, I would consider using Timer 1 in mode 14 (fast PWM, with TOP
value controlled by ICR1), with the prescaler set to 64. The timer would
then be clocked at 250 kHz, giving you the following ...
2
votes
Changing Frequency of PWM Pin on Arduino Uno
If you are prepared to use Timer 2 (Pin D3) this code will do it:
void setup()
{
pinMode (3, OUTPUT);
TCCR2A = bit (WGM20) | bit (WGM21) | bit (COM2B1); // fast PWM, clear OC2B on compare
...
2
votes
Accepted
Changing Frequency of PWM Pin on Arduino Uno
You can also use my newly-created AVR_PWM library to shield you from dealing with complex hardware registers
For example
#include "AVR_PWM.h"
#if ( PWM_USING_ATMEGA2560 )
// Pins tested ...
2
votes
Accepted
Frequency problems with DIY arduino and resonator
If the code runs at twice at the expected speed when clocked at
16 MHz, this can only be because either:
you fixed the program to run correctly when clocked at 8 MHz
you told the IDE that you are ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
frequency × 120arduino-uno × 41
pwm × 27
arduino-mega × 11
timers × 11
audio × 8
arduino-nano × 7
analogread × 7
sound × 7
programming × 6
oscillator-clock × 6
arduino-due × 5
c++ × 4
interrupt × 4
atmega328 × 4
signal-processing × 4
arduino-ide × 3
arduino-leonardo × 3
arduino-pro-mini × 3
sketch × 3
adc × 3
digital × 3
timing × 3
fuses × 3
serial × 2