Simple Sine wave generator delivers 100 mA!

Odessa

Senior Member
Occasionally the need arises to produce a 60 Hz sine wave, asynchronous to the mains voltage (and without using a xformer). The attached simple circuit does just that and provides 1.8V p-p @ 100 mA (although, the 50 Ohm output load is not shown on the schematic) output (Vcc) without using op-amps, crystals, xistors, or logic devices . By substituting the LM317T for the LM317L, ~ 1.5 A out could be obtained without modification to the circuit, other than perhaps a heat sink for the regulator.

Measured frequency is 59.17 Hz, so a little off, but good for many applications. The circuit uses the PWMOut command, at 20 KHz and a modified memory map of the sine function. Further tweaking could bring the frequency in even tighter, but at the expense of significant toil. The attached picture shows the output voltage, ac coupled into a 'scope. The 08M actually runs at ~5Vp and the output has a DC component near 3.75V.

This circuit uses the 08M running at 8 MHz. The 20 KHz PWM component can be ameliorated (i.e. smoothing or filtering of the output waveform) by introducing a 100 or so uH inductor between the PWM output pin and R3.

A more interesting project would be to use a 20X2 running much faster, and produce three sine-waves, 120 degrees out from each other. That may come sometime down the pike (if I ever get my 20X2s!).

If anybody wants the code (i.e. memory map), you can email me at chafalote@earthlink.net.

Odessa.
 

Attachments

Last edited:

manuka

Senior Member
Bravo on the "true sine wave" result (& your dry humour)! One assumes you're in the US/Can etc by the 60 Hz outcome-much of the world of course uses 50Hz. My eye caught your 20X2 mention, & since I'm presently eyeing "killer applications" for these darlings, I (& no doubt many others) would certainly appreciate code insights. Perhaps post here using the {code} ..... {/code} option ? Replace { }with [ ] of course. Stan. in NZ
 

Odessa

Senior Member
Hi Stan:

It should be noted that this circuit is really an ARBITRARY AC waveform generator; I just used a sine wave to illustrate its operation, but it could output triangle waves, etc. if the mapping for the output voltage is developed.

Sine waves are often used as motor drive sources, so obtaining good output power, that is, other than modest current levels, is attractive in those applications, so the LM317T is a great option there. It should also be noted that the fidelity of the AC waveform is plenty good for those type applications, and you won't find a circuit much simpler than this one, since most non-battery powered Picaxe circuits require some type of voltage regulation (Zener, etc.) at the input. This circuit just adds the PWM cap and resistor to the already present components to obtain a powerful sinewave output.

Regarding the application, there are really only two limitations: the operating voltage range of the Picaxes, and their speed. To generate an ac waveform on the supply pin, the voltage can't go much below about 2.5V or above 5.5V, and the execution speed of the BASIC code determines the highest frequency waveform that can be produced with reasonable fidelity.

In terms of the code for this particular circuit, initially I tried a loop but it was too slow, taking approx. 2.2 mSec to execute. For a 60 Hz sine wave, that means I could not even get 8 PWM output points to synthesize the waveform, too few, really (although Nyquist would say differently). Here's the code I tried for that:


Dirs=%00101
PWMout 2, Off
SetFreq m8


EEPROM 0,(0,200,0,225,0,243,0,255,1,8,1,11,1,11,1,8,0,255,0,242,0,225,0,200,0,167,0,126,0,78,0,33)
EEPROM (0,4,0,4,0,34,0,79,0,126,0,168)

Start:
For b13=0 to 42 Step 2
b12=b13+1
Read b13, b11
Read b12, b10
PWMout 2, 99,W5
Next b13
Goto Start

The EEPROM load was data points developed mathematically, based on the external component values in the circuit and the DC operating point. That data produced a distorted waveform, according to the predicted duty cycle that should have produced a sinewave. A pure sinewave mapping is not possible since the DC operating point is ~ 3.75V, a quarter of the way from the maximum operating supply voltage to circuit common. The current contribution via the PWM resistor weighs in more heavily during the low voltage portion of the PWM waveform than the high portion because circuit common is much further from the operating point than the varying supply voltage.

