谢谢 各位大神 ,这是基于MSP430的玻璃破碎代码,小弟想把算法移植。求大神帮忙翻译谢谢‘ 我qq292883168’; --COPYRIGHT--,BSD; Copyright (c) 2012, Texas Instruments Incorporated
; All rights reserved.
;
; Redistribution and use in source and binary forms, with or without
; modification, are permitted provided that the following conditions
; are met:
;
; * Redistributions of source code must retain the above copyright
; notice, this list of conditions and the following disclaimer.
;
; * Redistributions in binary form must reproduce the above copyright
; notice, this list of conditions and the following disclaimer in the
; documentation and/or other materials provided with the distribution.
;
; * Neither the name of Texas Instruments Incorporated nor the names of
; its contributors may be used to endorse or promote products derived
; from this software without specific prior written permission.
;
; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
; THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
; PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
; CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
; EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
; OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
; EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
; --/COPYRIGHT--
;******************************************************************************
; MSP430x2274 Glasbreakage Detector
;
;
; MSP430x2274
; -----------------------
; JTAG <--|SBWTCK/TEST P1.7/TDO|-->
; <--|DVcc P1.6/TDI|--> SFD
; <--|P2.5/Rosc P1.5/TMS|--> CCA
; <--|DVSS P1.4/TCK|--> FIFOP
; Xout <--|P2.7 P1.3 |--> FIFO
; Xin <--|P2.6 P1.2 |--> VREG_EN
; <--|RST/SBWTDIO P1.1 |--> RESETCC
; OA0I0 -->|P2.0 P1.0 |--> LED
; OA0O <--|P2.1 P2.4 |--> VREF+/OFFSET
; OA0I1 -->|P2.2 P2.3 |-->
; CSN <--|P3.0 P3.7 |--> BUZZER
; SI <--|P3.1 P3.6 |-->
; SO <--|P3.2 P3.5 |--> UCA0BXD
; SCLK <--|P3.3 P3.4 |--> UCA0TXD
; <--|AVss P4.7 |-->
; <--|AVcc P4.6 |<-- OA1I3
; Vcc_Mic <--|P4.0 P4.5 |-->
; <--|P4.1 P4.4 |--> OA1O
; <--|P4.2 P4.3 |-->
; -----------------------
; R.Kammel
; Texas Instruments Inc.
; September 2006
; Built with IAR Embedded Workbench Version: 3.41A
; Code Version 1.001
;******************************************************************************
#include
;-------------------------------------------------------------------------------
; Defines and Equals -
;-------------------------------------------------------------------------------
trigger call #SetDCO_12Mhz
bic.w #ENC, &ADC10CTL0 ; disable ADC10
bit.w #BIT3, &OA1CTL0_
jz cont_9 ; jump if AAF off
call #SetupADC10_cont_AAF ; execute if AAF on
jmp cont_10
cont_9 call #SetupADC10_cont_no_AAF
cont_10 bis.w #ENC+ADC10SC,&ADC10CTL0 ; enable ADC10 + start conversion
bic.b #LPM3, 0(SP) ; disable LPM3 mode
reti
no_trigger
bic.w #OAPM0+OAPM1,&OA0CTL0_ ; OP0 off
bic.w #OAPM0+OAPM1,&OA1CTL0_ ; OP1 off
bic.w #ENC,&ADC10CTL0 ; disable ADC10
bic.w #ADC10ON, &ADC10CTL0 ; ADC10 off
bic.b #BIT0, P4OUT ; microphone off
bic.b #BIT4, P2OUT ; offset off
bis.w #MC_1, TACTL ; up mode, TA start
reti
;------------------------------------------------------------------------------
ADC10_ISR;
;------------------------------------------------------------------------------
mov.w &ADC10MEM, temp1 ; save ADC10MEM to a working register
sub.w #512, temp1 ; subtract 512 because of 512 Offset
inc sample_count
call #signal_analysis
reti
;------------------------------------------------------------------------------
signal_analysis; analysing input signal 60ms = 2336 samples at fs=38961Hz
;------------------------------------------------------------------------------
cmp.w #2336, sample_count ; 2336 samples reached (60ms)?
jlo end_analyz ; if sample_count < 2336, unsigned
ADC_off bic.w #ENC+ADC10IE, &ADC10CTL0; disable ADC10
bic.w #OAPM0+OAPM1,&OA0CTL0_ ; OP0 amplifier off
bic.w #OAPM0+OAPM1,&OA1CTL0_ ; OP1 filter off
bic.b #BIT0, P4OUT ; mic off
bic.b #BIT4, P2OUT ; offset off
; begin pre-scaling
mov.w div_count_1, temp1
mov.w div_count_2, temp2
cmp.w temp2, temp1
jlo ratio_f_1 ; jump if div_count_1 < div_count_2
sub.w #0, temp1 ; begin shift values equal to their overflows
jz break_5 ; jump if div_count_1 = 0 -> if no overflow at integ_total occured
loop_1 cmp.w #1, temp2
jlo rrc_C_0 ; jump if div_count_2=0 and div_count_1!=0
bis.w #C, SR
rrc.w integ_HPB ; shifts integ_HPB through carry=1
dec.w temp2 ; decrement div_count_2 number once per shift operation
jmp cmp_temp1 ; finish div_count_2 test
rrc_C_0 bic.w #C, SR
rrc.w integ_HPB ; shifts integ_HPB through carry=0
cmp_temp1 bis.w #C, SR
rrc.w integ_total
dec.w temp1 ; sets carry while div_count_1!=0
cmp.w #1, temp1
jge loop_1 ; end shift values equal to their overflows
; end pre-scaling
break_5 ; begin division quotient=dividend/divisor
bit.w #8000, integ_HPB
jz cont_11 ; jump if integ_HPB(divisor) MSB="0"
bic.w #C, SR
rrc.w integ_HPB ; MSB="0" required
bic.w #C, SR
rrc.w integ_total ; shift to keep ratio konstant
cont_11 cmp.w #0,integ_HPB ; prevent division by zero
jeq ratio_f_1
mov.w integ_total, R15 ; R15 has dividend, R15 holds result
mov.w integ_HPB, R14 ; R14 has divisor
mov.w #16,R11 ; counter 16bit register = 16shifts
clr.w R13 ; A, R13 finaly holds the remainder
start rla.w R15 ; shift left by one
rlc.w R13 ; catches first bit of shiftet dividend
bis.w #1, R15 ; set last bit of dividend
sub.w R14,R13 ; A-divisor=A
jge loc1 ; A>=0 ?
add.w R14,R13
bic.w #1, R15 ; clear last bit depending on result of A-divisor=A
; A<0 bit one of dividend=1, A>0 bit one of dividend=0
loc1 dec.w R11
cmp.w #0,R11
jnz start
; end division quotient=dividend/divisor
; begin floating point of division
clr R12
rra R14 ; divider/4
rra R14
loop_2 sub.w R14, R13
cmp.w #0, R13
jl cont_test;
inc R12 ; counter, how often is divider/4 in remainder
cmp #3, R12 ; if more than 3 loops
jge cont_test
jmp loop_2
ratio_f_1 inc.w ratio_false ; set ratio false flag
jmp check_peaks
peakfalse inc.w peak_false ; set peak false flag
jmp check_zeros
zerofalse inc.w zero_false ; set zero crossing false flag
glass_break bis.b #BIT0,&P1OUT ; set P1.0 = 1, turn led on
bis.b #BIT7,&P3OUT ; set P3.7 = 1, turn buzzer on
call #delay_12Mhz ; delay led/buzzer active time
bic.b #BIT0,&P1OUT ; set P1.0 = 0, turn led off
bic.b #BIT7,&P3OUT ; set P3.7 = 0, turn buzzer off
break_6 bit.w #BIT3, &OA1CTL0_
jz cont_7 ; jump if AAF off
call #SetupADC10_wakeup_AAF ; execute if AAF on
jmp cont_8
cont_7 call #SetupADC10_wakeup_no_AAF
call #INITMEM
cont_8 call #SetDCO_8Mhz
bis.w #MC_1, TACTL ; up mode, TA start
mov.b #LPM3+GIE, SR ; enable LPM3 mode and global interrupts
end_analyz ret
;-------------------------------------------------------------------------------
SetupADC10_wakeup_AAF; Setup ADC10 comparator
;-------------------------------------------------------------------------------
mov.w #ADC10SHT_1+ADC10SR, &ADC10CTL0
; 8 ADC10CLK S&H, max 50ksps
mov.w #INCH_13+ADC10DIV_2+ADC10SSEL_3+CONSEQ_0, &ADC10CTL1
; Channel A13, ADC10CLK=SMCLK/3
; Single Channel Conversion
ret
;-------------------------------------------------------------------------------
SetupADC10_wakeup_no_AAF; Setup ADC10 comparator
;-------------------------------------------------------------------------------
mov.w #ADC10SHT_1+ADC10SR, &ADC10CTL0
; 8 ADC10CLK S&H, max 50ksps
mov.w #INCH_1+ADC10DIV_2+ADC10SSEL_3+CONSEQ_0, &ADC10CTL1
; Channel A1, ADC10CLK=SMCLK/3
; Single Channel Conversion
ret
;-------------------------------------------------------------------------------
SetupADC10_cont_AAF; Setup ADC10 signal analysis
;-------------------------------------------------------------------------------
mov.w #ADC10SHT_3+ADC10SR+MSC+ADC10ON+ADC10IE, &ADC10CTL0
; Ref: VR+ = Vcc and VR- = Vss
; 64 ADC10CLK S&H, max 50ksps
; Multi S&C, ADC on, ADC IE
mov.w #INCH_13+ADC10DIV_3+ADC10SSEL_3+CONSEQ_2, &ADC10CTL1
; Channel A13, ADC10CLK=SMCLK/4
; Repeat Single Channel Conversion
ret
;-------------------------------------------------------------------------------
SetupADC10_cont_no_AAF; Setup ADC10 signal analysis
;-------------------------------------------------------------------------------
mov.w #ADC10SHT_3+ADC10SR+MSC+ADC10ON+ADC10IE, &ADC10CTL0
; Ref: VR+ = Vcc and VR- = Vss
; 64 ADC10CLK S&H, max 50ksps
; Multi S&C, ADC on, ADC IE
mov.w #INCH_1+ADC10DIV_3+ADC10SSEL_3+CONSEQ_2, &ADC10CTL1
; Channel A1, ADC10CLK=SMCLK/4
; Repeat Single Channel Conversion
ret
;-------------------------------------------------------------------------------
SetupOP1_2; Setup OP1 & OP2
;-------------------------------------------------------------------------------
OP0 mov.b #OAFBR_6+OAFC_6+OANEXT,&OA0CTL1_
; Inverting PGA, gain=-7
; inv input external available
mov.b #OAN_1+OAP_0+OAPM_0+OAADC1,&OA0CTL0_
; inv input OA0I1 P2.2
; non inv input OA0I0 P2.0
; off mode, OA0O at A13 & P2.1
OP1 mov.b #OAFC_2,&OA1CTL1_ ; Unity gain buffer
mov.b #OAP_3+OAPM_0+OAADC0,&OA1CTL0_
; non inv input OA1I1 P4.6
; off mode, OA1O at A13 & P4.4
bis.b #0f0h,&ADC10AE1 ; P4.4 OA1O, P4.6 OA1I3
ret
;-------------------------------------------------------------------------------
SetupTA; Setup TA wake up
;-------------------------------------------------------------------------------
mov.w #TASSEL0, TACTL ; TACLK=ACLK=VLO
mov.w #OUTMOD_4+CCIE, TACCTL0 ; toggle mode @ P1.1, CCRO IE
mov.w #TACCR0_2ms, TACCR0 ;
ret
;-------------------------------------------------------------------------------
SetDCO_12Mhz; Set DCO to 12Mhz and ACLK = VLO
;-------------------------------------------------------------------------------
mov.b &CALBC1_12MHZ,&BCSCTL1 ; set range
mov.b &CALDCO_12MHZ,&DCOCTL ; set DCO step + modulation
mov.b #LFXT1S_2, &BCSCTL3 ; ACLK = VLO
ret
;-------------------------------------------------------------------------------
SetDCO_8Mhz; Set DCO to 8Mhz and ACLK = VLO
;-------------------------------------------------------------------------------
mov.b &CALBC1_8MHZ,&BCSCTL1 ; set range
mov.b &CALDCO_8MHZ,&DCOCTL ; set DCO step + modulation
mov.b #LFXT1S_2, &BCSCTL3 ; ACLK = VLO