Wiring Forum
http://wiring.org.co/cgi-bin/yabb/YaBB.pl
Other questions >> Other Wiring questions >> PulseOut
http://wiring.org.co/cgi-bin/yabb/YaBB.pl?num=1264711870

Message started by Titus on 01/28/10 at 20:51:10

Title: PulseOut
Post by Titus on 01/28/10 at 20:51:10
http://wiring.org.co/reference/pulseOut_.html

I got 2 questions about pulseOut

1)How will it affect the speed of the running program if you start an infinite pulse(and will you be able to use the pwm pin's you're not using to generate the pulse)

2)What is the maximum pulse it can generate. Because I would like to have about 2MHz

Thanks

Titus

Title: Re: PulseOut
Post by barragan on 01/30/10 at 00:52:56
hi Titus, the maximum parameter for the frequency is 65535, but you could use the new Timer2 library which executes a command given a fraction of the the main CPU clock, (16Mhz) so if you need a frequency of 2Mhz then you an use a prescaler CLOCK_DIV8 which means the CPU clock divided by 8 or 2Mhz. In your user function you can toggle a pin, like in the example provided: http://wiring.org.co/reference/libraries/Timer2/index.html

Title: Re: PulseOut
Post by Titus on 01/30/10 at 12:05:22
So, if I understand it correctly, this program will create an infinite pulse on pin 24 with frequency 2MHz?


Code:
#include "HardwareTimer2.h";

int pulsePin = 24;

void setup()
{
  pinMode(pulsePin, OUTPUT); 

  Timer2.set(Pulse(), CLOCK_DIV8);

  // start timer
  Timer2.start();
}

void loop()
{
 
}

void Pulse()
{
  digitalWrite(pulsePin,HIGH);
  digitalWrite(pulsePin,LOW);   
}


But does't void Pulse() take longer to execute then 1/2000000 s?

And the way this thing works is it stops the main program(void loop() ) every 1/2000000 s, doesn't it?

When it executed Pulse(), will it continue in void loop() where it stopped, or will it start void loop() over again.

Oh and this library isn't in wiring yet, according to wiring.

The 2MHz pulse is for the system clock of a TLC541:
http://focus.ti.com/lit/ds/symlink/tlc541.pdf

Edit:
 
 F_CPU / 8 in a 16Mhz will be 2000000
 2000000 / 255 = 7843,1373 overflows (full countings to 255)
1s / 7843,1373 = 0,0001275 s

though 1/2000000 = 0,0000005

I guess I'll have to use something else then wiring, as in a hardware oscillator.


Titus

Title: Re: PulseOut
Post by barragan on 01/30/10 at 17:31:33
The Timer 2 will generate an interruption every time executing your code, execution of code at high frequencies will slow down the general execution of the loop() but it doesn't stop the loop(), after finishing your function it will return to execute where it was before the interruption. You could try to run tests at slower frequencies, check the example provided with the library and uncomment the line of code that sets the Timer with the prescaler (comment the one that sets the timer with the milliseconds), you can load the example form the File->Examples-Libraries->Timer2
etc. (wiring version 0024 only)

Title: Re: PulseOut
Post by Titus on 01/30/10 at 22:43:07
Dear Barragan,

pulseOut(29, 10);
Isn't compiling anymore in 0024.
error: 'pulseOut' was not declared in this scope

Title: Re: PulseOut
Post by barragan on 01/31/10 at 01:12:02
you're right, please re-download and install 0024, I made a fix for it.

Wiring Forum » Powered by YaBB 2.5 AE!
YaBB Forum Software © 2000-2010. All Rights Reserved.