Home \ Help \ Search \ Login RSS

Welcome, Guest. Please Login

This forum is now READ-ONLY! Please visit http://forum.wiring.co/ for the new forum.

Wiring ForumOther questionsOther Wiring questions › PulseOut

Page Index Toggle Pages: 1
PulseOut (Read 5208 times)
01/28/10 at 20:51:10

Titus   Offline
YaBB Moderator
Wiring Soccer Robot!
Amsterdam

Posts: 176
*****
 
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
 

Check www.TeamVossius.nl for our Autonomous soccer robots!
IP Logged
 
Reply #1 - 01/30/10 at 00:52:56

barragan   Offline
YaBB Administrator

Posts: 939
*****
 
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
 
IP Logged
 
Reply #2 - 01/30/10 at 12:05:22

Titus   Offline
YaBB Moderator
Wiring Soccer Robot!
Amsterdam

Posts: 176
*****
 
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
« Last Edit: 01/30/10 at 14:42:24 by Titus »  

Check www.TeamVossius.nl for our Autonomous soccer robots!
IP Logged
 
Reply #3 - 01/30/10 at 17:31:33

barragan   Offline
YaBB Administrator

Posts: 939
*****
 
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)
 
IP Logged
 
Reply #4 - 01/30/10 at 22:43:07

Titus   Offline
YaBB Moderator
Wiring Soccer Robot!
Amsterdam

Posts: 176
*****
 
Dear Barragan,

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

Check www.TeamVossius.nl for our Autonomous soccer robots!
IP Logged
 
Reply #5 - 01/31/10 at 01:12:02

barragan   Offline
YaBB Administrator

Posts: 939
*****
 
you're right, please re-download and install 0024, I made a fix for it.
« Last Edit: 01/31/10 at 06:48:35 by barragan »  
IP Logged
 
Page Index Toggle Pages: 1