Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

need to create 2 pulse output from one pulse input

wozzzzza

Member level 3
Member level 3
Joined
Dec 10, 2008
Messages
65
Helped
0
Reputation
0
Reaction score
5
Trophy points
1,288
Activity points
1,686
trying to make a small circuit that when a high input pulse of around 200ms is received it will output 2 high pulses of around 200ms with 200ms gap
anyone assist how to do it? having problems finding answer.
 
Quik and dirty way using Arduino Nano or ATTINY85 :

1731931950113.png



Basically you drag and drop blocks to configure/program the Nano or ATTINY85 using mBlock. mBlock
generates Arduino C/C++ code from your block configuration, and using Arduino IDE programs the Nano
or ATTINY85 chip. Note Nano board ~ $3, Arduino IDE directly programs the Nano, whereas if using
ATTINY85 the Nano board is used to program it. Nano board has advantage its xtal controlled timing,
so quite accurate, over T and V. Using ATTINY85 w/o xtal ~ 10% timing error.

Note pulses generated when input pulse terminates. Easy to change to once 200 mS in is met 2 pulses
are generated and no more until input pulse terminates. Also if your input pulse comes from mechanical
contacts then that has to be debounced and affects your timing considerations. But easy to do with
mBlock coding.

mBlock is free. Nano, ATTINY85 -

1731933526058.png


1731932439875.png


Here is a sophisticated timer/pulse gen, just to show what can be done with Nano/mBlock -



mBlock project attached.


Regards, Dana.
 

Attachments

  • Two Pulse Triggered Generator.zip
    55.3 KB · Views: 12
Last edited:
Hi,

I´m with Dana ... I´d surely use a microcontroller.

This makes it especially easy in case a following pulse is present at the input while the output is still busy with outputting pulses.

Just: for every incoming pulse add "two" to a counter variable.
And the output reduces this counter variable by "1" for every pulse ... and stops when the counter is zero.

Klaus
 
Updated code.

Pulse too short

1731955894472.png



Pulse > 200 mS

1731955959955.png


Regards, Dana.
 

Attachments

  • Two Pulse Triggered Generator.zip
    55.4 KB · Views: 13
i thought about attiny85 and when you mentioned i just went this way as well.
that program actually didnt work for me at all for some reason even after changing the pin numbers to suit attiny85

i made my own that went like this.
thanks.
C-like:
void setup() {
  // put your setup code here, to run once:
  pinMode(0,OUTPUT);//pin 5 on ic
  pinMode(4,INPUT);//pin 3 on ic
  digitalWrite(0,0);
}

void loop() {
  // put your main code here, to run repeatedly:
  if(digitalRead(4) == 1){

    digitalWrite(0,1);
    delay(8);
    digitalWrite(0,0);
    delay(8);
    digitalWrite(0,1);
    delay(8);
    digitalWrite(0,0);
    delay(8);

  }else{

    digitalWrite(0,0);
  }
}
 
Hi,

again here I surely would use an interrupt solution.

this:
that program actually didnt work
is no error description.

and delay(8) wil not produce a 200ms pulse as requested in post#1

--> give good and complete informations and stay focussed.

Klaus
 
is no error description.

and delay(8) wil not produce a 200ms pulse as requested in post#1

--> give good and complete informations and stay focussed.

Klaus
no error message received, just didnt work.
delay 8 gives enough pulse. not after exact to the microsecond.
 
Your program, if the input stays high, generates repeating two pulse waveform,
rather than one set and then recycle only after input has gone back to ground.

Is that what you want ?

What pin numbers did you use ? I was using a Nano board so pin numbers would
have to change. Here is the mBlock code that was generated that worked :

1732016864308.png


Code:
// generated by mBlock5 for <your product>
// codes make you happy

#include <Arduino.h>
#include <Wire.h>
#include <SoftwareSerial.h>

float FirstPulseFlag = 0;
float PulseWidth = 0;

void GenTwoPulse(){
  digitalWrite(9,1);
  _delay(0.2);
  digitalWrite(9,0);
  _delay(0.2);
  digitalWrite(9,1);
  _delay(0.2);
  digitalWrite(9,0);

}
void PulseIn(){
  FirstPulseFlag = 0;
  PulseWidth = 0;
  // Pulse in detected ?
  if(digitalRead(5) == 1.000000){
    // Keep counting 1 mS increments until pin falls to "0"
    while(!(digitalRead(5) == 0.000000))
    {
      _loop();
      PulseWidth += 1;
      _delay(0.001);
      // If pulse in >= 200 mS then set flag to force generation of two
      // pulses, but only once until input pin faslls to 0 and code
      // start from begining again
      if((PulseWidth > 199)  &&  (FirstPulseFlag == 0.000000)){
        FirstPulseFlag = 1;
        GenTwoPulse();

      }

    }

  }

}

