Pages: [1]   Go Down
Author Topic: Digital PWM outputs  (Read 1990 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Another question I have regards to the PWM feature. Dimming of LEDs can be achieved through different duty cycles in a PWM circuit. Specifically, I want to be able to manipulate a 2kHz frequencies duty cycle from 10% - 50% through software for different analog input values, thus allowing me to dim a string. Is there a command in the software that will allow this? I have looked around but have not run across anything that allows this inside the software. Thanks again,

Daniel
Logged

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 9
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Despite its name, the analogWrite() function actually generates a digital PWM signal on pins 9, 10 or 11: http://www.arduino.cc/en/Reference/AnalogWrite

It's currently at 30 KHz, but you could change it with some 'magic' code to adjust the comparison register on the associated timer (1 or 2).
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Despite its name, the analogWrite() function actually generates a digital PWM signal on pins 9, 10 or 11: http://www.arduino.cc/en/Reference/AnalogWrite

It's currently at 30 KHz, but you could change it with some 'magic' code to adjust the comparison register on the associated timer (1 or 2).

Ahh I can't believe I missed that page. Thank you very much for the response. It is exactly what I needed.

Dan
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Where is the magic code? how can I do this? This sounds exactly like what I want. a controlled PWM frequency
Logged

p
london
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


simple stuff../ code correction..
how do I add an input value (because of pushbutton experiment) when using Knight Rider to create blinking sequence for LEDs.  

-im using the digitalWrite(pinNum,HIGH/LOW) and delay(time) example of the Knight Rider.

-later on I would wish to add a sound sensor

here's the code i was trying with,,

int pin2 = 2;
int pin3 = 3;
int pin4 = 4;
int pin5 = 5;

int timer= 100;

int pressurepad = 7; //choose the input pin (for a pushbutton)
int pressurepadd = 6;  

int val = 0;      // variable for reading the pin status

void setup() {
  pinMode (pin2, OUTPUT);  // declare LED as output
  pinMode (pin3, OUTPUT);  // declare LED as output
  pinMode (pin4, OUTPUT);  // declare LED as output
  pinMode (pin5, OUTPUT);  // declare LED as output
 
  pinMode(pressurepad, INPUT);    // declare pushbutton as input
  pinMode(pressurepadd, INPUT);    // declare pushbutton as input
}

void loop()
{
  val = digitalRead(pressurepad);  // read input value
  val = digitalRead(pressurepadd);  // read input value



if (val == LOW)
{                 //check if the input is HIGH (button released)        
    digitalWrite(pin2, HIGH);  
    delay (100);
    digitalWrite(pin2, LOW);
    delay(100);
    
    
    digitalWrite(pin3, HIGH);  
    delay (100);
    digitalWrite(pin3, LOW);
    delay(100);
    
    
    digitalWrite(pin4, HIGH);
    delay (100);
    digitalWrite(pin4, LOW);
    delay(100);
    
    
    digitalWrite(pin5, HIGH);
    delay (100);
    digitalWrite(pin5, LOW);
    delay(100);
    
      
    digitalWrite(pin5, HIGH);
    delay(100);
    digitalWrite(pin5, LOW);
    delay (100);
    
    
    digitalWrite(pin4, HIGH);
    delay(100);
    digitalWrite(pin4, LOW);
    delay (100);
    
    
    digitalWrite(pin3, HIGH);
    delay(100);
    digitalWrite(pin3, LOW);
    delay(100);
 
 }
 
 
  delay (100);
}  


many thanks,
p

Logged

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 9
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

rogwabbit: see this thread for more details: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1170282999/1

I'm hoping to add a function to set the PWM frequency soon.
Logged

Pages: [1]   Go Up
Jump to: