• AVR Freaks

AnsweredHot!Difference between capture and compare modes with examples

Page: << < ..678910.. > >> Showing page 9 of 13
Author
1and0
Access is Denied
  • Total Posts : 9287
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: I want to know the difference between capture and compare modes with examples 2018/07/25 08:18:44 (permalink)
+1 (1)
Putting the while(1) loop aside. Your trigger_pin() function toggles a pin high and then low. By the time your capture() function reads that pin, the pin is at low state, but it's looking to capture two edges. How do you think that will work?
 
Seriously, you really need to take a step back and think how are things work instead of blindly running code without an understanding of how it works.
 
eagle1
Super Member
  • Total Posts : 341
  • Reward points : 0
  • Joined: 2014/11/02 03:04:06
  • Location: Saudi Arabia
  • Status: offline
Re: I want to know the difference between capture and compare modes with examples 2018/07/25 08:21:43 (permalink)
0
I thought about that, and that's why I got an external source.
 
I edited my previous posts #159 & 160. It's working now but I need to know what the number means.
1and0
Access is Denied
  • Total Posts : 9287
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: I want to know the difference between capture and compare modes with examples 2018/07/25 08:26:48 (permalink)
+1 (1)
eagle1
The value is around 2970:
1. The signal from the Arduino is 100ms high 100ms low.
2. The PIC is running at 4MHz, so it's 1us instruction cycle.
3. The compare mode returns this value on the LCD which is 2970.
4. That is around 3ms, but the period is 100ms! What I'm missing here?

Okay, signal is 100 ms high and 100 ms low. What is the period of this signal?  100 ms?  200 ms? or what?
 
At an instruction cycle of 1 us, what is the count for 100 ms?  for 200 ms?  How big is an uint16_t type?
 
 
 
eagle1
Super Member
  • Total Posts : 341
  • Reward points : 0
  • Joined: 2014/11/02 03:04:06
  • Location: Saudi Arabia
  • Status: offline
Re: I want to know the difference between capture and compare modes with examples 2018/07/25 08:32:56 (permalink)
0
1and0
Okay, signal is 100 ms high and 100 ms low. What is the period of this signal?  100 ms?  200 ms? or what?
At an instruction cycle of 1 us, what is the count for 100 ms?  for 200 ms?  How big is an uint16_t type?

wow you're right! The 200ms is too big for uint16_t. I modified the Arduino code for 10ms so the period is 20ms.
 
Now I get 19970 on the LCD which is 20000us = 20ms!
 
Thank you so much, now I have a good idea about the capture mode.
DarioG
Allmächtig.
  • Total Posts : 54081
  • Reward points : 0
  • Joined: 2006/02/25 08:58:22
  • Location: Oesterreich
  • Status: offline
Re: I want to know the difference between capture and compare modes with examples 2018/07/25 08:44:24 (permalink)
0
"sì, ma ci avete rotto il cazzo"

GENOVA :D :D ! GODO
JorgeF
Super Member
  • Total Posts : 3340
  • Reward points : 0
  • Joined: 2011/07/09 11:56:58
  • Location: PT/EU @ Third rock from the Sun
  • Status: offline
Re: I want to know the difference between capture and compare modes with examples 2018/07/25 09:23:08 (permalink) ☄ Helpfulby eagle1 2018/07/25 09:29:33
+1 (1)
Hi
eagle1
1and0
Okay, signal is 100 ms high and 100 ms low. What is the period of this signal?  100 ms?  200 ms? or what?
At an instruction cycle of 1 us, what is the count for 100 ms?  for 200 ms?  How big is an uint16_t type?

wow you're right! The 200ms is too big for uint16_t. I modified the Arduino code for 10ms so the period is 20ms. 
Now I get 19970 on the LCD which is 20000us = 20ms!
 

In case you really need to work with the 200ms, use the TIMER1 clock pre-scaller to extend the compare range.
Its a trade-off between max signal period and resolution.

Best regards
Jorge
 
I'm here http://picforum.ric323.com too!
And it works better....
eagle1
Super Member
  • Total Posts : 341
  • Reward points : 0
  • Joined: 2014/11/02 03:04:06
  • Location: Saudi Arabia
  • Status: offline
Re: I want to know the difference between capture and compare modes with examples 2018/07/25 09:32:12 (permalink)
0
JorgeF
 
In case you really need to work with the 200ms, use the TIMER1 clock pre-scaller to extend the compare range.
Its a trade-off between max signal period and resolution.

OK, thank you for the information. So more periods with TIMER1 means less resolution! Interesting, for now I've done this for demonstration but of course if I need to measure longer pulses then the prescaler is the best solution.
1and0
Access is Denied
  • Total Posts : 9287
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: I want to know the difference between capture and compare modes with examples 2018/07/25 09:36:38 (permalink) ☄ Helpfulby eagle1 2018/07/25 09:37:06
+1 (1)
eagle1
OK, thank you for the information. So more periods with TIMER1 means less resolution! Interesting, for now I've done this for demonstration but of course if I need to measure longer pulses then the prescaler is the best solution.

Not necessarily. Counting the Timer overflow rollovers might be better.
post edited by 1and0 - 2018/07/25 09:38:19
eagle1
Super Member
  • Total Posts : 341
  • Reward points : 0
  • Joined: 2014/11/02 03:04:06
  • Location: Saudi Arabia
  • Status: offline
Re: I want to know the difference between capture and compare modes with examples 2018/07/25 09:37:43 (permalink)
0
1and0
 
Not necessarily. Counting the Timer overflow might be better.

You're just brilliant!
JorgeF
Super Member
  • Total Posts : 3340
  • Reward points : 0
  • Joined: 2011/07/09 11:56:58
  • Location: PT/EU @ Third rock from the Sun
  • Status: offline
Re: I want to know the difference between capture and compare modes with examples 2018/07/25 09:37:54 (permalink) ☄ Helpfulby eagle1 2018/07/25 09:39:13
+1 (1)
Hi
eagle1
JorgeF
 
In case you really need to work with the 200ms, use the TIMER1 clock pre-scaller to extend the compare range.
Its a trade-off between max signal period and resolution.

OK, thank you for the information. So more periods with TIMER1 means less resolution! Interesting, for now I've done this for demonstration but of course if I need to measure longer pulses then the prescaler is the best solution.

Not exactly "more periods", but "longer periods".
Now you are working with a clock for the Timer that as a period 1 us, so your captured result resolution is 1us.
If you configure the pre-scaller for 1:4 ratio, the Timer will receive a clock with a period of 4us, resulting in a 4us resolution of your compare result.
You get to work with larger period of the incoming signal, but lose resolution.
post edited by JorgeF - 2018/07/25 09:39:06

Best regards
Jorge
 
I'm here http://picforum.ric323.com too!
And it works better....
1and0
Access is Denied
  • Total Posts : 9287
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: I want to know the difference between capture and compare modes with examples 2018/07/25 09:43:32 (permalink) ☄ Helpfulby eagle1 2018/07/25 09:47:55
+1 (1)
JorgeF
If you configure the pre-scaller for 1:4 ratio, the Timer will receive a clock with a period of 4us, resulting in a 4us resolution of your compare result.
You get to work with larger period of the incoming signal, but lose resolution.

I have not given this any more thoughts, but I think you can clock out the prescaler to get 1 us resolution. ;) 
 
eagle1
Super Member
  • Total Posts : 341
  • Reward points : 0
  • Joined: 2014/11/02 03:04:06
  • Location: Saudi Arabia
  • Status: offline
Re: I want to know the difference between capture and compare modes with examples 2018/07/25 09:47:24 (permalink)
0
JorgeF
Not exactly "more periods", but "longer periods".
Now you are working with a clock for the Timer that as a period 1 us, so your captured result resolution is 1us.
If you configure the pre-scaller for 1:4 ratio, the Timer will receive a clock with a period of 4us, resulting in a 4us resolution of your compare result.
You get to work with larger period of the incoming signal, but lose resolution.

OK, long periods, first the CPP1 would get the pulse on its pin no matter which speed and prescaler the timer is. But the result is that whenever a trigger hit the pin. If the hit; e.g. the timer is running on prescaler 1:8, and the hit happened in the middle of the 8us resolution then the CPP won't get precise timings of the triggers.
jack@kksound
code tags!
  • Total Posts : 3193
  • Reward points : 0
  • Joined: 2014/05/14 10:03:19
  • Location: 0
  • Status: offline
Re: I want to know the difference between capture and compare modes with examples 2018/07/25 09:55:55 (permalink) ☄ Helpfulby eagle1 2018/07/25 09:57:52
+1 (1)
 If...the hit happened in the middle of the 8us resolution then the CPP won't get precise timings of the triggers.

This statement is true regardless of the clock speed of the timer clock, the only difference as the timer clock speed changes is that the the resolution of the result changes. You must decide what resolution (1us, 8 us ,etc) you require/desire in the result then you can determine the required timer clock speed/prescaler values.
eagle1
Super Member
  • Total Posts : 341
  • Reward points : 0
  • Joined: 2014/11/02 03:04:06
  • Location: Saudi Arabia
  • Status: offline
Re: I want to know the difference between capture and compare modes with examples 2018/07/25 09:59:48 (permalink)
0
jack@kksound
This statement is true regardless of the clock speed of the timer clock, the only difference as the timer clock speed changes is that the the resolution of the result changes. You must decide what resolution (1us, 8 us ,etc) you require/desire in the result then you can determine the required timer clock speed/prescaler values.

Of course that depends on the incoming signal specs.
jack@kksound
code tags!
  • Total Posts : 3193
  • Reward points : 0
  • Joined: 2014/05/14 10:03:19
  • Location: 0
  • Status: offline
Re: I want to know the difference between capture and compare modes with examples 2018/07/25 10:13:08 (permalink) ☄ Helpfulby eagle1 2018/07/25 10:14:17
+1 (1)
eagle1
jack@kksound
This statement is true regardless of the clock speed of the timer clock, the only difference as the timer clock speed changes is that the the resolution of the result changes. You must decide what resolution (1us, 8 us ,etc) you require/desire in the result then you can determine the required timer clock speed/prescaler values.

Of course that depends on the incoming signal specs.


Mostly it depends on the requirements of the measurement and some on the input signal. Resolution of measurement beyond the stability of the input signal may not be of much use (unless that instability is what you are measuring).
eagle1
Super Member
  • Total Posts : 341
  • Reward points : 0
  • Joined: 2014/11/02 03:04:06
  • Location: Saudi Arabia
  • Status: offline
Re: I want to know the difference between capture and compare modes with examples 2018/07/25 10:23:14 (permalink)
+1 (1)
jack@kksound
Mostly it depends on the requirements of the measurement and some on the input signal. Resolution of measurement beyond the stability of the input signal may not be of much use (unless that instability is what you are measuring).

Haven't gone through complicated situations as you described, I'm happy now that I just knew how to operate the capture mode and get reasonable results :)
 
The projects that I haven't even get into; like, operating nRF module, I guess won't deal with measuring signals.
 
But decoding the NEC remote control codes might be interesting with the capture mode, I'm excited for this project.
 
Like this one:

 
So 1.25ms isn't so difficult with 1us resolution.
JorgeF
Super Member
  • Total Posts : 3340
  • Reward points : 0
  • Joined: 2011/07/09 11:56:58
  • Location: PT/EU @ Third rock from the Sun
  • Status: offline
Re: I want to know the difference between capture and compare modes with examples 2018/07/25 10:33:25 (permalink)
+1 (1)
Hi
 
The 1.25ms and 2.25ms and 13.5ms periods are equivalent to 1250us 2250us and 13500us, so all values are valid for a 16bit count.
 
BTW, to decode this signal you will need to pick up both low-to-high and high-to-low transitions, so your operating values would be half of the above, and alternating the detection has exemplified by 1and0 in post #88
https://www.microchip.com/forums/FindPost/1060434
 

