📄 ads1100_demo.s43
字号:
;-------------------------------------------------------------------------------
; ADS1100_Demo.s43 - ADS1100 Bridge Sensor Readout Demo w/ MSP430F413
;
; Description: Program reads out an external ADS1100 Sigma-Delta ADC over the
; I2C interface. The differential input voltage is displayed as a signed number
; on a 3.5 digit LCD display. The displayed value is calculated using a 2-point
; calibration mechanism. During initial power-up (INFOA Flash memory is erased),
; two calibration data points are obtained (CalMin and CalMax) and stored into
; Flash memory. The range of CalMin to CalMax is projected into a display-value
; from 0 to CAL_MIN_MAX_SPAN. Button #1 is used to enter low-power mode,
; button #2 is used to re-calibrate. An external 32-kHz watch crystal is used
; for time interval generation and for driving the LCD.
;
; /|\ /|\ /|\
; | ADS1100 10k 10k MSP430F413
; | +-------+ | | +----------+
; +---|Vcc SDA|<-|---+>|P2.0 | +----------------------+
; o-------|VIN+ | | | S0-S23|--->| Varitronix 3.5 digit |
; o-------|VIN- | | | COM0|--->| Static LCD Display |
; +--|Vss SCL|<-+-----|P2.1 | +----------------------+
; \|/ +-------+ | |
; | XIN/XOUT|<---32.768KHz Watch Crystal
; | P1.6|<---Button #1 (low-active)
; | P1.7|<---Button #2 (low-active)
; +----------+
; Andreas Dannenberg
; Texas Instruments Inc.
; June 2004
; Built with IAR Embedded Workbench Version: 3.10A
;-------------------------------------------------------------------------------
#include "msp430x41x.h"
#include "I2C_Master.h"
CAL_MIN_MAX_SPAN EQU 1000 ; Scale value for CalMin/CalMax
; Definitions for ADS1100 A/D converter
ADS1100_SA EQU 048h ; ADS1100 I2C Slave Address
ADS1100_GAIN1 EQU 000h ; PGA Gain X1
ADS1100_GAIN2 EQU 001h ; PGA Gain X2
ADS1100_GAIN4 EQU 002h ; PGA Gain X4
ADS1100_GAIN8 EQU 003h ; PGA Gain X8
ADS1100_128SPS EQU 000h ; 128 Samples/s
ADS1100_32SPS EQU 004h ; 32 Samples/s
ADS1100_16SPS EQU 008h ; 16 Samples/s
ADS1100_8SPS EQU 00Ch ; 8 Samples/s
ADS1100_SC EQU 010h ; Single Conversion Mode
ADS1100_ST_BSY EQU 080h ; Start Conversion + Busy
; Circuit related definitions
BRIDGE_H EQU 038h ; IO pins for pos. bridge rail
BRIDGE_L EQU 007h ; IO pins for neg. bridge rail
BT_ISR_NRM EQU 0 ; Basic Timer ISR - Wakeup
BT_ISR_CL1 EQU 2 ; Basic Timer ISR - Show 'CAL'
BT_ISR_CL2 EQU 4 ; Basic Timer ISR - Display 'LO'
BT_ISR_CH1 EQU 6 ; Basic Timer ISR - Toggle CAL/HI
BT_ISR_CH2 EQU 8 ; Basic Timer ISR - Toggle CAL/HI
P1_ISR_NRM EQU 0 ; Port1 ISR - Normal Mode
P1_ISR_CL EQU 2 ; Port1 ISR - Cal Low Mode
P1_ISR_CH EQU 4 ; Port1 ISR - Cal High Mode
;-------------------------------------------------------------------------------
EXTERN I2CSetup ; Functions from I2C_Master.s43
EXTERN I2CRead16
EXTERN I2CWrite8
;-------------------------------------------------------------------------------
RSEG DATA16_N ; RAM
;-------------------------------------------------------------------------------
BtIsrMode DS 2 ; ISR Mode for Basic Timer
P1IsrMode DS 2 ; ISR Mode for Port 1
CalMinTmp DS 2 ; Vars to hold calib values
CalMaxTmp DS 2
LastADCValue DS 2
UpdateDisplay DS 1 ; Flag to request LCD update
;-------------------------------------------------------------------------------
RSEG CSTACK ; CPU stack
;-------------------------------------------------------------------------------
RSEG INFOA ; Info Flash Memory Block A
;-------------------------------------------------------------------------------
CalMin DS 2 ; 16-Bit minimum calibration const
CalMax DS 2 ; 16-Bit maximum calibration const
;-------------------------------------------------------------------------------
RSEG CODE ; Program code
;-------------------------------------------------------------------------------
RESET mov.w #SFE(CSTACK),SP ; Initialize stackpointer
call #Init_Sys ; Initialize system
mov.b #1,&UpdateDisplay ; Request LCD update
cmp.w &CalMin,&CalMax ; Are constants in Flash OK?
jne ConstsOK ; Jump if yes
mov.w #BT_ISR_CL1,&BtIsrMode ; Go to calibration mode
mov.w #P1_ISR_CL,&P1IsrMode
jmp Start
ConstsOK mov.w #BT_ISR_NRM,&BtIsrMode ; Go to measurement mode
mov.w #P1_ISR_NRM,&P1IsrMode
Start mov.b #ADS1100_SA,R12 ; ADS1100 I2C Slave Address
mov.b #ADS1100_8SPS+ADS1100_GAIN8,R14
call #I2CWrite8 ; Start conversions
bis.w #LPM3+GIE,SR ; Enter LPM3 w/ ints enabled
jmp $
;------------------------------------------------------------------------------
Init_Sys ; Set-up modules and control registers
;------------------------------------------------------------------------------
mov.w #WDTPW+WDTHOLD,&WDTCTL ; Stop WDT
SetupFLL2 bis.b #XCAP18PF,&FLL_CTL0 ; Set load capacitance for xtal
SetupLCD mov.b #0C5h,&LCDCTL ; Static LCD, segments = 0 - 23
SetupBT mov.b #BT_fLCD_DIV256+BTDIV+BT_fCLK2_DIV32,&BTCTL
; 0.25s BT Int, Set LCD freq
bis.b #BTIE,&IE2 ; Enable Basic Timer interrupt
SetupPorts clr.b &P1OUT ; P1OUTs = 0
mov.b #03Fh,&P1DIR ; P1.7/P1.6 input, others outp
mov.b #0c0h,&P1IES ; P1.7/P1.6 int on falling edge
clr.b &P1IFG
mov.b #0c0h,&P1IE ; Enable button intuerrupts
clr.b &P2OUT ; P2OUTs = 0
mov.b #0FCh,&P2DIR ; Set port but I2C pins to outputs
clr.b &P3OUT ; P3OUTs = 0
mov.b #0FFh,&P3DIR ; Set port to outputs
clr.b &P4OUT ; P4OUTs = 0
mov.b #0FFh,&P4DIR ; Set port to outputs
clr.b &P5OUT ; P5OUTs = 0
mov.b #0FFh,&P5DIR ; Set port to outputs
mov.b #BRIDGE_H,&P6OUT ; Enable bridge supply voltage
mov.b #0FFh,&P6DIR ; Set port to outputs
ret
;------------------------------------------------------------------------------
StoreCalInFlash ; Stores both calibration constants in on-chip Flash memory
;------------------------------------------------------------------------------
mov.w #FWKEY+FSSEL1+FN1,&FCTL2 ; SMCLK/3 = ~333kHz
mov.w #FWKEY,&FCTL3 ; Clear LOCK
mov.w #FWKEY+ERASE,&FCTL1 ; Enable segment erase
clr.w &SFB(INFOA) ; Dummy write, erase info A
mov.w #FWKEY+WRT,&FCTL1 ; Enable write
mov.w &CalMinTmp,&CalMin ; Program calibration constants
mov.w &CalMaxTmp,&CalMax
mov.w #FWKEY,&FCTL1 ; Done. Clear WRT
mov.w #FWKEY+LOCK,&FCTL3 ; Done. Set LOCK
ret
;-------------------------------------------------------------------------------
Mul32 ; Perform a 32-bit multiplication: R13:R12 = R13:R12 * R15:R14
;-------------------------------------------------------------------------------
push.w R10
push.w R11
mov.w R12,R10
mov.w R13,R11
clr.w R12
clr.w R13
Mul32_1 tst.w R10
jne Mul32_2
tst.w R11
jeq Mul32_4
Mul32_2 clrc
rrc.w R11
rrc.w R10
jnc Mul32_3
add.w R14,R12
addc.w R15,R13
Mul32_3 rla.w R14
rlc.w R15
jne Mul32_1
tst.w R14
jne Mul32_1
Mul32_4 pop.w R11
pop.w R10
ret
;-------------------------------------------------------------------------------
DivMod32u ; Perform a 32-bit unsigned division: R13:R12 = R13:R12 / R15:R14
;-------------------------------------------------------------------------------
push.w R9
push.w R10
push.w R11
clr.w R10
clr.w R11
mov.w #020h,R9
DivMod32u_1 rla.w R12
rlc.w R13
rlc.w R10
rlc.w R11
sub.w R14,R10
subc.w R15,R11
jnc DivMod32u_2
bis.w #1,R12
add.w #0ffffh,R9
jne DivMod32u_1
jmp DivMod32u_3
DivMod32u_2 add.w R14,R10
addc.w R15,R11
add.w #0ffffh,R9
jne DivMod32u_1
DivMod32u_3 mov.w R10,R14
mov.w R11,R15
pop.w R11
pop.w R10
pop.w R9
ret
;-------------------------------------------------------------------------------
DivMod32s ; Perform a 32-bit signed division: R13:R12 = R13:R12 / R15:R14
;-------------------------------------------------------------------------------
push.w R9
clr.w R9
tst.w R15
jge DivMod32s_1
inv.w R14
inv.w R15
inc.w R14
adc.w R15
bis.w #1,R9
DivMod32s_1 tst.w R13
jge DivMod32s_2
inv.w R12
inv.w R13
inc.w R12
adc.w R13
inv.w R9
DivMod32s_2 call #DivMod32u
bit.w #1,R9
jeq DivMod32s_3
inv.w R12
inv.w R13
inc.w R12
adc.w R13
DivMod32s_3 bit.w #2,R9
jeq DivMod32s_4
inv.w R14
inv.w R15
inc.w R14
adc.w R15
DivMod32s_4 pop.w R9
ret
;------------------------------------------------------------------------------
; Subroutine to display a signed 16-bit value in R12 on a 3.5 digit LCD. The
; value is clipped between -1999 and 1999. Clipping will be indicated by
; displaying 'HI' for values >1999 and 'LO' for values <-1999.
;
; CPU Registers used: R15, R14, R13, R12, not saved
;------------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -