timerx hitachi 3642/3644

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.

Reply to
icurmt
Loading thread data ...

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 (broeker@physik.rwth-aachen.de)
Even if all the snow were burnt, ashes would remain.
Reply to
Hans-Bernhard Broeker

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.

Reply to
icurmt

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

Reply to
Michael Biere

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.

Reply to
icurmtdude

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).

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

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          | paul@pcserviceselectronics.co.uk
    PC Services
              GNU H8 & mailing list info
             For those web sites you hate
Reply to
Paul Carpenter

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.

Reply to
icurmtdude

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

Not a problem..

--
Paul Carpenter          | paul@pcserviceselectronics.co.uk
    PC Services
              GNU H8 & mailing list info
             For those web sites you hate
Reply to
Paul Carpenter

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.