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

Quote
There is a difference between being a hobby product and being a toy.

The only thing different between a man and a boy is the size (price) of their toys.

Quote
Now, who's belittling the Arduino?

No at all
Tiny = baby
I am very new to the Arduino line of micro controllers and I know that tiny is in one of their board names.  I did not want someone to think I was talking about a specific board.
Logged

0
Offline Offline
Edison Member
*
Karma: 0
Posts: 1103
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I used this opportunity to check the digital...Fast routines.
This here is around the limit
Code:
#define ledPin 13
 Timer1.initialize(12);         // called every 12 us

 Timer1.attachInterrupt(callback);
 pinMode(ledPin, OUTPUT);

 int i;
 int pWidth = 0;
 void callback() {
   digitalWriteFast(ledPin, HIGH);   // set the LED on
   i = pWidth;
   while (i>0)  --i;
   pWidth +=4; //delay is 0, 4, 8, or 12 loops = 1.5, 3, 4.5, or 6us
   if(pWidth>12) pWidth=0;
   digitalWriteFast(ledPin, LOW);  
}

This uses nearly half of the processor time. It was not possible to make much faster interrupts; around those 83kHz seems to be the limits.
Pulses generated are 1.5, 3, 4.5, and 6us long, a much better fine tuning is possible here; my delay code is a little bit clumsy...

Remember that the pins for digital...Fast have to be constants!!
Logged

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

Thank you for the code.  I have printed it out and will look over it.  There are a few things I don't understand yet.

Is there a way or a function to output a byte to port D, pins 0-7?  It seems that the Duemilanove only manipulates bits.
« Last Edit: September 06, 2010, 03:21:18 pm by Phillyart » Logged

0
Offline Offline
Edison Member
*
Karma: 0
Posts: 1103
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Manipulation of "bits only" is a feature of the Arduino HAL. You can of course use the register layer below, as with any AVR chip!

----

You have to change my code in at least two ways
- the pulse must be output to four different lines during four succeding interrupts.
- each fourth interrupt must be delayed for 2 us to make exact 20kHz.

However it should be possible to change the timer initialization (prescaler) to have 12.5us interrupts
« Last Edit: September 06, 2010, 03:32:42 pm by mpeuser » Logged

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

Quote
It seems that the Duemilanove only manipulates bits.

No see:-

http://www.arduino.cc/en/Reference/PortManipulation
Logged

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

Mike,

Thank you for pointing that out to me.  How about this, Is there a windows based cross asembler that will work with the Duemilanove?
Logged

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

A cross-assembler in addition to the C++ compiler?
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.

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

Stand-alone would probably be better as it is intimidating to most people.  I have experience with 6502, 6809, 68705, 6811, and 8088.  You have better access and control of registers and memory and it is the ultimate in execution speed.
Logged

Pages: 1 [2]   Go Up
Jump to: