![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
iseron
Joined: 21 Feb 2004 Posts: 12 Location: Santiago - Chile
|
measure time for 1 input |
Posted: Thu Jul 15, 2004 10:30 am |
|
|
Hi.
Developing an IR receiver i need to measure the timeof duratio of pulses when receving. ( for a sony protocol)
How can i discriminate between 2 pulses?
For example and 600 ms pulse is a "zero" and a 1200 ms pulse is a "one".
Exists a simplfied code for that?
thnks
ignacio |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
Re: measure time for 1 input |
Posted: Thu Jul 15, 2004 10:47 am |
|
|
iseron wrote: | Hi.
Developing an IR receiver i need to measure the timeof duratio of pulses when receving. ( for a sony protocol)
How can i discriminate between 2 pulses?
For example and 600 ms pulse is a "zero" and a 1200 ms pulse is a "one".
Exists a simplfied code for that?
thnks
ignacio |
Use an input supporting 'interrupt on change' (RB4..7). In the interrupt code, if the edge is a rising edge (assuming the electronics decodes the pulses to +ve logic), reset a timer (timer2?). If it is a falling edge, take the reading from the timer. Depending on the setup used for the timer, you have a number proportional to the pulse width.
I have done a similar thing on a 12F675, where five different pulse widths have to be detected, by sitting in a loop (instead of using the interrupt), with:
Code: |
#define inp_mask (0x08)
int timeval;
int last;
setup_TIMER_0(RTCC_INTERNAL|RTCC_DIV_16);
last=GPIO;
while (last==GPIO) restart_wdt();
//Here I may have an edge on the incoming signal
if (GPIO & inp_mask) {
//Here the input is high
if (!(last & inp_mask)) {
// Here I have a rising edge on the pulse train.
set_timer0(0);
// Now I time the high pulse
while (GPIO & inp_mask) {
if (get_timer0()>=120) break;
}
timeval=get_timer0();
// The timer counts in 16uSec ticks from it's trigger point
// I can now check this value to see where I should be.
}
}
|
'GPIO', is programmed as the port I am watching, and 'inp_mask' is a mask matching the bit I am watching. 'timeval', counts the width of the pulse in 16uSec 'steps' (using the internal 4MHz oscillator on the 12F675), so for a pulse that is 1/2400th second wide, returns a count of 26. You can just test for the required 'width' to match your needs (in this case the processor is doing nothing else). The interrupt approach, would allow you to be doing other tasks while waiting.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
Re: measure time for 1 input |
Posted: Sat Jul 17, 2004 12:56 am |
|
|
iseron wrote: | Hi.
Developing an IR receiver i need to measure the timeof duratio of pulses when receving. ( for a sony protocol)
How can i discriminate between 2 pulses?
For example and 600 ms pulse is a "zero" and a 1200 ms pulse is a "one".
Exists a simplfied code for that?
thnks
ignacio |
Try Google search: pic ir receiver sircs
Erkki |
|
![](templates/subSilver/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|