Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Computer-controlled square-wave generator

Status
Not open for further replies.

niculaegeorge

New Member
I am trying for some time to control/drive a simple N-channel MOSFET gate with a computer. Therefore I need a TTL 5 to 12 V output signal from my computer. From what I know, the only output capable of such thing is Parallel Port/Centronics. However I'm not satisfied with that, because I can't get it to switch faster than 1ms. :( I've heard speculating that some people have managed to get the maximum switching time out of it, were one bit of info sent acts like a signal picked up by the switching transistors. I wish I could do that, but these are dreams. What I'm only after is kind of a simple square wave generator(emphasize> ONLY SQUARE WAVE) frequency controlled by the computer. What I'm having in mind is a low gate threshold MOSFET acting as a driver for a bigger MOSFET's intended for heavy inductive loads. How can it be more simpler than two transistors? Sadly I wish it were that simple. This low-threshold MOSFET should be controlled by ANY 1V DIGITAL OUTPUT FROM MY COMPUTER. There are MANY "Pick-up points" were I can extract such a digital signal that I can then control with the computer. One is the Parallel port (if someone would actually tell how to make it switch in the KHz range), second is the serial port (here I will need another simple circuit, I say simple because I'm only interested in fast square wave switching, therefore no amplification, no current, no analog signal. Only digital levels. Using pull-ups resistors and additional FET stages to raise the digital level require to open high power N MOSFETs- so what I have in mind is something ridiculous simple. Here using the serial port, I will also need a software). There are many ways I know in theory that a digital output can be extracted from the computer. Another I've heard can be done using the Joystick/MIDI output from a sound card. Another way is through the USB data out pin. But I've also seen another more accessible way to control power FET switching is through the audio output 3.5mm jack stereo output speakers from the sound card. Although in theory I can only achieve a maximum of 20KHz switching frequency, I have to be satisfied with that considering other inaccessible alternatives. The problem with the audio output, is the fact that is weak analog signal. So it must be converted in a high TTL digital output (Analog to Digital conversion ADC) like we **broken link removed**, **broken link removed**. I've tried with no success to build such circuits. I like this alternative, because I can easily generate for example exactly 13.4567 Hz in a coil using only a computer and few components which is difficult to do with expensive high precision/accuracy signal/function generators! What can it be more cool than that?
Another way through which I'm thinking of controlling the gate switching a MOSFET is through the use of a Soundcard that has a digital output. What can I do about that? :confused: Another possibility I'm considering is using the PWM yellow wire fan speed control going into any of the cooling fan in the computer.Is it possible to extract that PWM and use it to drive a low-threshold n channel MOSFET acting as a driver for a bigger more powerful heavy switching nMOSFET? If yes, then I'm going to also need the software that controls the speed of the fan). What schematic should I use? The only thing I am finding on the web regarding all these things, are people that are controlling leds, servos, motors, relays and all kinds of garbage, :mad: except a simple common ordinary MOSFET !!! Then you have a Square wave (only) generator controlled by the computer. Isn't that cool or what? ;) Another problem I have to consider with all these possibilities presented, is which of these can most easily provide an almost DC output for longer periods of time, say when I'm trying to output a 50% duty cycle 0.5 Hz frequency switching. This means that I'm not only interested in peaks, or one-shots or low duty cycle. So a S/R latch IC might be required. Therefore I seek a way to generate computer controlled high power/high frequency/adjustable duty-cycle/PWM fast switching using one of the methods described above. Can anybody please help me with advices, suggestions, links or a diagram or something?
 
Can anybody please help me with advices, suggestions
You already seem to have covered most options! Regarding the analogue audio output, that can easily be converted into logic-level signals suitable for driving FETs.
 
Here's a circuit which will convert an audio signal (100mV amplitude or greater, 3Hz to 20kHz) from the PC into a logic-level signal and drive a FET ...
 

Attachments

  • Audio2Logic.gif
    Audio2Logic.gif
    13.7 KB · Views: 316
  • Audio2Logic.asc
    3.8 KB · Views: 191
Exactly want I wanted. Nice! Great. Thank you! :D
I've build the circuit, and I have to say it works acceptable well, with a few minor drawbacks.
I have to mention that I know a little bit electronics theory, but my designing skill are 0, building skills 0, (more like -1 ) and not much practical experience whatsoever. :eek:
It seem to have some switching noise. How do I "de-bounce"/"clean" the fake switching after an audio raising/falling edge? :confused:
swithcing noise.JPG
I have noticed the 100k pot at the entry in the circuit, and the higher I go with the switching frequency the lower I have to adjust it. If I have a wav file with a square wave sweep from 10Hz to 500Hz, I will have to manually adjust it with the raising frequency. I don't like that. I thought about another solution regarding this. I could place the output of this circuit through a divide by 2 D latch: :eek:
D latch.gif
Now my input signal sent by the computer will be identical with the one seen at the output. Therefore, if this will be the case, then the 100K pot should be replaced with a lowest value acceptable. (I don't know how to calculate it but I know that we have to account for the working frequency band 1Hz-20KHz), so that with each raising and falling edge of the input pulse will be a one-shot with the pulse width slightly grater than the minimum seen by the latch. However the cleaning/de-bouncing the switching noise still presents as a problem :confused:. I think a some kind of threshold voltage level condition should be place, but where in the circuit or how, I don't know . A filter at the input? :confused: But won't that effect the working at higher frequencies? :confused:I don't know. How do we solve this? Please, I'm begging you, help…
 
It seem to have some switching noise
1) At which point in the circuit are you detecting the 'switching noise'?
2) What is the amplitude of your input signal?
3) That noise looks to me like ringing due to stray inductance. Have you built the circuit on a breadboard? Are all wires very short? Is the 'scope cable screened?
I have noticed the 100k pot at the entry in the circuit
It is for setting the bias so that Q1 collector is at half the supply voltage. If the bias is not correctly set then asymmetric clipping of the waveform may occur and only half of the wave may switch the FET.
the higher I go with the switching frequency the lower I have to adjust it.
The mid-rail setting point should be independent of frequency. It's possible the amplifier (Q1) gain is dropping off at higher frequencies. Try by-passing C2 with a 100n cap.

