Pages: [1]   Go Down
Author Topic: Pulse generator?  (Read 7104 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

HI all.
I want to make a programmable pulse generator using Arduino.
The "specifications" I need are the following:
A) first output generates 10 usec pulse with frequency 10 Hz.
B) One "enable" input. When it goes high all others pulses get generated.
All following pulses are generated once with relative delay to the first pulse A after B went high.
C) 10 usec pulse with variable 10-200 usec delay
D) 5-20 msec pulse with delay from 1 msec to 20 sec.
All pulses are TTL.
I would like to set up (throuhg comport or LPT port or USB) delay of pulse C, delay and width of pulse D.

Is it possible to do with one arduino uno board without a shield. 
Thank in advance for any advise where to start.

 
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 217
Posts: 13705
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Start reading the tutorial section - http://www.arduino.cc/en/Tutorial/HomePage - and the reference section - http://arduino.cc/en/Reference/HomePage

especially while()  micros() digitalRead() and digitalWrite() and last but not least the blink without delay example (reference page)

Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Santa Fe
Offline Offline
Full Member
***
Karma: 1
Posts: 201
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here is a script I use to do pulse width modulation for a electroplating tank
the pulse width is determined by a potentiometer to the analog in.

You could just as well control it with input from the USB port. There are lots of sample of how to do this in the Forum
Code:

// set pin numbers:
 int platepin = 2;
 int plateGrnd =3;
 int unplatepin =4;
 int unplateGrnd=5;
 int DutyHi;
 int DutyLo;   
float DutyRatio;
 
void setup() {
  // set the digital pin as output:
  pinMode(13, OUTPUT); 
  pinMode(2, OUTPUT);
  pinMode(3,OUTPUT); // go low when 6 is high
  pinMode(4, OUTPUT); 
  pinMode(5, OUTPUT);// go low when 7 is high
}
void Sequence_plating()
{
 
  digitalWrite(unplatepin,LOW);
  digitalWrite(unplateGrnd,HIGH);
  digitalWrite(platepin,HIGH);
  digitalWrite(plateGrnd,LOW);
  delay(10 *DutyHi/1023);
  digitalWrite(platepin, LOW);
  digitalWrite(plateGrnd,HIGH);
  digitalWrite(unplatepin, HIGH);
  digitalWrite(unplateGrnd,LOW);
  delay(10*(1023-DutyHi)/1023);
 }

void Get_Ratio()
{
    DutyHi = analogRead(0);
    DutyLo = 1023; //analogRead(1);
    DutyRatio = (DutyHi+1/(DutyLo+1)); // 1023/0 max
    if ( DutyHi <= 700) // warn that duty cycle is approching unplating
     {
       digitalWrite(13,HIGH);
      }
    else
      {
       digitalWrite(13,LOW);
      }
}


void loop()
{
  Get_Ratio();
  Sequence_plating();
 }
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 217
Posts: 13705
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Quote
first output generates 10 usec pulse with frequency 10 Hz.
for such short pulses you might need to take a look at the hardware timers - google playground timer arduino

Furthermore direct port manipulation might be needed for this kind of speed .
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i want to create pulse with tH=1us and TL=XXms....frequency 1MHZ,,,it is possible?
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 217
Posts: 13705
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I would write a separate sketch for that and do the pulse 1us in assembly.
Google direct port manipulation to set the line HIGH and LOW
and use NOP (assembler instruction) to get length exact 1 usec

Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Rapa Nui
Offline Offline
Edison Member
*
Karma: 60
Posts: 2073
Pukao hats cleaning services
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

http://www.avr-tutorials.com/assembly/calculating-execution-time-code-single-loop
http://www.avr-tutorials.com/assembly/calculating-execution-time-code-double-loop

AVR delay calculator:
http://electronics-lab.com/downloads/mcu/003/index.html

Quote
first output generates 10 usec pulse with frequency 10 Hz.

1. loop start: pin high
2. 158 cycles
Code:
; =============================
;    delay loop generator
;     158 cycles:
; -----------------------------
; delaying 156 cycles:
          ldi  R17, $34
WGLOOP0:  dec  R17
          brne WGLOOP0
; -----------------------------
; delaying 2 cycles:
          nop
          nop
; =============================
3. pin low (160cycles = 10usec)
4. 100ms period - we need (1.600.000 - 160) cycles (maybe minus 1 or 2 because of the loop)
Code:
; =============================
;    delay loop generator
;     1599840 cycles:
; -----------------------------
; delaying 1599831 cycles:
          ldi  R17, $1B
WGLOOP0:  ldi  R18, $4F
WGLOOP1:  ldi  R19, $F9
WGLOOP2:  dec  R19
          brne WGLOOP2
          dec  R18
          brne WGLOOP1
          dec  R17
          brne WGLOOP0
; -----------------------------
; delaying 9 cycles:
          ldi  R17, $03
WGLOOP3:  dec  R17
          brne WGLOOP3
; =============================
5. loop end

Not tested, just calculated  smiley  smiley



« Last Edit: March 31, 2014, 04:41:02 pm by pito » Logged

Pages: [1]   Go Up
Jump to: