EasyManua.ls Logo

Microchip Technology dsPIC30F - Page 304

Microchip Technology dsPIC30F
738 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
dsPIC30F Family Reference Manual
DS70061C-page 14-22 © 2004 Microchip Technology Inc.
Example 14-6 shows configuration and interrupt service code for the PWM mode of operation.
Example 14-6: PWM Mode Pulse Setup and Interrupt Servicing
; The following code example will set the Output Compare 1 module
; for PWM mode w/o FAULT pin enabled, a 50% duty cycle and a
; PWM frequency of 52.08 kHz at Fosc = 40 MHz. Timer2 is selected as
; the clock for the PWM time base and Timer2 interrupts
; are enabled.
CLR OC1CON ; Turn off Output Compare 1 Module.
MOV #0x0060, w0 ; Initialize Duty Cycle to 0x0060
MOV w0, OC1RS ; Write duty cycle buffer register
MOV w0, OC1R ; Write OC1R to initial duty cycle value
MOV #0x0006, w0 ; Load the working register with the new
MOV w0, OC1CON ; compare mode and write to OC1CON
MOV #0x00BF w0 ; Initialize PR2 with 0x00BF
MOV w0, PR2 ;
BSET IPC0, #T2IP0 ; Setup Timer 2 interrupt for
BCLR IPC0, #T2IP1 ; desired priority level
BCLR IPC0, #T2IP2 ; (this example assigns level 1 priority)
BCLR IFS0, #T21IF ; Clear Timer 2 interrupt flag
BSET IEC0, #T21IE ; Enable Timer 2 interrupts
BSET T2CON, #TON ; Start Timer2 with assumed settings
; Example code for Timer 2 ISR:
__T2Interrupt:
BCLR IFS0, #T21IF ; Reset respective interrupt flag
; Remaining user code here
RETFIE ; Return from ISR

Table of Contents

Other manuals for Microchip Technology dsPIC30F