I've designed a modified circuit to provide cleaner pulse edges, by using a CMOS Schmitt trigger, i.e. involving defined thresholds as you mention.
 

Attachments

  • Audio2Logic2.gif
    Audio2Logic2.gif
    11.9 KB · Views: 229
There are freeware programs you run on the PC, that generate the waveform using the sound card and output the waveform from the soundcard line out plug.

Here's one I have used before that seemed to work ok, (although the waveform shapes are not perfect at frequencies over 10kHz as the PC sound card uses a 44.1kHz DAC);
**broken link removed**
 
Computer Controlled positive pulse wave driving a MOSFET

1. At the output, directly visible on a light bulb, at ELF.
2. I don't know, I didn't measure it. (it turns out that this was the cause)
3. It's build on a breadboard. I try not to use wires at all. Connections are made using staples. I didn't use a scope.
After so many hours of failures, I finally made it to work, in a kind of hybrid "tweaked" state.
audio square wave generator.JPG
If you have seen what I have done to your circuit, I say> Please! Don't laugh! Have mercy! I'm a beginner! :eek: Show some understanding…:eek: please….I have no idea what I have done, but fortunately it works…I messed up everything, I know…mercy…I thrown in new components in hope it will work. I was lucky :eek:…Forgive me…That's not how electronics must be done, I know. But for better or worse, it works. :D
I have to admit, I hate analog processing. I just hate it. :mad: Too many things can go wrong. That's why I am extremely fond to digital electronics.You only have 1 or 0. Either works, either it doesn't. Simple. Nothing in between. ;) That's why I'm not very comfortable having this circuit drive my power mosfet directly. I'm more relaxed knowing that it's pure, clean, digital signal that is driving my FET. That is why I've changed the circuit. Instead of 2.5V in between the complementary transistors I used 3.3V. The reason why is because, It was readily available in my custom made altered CPU PSU power supply. So I just hook that voltage there. Probably it messed the circuit and your design, but I don't know. I managed to adjust it the way it is. I've replaced the 3.3V pin with a voltage divider. It seems not to work anymore when I put 2.5V there the way it was supposed to be, it only works now with 3.3 because of my adjustments.
I kind of understand how the circuit works, but not completely because the output on the gate of the FET in your original design, when I've test it, seems not to have the same PULSE WIDTH as the one generated by the computer.
This is why I hate analog processing of signal. :mad: So I took the generated pulses and put them through a D-type Flip/Flop so that, again, like I said, either is one or zero. Voltage level or Zero. Works or it doesn't. So know those short pulses (generated at the raising and falling edge of my original pulse in the computer) will be reconstructed.
Before the Schmitt trigger I used a capacitor C3 that seem to help in the ELF band between 0.0001Hz and 10 Hz. (0.0001 Hz means one pulse at every 2.7 hours). Probably you will go nuts, hearing that I'm stressing you design to switch on so low frequencies, especially when you design it from 3Hz upwards, but I don't see the harm. Strange enough it seem that this capacitor sometimes it's not required. Maybe something on my custom-made breadboard doesn't make a firm contact or something. I don't know. I will see when I move the circuit on a board.
Another very important aspect of your design, that I didn't figured out at first, was that it requires a "narrow band" for the input voltage. I didn't measure the input voltage in the circuit, but my master volume from windows is set at 14%. If I set it to 17% it starts to "jitter" if I can use that term, and bounce, and all that noise, and distortion after a falling edge from a pulse. So it took some time before I realized that. And is more likely to happen on low frequency. Above 500Hz it works well even without any additions. :)
With all these modifications, it seems that changing the R1 100K trimpot has no effect on the operation of the circuit whatsoever. Now the only adjustment that has a major impact on the working of the circuit seem to be the input voltage coming from the soundcard. The master volume in XP is set at 14%.
Regarding the answer Mr RB to my problem, I will reply to him and to those ho later on, read this post. I'm not after that. :( I know that probably the title of the thread doesn't accurately describe my real problem. I know, I know. There are hundreds of applications/software's that can put out square waves at the soundcard output and many other signals. I'm not after that. I know that. I want something else. Which is not obvious if one reads only the title of the thread. Ultimately, for example, I want to light a 220V 100W light bulb with positive pulse wave at 535.2 Hz from the audio output of my soundcard! Or I will want to drive a 20A current through a 4ohm coil at 1206.3456Hz using the audio output from the computer and a special software that has the ability of generating such signals with such a high accuracy frequency! :p Many software's specialized in signal generating from the soundcard, are unable to do that. Mostly can only generate an integer number as the frequency. Again, I don't want that! I want high accuracy with easy and cheap materials thus high accessibly! :eek:
Maybe this circuit won't have the frequency stability that I need, like say if I put out a consistent 45.5421 Hz it will fluctuate with +/- 0.001 Hz or higher. Ok, Ok, I accept that. It's acceptable. As long as such a method of generating the computer controlled positive pulse wave from the audio output is much more precise than your steady/rock hand on the potentiometer of your common signal generator, I'm ok with that. If it's slightly more precise/accurate that the common ordinary signal generator, I will take it.
GoldWave signal.JPG
I'm using GoldWave as the source signal, and has an extremely useful ability to generate any type of signals, with the "Expression Evaluator" tool. If you have a power amplifier it's even better! Of course the load impedance must be adjusted accordingly to have the required output power. Goldwave It's able to analyze/calculate/evaluate any mathematical function you input, and gives you the result of the function versus time as a wave. It can work with frequencies up to 0.0001 accuracy. Can also sweep a signal from x to y, Thus I can automatically program the computer to sweep from 0.0001 Hz to 5Hz in a one hour length wav file!!! (a lot of HDD space) This will AUTOMATICALLY advance the frequency by 0.0014 Hz with each passing second!!! And I don't have to turn a single knob!!! ISN'T THAT COOL OR WHAT? :D Show me another easy/accessible/cheap way of doing that!!! There is none!!!
I accept further suggestions, advices, improvements or simplifications regarding the circuit. Thanks for support. Namaste!
 
I have no problem with anyone modifying a circuit I've posted. Experimentation is what this hobby is all about. If it now works for you, great. I'm surprised your sound card can actually output anything below 3Hz. I was under the impression that most (all?) sound cards had AC-coupled outputs using a modest value of coupling cap which would severely attenuate ELF signals.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top