📄 sub_data_acq.s
字号:
;START_HEADER
;
; dsPIC30F6014 Demo Source File
; (c) Copyright 2005 Microchip Technology, All rights reserved
;
; --------------------------------------------------------------------------
; File Revision History:
; --------------------------------------------------------------------------
;
; $Log: sub_data_acq.s,v $
; Revision 1.4 2005/04/04 23:39:04 VasukiH
; Updated comments in header
;
; Revision 1.3 2005/04/04 23:14:38 VasukiH
; Updates for MPLAB C30 v1.30 compatiblity
;
; Revision 1.2 2003/11/04 02:33:46 VasukiH
; Mods to A/D - automated channel-scanning
;
; Revision 1.1.1.1 2003/08/23 00:38:33 VasukiH
; First import of demo source into CVS Repository
;
;
;
; --------------------------------------------------------------------------
;
; Software and Development Tools Info:
; --------------------------------------------------------------------------
; Tool Version
; --------------------------------------------------------------------------
; MPLAB IDE 7.0
; MPLAB C30 Toolsuite 1.30
; dsPICDEM(TM) Processor Board 1.10
; --------------------------------------------------------------------------
;
; File Notes:
; 1. This file uses the channel scanning feature in the A/D to convert
; potentiometer voltages RP1, RP2 and RP3, as well as the Temperature
; Sensor voltage.
; 2. It is also used to assign a new step size into a Sinetable so as to
; generate a frequency proportional to the value of PotRP1
;
;END_HEADER
.include "p30fxxxx.inc"
.include "common.inc"
.equ NUMSAMPLES, 4
.equ SAMPLINGDELAY, 16
.equ Sine100Step, 10*2
.equ Sine500Step, 50*2
.equ Sine1000Step, 100*2
.equ Sine1500Step, 150*2
.equ Sine2000Step, 200*2
.global PotRP1, PotRP2, PotRP3, TempSens
.section .nbss, bss, near
.align WORD
PotRP1: .space WORD
PotRP2: .space WORD
PotRP3: .space WORD
TempSens: .space WORD
.global _sub_data_acq
.section .text
_sub_data_acq:
push ADCON1 ;Save current A/D control register settings
push ADCON2
push ADCON3
push ADCHS
push ADCSSL
push ADPCFG
push.d w0
rcall _init_adc12_B
bset ADCON1, #ADON ;Turn on A/D
poll_ADIF:
btss IFS0, #ADIF ;Wait for IF bit to be set
bra poll_ADIF
bclr ADCON1, #ADON ;Turn off the A/D module
bclr IFS0, #ADIF ;Clear the A/D interrupt flag bit
bset IEC0, #ADIE ;Enable A/D interrupts for main loop
mov #ADCBUF0, w0
mov [w0++], w1
mov w1, PotRP2 ;Update variables based on
mov [w0++], w1 ;new conversions
mov w1, PotRP3
mov [w0++], w1
mov w1, PotRP1
mov [w0++], w1
mov w1, TempSens
CheckF1:
mov #0x0333, w0 ;PotRP1 value is used to decide
cp PotRP1 ;which frequency sinusoid will be generated.
bra gt, CheckF2 ;First check if PotRP1 lies in the region 0-1v
bset NewFreqSel, #0 ;1-2v, 2-3v, 3-4v or 4-5v
bra IsNewEqCurr ;Accordingly set a bit in the NewFreqSel variable.
;Then check if the NewFreqSel variable is equal to
;the CurrFreqSel variable.
CheckF2: ;If not, then an update is required.
mov #0x0666, w0 ;If equal then no update is necessary.
cp PotRP1
bra gt, CheckF3
bset NewFreqSel, #1
bra IsNewEqCurr
CheckF3:
mov #0x0999, w0
cp PotRP1
bra gt, CheckF4
bset NewFreqSel, #2
bra IsNewEqCurr
CheckF4:
mov #0x0CCC, w0
cp PotRP1
bra gt, ElseF5
bset NewFreqSel, #3
bra IsNewEqCurr
ElseF5:
bset NewFreqSel, #4
IsNewEqCurr:
mov NewFreqSel, w0 ;Next, check if tne new value of PotRP1 lies in
cp CurrFreqSel ;a different range than the current range.
bra z, exit ;This ensures that we do not update StepSize
mov w0, CurrFreqSel ;or reset the Pointer to the Sinetable if the new
;and old range are the same.
UpdateFrequency: ;Update the stepsize into the SineTable
btsc CurrFreqSel, #0 ;for the new frequency
mov #Sine100Step, w0 ;Between 0-1v = 100 Hz
btsc CurrFreqSel, #1
mov #Sine500Step, w0 ;Between 1-2v = 500 Hz
btsc CurrFreqSel, #2
mov #Sine1000Step, w0 ;Between 2-3v = 1000 Hz
btsc CurrFreqSel, #3
mov #Sine1500Step, w0 ;Between 3-4v = 1500 Hz
btsc CurrFreqSel, #4
mov #Sine2000Step, w0 ;Between 4-5v = 2000Hz.
mov w0, SineTableStep
mov #psvoffset(SineTable), w0
mov w0, SineTablePtr ;Reset the pointer to the Sinetable
exit:
clr NewFreqSel ;Clear the New Frequency Selection variable
pop.d w0
pop ADPCFG
pop ADCSSL ;Restore original A/D control registers
pop ADCHS
pop ADCON3
pop ADCON2
pop ADCON1
return
.end ;EOF
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -