Arbitary waveform generator using a micro-controller

Thread Starter

tapajitm

Joined Mar 3, 2017
7
Hello dear friends,

The following image is that of a Data signal, one waveform is used to represent logic level 1 and other 180 degree phase shifted waveform represents logic 0. Can someone please provide some input on how I may be able to generate the following waveforms on a micro-controller ?

Regards,
TM
 

Attachments

djsfantasi

Joined Apr 11, 2010
6,965
What you are looking for is a digital to analog converter. It would require two to three pins of your microprocessor. Two pins could be done with a 1V (or 2V) offset since otherwise you would require 5 different outputs (although two would not be used). Three pins would avoid that issue although the following pin states would not be used: 000, 001, 101, 110 & 111. But this does not present a problem.

Then, your code would write to the output pins corresponding to the level required, with the proper delays.
 

Thread Starter

tapajitm

Joined Mar 3, 2017
7
Hi,
The waveform is a signal, sharp edges and fast rise/fall times is generally not possible with the inbuilt DAC. What else can be done ??
 

davideather

Joined Dec 12, 2016
33
use a voltage divider to get your 3 volts quiescent signal. Then use 1 pin going hi or low to pull that signal (via a resistor) up or down to 4 or 2 volt respectively. You may need to buffer the output but speed will not be an issue.
 

ian field

Joined Oct 27, 2012
6,539
Hi,
The waveform is a signal, sharp edges and fast rise/fall times is generally not possible with the inbuilt DAC. What else can be done ??
Seems like you need an external flash DAC. Your micro could send arbitrary codes to it directly, or it could in some situations be simpler to burn a lookup table into EEPROM.
 

BR-549

Joined Sep 22, 2013
4,938
If he has to stick to that function in his image......it will take some study. A 4 usec input......but look where and how he wants to match the square. A switch at zero and peak.

So double the F and he want's to invert also.
 

MrChips

Joined Oct 2, 2009
22,102
What you are trying to generate looks like a digital signal. You don't really need a DAC to do this.

Your time scale shows intervals of 1μs. Commonly available DACs have settlling times of about 1μs and hence would be too slow for this application.

Take five resistors of equal resistance (e.g. 1kΩ each) and put them in series across the +5V and GND power rails. You will be able to tap off any voltage from 0V to 5V in 1V steps.

Use an analog switch such as CD4016 and select the voltages that you need, i.e. 2V, 3V, 4V.
Now all you need to do is to program the MCU to select the voltage you need at 1μs intervals.
 

MrChips

Joined Oct 2, 2009
22,102
A three bit DAC built using a resistor ladder can be very fast. I never intended that the TS use any other type of DAC
That's a clever idea.

How about a 2-bit ladder network? You only need three outputs, 2, 3 and 4V.

Hmmm, need to get to the design board and work out the values of the resistors.
 

djsfantasi

Joined Apr 11, 2010
6,965
That's a clever idea.

How about a 2-bit ladder network? You only need three outputs, 2, 3 and 4V.

Hmmm, need to get to the design board and work out the values of the resistors.
Yes, it could be done with two bits. However, in my mind I saw five levels, of which two aren't used. 0,1,2,3,4.
 

MrChips

Joined Oct 2, 2009
22,102
Yes, it could be done with two bits. However, in my mind I saw five levels, of which two aren't used. 0,1,2,3,4.
I could not find a solution with two bits.
Have not worked out the solution with three bits @ 5V.
A resistor network with R, 2R, 4R works with 8V supply.
 

MrChips

Joined Oct 2, 2009
22,102
Here is a 2-bit DAC that gives 2-3-4V output.

2-3-4V output.png
R1 = 80Ω
R2 = 240Ω
R3 = 100Ω
R4 = 400Ω
Vs = 5V

A requirement is that the MCU must be able to put the I/O pins Q1 and Q2 into a high impedance or input state.

With both Q1 and Q2 disabled, the output is 4V.
When Q1 is enabled as a sink to ground (while Q2 is disabled) the output is 2V
When Q2 is enabled as a sink to ground (while Q1 is disabled) the output is 3V.

Depending on the sink capability of the MCU output pin, you may want to scale up the value of the resistors by a factor of 2 or 3.

For example, double all the values to

R1 = 160Ω
R2 = 480Ω
R3 = 200Ω
R4 = 800Ω
 
I see this is an older post, but an interesting one, so I thought I'd add to Mr. Chip's nice answer with a similar solution for those who may visit here later. This should work with MCU chips that don't allow Hi-Z state on the output pins. Simply add two signal diodes and tweak the resistor values something like this:

Capture.JPG

Having said that, I think you'll find that most MCU chips are capable of Hi-Z on the digital output pins even if it isn't readily obvious. For instance, the AVR chips used on the Arduino boards can set the DO pins to Hi-Z by simply setting them to input mode in the user program and making sure the internal pullup resistors are not turned on. However, the question arises about whether this can be done quickly enough to satisfy your signal switching time requirements, which can be answered by a trip to the data book for that chip, whatever it is. Also, the resistor values may need to be changed to satisfy MCU drive limitations and input impedance of whatever load is being driven by this circuit.
 
Top