Pages: [1]   Go Down
Author Topic: Arduino and PWM  (Read 689 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 77
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

one question,
why the arduino function analogWrite only work in 6 pins?

I needed to use 7 PWM ports, so I wrote new function so that I was able to use up to 14 PWM pins.

Thanks
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 638
Posts: 50331
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Want to tell us anything about the function? How does it work? What timers does it use? What frequency is the duty cycle change?
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 77
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I used a part of the code found on arduino.cc website.

To make the LED fade, I used the function delayMicroseconds

worked well

Code:
   for(i=1;i<=1000;i++){
      digitalWrite(j, HIGH);
      delayMicroseconds(i);
        digitalWrite(j, LOW);
        delayMicroseconds(1000 - i);
    }
« Last Edit: May 23, 2010, 12:04:39 pm by dansku » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26495
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

And the processor load vs. using the PWM pins?
Why did you stop at 14?
What about the analogue pins?
« Last Edit: May 23, 2010, 12:10:49 pm by AWOL » Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

UK
Offline Offline
Faraday Member
**
Karma: 17
Posts: 2884
Gorm deficient
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

With the code snippet above, for 14 pins, you're looking at a refresh rate of around 70Hz, which will produce noticeable flicker on an LED.

The hardware pins operate at around 490Hz.
Logged

Per Arduino ad Astra

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 77
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

ah, that's the difference then
but i cant see it flickering smiley
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 634
Posts: 34559
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

For all the pins PWMed see:-
http://www.arduino.cc/playground/Main/PWMallPins
Logged

Pages: [1]   Go Up
Jump to: