Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

Arduino can be used for variable duty cycle square wave?

Status
Not open for further replies.

treez

Advanced Member level 5
Joined
Sep 22, 2008
Messages
7,602
Helped
561
Reputation
1,125
Reaction score
536
Trophy points
1,393
Location
cambridge
Activity points
76,160
Hello,
We are doing PWM dimming of LED drivers. We need to set up an Arduino board so that the Arduino can deliver the PWM dimming signal.
The PWM dimming signal has to be a variable duty cycle square wave at any frequency between 500Hz and 30KHz.
We would like the PWM dimming duty cycles to be smoothly changeable via a pot.
We want to have good dimming resolution, so for example, with the case of a PWM dimming frequency of 500Hz (2ms period), we would like at least 200 different duty cycles (evenly spaced) to be available, from 0 percent to 100 percent duty cycle.

We don’t need the pwm dimming frequency to be smoothly variable, but just need it selectable to , say 500Hz, 1KHz, 2KHz, 3KHz….up to 30KHz.

Is it true that the arduino is not suitable for this kind of thing?
 

jsherman

Junior Member level 3
Joined
Jul 2, 2013
Messages
25
Helped
7
Reputation
14
Reaction score
7
Trophy points
3
Activity points
264
A rough search on my end seems to indicate "not quite," but it will depend on the speed of your Arduino. Functionality-wise, Arduinos have a number of DAC inputs for the pot, each with 10 bit resolution if I recall. If your timer interrupt is fast enough, you can get 1024 duty cycles. There are a number of ways to get selectable frequencies. If you want 2^N frequencies, you can easily set up N digital input pins on read attached to switches and a pullup/pulldown network. That's the easy part.

Setting up the PWM, on the other hand, is a bit trickier. Normally you'd set up a timer interrupt at your desired frequency to achieve PWM. You probably want to scour the documentation for the Arduino timer interrupts for your chip, like this page:
http://letsmakerobots.com/content/arduino-101-timers-and-interrupts

From here you should be able to set up timer interrupts any way you want. However, you can't use digitalWrite in your interrupt because it's too slow at the higher frequencies. Instead you'll have to directly tell the ports what to do, kinda like this guy:
https://billgrundmann.wordpress.com/2009/03/03/to-use-or-not-use-writedigital/

He seems to be getting about 2 MHz out of his system. If you wanted 200 different duty cycles for your 30 kHz system, you'd need to be able to toggle your LED at 6 MHz to get your 7.6 bit accuracy.

tl;dr: I think an arduino is too slow to handle ~8 bits of PWM accuracy at 30 kHz
 
  • Like
Reactions: treez

    treez

    points: 2
    Helpful Answer Positive Rating

hamid159

Full Member level 3
Joined
Aug 25, 2013
Messages
176
Helped
14
Reputation
28
Reaction score
14
Trophy points
18
Location
Lahore
Activity points
1,206
The easy solution is that you can divide the ADC combinations to 200. (1024/200). So, by each 1024/200, you can increase duty cycle by 1%. It is simple way to do. For PWM Frequency, you may use two push buttons. (one for increasing Frequency and one for decreasing frequency).
For more information about duty cycle, see here.Motor Speed Control Using Arduino
 

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top