EmbeddedRelated.com
Forums
Memfault Beyond the Launch

timer overflow polling method-- help !!!

Started by njxi...@yahoo.com April 11, 2008
I want to use input capture fucntion to measure a signal period between two rising edges. Since the period under test could be very long, the timer overflow may happen. Thus a counter is needed to record the # of overflow. I don't want to use overflow interrupt, instead only want to use polling method to track 'TOF' flag.

My program works correctly if period is not long (no overflow). However when period is long (generating TOF oveflows), the overflow counter
Index x register) can not get the right value. Could somebody give a help and point out what's wrong?

My program for your reference:

ORG $1000
PERIOD RMB 2
EDGE1 RMB 2

ORG $1200
ldx #$0000

MOVB #$90,TSCR ; enable timer, set fast timer clear
MOVB #$FE,TIOS ; set pt0 to input capture
movb #$00,TMSK1 ; disable interrupt
MOVB #$24,TMSK2 ; scale by 16
MOVB #$01,TCTL4 ; set rising edge detection
MOVB #$01,TFLG1 ; clear flag bit / initialize

BCLR TFLG2,$7F ;clear TOF flag

BRCLR TFLG1,$01,* ; wait for the 1st rising edge
LDD TCO ;save the 1st TCNT value
STD EDGE1

loop brclr TFLG2,$80,Test ;check TOF flag set
inx ; if TOF, increase counter IX
movb #$80,TFLG2 ;clear TOF

Test BRCLR TFLG1,$01,loop ;check 2nd rising edge
LDD TCO ;save the 2nd TCNT value

SUBD EDGE1 ;subtraction
STD PERIOD

SWI
END

What are you doing with the overflow information stored in the X register when you are considering whether PERIOD is right or not?

Emmett Redd

________________________________

From: 6... on behalf of n...@yahoo.com
Sent: Fri 4/11/2008 3:47 PM
To: 6...
Subject: [68HC12] timer overflow polling method-- help !!!

I want to use input capture fucntion to measure a signal period between two rising edges. Since the period under test could be very long, the timer overflow may happen. Thus a counter is needed to record the # of overflow. I don't want to use overflow interrupt, instead only want to use polling method to track 'TOF' flag.

My program works correctly if period is not long (no overflow). However when period is long (generating TOF oveflows), the overflow counter
Index x register) can not get the right value. Could somebody give a help and point out what's wrong?

My program for your reference:

ORG $1000
PERIOD RMB 2
EDGE1 RMB 2

ORG $1200
ldx #$0000

MOVB #$90,TSCR ; enable timer, set fast timer clear
MOVB #$FE,TIOS ; set pt0 to input capture
movb #$00,TMSK1 ; disable interrupt
MOVB #$24,TMSK2 ; scale by 16
MOVB #$01,TCTL4 ; set rising edge detection
MOVB #$01,TFLG1 ; clear flag bit / initialize

BCLR TFLG2,$7F ;clear TOF flag

BRCLR TFLG1,$01,* ; wait for the 1st rising edge
LDD TCO ;save the 1st TCNT value
STD EDGE1

loop brclr TFLG2,$80,Test ;check TOF flag set
inx ; if TOF, increase counter IX
movb #$80,TFLG2 ;clear TOF

Test BRCLR TFLG1,$01,loop ;check 2nd rising edge
LDD TCO ;save the 2nd TCNT value

SUBD EDGE1 ;subtraction
STD PERIOD

SWI
END

Thanks for the help.

I used 1 Hz signal as the test signal. The timer clock period is 500KHz. So I am supposed to get about 8 overflows.

(one overflow duration is 65536/500KHz1 ms
in 1 second, the #of overflow should be: 1/131ms ~ 7)

However I received random number in X register evertime.

"Redd, Emmett R" wrote:
What are you doing with the overflow information stored in the X register when you are considering whether PERIOD is right or not?

Emmett Redd

________________________________

From: 6... on behalf of n...@yahoo.com
Sent: Fri 4/11/2008 3:47 PM
To: 6...
Subject: [68HC12] timer overflow polling method-- help !!!

I want to use input capture fucntion to measure a signal period between two rising edges. Since the period under test could be very long, the timer overflow may happen. Thus a counter is needed to record the # of overflow. I don't want to use overflow interrupt, instead only want to use polling method to track 'TOF' flag.

My program works correctly if period is not long (no overflow). However when period is long (generating TOF oveflows), the overflow counter
Index x register) can not get the right value. Could somebody give a help and point out what's wrong?

My program for your reference:

ORG $1000
PERIOD RMB 2
EDGE1 RMB 2

ORG $1200
ldx #$0000

MOVB #$90,TSCR ; enable timer, set fast timer clear
MOVB #$FE,TIOS ; set pt0 to input capture
movb #$00,TMSK1 ; disable interrupt
MOVB #$24,TMSK2 ; scale by 16
MOVB #$01,TCTL4 ; set rising edge detection
MOVB #$01,TFLG1 ; clear flag bit / initialize

BCLR TFLG2,$7F ;clear TOF flag

