Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 16: Digital to Analog Converter - PWM Implementation

Similar presentations


Presentation on theme: "Lecture 16: Digital to Analog Converter - PWM Implementation"— Presentation transcript:

1 Lecture 16: Digital to Analog Converter - PWM Implementation
Lecturers: Professor John Devlin Mr Robert Ross

2 Overview Implementation of a DAC using PWM Class Demonstration
Worked example – Software Loops Worked example – Timer Based

3 DAC PWM Implementation
Choose an operating frequency (this specifies the period of the DAC) Create a filter circuit to operate at the desired frequency Write software to vary on/off time When on – drive output high When off – drive output low

4 PWM software loop implementation
PWM can be generated in software simply by using loops This is generally bad design (timers use less CPU resources and are more accurate) A useful stepping stone to understanding DAC’s

5 PWM software loop implementation
MOV #100, R5 ; Period MOV #50, R6 ; ON Time setup MOV #0, R ; Comparison register BIS.b # b, &P1OUT ; bit 1 = high on_time INC R7 CMP R6,R7 ; has on time expired JNE on_time BIC.b # b, &P1OUT ;on time expired, bit 1 = low off_time CMP R5, R7 ; has off time expired JNE off_time JMP setup ; off time has expired

6 Timer based PWM implementation
Timers can be used to perform PWM with less CPU overhead – allowing processing for other tasks Design the following PWM timer: Period = 16.38ms F = 61kHz OFF Time climbs from 0 to 16.38ms and repeats from 0 Timers will be covered in detail in lecture 19

7 Timer based PWM implementation
SetupP1 BIS.B #0x0f,&P1DIR ; Set P1.0-P1.7 as outputs BIS.B # b,&P1SEL ; P1.2 and P1.4 TA/SMCLK options SetupP2 BIS.B # b,&P2DIR ; Set P2.6 and P2.7 as outputs Set_clock ; Set to calibrated 1MHz Clock MOV.B &CALBC1_1MHZ,&BCSCTL1 ; Set range; DCO = 1 MHz MOV.B &CALDCO_1MHZ,&DCOCTL ; Set DCO step + modulation setup_timer MOV.W #02000h,&TACCR ; CCR0 = PWM Period/2 MOV.W #0,&TACCR ; CCR1 = PWM_OFF_Time/2 MOV.W #00C0h,&TACCTL ; Output=Toggle/Set MOV.W #0230h, &TACTL ; CLK = SMCLK(1MHz), MODE = ; UP/DOWN

8 Timer based PWM implementation
MOV.W #0, R ; Initialise OFF_Time reset_countdown MOV.W #0FFh, R4 ; Initialise countdown main DEC R ; Decrement countdown JNZ main ; If countdown != 0, loop INC R ; Increment the OFF_time CMP &TACCR0, R ; Does OFF_Time = Period? JEQ reset_r ; If OFF_Time = Period, jump MOV.W R5,&TACCR1 ; Load OFF_Time into register JMP reset_countdown ; Loop again reset_r5 MOV.W #0, R ; Reset OFF time

9 Circuit Diagram Add a low pass filter to reduce switching noise and return an analog signal C should be small – otherwise DAC response will be low MSP430 R = 330k Analog Signal P1.2 C=100nF

10 Class Demonstration – Timer PWM
Without filtering circuitry With filtering circuitry:

11 Summary Digital to Analog converters allow digital electronics to output signals which are similar to real world continuous signals Pulse Width Modulation is a simple and widely used form of DAC


Download ppt "Lecture 16: Digital to Analog Converter - PWM Implementation"

Similar presentations


Ads by Google