timerx hitachi 3642/3644

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
Hi,

I am trying to count the number of pulses through timerx.

Infact, I need to observe two input pulses. I need to obtain the
pulses received on A between every input pulses to B. For example,
whenever I receive pulse on say B, I need to reset the counter A and
start counting the pulses A receives until B's next input.

Does it make sense to do it w/o setting any interrupts on A or B.

Some code example will be helpful.

Thanks.

Re: timerx hitachi 3642/3644

Quoted text here. Click to load it

Only if your "pulses" are considerably longer than the instruction
cycle time on your CPU, so you can afford to poll the pin states in a
close loop.  And then only if your CPU has nothing else to do during
that time.  Since the latter is rather unlikely to be the case, I
guess that means the overall answer is "no".

--
Hans-Bernhard Broeker ( snipped-for-privacy@physik.rwth-aachen.de)
Even if all the snow were burnt, ashes would remain.

Re: timerx hitachi 3642/3644
So I guess I need to just one interrupt, here on B, and so each time
that interrupt occurs, I can note down the counter value of A and use
the difference from the last value recorded.



Quoted text here. Click to load it

Re: timerx hitachi 3642/3644
Hi,

depending on your effective Interrupt latency (you may have some code
that may not be interrupted) it could be useful to capture the value of
TimerA with the edge of TimerB input and in parallel trigger the
interrupt. So you gain a lot of time to read out the TimerA value.

I think that should be possible though i'm not absolutely familiar with
the 3642/3644 peripherals.

Greetings from michael

Re: timerx hitachi 3642/3644
Hi there,

This is a question on implementation.

Since am counting the number of input pulses on A between each input pulse
on D through timerx, I have the following lines of code:

#define TMRX_ICRAH (* (volatile unsigned char *)    (0xf778))  /* Input
capture AH */

#define TMRX_ICRAL (* (volatile unsigned char *)    (0xf779))  /* Input
capture AL */


#pragma interrupt (count_pulses)
void count_pulses( void)
{
  UINT8 count[2];
  
  .. /* code to disable & clear input D timerx interrupt */
  ..
  ..
  count[0] = TMRX_ICRAH;
  count[1] = TMRX_ICRAL;
  ..
  .. /* clear timer overflow flag */
  .. /* enable interrupt D */
}

Let me know if this is the way to do it..I am not getting the correct
result when reading this counter.

thanks.



Re: timerx hitachi 3642/3644
On Wednesday, in article
    

Quoted text here. Click to load it

This style suggests an older version of GNU compiler, if you are using the
GNU compiler, then there are two sources for the latest versions
sourceforge and kpit, both are linked from the site in my sig.

You also might get answers from those who have used the H8 Tiny series
(3642/3644), in C and the timer interupts.

Theer is nothing wrong with asking questions here, but you might get more
help from the GNUH8 mailing list (URL in sig).

Quoted text here. Click to load it

Defining local scope variables (on the stack) inside an interupt routine
means nothing else will see them.

Quoted text here. Click to load it

Because nothing else is seeing the same variable. This also suggests you have
a different variable count[2] somewhere else otherwise there should have been
linking errors to undefined variables.

You need to define a file scope (at minimum) or global variable -

volatile UINT8 count[2];

The 'volatile' is crucial as the compiler is forced to reread the memory
location rather than rely on compiler optimisations to assume it has the
current value when the interupt routine has changed it.

The web site below for GNUH8 should be useful to you (even if using a
different compiler) for lots of ideas, samples and ability to join the
mailing list of similar users.

--
Paul Carpenter          | snipped-for-privacy@pcserviceselectronics.co.uk
<http://www.pcserviceselectronics.co.uk/ PC Services
We've slightly trimmed the long signature. Click to see the full one.
Re: timerx hitachi 3642/3644
Paul,

I am sorry the variable is defined globally. It was just a cut-paste
error. I wanted to include some code to just give an idea of what I was
doing.

Thanks for the urls. They look very helpful.



Re: timerx hitachi 3642/3644
On Wednesday, in article
    

Quoted text here. Click to load it

In which case if it is not created as a 'volatile' variable that is most
likely to be your problem.

Quoted text here. Click to load it

Not a problem..

--
Paul Carpenter          | snipped-for-privacy@pcserviceselectronics.co.uk
<http://www.pcserviceselectronics.co.uk/ PC Services
We've slightly trimmed the long signature. Click to see the full one.

Site Timeline