Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Papers

PWM Triangle Wave from two clocks

+5
−0

What follows is a proposed concept of a simple (in principle!) way to generate a fixed-amplitude triangle wave, using two clocks, an XOR gate, and not using any processor cycles.

It is practical in the low-mid-100-Hz ballpark, with typical mcu clocks. Motivating application is dither waveform for solenoid valve control signals.


SUMMARY

Two timers output two clocks A, B, with fixed 50% duty cycle. XOR(A,B) produces a symmetrical PWM triangle wave, with modulation frequency at ($f_{\rm A} + f_{\rm B})$ , and triangle frequency at $(f_{\rm A} - f_{\rm B})$. No other additional hardware. Illustrated below, showing how the XOR output is equivalent to a PWM. (click to zoom)

xor-pwm

Given a master clock $f_{\rm CPU}$, the available frequencies are:

$$f_{\rm TRIANGLE} = \frac{2 f_{\rm CPU}}{(n^2 - 1)}$$

"$n$" should be an odd integer. The two clocks are set to $f_{\rm CPU}/(n+1)$ and $f_{\rm CPU}/(n-1)$, to make the dividers even numbers, so that A and B can have 50% duty cycles.

The low-pass filter design is also parametrized by $n$. Let's define the passband at the triangle’s 5th harmonic, and the stopband at $(f_{\rm A} + f_{\rm B})$. The dimensionless value $f_{\rm STOP} / f_{\rm PASS}$ will represent the filter's transition band, and this value comes out to $n/5$.

The dimensionless transition band corresponds to "filter complexity". A narrower transition band places more demands on the filter design. Given a lower limit of this value, a practical upper limit for the triangle frequency can then be derived as

$$ \frac{f_{\rm TRIANGLE(max)}}{f_{\rm CPU}} = \frac{2}{25} \left(\frac{f_{\rm PASS}}{f_{\rm STOP}}\right)^2$$

The table below uses this formula to show typical limits of the application:

min acceptable $f_{\rm STOP}/f_{\rm PASS}$ max $f_{\rm TRIANGLE}/f_{\rm CPU}$
20 1 / 5000
40 1 / 20000
60 (shown in example) 1 / 45000
80 1 / 80000
100 1 / 125000

Example Circuit producing 199Hz from 10MHz f_cpu example-circuit

Simulation of above circuit. 0-1V inputs produce 12mV - 988 mV peaks simulation-full-scale

Detail showing less than 1% ripple. simulation-ripple-detail


Additional details of the analysis, and example showing the design calculation, are here (pdf file, 5 pages).

History
Why does this post require moderator attention?
You might want to add some details to your flag.

1 comment thread

General comments (5 comments)