English
Language : 

PIC16C781_13 Datasheet, PDF (111/188 Pages) Microchip Technology – 8-Bit CMOS Microcontrollers with A/D, D/A, OPAMP, Comparators and PSMC
PIC16C781/782
EXAMPLE 13-2: EXAMPLE PSMC CONFIGURATION FOR A BUCK MODE SWITCHING POWER
SUPPLY
;* PSMC Initialization
;* This code block will configure the PSMC
;* and all additional peripherals for a buck
;* mode switching power supply.
;*
;* Order of configuration
;* 1. PORTA/B I/O and analog configured
;* 2. DAC enabled, configured, and preset
;* 3. Op Amp enabled and configured
;* 4. Comparator C1 enabled and configured
;* 5. PSMC configured
;* 6. PSMC enabled
;********************************************
;* This code block will configure all analog ports.
;
BANKSEL TRISA
; Select Bank 1
MOVLW
B’00001011’
MOVWF
TRISA
; Set RA0,1,& 3 as inputs
MOVLW
B’11001110
MOVWF
TRISB
; Set RB1,2,3,6 & 7 as inputs
MOVLW
B’11101011’
MOVWF
ANSEL
; Set AN0,1,3,5,6 & 7 as analog
;*******************************************************
;* This code block will configure the DAC for VDD as
;* DACREF, and RB1/AN5/VDAC as an output.
BANKSEL
DACON0
; Select Bank 2
CLRF
MOVLW
MOVWF
DAC
B’11000000’
DACON0
; Set DAC to safe value
; Enable DAC, output
; and set DACREF = VDD
MOVLW
MOVWF
OUTPUT_VALUE
DAC
; Set dAC output level
;*******************************************************
;* This code block will configure the OPA module
;* as an Op Amp, with a 3 MHZ GBWP
MOVLW
MOVWF
B’10000001’
OPACON
; Set Op Amp mode and
; 2 MHz GBWP
;********************************************************
;* This code block will configure Comparator C1
;* for normal speed and output polarity,
;* input on AN6, and Reference from the VREF1
MOVLW
MOVWF
B’10001010’
CM1CON0
; Set C1; no ext out, norm
; speed & pol, VREF1, AN6
;********************************************************
;* This code block will configure the PSMC module
;* for PWM, Fosc/128, Single input, Single output
;* Non-inverting out, DC min = 0%, DC max = 50%
MOVLW
MOVWF
MOVLW
MOVWF
BSF
B’0000000’
PSMCCON0
B’00000110’
PSMCCON1
PSMCCON1,SMCON
; Set DCmin 0, DCmax 50, Fosc/128
; Set PWM, 1 in, 2 out, noninvert
; Enable PSMC
 2001-2013 Microchip Technology Inc.
Preliminary
DS41171B-page 111