📄 init_adc12.s
字号:
;START_HEADER
;
; dsPIC30F6014 Demo Source File
; (c) Copyright 2005 Microchip Technology, All rights reserved
;
; --------------------------------------------------------------------------
; File Revision History:
; --------------------------------------------------------------------------
;
; $Log: init_adc12.s,v $
; Revision 1.4 2005/04/04 23:44:42 VasukiH
; Updates to comments in file header
;
; Revision 1.3 2005/04/04 23:16:17 VasukiH
; Updates for MPLAB C30 v1.30 compatiblity
;
; Revision 1.2 2003/11/04 02:36:12 VasukiH
; Changed A/D init for auto-scanning and auto-sampling
;
; Revision 1.1.1.1 2003/08/23 00:38:32 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:
; This file contains two A/D initialization routines
; 1. _init_adc12_A
; 2. _init_adc12_B
;
; 1. _init_adc12_A Description:
; (i) This routine sets up the A/D for automatic sampling and conversion
; for input waveform on pin AN3 at a sampling rate of 8000 Hz.
; In this mode, the A/D module uses an internal counter to time sampling
; and trigger conversion. An interupt is generated at the end of 16
; conversions.
; (ii) The input on pin AN3 is a Low-pass filtered (4KHz cutoff) output of
; the MCP41010 8-bit Digital Potentiometer.
; (iii) Frequency analysis is performed on 256 samples that are collected by the
; A/D converter on pin AN3/RB3.
;
; 2. _init_adc12_B Description:
; (i) This routine sets up the A/D for scanning four input channels. These are
; - Potentiometer RP2 on pin AN4/RB4
; - Potentiometer RP3 on pin AN5/RB5
; - Potentiometer RP1 on pin AN6/RB6
; - Temperature Sensor on pin AN8/RB8
; Sampling is performed manually in software while conversion is also
; triggered manually.
; In this mode, the A/D module automatically scans 4 input channels, i.e.,
; the input channel to the module does not have to be changed in software.
; ISR processing is not enabled.
; (ii) One sample of each of the analog inputs RP1, RP2, RP3, Temp. Sensor are
; converted and displayed on the LCD and via the UART to HyperTerminal.
; RP1 also controls frequency of sine waves generated by the Digital Pot.
; MCP41010.
;
; Note: In Rev B silicon, all 5 input channels (AN3-AN6,AN8) may be scanned in the
; automatic sampling and auto-conversion mode.
;
;END_HEADER
.include "p30fxxxx.inc"
.global _init_adc12_A, _init_adc12_B ;Provide global scope to routines
.section .text ;Code section in FLASH memory
_init_adc12_A:
push w0 ;Save off w0 on to stack
bclr ADCON1, #ADON ;Turn Off A/D
mov #0x03E4 ,w0 ;Set up automatic sampling and
;conversion. Format conversion results
mov w0, ADCON1 ;to be read as 1.15(Q15) fractional data
mov #0x003C ,w0 ;Set up conversions per interrupt to 16
mov w0, ADCON2
mov #0x1F28 ,w0 ;Set up the Auto-sampling time and the
mov w0, ADCON3 ;Tad time to yield 8000 samples/second
mov #0x0003 ,w0 ;Set up the analog channel to convert
mov w0, ADCHS ;on pin AN3/RB3
mov #0xFFF7 ,w0 ;Set up AN3/RB3 as an analog pin
mov w0, ADPCFG ;and the rest as digital
mov #0x0000 ,w0 ;Disable channel scanning
mov w0, ADCSSL
bclr IFS0, #ADIF ;Clear A/D interrupt flag and
bset IEC0, #ADIE ;enable A/D ISR processing
mov.b #0b11100000, w0 ;Set up A/D interrupt priority
ior.b IPC2H ;to 7!!
pop w0 ;Restore w0
return ;Return to calling routine
_init_adc12_B:
push w0
mov #0x00E4, w0 ;Set up A/D for Autosample and converting
mov w0, ADCON1 ;with default read-format mode
mov #0x040C ,w0 ;Enable Channel scanning and set up
mov w0, ADCON2 ;interrupt flag to be set after 4 conversions
;Note: ISR processing itself is disabled
mov #0x030C ,w0 ;Set up Tad time of 6.5 * Tcy
mov w0, ADCON3 ;and a Sampling time of 3*Tcy
clr ADCHS ;ADCHS is not used for this excercise
mov #0x8170, w0 ;Set up Channel scanning for inputs
mov w0, ADCSSL ;AN4, AN5, AN6, AN8 and AN15
;AN15 will not be converted but is required for
;errata workaround
mov #0x7E8F, w0 ;Set up AN4, AN5, AN6 and AN8 as Analog pins
mov w0, ADPCFG
bclr IFS0, #ADIF ;Clear A/D Inerrupt flag
bclr IEC0, #ADIE ;Disable A/D ISR processing
pop w0 ;Restore w0
return ;Return to calling routine
.end ;EOF
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -