Please do not pass this job up as too simple. I have spent many hours trying to make this work, so I am willing to pay for your time and some extra.
Please name your price. The job only requires about 20 or so lines of code, but so far I have been unable to grasp the concepts required. I will use this code to complete my project and to form an understanding of the CCP1 capture module. I have not been able to find any sample code in MikroC.
I require a function written in the MikroC compiler to work on a PIC18f2520 chip. I would like the code commented so that I can understand how it works.
The function I require needs to read a 0 to 5 volt square wave that has a varying pulse width from the CCP1 pin RC2 and calculate the pulse width using CCP1 and Timer1. I am using a 20mhsz resinator and the lenth of the pulses widths vary from 0.5ms to 8ms. The value of the measured pulse width needs to be stored in variable " PulseWidth1". The function is called when pin RC0 is grounded. ie if (PORTC.B0==0 ) { } . While (1).
I have set TRISC.B2=1; I defined the variable PulseWidth1 as an unsigned int.
I require the pulse measurement to begin on the first rising edge to the next falling edge ie measure the pulse width when the signal is high. The value of PulseWidth1 needs to be output as such. 0.5ms = a value of PulseWidth1 = 50 1 ms = a value of PulseWidth1 = 100.
I require the settings for Timer1,Timer3, how to set up the interupts and how enable and clear flags.