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); ...
timemage's user avatar
  • 5,221
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 /...
Edgar Bonet's user avatar
  • 43.1k
14 votes
Accepted

Set PWM frequency to 25 kHz

I am posting this second answer since I realized it is possible to have 4 PWM channels at 25 kHz with 161 steps on a single Arduino Uno. This involves changing the main clock frequency to 8 MHz, ...
Edgar Bonet's user avatar
  • 43.1k
13 votes

Set PWM frequency to 25 kHz

You can configure Timer 1 to cycle at 25 kHz in phase correct PWM mode, and use it's two outputs on pins 9 and 10 like so: // PWM output @ 25 kHz, only on pins 9 and 10. // Output value should be ...
Edgar Bonet's user avatar
  • 43.1k
12 votes
Accepted

ArduinoUNO/MEGA, Is there a way to exceed 256 in analogWrite

Section 16, "16-bit Timer/Counter1 with PWM" of Atmel-8271J-AVR- ATmega-Datasheet_11/2015 describes using Timer/Counter-1 for 16-bit PWM, including sample code in both C and assembler. It might take a ...
JRobert's user avatar
  • 15.3k
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 ...
Gerben's user avatar
  • 11.3k
9 votes

ArduinoUNO/MEGA, Is there a way to exceed 256 in analogWrite

The simplest way is to change your value range to 0-255. You can't change analogWrite's range, since that is fixed in the core software. analogWrite(5, val >> 2); The >> 2 bit-shifts the ...
Majenko's user avatar
  • 105k
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 ...
Boggyman's user avatar
  • 609
5 votes

ArduinoUNO/MEGA, Is there a way to exceed 256 in analogWrite

I agree with @Majenko's answer, though here is a more "beginner" friendly method of doing the same. val = map(val,0,1023,0,255); analogWrite(pin, val); Not the most efficient, but still...
Dat Ha's user avatar
  • 2,913
5 votes

Programming standalone Atmega328p-PU with NE555N timer IC

No, you won't be able to build a 16 MHz clock signal using a 555 timer. That's far beyond the 555 capabilities (see N.B.). If you could squeeze out of the 555 a mere 1 MHz (which I seriously doubt), ...
Enric Blanco's user avatar
  • 2,114
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. ...
towe's user avatar
  • 865
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'...
Edgar Bonet's user avatar
  • 43.1k
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 ...
chrisl's user avatar
  • 16.3k
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 ...
timemage's user avatar
  • 5,221
4 votes

Pin toggle speed

If you compile the code and examine the results you can see how many instructions it will take, and thus how many clock cycles. It's slightly more complex because of what else happens in main() to ...
Majenko's user avatar
  • 105k
4 votes

Programming standalone Atmega328p-PU with NE555N timer IC

Yes, you could use a 555. You can also go even simpler and use an RC network. Even simpler still is to use the 1MHz RC network built in​ to the chip. The main drawback of these methods, and the 555 ...
Majenko's user avatar
  • 105k
4 votes

Programming standalone Atmega328p-PU with NE555N timer IC

The default configuration of these chips, as they come from the factory, is to use their internal 8 MHz RC oscillator downscaled at 1 MHz. So you do not need any extra oscillator to program them. ...
Edgar Bonet's user avatar
  • 43.1k
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 ...
Majenko's user avatar
  • 105k
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 ...
jsotola's user avatar
  • 1,515
3 votes

Ensuring specific frequency at specific time?

As mentioned in comments and other answers, using timer 1 for hardware-timed bit toggling is likely to produce better results than code using delays based on calls like delayMicroseconds(), primarily ...
James Waldby - jwpat7's user avatar
3 votes

Ensuring specific frequency at specific time?

Generating a linear frequency ramp with accurate timings is not an easy task. I am providing here only a partial answer, where I first go through the math of the problem, then give some ideas for the ...
Edgar Bonet's user avatar
  • 43.1k
3 votes
Accepted

Change Digispark clock speed, run at low voltage?

You can set the clock prescaler at run time. For example: #include <avr/power.h> void setup() { clock_prescale_set(clock_div_8); // etc... } More details in the documentation from avr-...
Edgar Bonet's user avatar
  • 43.1k
3 votes
Accepted

Playing a pcm file through a speaker with arduino

You are right that the values in a wav file are amplitudes. 16 bit signed values to be precise. And that amplitude is just a voltage. Negative values are normally a negative voltage, but they don't ...
Majenko's user avatar
  • 105k
3 votes

Programming standalone Atmega328p-PU with NE555N timer IC

It depends on how you're programming it. If you're using a bootloader to accept programming commands via a serial connection then you will need to use the clock method specified by the fuses ...
Ignacio Vazquez-Abrams's user avatar
3 votes

Generate 1.7 Mhz with PWM in Uno?

Expanding from my comment... any signal level generated by this kind of microcontroller can only last for an integer number of CPU cycles. In order to generate it, you first have to compute the timing ...
Edgar Bonet's user avatar
  • 43.1k
3 votes
Accepted

Arduino-based mains frequency monitor

I understand Arduino should be somewhat simpler [than PIC]. The whole Arduino platform (boards, core library and IDE) makes it super easy to get started and do simple things. However, if you want to “...
Edgar Bonet's user avatar
  • 43.1k
3 votes
Accepted

Arduino-based mains frequency monitor follow-up

You should remove the capacitor. It won't remove any DC offset because there can be no DC offset. From where would the DC offset be relative? There is only two points in the circuit, and both of them ...
Majenko's user avatar
  • 105k
3 votes

Listen for specific frequency

As stated in previous answers, frequency measurement is unlikely to be reliable because the microphone is going to pick up ambient noise, which is a combination of many individual frequencies. You ...
Edgar Bonet's user avatar
  • 43.1k
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, ...
Majenko's user avatar
  • 105k
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 ...
Edgar Bonet's user avatar
  • 43.1k

Only top scored, non community-wiki answers of a minimum length are eligible