To obtain more points in creating the waveform I eliminated the loop (to reduce code execution time) and went with consecutive PWMOut statements. Once the approximate execution time of each statement is known, it can be determined how many points will make up the waveform; the more the better. In this case, with the 08m running at 8 MHz, 40 points make up the waveform, and that takes 252 out of 256 available bytes of program memory. To adjust the frequency closer to 60 Hz, one data point would have to be eliminated, but the frequency accuracy would not be improved that much, and it would be at the expense of that lost point in the waveform synthesis.

Here is the code used to develop the waveform in the 'scope picture attached to the original post in this thread:

Dirs=%00101
PWMout 2, Off
SetFreq m8

Start:
PWMout 2, 99,200
PWMout 2, 99,220
PWMout 2, 99,242
PWMout 2, 99,265
PWMout 2, 99,290
PWMout 2, 99,306
PWMout 2, 99,320
PWMout 2, 99,330
PWMout 2, 99,335
PWMout 2, 99,340
PWMout 2, 99,343
PWMout 2, 99,340
PWMout 2, 99,335
PWMout 2, 99,330
PWMout 2, 99,320
PWMout 2, 99,306
PWMout 2, 99,290
PWMout 2, 99,265
PWMout 2, 99,242
PWMout 2, 99,220
PWMout 2, 99,199
PWMout 2, 99,169
PWMout 2, 99,138
PWMout 2, 99,110
PWMout 2, 99,83
PWMout 2, 99,60
PWMout 2, 99,39
PWMout 2, 99,23
PWMout 2, 99,11
PWMout 2, 99,4
PWMout 2, 99,2
PWMout 2, 99,4
PWMout 2, 99,11
PWMout 2, 99,23
PWMout 2, 99,39
PWMout 2, 99,60
PWMout 2, 99,83
PWMout 2, 99,110
PWMout 2, 99,138
PWMout 2, 99,169

Goto Start

You can see code symmetry has been sacrificed in lieu of waveform symmetry, the paramount requirement.

Any questions, fire away. Hope this is useful to members on this site.

Odessa
 
Last edited:

fernando_g

Senior Member
Direct frequency synthesis with a PICAXE! And with a lowly 08M!
I'm impressed at your resourcefulness.

However, I do have a quesion, actually a couple.
1-. How did you develop the actual PWM operating points? With an Excell spreadsheet and by trial and error?

2-. Why do you use the same VCC output with the superimposed AC component to power up the PICAXE.... Wouldn't it be better to have its own dedicated 5v regulator instead? Or is this part of some feedback mechanism?

Edit; A quick calculation shows the required inductor value for a corner frequency of 20 Khz would have to be 3.5 millihenry.
 
Last edited:

Odessa

Senior Member
Hi Fernando:


1-. How did you develop the actual PWM operating points? With an Excell spreadsheet and by trial and error?\

First off, obtaining the resistor values was not trivial, although it may look like it was since they are simply presented in the schematic for you. There are many combinations that will not work.

Initial mathematical derivation produces D.C.=(1+sin(2*Pi*f*t))/(2+sin(2*Pi*f*t)), and this produces the values in the EEPROM load for the loop in the first try. But, as previously stated, the waveform is too distorted.

The second attempt is produced via 198 sin(2*Pi*f*t) + 200, however, that is also distorted and needs to be modified to approximate the first equation above.

Empirical approximation in modifying approximately 30% of the resultant data points provided the final curve.

2-. Why do you use the same VCC output with the superimposed AC component to power up the PICAXE.... Wouldn't it be better to have its own dedicated 5v regulator instead? Or is this part of some feedback mechanism?

The circuit is optimized for minimum component count and simplicity. Your suggestion of using a dedicated regulator works, and an AC output waveform with greater amplitude could result, but at the expense of more money, space, etc. You would still require a fairly tightly regulated input voltage to the 08M. The circuit as shown DOES use the output/supply voltage as a feedback path to determine the duty cycle.

