# Tag Info

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 /...
• 43.1k
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, ...
• 43.1k

### 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 ...
• 43.1k
Accepted

### Why do I get negative voltages for a PWM waveform?

At first you had the scope AC (Alternating Current) coupled. Then you switched it to DC (Direct Current) coupled. AC coupling is used to remove the DC component of a signal. It places a large ...
• 7,325
Accepted

### How to output a true analog voltage at output pin

You basically have three options: Switch to an Arduino Due which has a built-in DAC which outputs a real voltage. Add an external DAC chip (such as the MCP4821/2) to create the voltage for you Use a ...
• 105k
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 ...
• 15.3k

### 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 ...
• 11.3k

### 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 ...
• 105k
Accepted

### How do you get 2 PWM pins to inversely bitbang at 25 KHz on a Nano?

There are various solutions. I suggest using two PWM channels driven by a single timer. This way you do not have to worry about synchronizing two timers. You can configure the channels identically, ...
• 43.1k

### How to output a true analog voltage at output pin

At 5V, a 1 ohm resistor will try to sink 1A and far exceed the 40mA specs. Please use at least a 5/0.040=125 ohm resistor to protect your pin. And if you put the a capacitor between your resistor ...
• 2,332

### Can’t set duty cycle to 0% with custom PWM

That is how it is supposed to be. In this fast PWM mode, the duty cycle is (OCR1A+1)/(ICR1+1). If you want a duty cycle of zero, you have to disengage the PWM and turn the pin to OUTPUT LOW. This is ...
• 43.1k

### Dshot implementation on Arduino (ESC protocol)

In short, I ended up creating a library capable to drive multiple DShot600 ESCs: DShot-Arduino It still need a lot more polish, but the bit-banging works really well. SPI method I tried the method ...
• 161

### How do I set a 25 kHz PWM signal on an ESP-WROOM-32?

It is very simple to set up a PWM signal at any frequency you desire, with any resolution you desire, provided you don't exceed the maximum 'bandwidth': the frequency multplied by the resolution must ...
• 1,400
Accepted

### Can I use the PWM pins as regular digital input/output pins?

Yes you can use them as ordinary digital io pins. PWM is essentially a normal digital output pin that is repeatedly turned on and off at a high rate. The magic is that the turning off and on is done ...
• 393
Accepted

### Is it possible to measure analog output?

First: Why would you need to measure the PWM value. You already know it; it's saved in the val variable. Why not just use this variable for later use in code? Second: Doing the analogRead on the same ...
• 16.3k

### How do I convert 0-5v PWM to a 0-12v PWM

I advice you to learn about basics of how to connect external components to MCU. Anwser to your question is simple transistor amplifier... So you can use bipolar transistor (NPN/PNP) or MOSFET... ...
• 161

### 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 ...
• 609

### 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...
• 2,913

### Transistor amplifier to drive speaker using Arduino PWM

Your amplifier arrangement is fundamentally flawed. At the moment you are "tickling" the top end of the electromagnet in the speaker - that is, you are energising it when the Arduino outputs a HIGH, ...
• 105k
Accepted

### Platform-independent functions for FastPWM?

It is highly unlikely there would be direct 1:1 functions that implement such discrete operations. Simply because such operations are pretty unique to a single family of microcontrollers. They are too ...
• 105k

### Why are the PWM variables in this RC code snippet handled this way? What are the magic numbers?

There is not enough context to be certain, but given the variable names I can assume that this is code from a sketch that receives information from an RC controller and is intended to control parts of ...
• 105k
Accepted

### Output voltage range between 0-5v

Short answer: No. Arduino Unos and Megas have PWM (Pulse Width Modulation) output, which rapidly turn the output on and off with a varying "duty cycle" (The ratio of on time to off time.) ...
• 5,702

### Dimming this ~30V led with PWM, what do I need?

It will not be possible for you to PWM dim your LED with that LED driver (power supply). That is a constant current driver with under/over-voltage protection. It delivers a specific amount of current (...
• 105k

### Fast PWM with Arduino, the inputs outputs don't work

This line: TIMSK = (1<<OCIE1A) | (1<<TOIE1); enables a couple of interrupts generated by Timer 1. Whenever you enable an interrupt source, you should make sure that the matching ISR has ...
• 43.1k
Accepted

### How can I maintain PWM output while still performing other tasks?

PWM just runs once started. It's all managed by a completely separate bit of silicon inside the chip. Once you have done analogWrite(...) the PWM will just keep going until you tell it otherwise.
• 105k

### Can I connect a PWM pin on one Arduino to an analog input on another?

For greater precision, less code, faster execution and no need for capacitors read the PWM "analog" signal on the other Arduino from a digital input pin with pulseIn(pin, HIGH, timeout) The timeout ...
Accepted

### How to eliminate noise from PWM controlled 12V fan at low speed

I had the same problem with a 5V fan. Something simple worked for me: To decrease the PWM frequency. You probably want to do this using pin 9 or 10 (for the Uno) as changing the frequencies of other ...
• 56
Accepted

### If a Timer is used, disabling some PWM pins, can I still use those pins for Digital write?

If I enable Timer 5, does that mean that I can't use these pins for anything else? Or does it only mean I can't use those pins for AnalogWrite, and that I can still use those pins for DigitalWrite. ...
• 7,969

### How to run multiple functions one after another?

It simply is not possible for the processor to run both functions at once. What probably is happening is that the sequence of functions executes too fast to distinguish it as two sequential processes. ...
• 15.3k