HCS08: Hot to set TPM in Input Capture on falling edge only

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

HCS08: Hot to set TPM in Input Capture on falling edge only

3,850件の閲覧回数
Spell
Contributor I
Hi all,
I'm tryng to set channel 1 of TPM2 in input capture mode and to set the interrupt on falling edge only.
I set the control and status register in this way:

TPM2C1SC = 0x48;

My problem is that the interrupt flag is set on both edge and not only on falling edge...

Someone can help me???

regards,
filippo
ラベル(1)
0 件の賞賛
9 返答(返信)

888件の閲覧回数
tonyp
Senior Contributor II
Setting looks correct.  Could it be a noise / bouncing switch problem?  (How are you testing?)
0 件の賞賛

888件の閲覧回数
Spell
Contributor I
Hi tonyp,
I don't think is a noise problem because with an oscilloscope I can see clearly the interrupt is called on every edge and not only in the falling edge.
If I change the configuration of the edge in the TPM2C1SC register never change, the interupt flag is always set on both edge.

regards,
filippo
0 件の賞賛

888件の閲覧回数
bigmac
Specialist III
Hello filippo,
 
You have not clarified whether you are using any form of mechanical switch to provide the input signal.  All mechanical switches do bounce to varing degrees, and it is possible that both edges can spuriously occur at each transition.
 
For test purposes, you might set the channel to detect both edges, and then see how many times the channel flag becomes set after a single switch transition.  This test can be done outside of the channel ISR.  Simply provide a tight loop, while waiting for the the channel flag to become set.  Once it is set, clear the flag, read and store the capture value (perhaps within an array), and then wait for the next capture event.
 
If there is more than a single reading for each transition, you have bounce occurring.  The sequence of capture values will indicate the timing of any bounce.
 
Regards,
Mac
 
0 件の賞賛

888件の閲覧回数
Spell
Contributor I


You have not clarified whether you are using any form of mechanical switch to provide the input signal.  All mechanical switches do bounce to varing degrees, and it is possible that both edges can spuriously occur at each transition.

I don't use a mechanical switch for generate the edge, there is another MCU that generate the edge.
I use this edge to determine a start condition on a data line,that is a transition from low level to high and then from high to low.
I must have an interrupt on the second edge only (falling edge) but with all kind of input capture configuration the channel flag becomes set in both edges.
0 件の賞賛

888件の閲覧回数
peg
Senior Contributor IV
Hi Filippo,

Are you properly clearing the flag in the ISR?
Which device are you using?
Show us your ISR code.
Exactly how are you determining that it is working wrongly?


0 件の賞賛

888件の閲覧回数
Spell
Contributor I
Code:
INTERRUPT_KEYWORD void daliRx_InterruptHandler(void) {  __asm {                               /* The HCS08 does not save H on interrupt. */    PSHH  }  /* Clearing the flag requires reading it and then writing it. */  if ( gTPM2C1SC_c & gTPMxCnSC_F_c ) {    gTPM2C1SC_c &= ~gTPMxCnSC_F_c;a    daliStartRxCallBack();  }  __asm {    PULH  }}

This my interrupt service routine.
My device is a MC13213.
I can determine that the interrupt is working wrongly because I toggle a pin when the service interrupt is called and I can see clearly that this pis toggle in both edges which any kind of configuration of the timer channel.

regards,
filippo
0 件の賞賛

888件の閲覧回数
bigmac
Specialist III
Hello,
 
With your undefined macros or constants that you use, it is impossible to say whether the interrupt flag is being cleared or not.  The most direct method of clearing the flag is as follows -
 
TPM2C1SC_CH1F = 0;
 
This uses a standard bit definition, as defined within the HCS08 header files.  Note that because a specific register bit is being addressed, this stipulates that it is a read-modify-write process, which entirely meets the requirements of the flag clearing process, i.e. read the register and then write a zero to the flag bit.
 
Alternatively, the following should also work correctly -
 
TPM2C1SC &= 0x7F;
 
Regards,
Mac
 
0 件の賞賛

888件の閲覧回数
Spell
Contributor I
I'm using code generated with Beekit so I don't have this standard bit defiition. But I don't think is this the problem because my macros are defined in this way:

#define gTPM2C1SC_c         TPM2C1SC
#define gTPMxCnSC_F_c     0x80

So I think to clear in the right way the interrupt flag.

regards,
filippo
0 件の賞賛

888件の閲覧回数
peg
Senior Contributor IV
Hi,

If you have set it for falling edges then it only triggers on falling edges!
It does work!
Turn that timebase down a little further.
I've got hundreds of GT16's doing it all day, everyday on positive edges ($44).
What device are you using and again where are the edges coming from?

0 件の賞賛