Pages: [1]   Go Down
Author Topic: Difference between PWM pins and standard pins  (Read 1486 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 4
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

This is surely a newbeeic question, but after not finding an explanation in the reference documentation I must submit  :-[

As stated, there are 6 PWM capable digital I/O pins on the Duemilanove. PWM beeing the operation of setting the pins to HIGH and LOW consequently to form a square wave, how are these pins any different from the other D-I/O pins that also have this capability?

Im currently running a 12VDC fan of a transistor on/off circuit from pin 7 (which is not a PWM pin) and I'm able to regulate the operating voltage of the fan, thus controlling its speed, by delaying switching between HIGH and LOW on that pin. :o
Logged

B0100111001000011, USA
Offline Offline
Edison Member
*
Karma: 0
Posts: 1503
I'm confused.  Wait, maybe not..
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The PWM pins use a built in timer to generate the square wave.  While in theory, the same thing could be achieved without a PWM pin, these pins are specifically connected to do so.

The other pins can be "hacked" to do the same thing, but it's complicated.

Both types of pins can also be used as "traditional" Digital I/O pins with HIGH or LOW settings.
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17292
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, it's not unlike serial communications capabilities. The standard AVR chip used in an Arduino (168/328) has internal USART hardware circuitry that is attached to only pins 0 and 1. However one can use software functions to do serial communications on any of the digital I/O pins. So it's a case that every specific AVR processor type used has built in hardware capabilities that are assigned to specific I/O pins. The AVR datasheet for a specific processor is the best source to understand the 'extra' capabilities of each and every I/O pin.

Lefty
Logged

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

Thank you for the answers!

Quote
The other pins can be "hacked" to do the same thing, but it's complicated.

The code I use to run this "pseudo-pwm" (?) isnt very complicated at all, I might not have understood the definition completely though. Including for completion.

Code:
void setup()
{
Serial.begin(9600);
pinMode(7, OUTPUT);
}

unsigned char speed;
unsigned int low = 1;
unsigned int high = 10;
unsigned int baseTime = 10;

void loop()
{

digitalWrite(7,LOW);
delayMicroseconds(low*10);
digitalWrite(7,HIGH);
delayMicroseconds(high*10);

if (Serial.available())
{
speed = Serial.read() - 48;
low = speed;
high = baseTime - speed;
}


}
Source: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1231205087/0
Logged

B0100111001000011, USA
Offline Offline
Edison Member
*
Karma: 0
Posts: 1503
I'm confused.  Wait, maybe not..
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Well, what I meant was modifying timers to make it possible to maintain the PWM signal whilst doing other things in the program (much as you can analogWrite(), and then do something else, maintaining the signal).
Logged

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

Ah, yes of course. That is a good point. Scrapping this for analogWrite(). Thank you!
Logged

Pages: [1]   Go Up
Jump to: