Author Topic: Just one command !  (Read 4542 times)

0 Members and 1 Guest are viewing this topic.

Offline e-thoughtTopic starter

  • Contributor
  • Posts: 30
  • Country: 00
  • if you live twice, then you should think twice too
Just one command !
« on: April 01, 2015, 02:17:04 pm »
I'm searching how to measure time between two rising edjes, i've got all the config for it, but i miss just the command that gives the value of the timer at a given moment in mikroc language ! please need help.

P-S: i really worked on learning mikroc, so don't think i'm just a lazy person ^^.

B.Z
Cordially.
« Last Edit: April 01, 2015, 02:36:25 pm by e-thought »
God, i'm begging your mercy !
 

Offline senso

  • Frequent Contributor
  • **
  • Posts: 951
  • Country: pt
    • My AVR tutorials
Re: Just one command !
« Reply #1 on: April 01, 2015, 03:21:14 pm »
Read the timer register?
 

Offline e-thoughtTopic starter

  • Contributor
  • Posts: 30
  • Country: 00
  • if you live twice, then you should think twice too
Re: Just one command !
« Reply #2 on: April 01, 2015, 04:15:34 pm »
yes, to know the time between two rising edje for example.
God, i'm begging your mercy !
 

Offline Jeroen3

  • Super Contributor
  • ***
  • Posts: 4195
  • Country: nl
  • Embedded Engineer
    • jeroen3.nl
Re: Just one command !
« Reply #3 on: April 01, 2015, 05:28:22 pm »
Refer to the header file containing chip definitions. This sould include defines to access the timer register.
 

Offline e-thoughtTopic starter

  • Contributor
  • Posts: 30
  • Country: 00
  • if you live twice, then you should think twice too
Re: Just one command !
« Reply #4 on: April 01, 2015, 06:50:55 pm »
that didn't help, i went to help on mikroc, but didn't find how to get the time between two rising edjes for example, even if i know how to set the timer to detect rising edje i can't get the time of it :/.
God, i'm begging your mercy !
 

Offline Jeroen3

  • Super Contributor
  • ***
  • Posts: 4195
  • Country: nl
  • Embedded Engineer
    • jeroen3.nl
Re: Just one command !
« Reply #5 on: April 01, 2015, 07:02:06 pm »
You should tell at least what chip you're using for us to be of any more help.
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Just one command !
« Reply #6 on: April 01, 2015, 07:06:31 pm »
Easy: deltaT = T1 - T0 is all you need.
================================
https://dannyelectronics.wordpress.com/
 

Offline e-thoughtTopic starter

  • Contributor
  • Posts: 30
  • Country: 00
  • if you live twice, then you should think twice too
Re: Just one command !
« Reply #7 on: April 01, 2015, 07:11:10 pm »
I'm using p16f690.

@Dannyf: the thing i'm searching, is how to get the value of t1 and t0 ?
God, i'm begging your mercy !
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 13133
Re: Just one command !
« Reply #8 on: April 01, 2015, 07:20:56 pm »
Its not simple. its not just one command.

Let Timer 1 free-run from an internal clock with the prescaler set so it doesn't roll over more often than the expected maximum interval between +ve edges.

Set up the CCP module to capture on a positive edge on the CCP1 pin and read the CCP1PR register pair every capture event to get a 'timestamp' for the edge.  You can do this in a CCP ISR or simply poll the CCP1IF, resetting it after reading CCP1PR.   

Subtract the two timestamps.

 

Offline e-thoughtTopic starter

  • Contributor
  • Posts: 30
  • Country: 00
  • if you live twice, then you should think twice too
Re: Just one command !
« Reply #9 on: April 01, 2015, 07:34:10 pm »
@Ian.M thank you very much, with your help, i have now an idea what i must do.
God, i'm begging your mercy !
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 13133
Re: Just one command !
« Reply #10 on: April 01, 2015, 08:19:33 pm »
There's also the T1G (Timer 1 gate) + external +ve edge triggered flipflop method.

Wire the flipflop as a divide by 2 stage with the input signal applied to its CLK input and its Q output going to the T1G gate.

Set up timer 1 to run from an internal clock gated by T1G (active high).
Poll the RA4/T1G pin and zero Timer 1 when its low. 
Wait for it to go high then back low.
Read duration directly from Timer 1.

An output pin connected to the flipflop RST input may be useful to hold the gate off till you want to take a measuremernt.

You may want to consider using an enhanced midrange device (PIC16F1xxx) as many of them have a Timer 1 gate circuit with an internal flipflop for period measurement and a one-shot circuit so you can get a single reading without having to worry about another pulse arriving before you've read the result.
« Last Edit: April 01, 2015, 08:47:41 pm by Ian.M »
 

Offline e-thoughtTopic starter

  • Contributor
  • Posts: 30
  • Country: 00
  • if you live twice, then you should think twice too
Re: Just one command !
« Reply #11 on: April 01, 2015, 08:39:02 pm »
thank you very much, you're much helping me.when i get it done, i'll share the code to help others : D
God, i'm begging your mercy !
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 13133
Re: Just one command !
« Reply #12 on: April 01, 2015, 08:52:13 pm »
The flipflop + gate method is easier for long intervals as when Timer 1 overflows, you can simply count the number of times TMR1IF gets set and use that count as the high word of a 32 bit result.

The CCP capture timestamp difference method gets gnarly if the interval is ever longer than the timer overflow period and the code to count overflows and compensate is particularly evil and sequence critical.

N.B I corrected the previous post to make more sense.
 

Offline e-thoughtTopic starter

  • Contributor
  • Posts: 30
  • Country: 00
  • if you live twice, then you should think twice too
Re: Just one command !
« Reply #13 on: April 01, 2015, 09:09:44 pm »
my time interval is between 15us and 10ms so i guess it's too small
God, i'm begging your mercy !
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 13133
Re: Just one command !
« Reply #14 on: April 01, 2015, 09:22:15 pm »
15us will be really tricky - that's only 30 instruction cycles @8MHz Fosc.

It should however be manageable in assembler or by the flipflop/T1G method.
It *MAY* be possible in C code if both timestamp variables are in the common (unbanked) RAM area.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf