Software sets ADC10SC to start sample and conversion - ADC10SC ; automatically cleared at EOC.. ADC10 internal oscillator/4 times sample ; 64x and conversion.. In Mainloop MSP430 waits i
Trang 1; MSP430F20x2 Demo - ADC10, Sample A10 Temp and Convert to oC and oF
;
; Description: A single sample is made on A10 with reference to internal
; 1.5V Vref Software sets ADC10SC to start sample and conversion - ADC10SC
; automatically cleared at EOC ADC10 internal oscillator/4 times sample
; (64x) and conversion In Mainloop MSP430 waits in LPM0 to save power until
; ADC10 conversion complete, ADC10_ISR will force exit from any LPMx in
; Mainloop on reti Result is converted to Temperature represented as
; BCD 0000 - 0145 representing oC saved at 0200h and 0000 - 0292 representing
; oF saved at 0202h Temperature sensor offset and slope will vary from device
; to device per datasheet tolerance
; Uncalibrated temperature measured from device to devive will vary with
; slope and offset - please see datasheet
; ACLK = n/a, MCLK = SMCLK = default DCO ~1.2MHz, ADC10CLK = ADC10OSC/4
;
; MSP430F20x2
;
-; /|\|
XIN|-; | | |
; |RST
XOUT|-; | |
; |A10 |
;
; L Westlund
; Texas Instruments Inc
; May 2006
; Built with IAR Embedded Workbench Version: 3.41A
;*******************************************************************************
#include "msp430x20x2.h"
RSEG CSTACK ; Define stack segment
RSEG CODE ; Assemble to Flash memory
; -RESET mov.w #SFE(CSTACK),SP ; Initialize stackpointer
StopWDT mov.w #WDTPW+WDTHOLD,&WDTCTL ; Stop WDT
SetupADC10 mov.w #INCH_10+ADC10DIV_3,&ADC10CTL1 ; Temp Sensor ADC10CLK/4 mov.w #SREF_1+ADC10SHT_3+REFON+ADC10ON+ADC10IE,&ADC10CTL0 ;
mov.w #30,&TACCR0 ; Delay to allow Ref to settle
bis.w #CCIE,&TACCTL0 ; Compare-mode interrupt
mov.w #TACLR+MC_1+TASSEL_2,&TACTL; up mode, SMCLK
bis.w #LPM0+GIE,SR ; Enter LPM0, enable interrupts bic.w #CCIE,&TACCTL0 ; Disable timer interrupt
dint ;
;
Mainloop bis.w #ENC+ADC10SC,&ADC10CTL0 ; Start sampling/conversion
bis.w #CPUOFF+GIE,SR ; LPM0, ADC10_ISR will force exit call #Trans2TempC ; Transform voltage to temperature call #BIN2BCD4 ; R13 = TempC = 0000 - 0145 BCD mov.w R13,&0200h ; 0200h = temperature oC
call #Trans2TempF ; Transform voltage to temperature call #BIN2BCD4 ; R13 = TempF = 0000 - 0292 BCD mov.w R13,&0202h ; 0202h = temperature oF
jmp Mainloop ; << breakpoint here
;
; -; Input: ADC10MEM 0000 - 0FFFh, R11, R12, R14, R15 working register
; Output: R12 0000 - 091h
mov.w &ADC10MEM,R12 ;
mov.w #423,R11 ; C
Trang 2call #MPYU ;
bic.w #00FFh,R14 ; /1024
add.w R15,R14 ;
swpb R14 ;
rra.w R14 ;
rra.w R14 ;
mov.w R14,R12 ;
ret ;
;
; -; Input: ADC10MEM 0000 - 0FFFh, R11, R12, R14, R15 working register ; Output: R12 0000 - 0124h
mov.w &ADC10MEM,R12 ;
mov.w #761,R11 ; F call #MPYU ;
bic.w #00FFh,R14 ; /1024
add.w R15,R14 ;
swpb R14 ;
rra.w R14 ;
rra.w R14 ;
mov.w R14,R12 ;
ret ;
;
; -BIN2BCD4 ; Subroutine converts binary number R12 -> Packed 4- digit BCD R13 ; Input: R12 0000 - 0FFFh, R15 working register ; Output: R13 0000 - 4095
mov.w #16,R15 ; Loop Counter clr.w R13 ; 0 -> RESULT LSD BIN1 rla.w R12 ; Binary MSB to carry dadd.w R13,R13 ; RESULT x2 LSD jnz BIN1 ; Not through ret ;
;
; -MPYU ; Unsigned Multipy R11 x R12 = R15|R14 ; Input: R11, R12 R10 and R13 are working registers ; Output: R15, R14
clr.w R14 ; 0 -> LSBs result clr.w R15 ; 0 -> MSBs result MACU clr.w R13 ; MSBs multiplier mov.w #1,R10 ; bit test register MPY2 bit.w R10,R11 ; test actual bit jz MPY1 ; IF 0: do nothing add.w R12,R14 ; IF 1: add multiplier to result addc.w R13,R15 ;
MPY1 rla.w R12 ; multiplier x 2 rlc.w R13 ;
rla.w R10 ; next bit to test jnc MPY2 ; if bit in carry: finished ret ; Return from subroutine ;
; -TA0_ISR; ISR for TACCR0 clr.w &TACTL ; Clear Timer_A control registers
Trang 3bic.w #LPM0,0(SP) ; Exit LPMx, interrupts enabled reti ;
; -ADC10_ISR;
bic.w #LPM0,0(SP) ; Exit LPM0 on reti
reti ;
;
COMMON INTVEC ; Interrupt Vectors
ORG ADC10_VECTOR ; ADC10 Vector
DW ADC10_ISR
ORG TIMERA0_VECTOR ; Timer_A0 Vector
DW TA0_ISR
ORG RESET_VECTOR ; POR, ext Reset
DW RESET
END