Download presentation

Presentation is loading. Please wait.

Published byTrevor Lakins Modified over 2 years ago

1
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

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

3
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)

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

5
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;

6
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%

7
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

8
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)

9
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

10
Demo

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

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google