void _delay(float seconds) {
  long endTime = millis() + seconds * 1000;
  while(millis() < endTime) _loop();
}

void setup() {
  pinMode(9,OUTPUT);
  pinMode(5,INPUT);
  FirstPulseFlag = 0;
  PulseWidth = 0;
  while(1) {
      // Pulse in occured ?
      PulseIn();

      _loop();
  }

}

void _loop() {
}

void loop() {
  _loop();
}

Note my Nano pin #'s would not have worked on ATTINY85. I would have to change them.

When you changed pin numbers did your scope trigger not display a single shot waveform ?
Possibly you missed the fact the mBlock program only generates 1 burst of the two pulses
and then has to be retriggered to get each/next 2 pulse sequence.


Regards, Dana.
 
Last edited:
trying to make a small circuit that when a high input pulse of around 200ms is received it will output 2 high pulses of around 200ms with 200ms gap
anyone assist how to do it? having problems finding answer.
Pulse input detect meaning what? trailing edge around 200 ms +/- 50% or step detection at least 200 ms as Danadak did?
 
no error message received, just didnt work.
delay 8 gives enough pulse. not after exact to the microsecond.
you want to say: compilation without error and without warnings. (Correct me if I´m wrong)

It did not work:
Again: This tells nothing. Maybe you did not supply power to your microcontroller. Or any of thousands of other possible issues.
--> show your schematic
--> tell us your test setup
--> tell us step by step what you did
--> tell us what you expect. In detail
--> tell us what not was like expected. in detail

8 vs 200. If you want 200 .. why did you choose 8 then? I mean: you should have a reason to "not" use the desired value.
Or is it just because it is less effort to write "8" instead of "200"?

.. what about adding a couple of lines for debuggin .. just to see what the software does.

Klaus
 
@OP, to Tony's observation I tested input trigger to be at lease 200 mS width, which you did not,
as you described in your post # 1. If its less than 200 mS no pulses occur.....in the mBlock solution.

Have your conditions changed for the design ?

As an aside I showed mBlock as a solution because of uncertainty if you knew how to write
code, so ignore it. I use both C and block languages, the latter when I need a quick and dirty
solution, the former for more involved projects. mBlock used by 6'th grade kids (and me) to program
'robots, ist great for visual learners. Keeps students out of the weeds, and me at my age having to keep
a C programmers guide glued to my forehead because I have so many languages rattling around in my head
since early 1970's.

Look what it takes to bring up a server (in this case Tuniot) on an ESP8266 or ESP32, hard to beat
in productivity :

1732018250338.png


Block languages like Scratch, Nodered, Flowcode, Visuino.....all great tools.
 
Last edited:
@dana:

I understand that this code is generated ...

But from your understanding: Does it make sense to use a "float" for
* FirstPulseFlag
* PulseWidth
* and to compare with digitalRead()

I personally would use an integer in all three places. Especially for a ATTINY85. But I´m no software expert.

Klaus
 
Many Block languages "hide" from user, the nuances of C, hence use of floats.
--- Updated ---

Note to OP, in post #12 thats actually a client shown in Tuniot blocks, a server
is equally easy.
 
Last edited:
i bench tested with LEDS, change the nano pins in original code to
pinMode(0,OUTPUT);//pin 5 on ic
pinMode(4,INPUT);//pin 3 on ic
but did nothing so write my own code similar and worked. didnt really debug the other one too far apart from changing the pin numbers.
works now is the main thing, works bench works real life.
 
How can it work great with this code you posted earlier ?

void setup() {
// put your setup code here, to run once:
pinMode(0,OUTPUT);//pin 5 on ic
pinMode(4,INPUT);//pin 3 on ic
digitalWrite(0,0);
}

void loop() {
// put your main code here, to run repeatedly:
if(digitalRead(4) == 1){

digitalWrite(0,1);
delay(8);
digitalWrite(0,0);
delay(8);
digitalWrite(0,1);
delay(8);
digitalWrite(0,0);
delay(8);

}else{

digitalWrite(0,0);
}
}

And you asked it have a min input PW of 200 mS ?

trying to make a small circuit that when a high input pulse of around 200ms is received it will output 2 high pulses of around 200ms with 200ms gap
anyone assist how to do it? having problems finding answer.

And you never answered the questions if button held down does it keep repeating double pulses or
just gen 1 set and wait until button released to setup for another button press ?

I dont get what you are doing ?
 
How can it work great with this code you posted earlier ?



And you asked it have a min input PW of 200 mS ?



And you never answered the questions if button held down does it keep repeating double pulses or
just gen 1 set and wait until button released to setup for another button press ?

I dont get what you are doing ?
it can repeat all the time if it wants to, doesnt affect anything. i found my circuit requires a double pulse to do its operation thats all.
 
To me the given informations make no sense ... they are just confusing, because they contradict each other.

Klaus
 

LaTeX Commands Quick-Menu:

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top