📄 vppcntrl.asm
字号:
; Software License Agreement
;
; The software supplied herewith by Microchip Technology Incorporated (the "Company")
; for its PICmicro(r) Microcontroller is intended and supplied to you, the Company's
; customer, for use solely and exclusively on Microchip PICmicro Microcontroller
; products.
;
; The software is owned by the Company and/or its supplier, and is protected under
; applicable copyright laws. All rights are reserved. Any use in violation of the
; foregoing restrictions may subject the user to criminal sanctions under applicable
; laws, as well as to civil liability for the breach of the terms and conditions of
; this license.
;
; THIS SOFTWARE IS PROVIDED IN AN "AS IS" CONDITION. NO WARRANTIES, WHETHER EXPRESS,
; IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
; MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE
; COMPANY SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
; CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
;
;###############################################################################
; filename: VppCntrl.ASM
; Vpp Control functions
;
; This file implements a regulated boost power supply.
; The following resources are used by this module:
; CCP
; ADC channel
; Timer
;
;###############################################################################
GLOBAL lastADRES
#include <P16C745.inc>
#include "pid.inc"
errorlevel -302 ; suppress message 302 from list file
udata
PowerState res 1 ; Power Status Flag
#define PowerGood PowerState,0
#define PowerHigh PowerState,1
#define PowerLow PowerState,2
#define PowerON PowerState,7
pwm res 1 ; temporary value for CCP loader
Result res 2 ; final calculation
skip res 1
lastADRES res 1
; Set Points for voltage regulator.
V5V equ .92 ; counts for 5v from Regulator
VCHECK equ .220 ; regulator setpoint (13v)
PWM_MAX equ .130 ; 75% PWM Maximum
PWM_MIN equ .13 ; 5% PWM Minimum
skip_reload equ .10
PORT1 code
VppInit
global VppInit
pagesel InitPID
call InitPID
pagesel SetTarget
movlw VCHECK
call SetTarget
clrf STATUS ; Bank0
return
VppLow
global VppLow
; cause Vpp to be 5v
banksel PowerState
bcf PowerON
banksel CCP1CON
clrf CCP1CON ; turn off CCP
clrf STATUS ; Bank0
return
VppHigh
global VppHigh
; cause Vpp to be 13v
; does not return until regulator is running
; setup ADC
banksel ADCON1
movlw 0x04
movwf ADCON1
banksel ADCON0
movlw 0x89 ; configure ADC for Fint/32 and AN1.
movwf ADCON0 ; Turn ADC on
banksel PORTC
clrf PORTC
banksel TRISC
bcf TRISC,2 ; set RC2 as output
bsf TRISA,1
; setup CCP
banksel PR2
movlw .63 ; 93.75khz Timer 2
movwf PR2
banksel T2CON
movlw 0x7C ; T2 postscale 1/16
movwf T2CON
movlw PWM_MAX
pagesel updateCCP
call updateCCP
banksel PowerState
bcf PowerGood
bcf INTCON,GIE ; Disable Global IRQ for a little bit
banksel TMR2
clrf TMR2 ; Clear T2 Counter
banksel PIR1
bcf PIR1,TMR2IF ; Clear T2 Pending IRQ
banksel PIE1
bsf PIE1,TMR2IE ; Enable T2 IRQ
banksel INTCON
bsf INTCON,PEIE ; Enable Peripheral IRQ
bsf INTCON,GIE ; Enable Global IRQ
bsf ADCON0,GO
banksel PowerState
bsf PowerON
clrf STATUS ; Bank0
return
VddOff
global VddOff
banksel PORTB
movf PORTB,W
iorlw 0x80
movwf PORTB
; turns on the Vdd transistor
clrf STATUS ; Bank0
return
VddOn
global VddOn
; turns off the Vdd transistor.
banksel PORTB
movf PORTB,w
andlw 0x7F
movwf PORTB
clrf STATUS ; Bank0
return
VppOn
global VppOn
banksel PORTA ; make RA0 high
movf PORTA,W
iorlw 0x01
movwf PORTA
clrf STATUS ; Bank0
return
VppOff
global VppOff
; make RA0 low
banksel PORTA
movf PORTA,W
andlw 0xFE
movwf PORTA
clrf STATUS ; Bank0
return
updateCCP
; place W value in CCPL & CCPCON<5:4>
banksel pwm
movwf pwm
sublw PWM_MAX
btfsc STATUS,C
goto uc
movlw PWM_MAX
movwf pwm
uc
swapf pwm,w
andlw 0x30
iorlw 0x0F
banksel CCP1CON
movwf CCP1CON
banksel pwm
rrf pwm,f
rrf pwm,w
andlw 0x3F
banksel CCPR1L
movwf CCPR1L
return
DoSwitcher
global DoSwitcher
banksel skip
decfsz skip,f
goto switcherdone
movlw skip_reload
movwf skip
banksel ADRES
movf ADRES,w
; start next ADC
bsf ADCON0,GO
banksel lastADRES
movwf lastADRES
banksel PowerState
btfss PowerON
goto switcherdone
pagesel doPID
call doPID
pagesel updateCCP
call updateCCP
switcherdone
banksel PIR1
bcf PIR1,TMR2IF
banksel PORTB
return
PWMOn
global PWMOn
bsf STATUS,RP0 ; Bank1
bcf TRISC,1 ; make RC1 an output
movlw .74
movwf PR2
bcf STATUS,RP0 ; Bank0
return
PWMOff
global PWMOff
bsf STATUS,RP0 ; Bank1
bsf TRISC,1 ; make RC1 an input
movlw .63
movwf PR2
bcf STATUS,RP0 ; Bank0
return
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -