hello there, i'm wiriting a code in assembly language using PIC16F877A, my input is a sequence of pulses with variable dutycycle from an acceleromter to 1 pin , but i'm having an issue calculating an exact dutycycle for the input, (i.e starting the measurement from the rising edge)...thx
I just have a squence of square pulses, having a certain period and frequency, which will be inputted to a pin of the Microcontroller..... I just want to know how can I calculate the dutycycle for this input, other that this example:
while RC0=0
toff=toff+1
wend
while RC0=1
ton=ton+1
wend
dutycycle=ton/(ton+toff)
The thing is that I want to calculate the dutycycle, but starting from the rising edge of the pulse sequence over a period...
You're going to use the same principle, but using Timer1.
Should be something like this:
1. Wait for low-to-high transition.
2. Start timer1, being set for the period you're expecting.
3. Wait for high-to-low transition.
4. Stop timer and store value.
5. Timer value divided by the [known] period is the duty cycle.