I need to convert a 0/1 signal to pulse when the output changes - Page 1
Forum section: electronics / beginners

author: Deactivated-1
author_rank: Frequent Contributor
timestamp: February 15, 2020, 09:02:43 pm
content: I have MOSFETs switching relays (low side) for a tube amp and I need to get a pulse that pulses each time any mosfet turns off/on.is there a simple circuit that does this?

author: Circlotron
author_rank: Super Contributor
timestamp: February 15, 2020, 09:20:59 pm
content: Differentiate the rising and falling edges of the mosfet gate drive.

author: brucehoult
author_rank: Super Contributor
timestamp: February 15, 2020, 09:25:07 pm
content: You want both 0->1 and 1->0 changes on any MOSFET to produce a 0->1->0 pulse on an output?What do you want to do if more than one changes at the same time -- or at least before the previous pulse finishes?I think what you'll need to do is:1) XOR together all the MOSFET outputs2) create a 0->1 triggered one-shot3) create a 1->0 triggered one-shot (can be the same as the above, with an inverter before it)4) OR together the previous two signalsAlternatively, you could do 2-3 for each MOSFET and then OR together all the outputs.This seems definitely complex enough that it would be simplest to use a microcontroller with enough digital inputs and a very short program.

author: Dmeads
author_rank: Regular Contributor
timestamp: February 16, 2020, 07:44:27 am
content: Okay so look at the schematic I drew. I think this is what youre trying to do.Link the signal going into your MOSFET to one input of an OR gate. Tie the other input of the OR gate to Ground. (this is called enabling the gate, because x OR 0 is always x), so you will just get whatever your input signal is (0 or 1) on the output of the OR gate.You can then send this to a one shot (mentioned above). This can give you a longer pulse out than the input. Lets say your input signal is low (0), then it is high (1) for 20ms. Depending on the one shot circuit and the external components attatched to it, you could get an output pulse that is high for maybe 100ns or greater (all depends on the one shot circuit).If you want the pulse to be the same length as your input signal, just use the output of the OR gate (although there will be a slight propagation delay in the order of nano seconds).in other words: want pulse to stay high even after input signal has gone low? Use oneshot, otherwise, just use output of OR gate.555 timers can be used for one shots and so can 74121 chips. If you use electrolytic caps with the 74121 make sure to use a switching diode too (see attatched datasheet) for proper operation.Hope this helps!-Dom555 timer:http://www.ti.com/lit/ds/symlink/lm555.pdf74121:https://pdf1.alldatasheet.com/datasheet-pdf/view/177142/FAIRCHILD/DM74121.htmlmore info on oneshots:https://www.utm.edu/staff/leeb/3b3.htm

author: Dmeads
author_rank: Regular Contributor
timestamp: February 16, 2020, 07:47:54 am
content: If you also need a pulse when the MOSFET turns off, do eveything the same except use a NOR gate instead of an OR gate. This will still give a high pulse out when the input signal is low

author: Dmeads
author_rank: Regular Contributor
timestamp: February 16, 2020, 07:55:35 am
content: alternativley if you dont want to do all that you might be able to use an arduino and code it something like:Code:int signal;int my_delay; // delay in mssignal = digitalRead(input pin); // reads your input signalif (signal == 1){digitalWrite(output pin, HIGH); // this makes a pulse high for however long of a delay you want, 5000ms = 5second etc.delay(my_delay);digitalWrite(output pin, LOW); // after, the pulse will go back low}

author: brucehoult
author_rank: Super Contributor
timestamp: February 16, 2020, 08:28:07 am
content: Well, an AVR chip rather than a whole Arduino.And the code might look like this:Code:long lastVals, lastTrigger;void checkVals(){long now = millis();long newVals = (long)PORTA<<24 | (long)PORTB<<16 | (long)PORTC<<8 | (long)PORTD;newVals &= ACTIVE_INPUT_MASK;if (newVals != lastVals) {lastTrigger = now;lastVals = newVals;digitalWrite(OUTPIN, high);}if ((now - lastTrigger) > ONESHOTTIME) {digitalWrite(OUTPIN, low);}}Call checkVals() regularly. And of course you need some more code to set up the ports initially, and you need to specify your constants.This will let you deal with up to 32 inputs, depending on how many digital IO pins your particular AVR has and how many you need :-)