# Drawing Circles on a Tight Budget Using an 8-pin PIC12F675 microcontroller, harmonic oscillator theory and software PWM to generate in-phase sine and cosine.

## Presentation on theme: "Drawing Circles on a Tight Budget Using an 8-pin PIC12F675 microcontroller, harmonic oscillator theory and software PWM to generate in-phase sine and cosine."— Presentation transcript:

Drawing Circles on a Tight Budget Using an 8-pin PIC12F675 microcontroller, harmonic oscillator theory and software PWM to generate in-phase sine and cosine signals Catalin Patulea cat@vv.carleton.ca Second year Software Engineering student Carleton University

Overview Microchip PIC12F675 Reconstruction Filter Reconstruction Filter Oscilloscope X Y Software PWM Harmonic Oscillator (90° out of phase) Harmonic Oscillator

Harmonic Oscillator: Theory Second order recursive relation Can be modeled using the z-transform Can verify stability and period over integers (FSM) Y(n) = K·Y(n-1) - Y(n-2) Y(n-1)Y(n-2) Y(n)

Harmonic Oscillator: Design “Angular increment” Frequency determined by K Phase and amplitude determined by Y(0) and Y(1)

Harmonic Oscillator: Implementation Three 16-bit state variables “Seed” the oscillator Compute next sample (2cos(5°) ≈ K = 2 1 - 2 -7 ) Shift samples down static signed int x0, x1, x2; x0 = 0; x1 = 11; x2 = (x1 > 7) - x0; x0 = x1; x1 = x2;

Software PWM PWM is Pulse Width Modulation Constant frequency, variable duty cycle Average value proportional to duty factor Easily generated on a digital μC output pin PWM + reconstruction filter = poor man’s DAC 10% 40% 100%

Reconstruction Filter Intuitively, a short-term averager Low-pass filter with corner frequency between output frequency and PWM frequency –Cut out high-frequency “garbage” –Avoid attenuating useful signal If PWM frequency is high enough (compared to output frequency), RC will do just fine 70% Re- construction Filter

Summary 8-pin PIC12F675, two resistors, two capacitors 62 lines of C code (17% ROM, 46% RAM) –Room for optimization in assembly ~ 1 Hz in-phase sine and cosine, sampled at ~ 70 Hz Applications –QAM (Quadrature Amplitude Modulation)

Pros and Cons Small, few components –No external oscillator Cheap –About 3 \$ Low footprint –No look-up table Dynamically changing the frequency requires recomputing only 3 coefficients Dynamic frequency variations are limited by reconstruction filter Probably needs an amplifier to drive anything significant Probably not well-suited for high frequency or high quality conditions

Demo

Q & A Microchip PIC12F675 Reconstruction Filter Reconstruction Filter Oscilloscope X Y Software PWM Harmonic Oscillator (90° out of phase) Harmonic Oscillator

Download ppt "Drawing Circles on a Tight Budget Using an 8-pin PIC12F675 microcontroller, harmonic oscillator theory and software PWM to generate in-phase sine and cosine."

Similar presentations