I am having a problem with time measurement in an application that I am developing using a S08SH. I am using (Processor Expert) FC1:FreeCntr with timer TPM10 to generate an interrupt every 5mS. This works fine. I am then trying to use FC161:FreeCntr16 with timer TPM20 to measure a time interval: -
In the FC1:FreeCntr ISR I start the FC161 timer. A separate software event stops the timer and I read the elapsed time - except that it doesn't work.
To investigate the problem I created a simple simulation project.
The value in TPM2CNT was always wrong and the only it would work was if I set a breakpoint somewhere in the ISR and then manually changed registers TPM20SC from 0xD0 to 0x50 and TPM2MOD from 0x0003 to 0xFFFF.
TPM2CNT then held a value that related to the duration of the simple delay loop. However, I cannot find a way to set these register values for FC161:FreeCntr16 using the component Inspector in Processor Expert.
Hi Cox.
To check your problem we need more information.
1. your CW version:
- if you use classic version: Start the IDE and click on Help | About Freescale CodeWarrior. Click on Installed Products.Save all info displayed into a txt file and send it to me.
- if you use eclipse version: Start the IDE and click on Help | About CodeWarrior Development Studio. Send me the version and build id.
2. your demo project.
Thus I can test it directly from my side.
Thanks.
Have a great day,
Jennie Zhang
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hi Jennie, please call me Julian - it sounds less formal.
My CW installation is Version 10.7 Build Id: 160721
I hope I have done the next step correctly - I have never used this facility
I used the export wizard > Export | General | Archive file
I selected the project in the left hand window and all files in the right hand window.
Hi Julian,
Sorry for the late, I was not in office this week thus I don't have a SH4 board in hand now.
However I checked your code you use FreeCntr16 component tor TPM2 counting. This is counter for long time period. I suggest you use FreeCntr for TPM2 instead. See how it works?
I will test your code with board once I get to office next week.
Have a great day,
Jennie Zhang
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Thanks for the reply.
Perhaps you could explain: - If I am reading the value in TPM2 count register - that contains the number of ticks since I enabled FreeCntr16 so is that not the most accurate measurement possible? If i only need a 16-bit result and no interrupt, Is there a method to start, stop and reset TPM2 directly so that I don't need FreeCntr16 at all? In real time the elapsed time will be between 0.5mS and 15mS.
Hi Julian
I finally found a board to test your project. here is my testing result
here, I set breakpoint at FC161_Reset()
in Variable window: Time is 0x223
in Registers window: TPM2CNT is 0x0227
these two values are different. This is because the program runs from previous line to FC161_Reset() takes a few clock.
Please let me know what else you think abnormal.
Have a great day,
Jennie Zhang
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Further to the above it appears that the only register that I have to change is TPM2MOD. I was able to change the value by changing the FC161 resolution from 1uS (3) to 16mS (0xF9FF), but I don't know if this is the correct way to do things. All I want is a counter that will start when software tells it to start and stop when software tells it to stop, at which point software can read the number of ticks.