Best regards
Jorge
 
I'm here http://picforum.ric323.com too!
And it works better....
eagle1
Super Member
  • Total Posts : 341
  • Reward points : 0
  • Joined: 2014/11/02 03:04:06
  • Location: Saudi Arabia
  • Status: offline
Re: I want to know the difference between capture and compare modes with examples 2018/07/25 10:39:58 (permalink)
0
JorgeF
Hi
The 1.25ms and 2.25ms and 13.5ms periods are equivalent to 1250us 2250us and 13500us, so all values are valid for a 16bit count.

That's good.
 
 

BTW, to decode this signal you will need to pick up both low-to-high and high-to-low transitions, so your operating values would be half of the above, and alternating the detection has exemplified by 1and0 in post #88
https://www.microchip.com/forums/FindPost/1060434 

Yeah, but that is for the compare mode. Do you mean the same procedure of the alterning between the receiving transitions for the capture mode? 

But isn't it possible to measure from LOW/HIGH to the next /LOW/HIGH transitions? The period 1.25ms is time from first rising edge to the next one.
JorgeF
Super Member
  • Total Posts : 3340
  • Reward points : 0
  • Joined: 2011/07/09 11:56:58
  • Location: PT/EU @ Third rock from the Sun
  • Status: offline
Re: I want to know the difference between capture and compare modes with examples 2018/07/25 11:12:42 (permalink) ☄ Helpfulby eagle1 2018/07/25 17:35:31
+1 (1)
eagle1
 
But isn't it possible to measure from LOW/HIGH to the next /LOW/HIGH transitions? The period 1.25ms is time from first rising edge to the next one.

Maybe, but I think the decoding of that signal may prove a bit more complex.
Notice the high pulses all have the same width. The "0" and "1" are encoded in the duration of the low time.
A "0" is 0.75ms low high, followed by 0.75ms high low; a "1" is 1.5ms low, followed by 0.75ms high.0.75ms high, followed by a 01.5ms low.
I didn't gave it a lot of attention, but a simple period measurement might work well in a sequence of "000000" or "111111" but have trouble with "01" or a "10" transitions.
 
post edited by JorgeF - 2018/07/25 11:35:03

Best regards
Jorge
 
I'm here http://picforum.ric323.com too!
And it works better....
PStechPaul
Super Member
  • Total Posts : 2289
  • Reward points : 0
  • Joined: 2006/06/27 16:11:32
  • Location: Cockeysville, MD, USA
  • Status: offline
Re: I want to know the difference between capture and compare modes with examples 2018/07/25 12:50:33 (permalink) ☄ Helpfulby eagle1 2018/07/25 17:42:29
+2 (2)
Apparently there are several different codes for NTC R/C signals:
 
https://www.vishay.com/docs/80071/dataform.pdf
 
https://www.circuitvalley.com/2013/09/nec-protocol-ir-infrared-remote-control.html
 
According to the second link, the pulse times are 1.125 mSec and 2.25 mSec. And there is also a carrier frequency of 30-56 kHz, which needs to be considered and processed.
 

 
You could also decode the NEC signal by first detecting the start sequence of 9 mSec HIGH and 4.5 mSec LOW, and then reading the detector state at 1.125 mSec +0.5625/2 mSec = 1.41 mSec after each HIGH transition. If the signal is HIGH, it is a logical 0. If it is LOW, it is a logical 1. This is similar to the way an RS-232 signal is decoded, although it uses a fixed data rate so the signal can be sampled at the center of each bit frame.
 
The NEC protocol uses a 8 bit address and data, each of which are followed by an inverse signal, so each transmission has an equal number of ones and zeros, and thus a fixed transmission length of 67.5 mSec.
 

 
More complex than I thought. The second link includes source code for a PIC12F615 for the transmitter and a PIC12F675 for the receiver, so it does not use a CCP module.

 
Page: << < ..678910.. > >> Showing page 9 of 13
Jump to:
© 2019 APG vNext Commercial Version 4.5