BRCLR TFLG1,$01,* ; wait for the 1st rising edge
LDD TCO ;save the 1st TCNT value
STD EDGE1

loop brclr TFLG2,$80,Test ;check TOF flag set
inx ; if TOF, increase counter IX
movb #$80,TFLG2 ;clear TOF

Test BRCLR TFLG1,$01,loop ;check 2nd rising edge
LDD TCO ;save the 2nd TCNT value

SUBD EDGE1 ;subtraction
STD PERIOD

SWI
END

I used 1 Hz signal as the test signal. The timer clock period is 500KHz. So I am supposed to get about 8 overflows.

(one overflow duration is 65536/500KHz= 131 ms
in 1 second, the #of overflow should be: 1/131ms ~ 7)

However I received random number in X register evertime.

I want to use input capture fucntion to measure a signal period between two rising edges. Since the period under test could be very long, the timer overflow may happen. Thus a counter is needed to record the # of overflow. I don't want to use overflow interrupt, instead only want to use polling method to track 'TOF' flag.
>
>My program works correctly if period is not long (no overflow). However when period is long (generating TOF oveflows), the overflow counter
>Index x register) can not get the right value. Could somebody give a help and point out what's wrong?
>
>My program for your reference:
>
> ORG $1000
>PERIOD RMB 2
>EDGE1 RMB 2
>
> ORG $1200
> ldx #$0000
>
> MOVB #$90,TSCR ; enable timer, set fast timer clear
> MOVB #$FE,TIOS ; set pt0 to input capture
> movb #$00,TMSK1 ; disable interrupt
> MOVB #$24,TMSK2 ; scale by 16
> MOVB #$01,TCTL4 ; set rising edge detection
> MOVB #$01,TFLG1 ; clear flag bit / initialize
>
> BCLR TFLG2,$7F ;clear TOF flag
>
> BRCLR TFLG1,$01,* ; wait for the 1st rising edge
> LDD TCO ;save the 1st TCNT value
> STD EDGE1
>
>loop brclr TFLG2,$80,Test ;check TOF flag set
> inx ; if TOF, increase counter IX
> movb #$80,TFLG2 ;clear TOF
>
>Test BRCLR TFLG1,$01,loop ;check 2nd rising edge
> LDD TCO ;save the 2nd TCNT value
>
> SUBD EDGE1 ;subtraction
> STD PERIOD
>
> SWI
> END
>
>

There is an example from Freescale, it is for older HC11 but could be
usable.

Go to:

http://www.freescale.com/

- In right upper corner at Enter keyword, enter the word examplescod and
search
- Download "Examples from HC11 Reference manual" (first item in list)
- unzip until you find the text file EX10 and search for "TIMER EXAMPLE 10-3
Measuring Long Periods with IC" about one third from top

Anders

> -----Original Message-----
> From: 6... [mailto:6...]
> On Behalf Of n...@yahoo.com
> Sent: Friday, April 11, 2008 11:13 PM
> To: 6...
> Subject: [68HC12] Re: timer overflow polling method-- help !!!
>
> I used 1 Hz signal as the test signal. The timer clock period
> is 500KHz. So I am supposed to get about 8 overflows.
>
> (one overflow duration is 65536/500KHz= 131 ms
> in 1 second, the #of overflow should be: 1/131ms ~ 7)
>
> However I received random number in X register evertime.
>
> I want to use input capture fucntion to measure a signal
> period between two rising edges. Since the period under test
> could be very long, the timer overflow may happen. Thus a
> counter is needed to record the # of overflow. I don't want
> to use overflow interrupt, instead only want to use polling
> method to track 'TOF' flag.
> >
> >My program works correctly if period is not long (no
> overflow). However when period is long (generating TOF
> oveflows), the overflow counter
> >Index x register) can not get the right value. Could
> somebody give a help and point out what's wrong?
> >
> >My program for your reference:
> >
> > ORG $1000
> >PERIOD RMB 2
> >EDGE1 RMB 2
> >
> > ORG $1200
> > ldx #$0000
> >
> > MOVB #$90,TSCR ; enable timer, set fast timer clear
> > MOVB #$FE,TIOS ; set pt0 to input capture
> > movb #$00,TMSK1 ; disable interrupt
> > MOVB #$24,TMSK2 ; scale by 16
> > MOVB #$01,TCTL4 ; set rising edge detection
> > MOVB #$01,TFLG1 ; clear flag bit / initialize
> >
> > BCLR TFLG2,$7F ;clear TOF flag
> >
> > BRCLR TFLG1,$01,* ; wait for the 1st rising edge
> > LDD TCO ;save the 1st TCNT value
> > STD EDGE1
> >
> >loop brclr TFLG2,$80,Test ;check TOF flag set
> > inx ; if TOF, increase counter IX
> > movb #$80,TFLG2 ;clear TOF
> >
> >Test BRCLR TFLG1,$01,loop ;check 2nd rising edge
> > LDD TCO ;save the 2nd TCNT value
> >
> > SUBD EDGE1 ;subtraction
> > STD PERIOD
> >
> > SWI
> > END
> >
> >
> >
> >

Memfault Beyond the Launch