Go Down

Topic: PWM pins (Read 3246 times) previous topic - next topic


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.

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.


I used this opportunity to check the digital...Fast routines.
This here is around the limit
Code: [Select]

#define ledPin 13
Timer1.initialize(12);         // called every 12 us

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!!


Sep 06, 2010, 10:13 pm Last Edit: Sep 06, 2010, 10:21 pm by Phillyart Reason: 1
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.


Sep 06, 2010, 10:26 pm Last Edit: Sep 06, 2010, 10:32 pm by mpeuser Reason: 1
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


It seems that the Duemilanove only manipulates bits.

No see:-




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


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


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.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131