Using TPMCH0 on S08 MCU as a Counter from external square signal source

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Using TPMCH0 on S08 MCU as a Counter from external square signal source

Jump to solution
1,183 Views
eduardobuezas
Contributor I

Hello colleagues!

I'm a starter in MCU programming.

 

I'm in a project where I need to use S08 pin TPMCH0 as an
external square signal input, and count the number of pulses there. I selected
a Capture component in CW, but unfortanetly couldn't neither configure nor
create a C code to get the count on this TPM register. When I try to set Reset
and Get commands, compiling returns me a lot of errors regarding de arguments
and definitions I couldn't resolve.

 

Do you have a clear example of how to handle this issue,
I mean, a file with examples of similar applications, or could you guide me in
how to resolve this situation?

 

Thanks in advance for your quick response and knowledge.

 

Eduardo Buezas

 

Labels (1)
0 Kudos
1 Solution
790 Views
CarlosCasillas
NXP Employee
NXP Employee

Hello Eduardo,

I have attached to this post an example project for CodeWarrior v10.x which configures TPM1CH0 of MC9S08SH8 MCU for Input Capture mode. The Input Capture and Timer overflow interrupts are declared and serviced, and you could add your custom code inside the functions.

Hope this will be useful for you.
Best regards!

/Carlos

View solution in original post

0 Kudos
9 Replies
790 Views
bigmac
Specialist III

Hello Eduardo,

The use of TPM input capture mode is usually applicable to when the period between input pulses needs to be measured.  However, it would seem that your specific requirement is to measure the number of incoming pulses only.  You would therefore need to separately count the number of input capture events occurring using a separate counter global variable.  For each input capture interrupt, the counter would be incremented within the ISR.  The TPM channel register does not provide useful information for your specific requirement.

An alternative approach would be to feed the input pulses to the TCLK input of the TPM module.  For this case, the TPM counter register would provide a count of the number of pulses received since the register was last zeroed.  It is simply a matter of reading the register - the channels associated with the particular TPM module are not used.  With this method interrupts are not necessary unless you require to handle large count values where TPM overflow can occur. Of course, the prescale divider for the TPM will need to be set for divide by one.

Either approach can be made to work.  If you require to make use of other channels associated with the TPM module, you would use the input capture count method.  If not, using the external clock input would be simpler, and requires fewer interrupts, if any.

Regards,

Mac

0 Kudos
791 Views
CarlosCasillas
NXP Employee
NXP Employee

Hello Eduardo,

I have attached to this post an example project for CodeWarrior v10.x which configures TPM1CH0 of MC9S08SH8 MCU for Input Capture mode. The Input Capture and Timer overflow interrupts are declared and serviced, and you could add your custom code inside the functions.

Hope this will be useful for you.
Best regards!

/Carlos

0 Kudos
790 Views
eduardobuezas
Contributor I

Hi Carlos, I didn't found the attached example....

I would appreciate if you could send me it

Thanks in advance

0 Kudos
790 Views
CarlosCasillas
NXP Employee
NXP Employee

Maybe it is still waiting for virus scan. Please take a look in a little while...

Best regards!

/Carlos

0 Kudos
790 Views
eduardobuezas
Contributor I

Nothing. I'm new in this forum. Where should it be? I guess with your post here in the forum.

In my email inbox either, there is nothing attached.

Could you send it again?

Thanks

0 Kudos
790 Views
CarlosCasillas
NXP Employee
NXP Employee

Hello. Yes, it is an attachment on the post, and you can find the discussion at the following link:

https://community.freescale.com/thread/306448

Best regards!

/Carlos

0 Kudos
790 Views
eduardobuezas
Contributor I

You made the code in assembler or C?

I didn't find a .mcp file in the zip you sent.

Regards

0 Kudos
790 Views
CarlosCasillas
NXP Employee
NXP Employee

It is for C, but doesn't include a .mcp file because it is for CodeWarrior 10.x (Eclipse). If you don't have CW 10.x, you could just open the main.c file on a text editor.

Best regards!

/Carlos

0 Kudos
790 Views
eduardobuezas
Contributor I

Ok, I was not at that link. Now I got it. I'll try and let you know

Thanks for your help

0 Kudos