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 /...
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, ...
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 ...
13
votes
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 ...
13
votes
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 ...
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 ...
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 ...
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 ...
8
votes
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, ...
7
votes
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 ...
7
votes
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 ...
6
votes
Accepted
Why does an RGB LED between VCC and PWM work?
This is a common arrangement and is known as Common Anode, and the I/O pin is said to be sinking current.
To better understand what is happening here it's best to think of an I/O pin as a two-...
6
votes
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 ...
6
votes
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 ...
6
votes
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 ...
6
votes
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 ...
6
votes
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... ...
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
Simple Speed question - Mapping PWM values
The analogWrite() function takes a value that is between 0 (fully off) and 255 (fully on).
Your value of 150 to 240 is a value within that range of 0 to 255 and represents a percentage of the "on ...
5
votes
Accepted
Atmega328 PWM frequency setting not working
Your code assumes that TCCR0n are zero. But what if they are not. What if there is some hidden initialization?
Timer0 is used by the Arduino micro/millis counter and the prescale (TCCR0B) is ...
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...
5
votes
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, ...
5
votes
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 ...
5
votes
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 ...
5
votes
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
votes
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 (...
5
votes
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 ...
4
votes
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 ...
4
votes
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
pwm × 488arduino-uno × 165
led × 54
timers × 51
motor × 46
arduino-mega × 43
servo × 39
frequency × 28
analogwrite × 27
arduino-nano × 24
atmega328 × 17
interrupt × 16
programming × 15
pins × 14
power × 12
audio × 12
arduino-ide × 11
analogread × 11
current × 11
c++ × 10
attiny × 10
i2c × 9
arduino-due × 9
adafruit × 9
voltage-level × 8