AnsweredAssumed Answered

Use timer interrupt (capture) to measure an accelerometer

Question asked by Jesus Gomez on May 15, 2012
Latest reply on May 16, 2012 by Jesus Gomez

Hi i am trying to measure a Memsic 2125 accelerometer, (measuring the pulse width) and i am using a Adapt9s12e128 board with a MC9S12E128, i am trying to use this code, but it seems that the isr is not working or that it's not doing anything (the accelerometer has 2 channels, but they are the same just differ on the axis, so if one works it's easy to make the other0


this is the code i am using, i hope you can help me find the error (the oscillator freq is 24 MHz via PLL)


            ORG RAMStart
 ; Insert here your data definition.
            org $3000
cnt         dc.w 0
trans       dc.w 0
per         dc.w 0
posx        dc.w $0
; code section
            ORG   ROMStart

            ;bus 24/2=12Mhz T=1/12Mhz=.083333 us, overflow en 5461.33 us => 5.46133 ms = 183 Hz ov
            ;LDS   #RAMEnd+1       ; initialize the stack pointer            
            movb #$90, TIM1_TSCR1 ;timer,banderas rapidas
            movb #0, TIM1_TSCR2 ;no int ov, no presc
            movb #$e0, TIM1_TIOS ;1 capturas  c0
            movb #1, TIM1_TCTL3 ;1 capt tran pos #5
            movb #$10,TIM1_TIE ;int 1 capt #$30
            movb #$ff,TIM1_TFLG1 ;borra banderas            
            movw #$ffff,DDRAD
            movw #$ffff,ATDDIEN
            movb #1,DDRP ;salida led rojo
 ;sensor 100 Hz PWM 50% dtcy = 0g 100Hz=10ms=10,000us
 ;form= |`TH`|_TL_| Tx=periodo F=TH/Tx
            bset PTP,mPTIP_PTIP0
            movw posx,PTAD  
            bra main
            ldd TIM1_TCNT  ;borr band
            std trans
            movb #2,TIM1_TCTL3; config timer trans baja
            brclr TIM1_TFLG1,mTIM1_TFLG1_C4F,*
            ldd TIM1_TCNT
            std per
            subd trans ;long
            std posx ;tiempo
            movb #1,TIM1_TCTL3

;*                 Interrupt Vectors                          *
            ORG   $FFFE
            DC.W  Entry           ; Reset Vector
            org   Vtim0ch4
            dc.w  medicionx