Edit; A quick calculation shows the required inductor value for a corner frequency of 20 Khz would have to be 3.5 millihenry.

100 uH is not intended to filter the 20 KHz, rather it would smooth the much higher frequency components (rising and falling edges) of the PWM output signal from the 08M. Introducing a larger inductor value would probably distort the waveform and require further attention to determining the D.C. values, but, it could be done, and yes, the output waveform would be smoother; however an additional LC filter introduced at the output with the larger inductor would have the same effect, but without the distortion to the D.C. control loop. That would introduce a phase shift in the output, but in most applications that would be a don't-care.

Thanks for your comments, Odessa.
 
Last edited:

fernando_g

Senior Member
Ok, got your explanation.
My question on the separate regulator was sparked (pun intended!) by your suggestion on a three phase generator. In that instance, the question would be.....which of the three phases would be employed to power the PICAXE? Or would a separate supply would be needed?

An academic question at this point of time, the first hurdle would be to synthetize all three sinewaves with the proper phase relationship.
 

premelec

Senior Member
Thanks for this interesting application! I'm having trouble understanding why you have the output sine wave feeding the V+ of the PICAXE - or is this a schematic error?

I guess the intent of simplicity is your driving force - I'd probably put a diode in series with V+ and a capacitor across the PICAXE -
and perhaps a regulator if you wanted higher voltage swing as then the modulated LM317 could run at full tilt.. in any case good work for getting me more to think about :)
 
Last edited:

premelec

Senior Member
Some other methods...

I'm reminded by this work of romanblack.com 1 bit sound synthesiser stuff and Don Lancasters magic number sequences at tinaja.com - very interesting opportunities for more developent... perhaps touchtones and such... PICAXE onward!
 

Odessa

Senior Member
Hi Fendando:

"My question on the separate regulator was sparked (pun intended!) by your suggestion on a three phase generator. "

Yes, understood, good question. I will reserve comment on my approach there until I have a chance to build and test. I will again strive for minimum component count. If/when I develop that, I will post again on this forum with details. In the meantime, though, if you really need that polyphase source, a workable solution would be to use a pot off the output of this 08M circuit with a cap, making an RC filter and adjusting the slop in the capacitor value with the pot to achieve the desired phase lag, then use a gain stage with an emitter follower in the feedback loop to equalize the amplitude with the source waveform and achieve the desired output current. This could then be repeated again to obtain the third waveform. Not too elegant, but functional.

Hi Premelec:

I'm having trouble understanding why you have the output sine wave feeding the V+ of the PICAXE - or is this a schematic error?

No schematic error. I am attaching another picture here where you can see both the output waveform, and the PWM output of the 08M. Usually, applications employ only the time-varying element (Duty Cycle) of the PWM signal to achieve desired signal amplitudes; this application not only uses that, but also simultaneous varying AMPLITUDE of the PWM signal; this creates two degrees of freedom in the control loop and eliminates the requirement for an additional precision voltage regulator (or expensive voltage reference) to power up the 08M. The degree of freedom created by the varying PWM amplitude, i.e. making it both the input AND the output of the circuit essentially removes any otherwise present initial tolerance and drift with time/temperature to the 08M supply pin that would distort the output signal and introduce expensive components in the supply path. The resulting circuit is the simplest possible solution (at least that I can think of).

This is similar to taking ratiometric measurments with the on-board A/Ds. Maybe it would help you to think of it that way.

I guess the intent of simplicity is your driving force - I'd probably put a diode in series with V+ and a capacitor across the PICAXE -

A diode in series with the supply pin would create the initial offset, and drift-over-time problems I refer to above.

Thanks again for your comments, Odessa.
 

Attachments

MPep

Senior Member
What a neat approach! Bravo, well done indeed.
Perhaps now post in the Finished USer Projects area.
 
Top