I'm attempting to use timer0 on the PIC16F877 to work out the duty cycle of an accelerometer(ADXL213).
I got the basic idea of how to write the code, from an example code which is in assembly and I'm writing my code in C.
The bit i can not figure out is when the rising edge arrives on the XOUT or YOUT pin, how to get the time and save it, to be used in calculation later.
The code below is a section from a function, i can't figure how to store the value from TMRO into T1XHi in C language. Also I can't figure out how Timer0H is incremented.
The PIC used in this example code is PIC16F84 but the method is more or less the same.
I have attached the full code and data sheet for the components.
Any help would be great
Thank you very much for your time
I got the basic idea of how to write the code, from an example code which is in assembly and I'm writing my code in C.
The bit i can not figure out is when the rising edge arrives on the XOUT or YOUT pin, how to get the time and save it, to be used in calculation later.
The code below is a section from a function, i can't figure how to store the value from TMRO into T1XHi in C language. Also I can't figure out how Timer0H is incremented.
Rich (BB code):
0020 00123 ReadAccel
0020 00124 EDGE1
0020 1805 00125 btfsc PORTA,XOUT ;Wait for low on XOUT
0021 2820 00126 goto EDGE1
0022 00127 EDGE2
0022 1C05 00128 btfss PORTA,XOUT ;Wait for high on XOUT
0023 2822 00129 goto EDGE2
0024 0181 00130 clrf TMR0 ;Clear Timer
0025 01B3 00131 clrf Timer0H
0026 110B 00132 bcf INTCON,T0IF ;Enable Timer0 overflow interrupt
0027 168B 00133 bsf INTCON,T0IE
0028 00134 EDGE3
0028 1805 00135 btfsc PORTA,XOUT ;Look for falling edge on XOUT
0029 2828 00136 goto EDGE3
002A 0801 00137 movf TMR0,W ;Save Timer0H:TMR0 as T1X
002B 008D 00138 movwf T1XLo
002C 0833 00139 movf Timer0H,W
002D 008C 00140 movwf T1XHi
I have attached the full code and data sheet for the components.
Any help would be great
Thank you very much for your time
Attachments
-
190.4 KB Views: 12
-
262.6 KB Views: 9