AnsweredAssumed Answered

Input Capture on MC9S08QG8

Question asked by ikauf ikauf on Aug 9, 2009
Latest reply on Aug 14, 2009 by ikauf ikauf



I failed trying initialize input capture mode for a couple of days on this device. I am little frustrated at this moment.


I am not so new to freescale controllers, working on different HC08/ HCS08 and HCS12 types. I started two years ago from zero, never done coding before. But at this time I can say that these controllers are very "cool" and I like the work with them.


To my setup/problem:


I have a windsensor wich sending pulses to my QG8 Demoboard. The windsensor is driven by two fans wich I can control in speed. I have also a debouncing circuit between my sensor and the QG8. I want in the end configuration measuring the windspeed. Input capture seems to be the best solution for me. I also have to say, I never worked with the TPM Module before.


I have two variables




and reading/store the channel register by





I can also do another way





Wich is the better way?


In Debug mode I can see that the variable TPMCH0VAL_RISE do not change when I let the fans blowing faster or slower. (This is my problem)


Here is my code:


In this code I trying to understand the basics of the input capture function. This means that this code is not the "last word". I only trying here to capture a rising edge and store it to my variable in the first step. If this works I will try to switch to falling edge cause I have to measure one period. One period consists falling and rising edge.


TPMCH0VAL:      DS.B   2
; code section
            ORG    ROMStart

            LDHX   #RAMEnd+1                   ;initialize the stack pointer
            lda #%00000011                      ;ResetPin enable
            sta SOPT1
            lda #%10010111                      ;OSC Trimm ~8MHz
            sta ICSTRM
            mov #%11000111,ICSC1           ;int. Osc. on
            mov #%00000000,ICSC2           ;ext. Osc. off
            CLI                                       ;enable interrupts
            jsr init_timer                           ;initialize the timer
            BRA    mainLoop

            mov #%00000000,TPMMODH   ;I am not sure what should stand here for input capture
            mov #%00000001,TPMMODL    ;But I know I should write a value in it for normal counter operation
            mov #%01000100,TPMC0SC    ;Timer 1 Channel 0,Input capture only, rising edges only
            mov #%00001000,TPMSC        ;Interrupt disabled, work as input capture, busclock = sourceclock, Divided by 1

;* spurious - Spurious Interrupt Service Routine.             *
;*             (unwanted interrupt)                           *
spurious:                                          ; placed here so that security value
            NOP                                    ; does not change all the time.


TPMOVF_ISR:                                   ;I will never come here with this timersetup

TPMCH0_ISR:                                    ;Start of Timer 1 Channel 0 ISR

            ;pshh                                  ;save H:X
            sei                                      ;disable (whole) interrupts
            ldhx TPMC0VH+TPMC0VL        ;Load 16 Bit value to Index Register
            sthx TPMCH0VAL_RISE           ;save content to "my defined Ram variable"
            lda TPMC0SC
            bclr 7,TPMC0SC                    ;clear Channel 0 Flag
            ;mov #%01011000,TPM1C0SC ;setup Channel 0 for falling edge (i also should
                                                     ;measure the other side of one period)
            ;brclr 7,TPM1C0SC,FALLING_EDGE  ;wait here for the falling edge
            ;ldhx TPM1C0VH+TPM1C0VL          ;Load 16 Bit value to Index Register
            ;sthx TPM1CH0VAL_FALL              ;save content to "my defined Ram variable"
            ;lda TPM1C0SC
            ;bclr 7,TPM1C0SC                       ;clear Channel 0 Flag
            ;mov #%00001000,TPM1SC          ;Interrupts enabled, work as input capture,
                                                           ;busclock = sourceclock, Divided by 1,
                                                           ;this stand here cause I do only

                                                           ;once a timer initialisation after reset and 
                                                           ;this should be enought
            ;pulh                           ;restore H:X
            cli                            ;enable (whole) interrupts
            rti                            ;End of interrupt

;*                 Interrupt Vectors                          *
            ORG   Vrti
            DC.W  spurious        ; RTI  
            DC.W  spurious        ; RESERVED2
            DC.W  spurious        ; RESERVED3
            DC.W  spurious        ; ACMP
            DC.W  spurious        ; ADC
            DC.W  spurious        ; KEYBOARD
            DC.W  spurious        ; IIC
            DC.W  spurious        ; SCITX
            DC.W  spurious        ; SCIRX
            DC.W  spurious        ; SCIERR
            DC.W  spurious        ; SPI
            DC.W  spurious        ; MTIM
            DC.W  spurious        ; RESERVED 13
            DC.W  spurious        ; RESERVED 14
            DC.W  spurious        ; RESERVED 15
            DC.W  spurious        ; RESERVED 16
            DC.W  spurious        ; TPMOVF
            DC.W  spurious        ; TPMCH1
            DC.W  TPMCH0_ISR      ; TPMCH0
            DC.W  spurious        ; RESERVED
            DC.W  spurious        ; LVD
            DC.W  spurious        ; IRQ 
            DC.W  spurious        ; SWI
            DC.W  _Startup        ; RESET



Can anyone tell me please am I on the right way?


Wich way is better to save the content of the Timerregister mov or ldhx?


 How I can see "more" in Debug mode?

 cause this? 

***When background mode is active, the timer counter and the coherency mechanism are frozen such that the

buffer latches remain in the state they were in when the background mode became active even if one or

both bytes of the counter are read while background mode is active.***



In the Datasheet stands:


When either byte of the 16-bit capture register is read, both bytes are latched into a buffer to support

coherent 16-bit accesses regardless of order.


WHere is this buffer? 





Please give me somone some input wich I can capture!:smileyhappy:


Best regards


Ingo Kauf





Message Edited by mnemonic on 2009-08-09 08:52 PM