Questions tagged [pwm]

PWM is a form of signal modulation that allows digital output to approximate an analog signal. Use this for questions about using the PWM pins (marked with ~).

Filter by
Sorted by
Tagged with
23
votes
1answer
50k views

What is the frequency of PWM output on Arduino

What frequency do Arduinos use for normal PWM when you use analogWrite()? And is it different for different Arduino model? I'm interested specifically in the Mega 2560, but also want to know if it's ...
23
votes
2answers
26k views

Why do some pins have a different PWM frequency?

According to the Arduino reference for analogWrite(), the PWM frequency on most pins is ~490 Hz. However, it's ~980 Hz for pins 5 and 6 on the Uno, and for pins 3 and 11 on the Leonardo. Why are ...
12
votes
2answers
60k views

Set PWM frequency to 25 kHz

I currently can set four PWM pins to around 31 kHz with the following code: void setup() { TCCR1B = TCCR1B & B11111000 | B00000001; // Set PWM frequency for D9 & D10: pinMode(...
12
votes
6answers
26k views

How to output a true analog voltage at output pin

Regarding my program, it is a program that does some calculations and then outputs a voltage based on the result using analogWrite function. However my problem is that I had done my programming based ...
10
votes
2answers
30k views

Increase PWM bit resolution

I would like to increase the PWM bit resolution of the Arduino Uno. At this moment it is 8-bit which I consider too low. Is this possible without losing the ability of interrupts and delays? Koen ...
9
votes
2answers
10k views

How precise is the timing of pulseIn()?

I've been using the pulseIn() function for processing PWM-based binary data encoding. It works well for distinguishing pulses which are significantly different lengths, e.g. 500us vs. 1500us. That ...
9
votes
2answers
4k views

Does millis() conflict with the PWM pins associated with timer 0?

I've read that the millis() function uses the same timer as a couple of PWM pins. If you're using those PWM pins, will millis() still return the correct value?
9
votes
3answers
3k views

Controlling water temperature accurately

I have following setup: Arduino Duemilanove Small water heater connected with optical relay (PWM is ok) Waterproof DS18B20 temperature sensor Unknown amount of water (but temperature sensor and ...
8
votes
1answer
2k views

How can the Arduino Uno support up to 12 servos if it only has 6 digital PWM pins?

According to this: The Servo library supports up to 12 motors on most Arduino boards and 48 on the Arduino Mega. On boards other than the Mega, use of the library disables analogWrite() (PWM) ...
7
votes
9answers
33k views

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

I am trying to build a simple fan controller (single fan). So far I have successfully created a circuit which powers the fan with an external 12v DC adapter and added a transistor (NPN) to switch it ...
7
votes
3answers
3k views

Write PWM with only 8 bit? (Timer2)

I have a problem with the Servo library. I need to read a PPM signal and create a PWM signal of each channel. The problem is that PPM has a higher resolution than PWM so I want to use the 16 bit ...
7
votes
4answers
2k views

Adjust time calculation after Timer0 frequency change

I have an Arduino Nano with an 328P and need all 6 PWM pins. Thus, I had to adjust the prescaler and WGM Mode of Timer0. It is now in phase correct PWM mode with a prescaler of 1. TCCR0A = _BV(...
6
votes
6answers
3k views

Is it possible to generate an exact 15 kHz clock pulse using an Arduino?

I want to generate a 15 kHz pulse with an Arduino using Timer1, but the problem is that if we want a 15000 Hz clock we need to initialize the timer with 1/15000 seconds or 66.66 microseconds, but we ...
6
votes
1answer
1k views

Why does an LED sometimes flash when increasing brightness?

This is admittedly a cross-post from LED fade malfunction (random flash) but I can't get an answer on the Arduino forum. I was mucking around with some very basic code and I noticed that when ...
6
votes
1answer
6k views

Difference between PWM and regular output port for servos?

I have been controlling my servomotors for a while now only using pin 0. After some research, it has became apparent to me that the ports with ~ are the PWM pins. I thought that all pins sent out ...
5
votes
4answers
16k views

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

I was considering several different ways to send simple data from one Arduino to another when I though, why not connect a PWN pin of one Arduino to the analog pin on another? I could send simple ...
5
votes
3answers
1k views

Why does an RGB LED between VCC and PWM work?

I'm an Arduino beginner and I recently bought a cheap starter kit on eBay. One of the lessons in the starter kit is an RGB LED controlled by 3 PWM output pins. However, the arrangement of the ...
5
votes
1answer
393 views

Arduino PWM malfunctioning

I am controlling 4 motors using the PWM ports on an Arduino Uno (3,9,10,11). For some reason, the motor hooked up to port 11 doesn't move with my current code. I know it's a code issue because I can ...
5
votes
1answer
1k views

PWM signaling with Arduinos: What is the reason for the ground connection?

This may sound like a very dumb question and I apologise in advance. I've gone through reading about PWM and working on some example sketches to control PC fan speeds using PWM and Arduino. In all ...
5
votes
2answers
1k views

How can I use PWM in power saving mode (ATmega328)?

I fail to use PWM in power saving mode. The output behaves erratically. This should be possible, I guess. The following is a minimal working example: /* MWE: Cannot use PWM in any power saving ...
5
votes
2answers
161 views

How to move my robot in the right direction?

After all there is more question poping up then answers i decide to upload the pdf where is everything writen, like the wire, motor type and what we can and can't use. Here is the link pdf format of ...
5
votes
1answer
484 views

Help managing the fallout from timer0 mode and prescaler change on ATMega2560 without modifying wiring.c

For a driving application I need the PWM mode to be phase correct and the prescaler to be 1. The issue is that the board I am working with has the load hooked up to a PWM pin reliant on timer0. The ...
5
votes
1answer
886 views

Simulating touchscreen input using PWM

I'm porting a project from a teensy microcontroller to the arduino. Essentially the project uses a microcontroller to simulate touchscreen input for the Nintendo 3DS console. I am doing this by ...
4
votes
4answers
3k views

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

I am using Arduino UNO/MEGA, I want to analogWrite(pin, val); where the value is 0-1023. How can I make that ? Thanks.
4
votes
1answer
2k views

Why do I get negative voltages for a PWM waveform?

I used my Arduino Uno's pin 3 to generate a PWM output. The code is: void setup() { // Put your setup code here, to run once: } void loop() { analogWrite(3, 180); } I connected the output ...
4
votes
2answers
12k views

attiny85 and arduino - analogRead + pwmOut

I am using the Arduino IDE to program the attiny85. I want to take an incoming analog reading, then based on that reading, output a specific PWM value. Here's my circuit: and here's my code: // to ...
4
votes
2answers
5k views

How to increment and decrement an output voltage by using two buttons?

I'm trying to create a code using an Arduino Uno board to increment and decrement the output voltage of the Arduino Uno which is 5 volts and I need to step it up to 10 volts which I have done below. ...
4
votes
2answers
823 views

Can a timer be used in both CTC and (fast) PWM mode simultaneously?

I would like to generate a sequence of pulses of varying lengths in the range of 0-100us, so that from the start of one pulse to the start of the next there is a delay of 100us. I have set up timer0 ...
4
votes
4answers
32k views

Generating a PWM frequency greater than 125 kHz using Arduino Uno

I need to obtain a PWM frequency of at least 125 kHz. I plan to drive a pair of MOSFETs using this PWM as the driver signal. The below code gives a 1 kHz frequency. Can I just change the ...
4
votes
1answer
3k views

Fading the brightness of LEDs using MAX7219 and PWM

I am doing a project with bi-color led matrix 8x8 and MAX7219 as the LED driver. I want to implement a fading effect on the LEDs, like mixing the two colors by varying the individual duty cycles. My ...
3
votes
5answers
2k views

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

I have a Arduino which I would like to use to control a 12v PWM fan for speed control. I know about the 0-3.3v to 0-5v logic level shifter, is there a similar option for 0-5v to 0-12v? Or is there a ...
3
votes
3answers
2k views

Arduino PWM fading led

I am trying to blink an LED with PWM on Arduino. I don't know what is wrong but my LED is not fading as expected. What is wrong? I think that I have bad registers settings, but I am not sure. LED ...
3
votes
3answers
4k views

Arduino Code for Pulse Skip Modulation (PSM)

I have recently bought this light dimmer, and only when I received it I noticed it works with PSM (Pulse Skip Modulation) and not PWD (Pulse Width Modulation). Does anyone know how to write Arduino ...
3
votes
2answers
6k views

Dshot implementation on Arduino (ESC protocol)

Does anyone one know if it's possible to implement Dshot on Arduino? I want to interface the Arduino with ESCs (electric speed controllers). These ESCs use Dshot, (https://oscarliang.com/dshot/) a ...
3
votes
4answers
10k views

Transistor amplifier to drive speaker using Arduino PWM [closed]

I have been working on a project lately which uses Arduino to play a wav file from SD card. I am using TMRPCM library which made the job very easy. But the problem is that the output sound in the ...
3
votes
2answers
1k views

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

It's my understanding that when a Timer is used on an Arduino (in my case the Arduino Mega), it can disable analog write on some PWM pins, which pins depends on the Timer being used. For instance on ...
3
votes
3answers
17k views

Use Arduino's PWM to control motor direction?

I'm looking for a way to allow Arduino to control a motor using PWM. So far what I have gathered is that using Arduino's PWM sets the digital value of 255 to 5v and 0 to 0v. However what I am ...
3
votes
3answers
19k views

Arduino Nano PWM frequency

I have been using an Arduino Nano as a PWM controller for a heating element. I am currently using D11 (PB3). I could change, although all pins with PWM are in use, and would require a re-write and re-...
3
votes
2answers
27k views

How to control 19 RGB LED strips with one arduino?

I need to light up 19 RGB LED strips, which it seems would require 19*3=57 PWM outs and 57 transistors. The transistors aren't an issue, but of course the 57 PWM's is. Even if I hacked the digital ...
3
votes
2answers
857 views

timer0_millis always returns 0

I am trying to make a simple debounce function as explained here but the condition if((millis()-timeCheck)>reboundDelay) is never met. As you can see in my code below, I am trying to control a PWM ...
3
votes
1answer
163 views

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

I want to generate a PWM signal that I can turn on and off with a button press without using interrupts. Is there a way to keep the PWM output going while running other processes?
3
votes
2answers
563 views

how to solve Varing duty cycle value while using Pulsein()

Well im new to coding, but i do have the basic knowledge. I'm using an UNO to measure a duty cycle. The source of pulse is a Tektronic signal generator (Duty cycle set to 50.000 with frequency of 2khz)...
3
votes
1answer
4k views

Do I need to use a resistor if I am using a potentiometer to control an LED's brightness?

I am currently tinkering with an arduino, and am using a potentiometer to change the brightness of an LED. I understand that usually, a resistor is added to the circuit to limit the current flowing ...
3
votes
1answer
214 views

What does “Update of OCR1x at” mean in the WGM table of ATMEGA328?

I just finished a reading a couple of online guides on how to use timer registers with pulse width modulation, so I'm still new to its concept. When I looked in the ATMEGA328 specification sheet, I ...
3
votes
1answer
182 views

Timer interrupt triggers too often

The following question is based on the Arduino Pro Mini (8MHz, 3.3V) I'm in process of developing (yet another) LED strip driver shield. For that I wrote a simple control loop, that adjusts the ...
3
votes
1answer
125 views

Arduino uno PWM CTC mode - strange behaviour on interrupt

i have this simple code that i use for generating a square wave signal of 125 KHz on pin 9 using Timer1 in the "Clear Timer on Compare Match (CTC) Mode". I also use Timer1 Compare Match A interrupt ...
3
votes
1answer
1k views

PWM multiplexing on Arduino nano

simulate this circuit – Schematic created using CircuitLab Its a simple project. I am trying to drive 3 RGB LEDs using Arduino Nano. Since Arduino Nano does not have 9 PWM pins, the only ...
3
votes
3answers
1k views

Is it possible to control the speed of DC motors with Arduino's analogWrite() using analog pins?

I'm trying to control the speed of two DC motors that are connected to a dual H bridge. I always used digital PWM pins with analogWrite() to change the speed, but since I'm making a project that will ...
3
votes
5answers
38k views

Control Speed of DC FAN Using Arduino PID Library

I want to make a circuit that control speed of DC fan Using Arduino PID Library to get thing at specific temperature. The circuit looks like this but can be changed, The dc fan motor connected to PWM ...
3
votes
1answer
46 views

(Arduino Uno) PWM output (and servo plugged on it) becomes unstable if I use 1Wire on another pin

Unnecessary context but hey I'm guessing you might be interested Hi, I want to build a PID temperature regulator with a servo that presses on a silicon pipe to adjust the flux of liquid passing ...

1
2 3 4 5
10