Click here to Skip to main content
15,888,977 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I have been trying to find out how to set up a timer on a PIC4321 which will start timing once a switch is pushed and stop timing once it is depressed. The time of the switch being pressed will then be outputted. I am not aware how to achieve this without utilizing time.h which is not available in MCC18 or assembly code which I am trying to avoid.

What I have tried:

I have tried to implement a for loop which will count the number of cycles that the switch is depressed, however I cannot exit, when the switch is depressed.
Posted
Updated 3-Sep-16 8:59am
Comments
Richard MacCutchan 2-Sep-16 3:24am    
This has nothing to do with time.h which is a source header for the C compiler. The first thing you need to do is find out how to get signalled from the PIC when the switch changes state. And the second thing is how to get timing information from the device.

1 solution

Stay away from timers because they are "high level abstractions" of hardware. They are very incorrect and even more in comparisions. The error rate is to great to accept. Any looping is bad.

Use some hardware high resolution API like Tick count of the processor. Maybe here is some useful example.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900